summaryrefslogtreecommitdiffstats
path: root/src/multimedia/video
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-03-23 13:20:26 +0100
committerLars Knoll <lars.knoll@qt.io>2021-04-06 08:11:39 +0000
commit9aaec39aef634a9f2d972f35484a566bdd01ecd6 (patch)
tree05263139a5c8121655ab846953d469e6dfdec137 /src/multimedia/video
parent33d4ef6367ad49c40ec77af69ab1165989a65064 (diff)
QVideoFrame should be constructed with a QSurfaceFormat
This was inconsistent so far. QVideoFrame had half the properties of QVideoSurfaceFormat, but was missing some parts that are required to render the frame properly. Giving it a QVideoSurfaceFormat means that the QVideoFrame is self describing and can be rendered without additional information. Change-Id: Idb2757ee6a29020bd72c9c50891309ee8d8a8bfc Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/video')
-rw-r--r--src/multimedia/video/qvideoframe.cpp54
-rw-r--r--src/multimedia/video/qvideoframe.h6
2 files changed, 34 insertions, 26 deletions
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index 9c291e40e..8ca606b4a 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -42,6 +42,7 @@
#include "qimagevideobuffer_p.h"
#include "qmemoryvideobuffer_p.h"
#include "qvideoframeconversionhelper_p.h"
+#include "qvideosurfaceformat.h"
#include <qimage.h>
#include <qmutex.h>
@@ -102,9 +103,8 @@ class QVideoFramePrivate : public QSharedData
{
public:
QVideoFramePrivate() = default;
- QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format)
- : size(size)
- , pixelFormat(format)
+ QVideoFramePrivate(const QVideoSurfaceFormat &format)
+ : format(format)
{
}
@@ -113,11 +113,10 @@ public:
delete buffer;
}
- QSize size;
qint64 startTime = -1;
qint64 endTime = -1;
QAbstractVideoBuffer::MapData mapData;
- QVideoFrame::PixelFormat pixelFormat = QVideoFrame::Format_Invalid;
+ QVideoSurfaceFormat format;
QAbstractVideoBuffer *buffer = nullptr;
int mappedCount = 0;
QMutex mapMutex;
@@ -308,8 +307,8 @@ QVideoFrame::QVideoFrame()
\note This doesn't increment the reference count of the video buffer.
*/
-QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format)
- : d(new QVideoFramePrivate(size, format))
+QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoSurfaceFormat &format)
+ : d(new QVideoFramePrivate(format))
{
d->buffer = buffer;
}
@@ -320,8 +319,8 @@ QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelF
The \a bytesPerLine (stride) is the length of each scan line in bytes, and \a bytes is the total
number of bytes that must be allocated for the frame.
*/
-QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format)
- : d(new QVideoFramePrivate(size, format))
+QVideoFrame::QVideoFrame(int bytes, int bytesPerLine, const QVideoSurfaceFormat &format)
+ : d(new QVideoFramePrivate(format))
{
if (bytes > 0) {
QByteArray data;
@@ -342,11 +341,9 @@ QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFo
\sa pixelFormatFromImageFormat()
*/
QVideoFrame::QVideoFrame(const QImage &image)
- : d(new QVideoFramePrivate(
- image.size(), pixelFormatFromImageFormat(image.format())))
+ : d(new QVideoFramePrivate(QVideoSurfaceFormat(image.size(), pixelFormatFromImageFormat(image.format()))))
{
- if (d->pixelFormat != Format_Invalid)
- d->buffer = new QImageVideoBuffer(image);
+ d->buffer = new QImageVideoBuffer(image);
}
/*!
@@ -417,11 +414,19 @@ bool QVideoFrame::isValid() const
}
/*!
- Returns the color format of a video frame.
+ Returns the pixel format of this video frame.
*/
QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const
{
- return d->pixelFormat;
+ return d->format.pixelFormat();
+}
+
+/*!
+ Returns the surface format of this video frame.
+*/
+QVideoSurfaceFormat QVideoFrame::surfaceFormat() const
+{
+ return d->format;
}
/*!
@@ -438,7 +443,7 @@ QVideoFrame::HandleType QVideoFrame::handleType() const
*/
QSize QVideoFrame::size() const
{
- return d->size;
+ return d->format.frameSize();
}
/*!
@@ -446,7 +451,7 @@ QSize QVideoFrame::size() const
*/
int QVideoFrame::width() const
{
- return d->size.width();
+ return size().width();
}
/*!
@@ -454,7 +459,7 @@ int QVideoFrame::width() const
*/
int QVideoFrame::height() const
{
- return d->size.height();
+ return size().height();
}
/*!
@@ -580,8 +585,9 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
return false;
if (d->mapData.nPlanes == 1) {
+ auto pixelFmt = d->format.pixelFormat();
// If the plane count is 1 derive the additional planes for planar formats.
- switch (d->pixelFormat) {
+ switch (pixelFmt) {
case Format_Invalid:
case Format_ARGB32:
case Format_ARGB32_Premultiplied:
@@ -616,9 +622,9 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
// UV planes are sometimes not aligned.
// We calculate the stride using the UV byte count to always
// have a correct stride.
- const int height = d->size.height();
+ const int height = this->height();
const int yStride = d->mapData.bytesPerLine[0];
- const int uvHeight = d->pixelFormat == Format_YUV422P ? height : height / 2;
+ const int uvHeight = pixelFmt == Format_YUV422P ? height : height / 2;
const int uvStride = (d->mapData.nBytes - (yStride * height)) / uvHeight / 2;
// Three planes, the second and third vertically (and horizontally for other than Format_YUV422P formats) subsampled.
@@ -635,7 +641,7 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
// Semi planar, Full resolution Y plane with interleaved subsampled U and V planes.
d->mapData.nPlanes = 2;
d->mapData.bytesPerLine[1] = d->mapData.bytesPerLine[0];
- d->mapData.data[1] = d->mapData.data[0] + (d->mapData.bytesPerLine[0] * d->size.height());
+ d->mapData.data[1] = d->mapData.data[0] + (d->mapData.bytesPerLine[0] * height());
break;
}
case Format_IMC1:
@@ -644,8 +650,8 @@ bool QVideoFrame::map(QVideoFrame::MapMode mode)
// but with lines padded to the width of the first plane.
d->mapData.nPlanes = 3;
d->mapData.bytesPerLine[2] = d->mapData.bytesPerLine[1] = d->mapData.bytesPerLine[0];
- d->mapData.data[1] = d->mapData.data[0] + (d->mapData.bytesPerLine[0] * d->size.height());
- d->mapData.data[2] = d->mapData.data[1] + (d->mapData.bytesPerLine[1] * d->size.height() / 2);
+ d->mapData.data[1] = d->mapData.data[0] + (d->mapData.bytesPerLine[0] * height());
+ d->mapData.data[2] = d->mapData.data[1] + (d->mapData.bytesPerLine[1] * height() / 2);
break;
}
default:
diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h
index 650ad7537..bd69095da 100644
--- a/src/multimedia/video/qvideoframe.h
+++ b/src/multimedia/video/qvideoframe.h
@@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE
class QSize;
class QVideoFramePrivate;
class QAbstractVideoBuffer;
+class QVideoSurfaceFormat;
class Q_MULTIMEDIA_EXPORT QVideoFrame
{
@@ -119,8 +120,8 @@ public:
};
QVideoFrame();
- QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format);
- QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
+ QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoSurfaceFormat &format);
+ QVideoFrame(int bytes, int bytesPerLine, const QVideoSurfaceFormat &format);
QVideoFrame(const QImage &image);
QVideoFrame(const QVideoFrame &other);
~QVideoFrame();
@@ -134,6 +135,7 @@ public:
PixelFormat pixelFormat() const;
+ QVideoSurfaceFormat surfaceFormat() const;
QVideoFrame::HandleType handleType() const;
QSize size() const;