forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ImageConverter.outData() must return shared instance. wang-bin#1046
several apis are added, to avoid deep copy
- Loading branch information
Showing
8 changed files
with
39 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -59,6 +59,11 @@ QByteArray Frame::frameData() const | |
return d_func()->data; | ||
} | ||
|
||
int Frame::dataAlignment() const | ||
{ | ||
return d_func()->data_align; | ||
} | ||
|
||
QByteArray Frame::data(int plane) const | ||
{ | ||
if (plane < 0 || plane >= planeCount()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
ImageConverter: Base class for image resizing & color model convertion | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -35,9 +35,12 @@ class ImageConverter //export is not needed | |
{ | ||
DPTR_DECLARE_PRIVATE(ImageConverter) | ||
public: | ||
enum { DataAlignment = 16 }; | ||
|
||
ImageConverter(); | ||
virtual ~ImageConverter(); | ||
|
||
// the real data starts with DataAlignment (16bit) aligned address | ||
QByteArray outData() const; | ||
// return false if i/o format not supported, or size is not valid. | ||
// TODO: use isSupported(i/o format); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -61,7 +61,17 @@ class Q_AV_EXPORT Frame | |
*/ | ||
int bytesPerLine(int plane = 0) const; | ||
// the whole frame data. may be empty unless clone() or allocate is called | ||
// real data starts with dataAlignment() aligned address | ||
QByteArray frameData() const; | ||
int dataAlignment() const; | ||
uchar* frameDataPtr(int* size = NULL) const { | ||
const int a = dataAlignment(); | ||
uchar* p = (uchar*)frameData().constData(); | ||
const int offset = (a - ((uintptr_t)p & (a-1))) & (a-1); | ||
if (size) | ||
*size = frameData().size() - offset; | ||
return p+offset; | ||
} | ||
// deep copy 1 plane data | ||
QByteArray data(int plane = 0) const; | ||
uchar* bits(int plane = 0); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -52,7 +52,8 @@ class Q_AV_EXPORT VideoFrame : public Frame | |
VideoFrame(); | ||
//must set planes and linesize manually if data is empty | ||
// must set planes and linesize manually | ||
VideoFrame(int width, int height, const VideoFormat& format, const QByteArray& data = QByteArray()); | ||
// alignment: data ptr alignment | ||
VideoFrame(int width, int height, const VideoFormat& format, const QByteArray& data = QByteArray(), int alignment = 1); | ||
VideoFrame(const QImage& image); | ||
VideoFrame(const VideoFrame &other); | ||
~VideoFrame(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV (from 2013) | ||
|
@@ -36,6 +36,7 @@ class FramePrivate : public QSharedData | |
public: | ||
FramePrivate() | ||
: timestamp(0) | ||
, data_align(1) | ||
{} | ||
virtual ~FramePrivate() {} | ||
|
||
|
@@ -44,6 +45,7 @@ class FramePrivate : public QSharedData | |
QVariantMap metadata; | ||
QByteArray data; | ||
qreal timestamp; | ||
int data_align; | ||
}; | ||
|
||
} //namespace QtAV | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
VideoCapture.cpp: description | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -84,7 +84,9 @@ class CaptureTask : public QRunnable | |
QMetaObject::invokeMethod(cap, "failed"); | ||
return; | ||
} | ||
if (file.write(frame.frameData()) <= 0) { | ||
int sz = 0; | ||
const char* data = (const char*)frame.frameDataPtr(&sz); | ||
if (file.write(data, sz) <= 0) { | ||
qWarning("VideoCapture is failed to write captured frame with original format"); | ||
QMetaObject::invokeMethod(cap, "failed"); | ||
file.close(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/****************************************************************************** | ||
QtAV: Multimedia framework based on Qt and FFmpeg | ||
Copyright (C) 2012-2016 Wang Bin <[email protected]> | ||
Copyright (C) 2012-2018 Wang Bin <[email protected]> | ||
* This file is part of QtAV | ||
|
@@ -154,11 +154,12 @@ VideoFrame::VideoFrame() | |
{ | ||
} | ||
|
||
VideoFrame::VideoFrame(int width, int height, const VideoFormat &format, const QByteArray& data) | ||
VideoFrame::VideoFrame(int width, int height, const VideoFormat &format, const QByteArray& data, int alignment) | ||
: Frame(new VideoFramePrivate(width, height, format)) | ||
{ | ||
Q_D(VideoFrame); | ||
d->data = data; | ||
d->data_align = alignment; | ||
} | ||
|
||
VideoFrame::VideoFrame(const QImage& image) | ||
|
@@ -353,7 +354,7 @@ QImage VideoFrame::toImage(QImage::Format fmt, const QSize& dstSize, const QRect | |
VideoFrame f(to(VideoFormat(VideoFormat::pixelFormatFromImageFormat(fmt)), dstSize, roi)); | ||
if (!f) | ||
return QImage(); | ||
QImage image((const uchar*)f.frameData().constData(), f.width(), f.height(), f.bytesPerLine(0), fmt); | ||
QImage image(f.frameDataPtr(), f.width(), f.height(), f.bytesPerLine(0), fmt); | ||
return image.copy(); | ||
} | ||
|
||
|
@@ -395,7 +396,7 @@ VideoFrame VideoFrame::to(const VideoFormat &fmt, const QSize& dstSize, const QR | |
qWarning() << "VideoFrame::to error: " << format() << "=>" << fmt; | ||
return VideoFrame(); | ||
} | ||
VideoFrame f(w, h, fmt, conv.outData()); | ||
VideoFrame f(w, h, fmt, conv.outData(), ImageConverter::DataAlignment); | ||
f.setBits(conv.outPlanes()); | ||
f.setBytesPerLine(conv.outLineSizes()); | ||
if (fmt.isRGB()) { | ||
|