diff options
6 files changed, 81 insertions, 76 deletions
diff --git a/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp b/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp index 0175cb938..990ab2bd4 100644 --- a/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp +++ b/src/multimedia/platform/gstreamer/common/qgstvideorenderersink.cpp @@ -194,10 +194,7 @@ bool QGstVideoRenderer::present(QVideoSink *sink, GstBuffer *buffer) } } - QVideoFrame frame( - videoBuffer, - m_format.frameSize(), - m_format.pixelFormat()); + QVideoFrame frame(videoBuffer, m_format); QGstUtils::setFrameTimeStamps(&frame, buffer); sink->newVideoFrame(frame); diff --git a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimagecapture.cpp b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimagecapture.cpp index d893193b1..ceeb6d068 100644 --- a/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimagecapture.cpp +++ b/src/multimedia/platform/gstreamer/mediacapture/qgstreamercameraimagecapture.cpp @@ -202,7 +202,7 @@ bool QGstreamerCameraImageCapture::probeBuffer(GstBuffer *buffer) auto *gstBuffer = new QGstVideoBuffer(buffer, previewInfo); auto fmt = QGstUtils::formatForCaps(caps, &previewInfo); - QVideoFrame frame(gstBuffer, fmt.frameSize(), fmt.pixelFormat()); + QVideoFrame frame(gstBuffer, fmt); QImage img = frame.image(); if (img.isNull()) return true; 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; diff --git a/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp b/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp index 8acad9735..b995f94a1 100644 --- a/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp +++ b/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp @@ -76,7 +76,7 @@ void SurfaceHolder::presentDummyFrame(const QSize &size) if (m_surface && m_surface->supportedPixelFormats().count() > 0) { QVideoFrame::PixelFormat pixelFormat = m_surface->supportedPixelFormats().value(0); QVideoSurfaceFormat format(size, pixelFormat); - QVideoFrame frame(size.width() * size.height() * 4, size, size.width() * 4, pixelFormat); + QVideoFrame frame(size.width() * size.height() * 4, size.width() * 4, QVideoSurfaceFormat(size, pixelFormat)); if (!m_surface->isActive()) m_surface->start(format); diff --git a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp index e15ffa248..e83bdbf7c 100644 --- a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp +++ b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp @@ -31,6 +31,7 @@ #include <QtTest/QtTest> #include <qvideoframe.h> +#include <qvideosurfaceformat.h> #include "private/qmemoryvideobuffer_p.h" #include <QtGui/QImage> #include <QtCore/QPointer> @@ -190,7 +191,7 @@ void tst_QVideoFrame::create() QFETCH(int, bytes); QFETCH(int, bytesPerLine); - QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + QVideoFrame frame(bytes, bytesPerLine, QVideoSurfaceFormat(size, pixelFormat)); QVERIFY(frame.isValid()); QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); @@ -229,7 +230,7 @@ void tst_QVideoFrame::createInvalid() QFETCH(int, bytes); QFETCH(int, bytesPerLine); - QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + QVideoFrame frame(bytes, bytesPerLine, QVideoSurfaceFormat(size, pixelFormat)); QVERIFY(!frame.isValid()); QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); @@ -264,7 +265,7 @@ void tst_QVideoFrame::createFromBuffer() QFETCH(QSize, size); QFETCH(QVideoFrame::PixelFormat, pixelFormat); - QVideoFrame frame(new QtTestDummyVideoBuffer(handleType), size, pixelFormat); + QVideoFrame frame(new QtTestDummyVideoBuffer(handleType), QVideoSurfaceFormat(size, pixelFormat)); QVERIFY(frame.isValid()); QCOMPARE(frame.handleType(), handleType); @@ -358,7 +359,7 @@ void tst_QVideoFrame::createNull() // Null buffer (shouldn't crash) { - QVideoFrame frame(nullptr, QSize(1024,768), QVideoFrame::Format_ARGB32); + QVideoFrame frame(nullptr, QVideoSurfaceFormat(QSize(1024,768), QVideoFrame::Format_ARGB32)); QVERIFY(!frame.isValid()); QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_ARGB32); @@ -383,7 +384,7 @@ void tst_QVideoFrame::destructor() QPointer<QtTestDummyVideoBuffer> buffer = new QtTestDummyVideoBuffer; { - QVideoFrame frame(buffer, QSize(4, 1), QVideoFrame::Format_ARGB32); + QVideoFrame frame(buffer, QVideoSurfaceFormat(QSize(4, 1), QVideoFrame::Format_ARGB32)); } QVERIFY(buffer.isNull()); @@ -440,7 +441,7 @@ void tst_QVideoFrame::copy() QPointer<QtTestDummyVideoBuffer> buffer = new QtTestDummyVideoBuffer(handleType); { - QVideoFrame frame(buffer, size, pixelFormat); + QVideoFrame frame(buffer, QVideoSurfaceFormat(size, pixelFormat)); frame.setStartTime(startTime); frame.setEndTime(endTime); @@ -530,7 +531,7 @@ void tst_QVideoFrame::assign() QVideoFrame frame; { - QVideoFrame otherFrame(buffer, size, pixelFormat); + QVideoFrame otherFrame(buffer, QVideoSurfaceFormat(size, pixelFormat)); otherFrame.setStartTime(startTime); otherFrame.setEndTime(endTime); @@ -624,7 +625,7 @@ void tst_QVideoFrame::map() QFETCH(QVideoFrame::PixelFormat, pixelFormat); QFETCH(QVideoFrame::MapMode, mode); - QVideoFrame frame(mappedBytes, size, bytesPerLine, pixelFormat); + QVideoFrame frame(mappedBytes, bytesPerLine, QVideoSurfaceFormat(size, pixelFormat)); QVERIFY(!frame.bits()); QCOMPARE(frame.mappedBytes(), 0); @@ -739,45 +740,45 @@ void tst_QVideoFrame::mapPlanes_data() planarBuffer->m_numBytes = sizeof(bufferData); QTest::newRow("Planar") - << QVideoFrame(planarBuffer, QSize(64, 64), QVideoFrame::Format_YUV420P) - << (QList<int>() << 64 << 36 << 36) - << (QList<int>() << 512 << 765); + << QVideoFrame(planarBuffer, QVideoSurfaceFormat(QSize(64, 64), QVideoFrame::Format_YUV420P)) + << (QList<int>() << 64 << 36 << 36) + << (QList<int>() << 512 << 765); QTest::newRow("Format_YUV420P") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_YUV420P) - << (QList<int>() << 64 << 62 << 62) - << (QList<int>() << 4096 << 6080); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_YUV420P)) + << (QList<int>() << 64 << 62 << 62) + << (QList<int>() << 4096 << 6080); QTest::newRow("Format_YV12") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_YV12) - << (QList<int>() << 64 << 62 << 62) - << (QList<int>() << 4096 << 6080); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_YV12)) + << (QList<int>() << 64 << 62 << 62) + << (QList<int>() << 4096 << 6080); QTest::newRow("Format_NV12") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_NV12) - << (QList<int>() << 64 << 64) - << (QList<int>() << 4096); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_NV12)) + << (QList<int>() << 64 << 64) + << (QList<int>() << 4096); QTest::newRow("Format_NV21") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_NV21) - << (QList<int>() << 64 << 64) - << (QList<int>() << 4096); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_NV21)) + << (QList<int>() << 64 << 64) + << (QList<int>() << 4096); QTest::newRow("Format_IMC2") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_IMC2) - << (QList<int>() << 64 << 64) - << (QList<int>() << 4096); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_IMC2)) + << (QList<int>() << 64 << 64) + << (QList<int>() << 4096); QTest::newRow("Format_IMC4") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_IMC4) - << (QList<int>() << 64 << 64) - << (QList<int>() << 4096); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_IMC4)) + << (QList<int>() << 64 << 64) + << (QList<int>() << 4096); QTest::newRow("Format_IMC1") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_IMC1) - << (QList<int>() << 64 << 64 << 64) - << (QList<int>() << 4096 << 6144); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_IMC1)) + << (QList<int>() << 64 << 64 << 64) + << (QList<int>() << 4096 << 6144); QTest::newRow("Format_IMC3") - << QVideoFrame(8096, QSize(60, 64), 64, QVideoFrame::Format_IMC3) - << (QList<int>() << 64 << 64 << 64) - << (QList<int>() << 4096 << 6144); + << QVideoFrame(8096, 64, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_IMC3)) + << (QList<int>() << 64 << 64 << 64) + << (QList<int>() << 4096 << 6144); QTest::newRow("Format_ARGB32") - << QVideoFrame(8096, QSize(60, 64), 256, QVideoFrame::Format_ARGB32) - << (QList<int>() << 256) - << (QList<int>()); + << QVideoFrame(8096, 256, QVideoSurfaceFormat(QSize(60, 64), QVideoFrame::Format_ARGB32)) + << (QList<int>() << 256) + << (QList<int>()); } void tst_QVideoFrame::mapPlanes() @@ -988,7 +989,7 @@ do { \ void tst_QVideoFrame::isMapped() { - QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + QVideoFrame frame(16384, 256, QVideoSurfaceFormat(QSize(64, 64), QVideoFrame::Format_ARGB32)); const QVideoFrame& constFrame(frame); TEST_UNMAPPED(frame); @@ -1018,7 +1019,7 @@ void tst_QVideoFrame::isMapped() void tst_QVideoFrame::isReadable() { - QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + QVideoFrame frame(16384, 256, QVideoSurfaceFormat(QSize(64, 64), QVideoFrame::Format_ARGB32)); QVERIFY(!frame.isMapped()); QVERIFY(!frame.isReadable()); @@ -1041,7 +1042,7 @@ void tst_QVideoFrame::isReadable() void tst_QVideoFrame::isWritable() { - QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + QVideoFrame frame(16384, 256, QVideoSurfaceFormat(QSize(64, 64), QVideoFrame::Format_ARGB32)); QVERIFY(!frame.isMapped()); QVERIFY(!frame.isWritable()); @@ -1218,7 +1219,7 @@ void tst_QVideoFrame::image() QFETCH(int, bytesPerLine); QFETCH(QImage::Format, imageFormat); - QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + QVideoFrame frame(bytes, bytesPerLine, QVideoSurfaceFormat(size, pixelFormat)); QImage img = frame.image(); QVERIFY(!img.isNull()); @@ -1231,8 +1232,7 @@ void tst_QVideoFrame::emptyData() { QByteArray data(nullptr, 0); QVideoFrame f(new QMemoryVideoBuffer(data, 600), - QSize(800, 600), - QVideoFrame::Format_ARGB32); + QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_ARGB32)); QVERIFY(!f.map(QVideoFrame::ReadOnly)); } |