diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-04-13 10:09:11 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-04-16 11:00:32 +0000 |
commit | 919d33f108f3cd54b4d36d873bda63eb22cfcfd5 (patch) | |
tree | 3d4e547486fdf2cf78b499b1f0315f84a4fbe1c9 | |
parent | 1306531589d45a96a39db6e37706c30bf38934db (diff) |
Remove QVideoFrame(QImage) constructor
It doesn't make a lot of sense and only ever worked for some
image formats. In addition, it's never used except for some auto tests.
Change-Id: I6a32eabca8c36646ffc11d728e9cdf9b2f74d758
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/multimedia/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/multimedia/video/qimagevideobuffer.cpp | 86 | ||||
-rw-r--r-- | src/multimedia/video/qimagevideobuffer_p.h | 80 | ||||
-rw-r--r-- | src/multimedia/video/qvideoframe.cpp | 24 | ||||
-rw-r--r-- | src/multimedia/video/qvideoframe.h | 5 | ||||
-rw-r--r-- | src/multimedia/video/qvideotexturehelper.cpp | 84 | ||||
-rw-r--r-- | src/multimedia/video/qvideotexturehelper_p.h | 3 | ||||
-rw-r--r-- | tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp | 10 | ||||
-rw-r--r-- | tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp | 221 |
9 files changed, 99 insertions, 415 deletions
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt index eab2f49e8..ec309e0bd 100644 --- a/src/multimedia/CMakeLists.txt +++ b/src/multimedia/CMakeLists.txt @@ -62,7 +62,6 @@ qt_internal_add_module(Multimedia recording/qmediaencodersettings.cpp recording/qmediaencodersettings.h recording/qmediarecorder.cpp recording/qmediarecorder.h recording/qmediarecorder_p.h video/qabstractvideobuffer.cpp video/qabstractvideobuffer_p.h - video/qimagevideobuffer.cpp video/qimagevideobuffer_p.h video/qmemoryvideobuffer.cpp video/qmemoryvideobuffer_p.h video/qvideoframe.cpp video/qvideoframe.h video/qvideosink.cpp video/qvideosink.h diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp deleted file mode 100644 index 58ec66fa1..000000000 --- a/src/multimedia/video/qimagevideobuffer.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qimagevideobuffer_p.h" - -#include <qimage.h> - -QT_BEGIN_NAMESPACE - -/*! - * \class QImageVideoBuffer - * \internal - * - * A video buffer class for a QImage. - */ - -QImageVideoBuffer::QImageVideoBuffer(const QImage &image) - : QAbstractVideoBuffer(QVideoFrame::NoHandle) -{ - this->image = image; -} - -QImageVideoBuffer::~QImageVideoBuffer() = default; - -QVideoFrame::MapMode QImageVideoBuffer::mapMode() const -{ - return m_mapMode; -} - -QImageVideoBuffer::MapData QImageVideoBuffer::map(QVideoFrame::MapMode mode) -{ - MapData mapData; - if (m_mapMode == QVideoFrame::NotMapped && image.bits() && mode != QVideoFrame::NotMapped) { - m_mapMode = mode; - - mapData.nBytes = int(image.sizeInBytes()); - mapData.nPlanes = 1; - mapData.bytesPerLine[0] = image.bytesPerLine(); - mapData.data[0] = image.bits(); - } - - return mapData; -} - -void QImageVideoBuffer::unmap() -{ - m_mapMode = QVideoFrame::NotMapped; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/video/qimagevideobuffer_p.h deleted file mode 100644 index 15176f52c..000000000 --- a/src/multimedia/video/qimagevideobuffer_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QIMAGEVIDEOBUFFER_P_H -#define QIMAGEVIDEOBUFFER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qabstractvideobuffer_p.h> -#include <qvideoframe.h> - -QT_BEGIN_NAMESPACE - -class QImage; - -class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer -{ -public: - QImageVideoBuffer(const QImage &image); - ~QImageVideoBuffer(); - - QVideoFrame::MapMode mapMode() const override; - - MapData map(QVideoFrame::MapMode mode) override; - void unmap() override; - -private: - QVideoFrame::MapMode m_mapMode = QVideoFrame::NotMapped; - QImage image; -}; - -QT_END_NAMESPACE - - -#endif diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp index 9995b9708..8f95706bb 100644 --- a/src/multimedia/video/qvideoframe.cpp +++ b/src/multimedia/video/qvideoframe.cpp @@ -39,7 +39,7 @@ #include "qvideoframe.h" -#include "qimagevideobuffer_p.h" +#include "qvideotexturehelper_p.h" #include "qmemoryvideobuffer_p.h" #include "qvideoframeconversionhelper_p.h" #include "qvideoframeformat.h" @@ -263,6 +263,7 @@ QVideoFrame::QVideoFrame() } /*! + \internal Constructs a video frame from a \a buffer with the given pixel \a format and \a size in pixels. \note This doesn't increment the reference count of the video buffer. @@ -279,35 +280,22 @@ QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat & 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, int bytesPerLine, const QVideoFrameFormat &format) +QVideoFrame::QVideoFrame(const QVideoFrameFormat &format) : d(new QVideoFramePrivate(format)) { + auto *textureDescription = QVideoTextureHelper::textureDescription(format.pixelFormat()); + qsizetype bytes = textureDescription->bytesForSize(format.frameSize()); if (bytes > 0) { QByteArray data; data.resize(bytes); // Check the memory was successfully allocated. if (!data.isEmpty()) - d->buffer = new QMemoryVideoBuffer(data, bytesPerLine); + d->buffer = new QMemoryVideoBuffer(data, textureDescription->stride*format.frameWidth()); } } /*! - Constructs a video frame from an \a image. - - \note This will construct an invalid video frame if there is no frame type equivalent to the - image format. - - \sa pixelFormatFromImageFormat() -*/ -QVideoFrame::QVideoFrame(const QImage &image) - : d(new QVideoFramePrivate(QVideoFrameFormat(image.size(), - QVideoFrameFormat::pixelFormatFromImageFormat(image.format())))) -{ - d->buffer = new QImageVideoBuffer(image); -} - -/*! Constructs a shallow copy of \a other. Since QVideoFrame is explicitly shared, these two instances will reflect the same frame. diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h index 2d5e2d57e..1ee2de622 100644 --- a/src/multimedia/video/qvideoframe.h +++ b/src/multimedia/video/qvideoframe.h @@ -76,9 +76,7 @@ public: }; QVideoFrame(); - QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format); - QVideoFrame(int bytes, int bytesPerLine, const QVideoFrameFormat &format); - QVideoFrame(const QImage &image); + QVideoFrame(const QVideoFrameFormat &format); QVideoFrame(const QVideoFrame &other); ~QVideoFrame(); @@ -126,6 +124,7 @@ public: QImage toImage() const; + QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format); private: QExplicitlySharedDataPointer<QVideoFramePrivate> d; }; diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp index 706844022..77ad98f3e 100644 --- a/src/multimedia/video/qvideotexturehelper.cpp +++ b/src/multimedia/video/qvideotexturehelper.cpp @@ -45,135 +45,167 @@ namespace QVideoTextureHelper static const TextureDescription descriptions[QVideoFrameFormat::NPixelFormats] = { // Format_Invalid - { 0, + { 0, 0, + [](QSize) { return 0; }, { QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat}, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_ARGB32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_ARGB32_Premultiplied - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_RGB32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_BGRA32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_BGRA32_Premultiplied - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_ABGR32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_BGR32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_AYUV444 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_AYUV444_Premultiplied - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_YUV420P - { 3, + { 3, 1, + [](QSize s) { return 3*s.width()*s.height() / 2; }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_YUV422P - { 3, + { 3, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 1 }, { 2, 1 } } }, // Format_YV12 - { 3, + { 3, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_UYVY - { 1, + { 1, 2, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 2, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_YUYV - { 1, + { 1, 2, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 2, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_NV12 - { 2, + { 2, 1, + [](QSize s) { return 3*s.width()*s.height() / 2; }, { QRhiTexture::R8, QRhiTexture::RG8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_NV21 - { 2, + { 2, 1, + [](QSize s) { return 3*s.width()*s.height() / 2; }, { QRhiTexture::R8, QRhiTexture::RG8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_IMC1 - { 3, + { 3, 1, + [](QSize s) { + // IMC1 requires that U and V components are aligned on a multiple of 16 lines + return s.width()*((s.height()*3/2 + 15) & ~15 + s.height()/2); + }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_IMC2 - { 2, + { 2, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 2 }, { 1, 1 } } }, // Format_IMC3 - { 3, + { 3, 1, + [](QSize s) { + // IMC3 requires that U and V components are aligned on a multiple of 16 lines + return s.width()*((s.height()*3/2 + 15) & ~15 + s.height()/2); + }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_IMC4 - { 2, + { 2, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 2 }, { 1, 1 } } }, // Format_Y8 - { 1, + { 1, 1, + [](QSize s) { return s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_Y16 - { 1, + { 1, 2, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R16, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_P010 - { 2, + { 2, 2, + [](QSize s) { return 3*s.width()*s.height(); }, { QRhiTexture::R16, QRhiTexture::RG16, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_P016 - { 2, + { 2, 2, + [](QSize s) { return 3*s.width()*s.height(); }, { QRhiTexture::R16, QRhiTexture::RG16, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_Jpeg - { 1, + { 1, 0, + [](QSize) { return 0; }, { QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } } diff --git a/src/multimedia/video/qvideotexturehelper_p.h b/src/multimedia/video/qvideotexturehelper_p.h index 153752010..e0b72243a 100644 --- a/src/multimedia/video/qvideotexturehelper_p.h +++ b/src/multimedia/video/qvideotexturehelper_p.h @@ -57,8 +57,11 @@ struct TextureDescription int x; int y; }; + using BytesForSize = int(*)(QSize s); int nplanes; + int stride; + BytesForSize bytesForSize; QRhiTexture::Format textureFormat[maxPlanes]; SizeScale sizeScale[maxPlanes]; }; diff --git a/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp b/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp index aa1a00a3a..75d08552d 100644 --- a/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp +++ b/tests/auto/integration/qdeclarativevideooutput/tst_qdeclarativevideooutput.cpp @@ -73,7 +73,7 @@ void SurfaceHolder::presentDummyFrame(const QSize &size) { if (m_surface) { QVideoFrameFormat format(size, QVideoFrameFormat::Format_ARGB32_Premultiplied); - QVideoFrame frame(size.width() * size.height() * 4, size.width() * 4, format); + QVideoFrame frame(format); m_surface->newVideoFrame(frame); @@ -339,8 +339,12 @@ void tst_QDeclarativeVideoOutput::paintSurface() QVERIFY(surface); videoOutput->setSize(QSize(2, 2)); - QImage img(rgb32ImageData, 2, 2, 8, QImage::Format_RGB32); - surface->newVideoFrame(img); + QVideoFrame frame(QVideoFrameFormat(QSize(2, 2), QVideoFrameFormat::Format_ARGB32)); + frame.map(QVideoFrame::ReadWrite); + QCOMPARE(frame.mappedBytes(), 16); + memcpy(frame.bits(), rgb32ImageData, 16); + frame.unmap(); + surface->newVideoFrame(frame); } void tst_QDeclarativeVideoOutput::sourceRect() diff --git a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp index 6269baaae..db888fc60 100644 --- a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp +++ b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp @@ -65,8 +65,6 @@ private slots: void createFromBuffer_data(); void createFromBuffer(); void createFromImage_data(); - void createFromImage(); - void createFromIncompatibleImage(); void createNull(); void destructor(); void copy_data(); @@ -75,11 +73,8 @@ private slots: void assign(); void map_data(); void map(); - void mapImage_data(); - void mapImage(); void mapPlanes_data(); void mapPlanes(); - void imageDetach(); void formatConversion_data(); void formatConversion(); @@ -174,24 +169,18 @@ void tst_QVideoFrame::create_data() QTest::newRow("64x64 ARGB32") << QSize(64, 64) - << QVideoFrameFormat::Format_ARGB32 - << 16384 - << 256; + << QVideoFrameFormat::Format_ARGB32; QTest::newRow("32x256 YUV420P") << QSize(32, 256) - << QVideoFrameFormat::Format_YUV420P - << 13288 - << 32; + << QVideoFrameFormat::Format_YUV420P; } void tst_QVideoFrame::create() { QFETCH(QSize, size); QFETCH(QVideoFrameFormat::PixelFormat, pixelFormat); - QFETCH(int, bytes); - QFETCH(int, bytesPerLine); - QVideoFrame frame(bytes, bytesPerLine, QVideoFrameFormat(size, pixelFormat)); + QVideoFrame frame(QVideoFrameFormat(size, pixelFormat)); QVERIFY(frame.isValid()); QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); @@ -208,29 +197,21 @@ void tst_QVideoFrame::createInvalid_data() { QTest::addColumn<QSize>("size"); QTest::addColumn<QVideoFrameFormat::PixelFormat>("pixelFormat"); - QTest::addColumn<int>("bytes"); - QTest::addColumn<int>("bytesPerLine"); QTest::newRow("64x64 ARGB32 0 size") - << QSize(64, 64) - << QVideoFrameFormat::Format_ARGB32 - << 0 - << 45; - QTest::newRow("32x256 YUV420P negative size") - << QSize(32, 256) - << QVideoFrameFormat::Format_YUV420P - << -13288 - << 32; + << QSize(0, 64) + << QVideoFrameFormat::Format_ARGB32; + QTest::newRow("32x256 YUV420P 0 size") + << QSize(32, 0) + << QVideoFrameFormat::Format_YUV420P; } void tst_QVideoFrame::createInvalid() { QFETCH(QSize, size); QFETCH(QVideoFrameFormat::PixelFormat, pixelFormat); - QFETCH(int, bytes); - QFETCH(int, bytesPerLine); - QVideoFrame frame(bytes, bytesPerLine, QVideoFrameFormat(size, pixelFormat)); + QVideoFrame frame(QVideoFrameFormat(size, pixelFormat)); QVERIFY(!frame.isValid()); QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); @@ -293,42 +274,6 @@ void tst_QVideoFrame::createFromImage_data() << QVideoFrameFormat::Format_ARGB32_Premultiplied; } -void tst_QVideoFrame::createFromImage() -{ - QFETCH(QSize, size); - QFETCH(QImage::Format, imageFormat); - QFETCH(QVideoFrameFormat::PixelFormat, pixelFormat); - - const QImage image(size.width(), size.height(), imageFormat); - - QVideoFrame frame(image); - - QVERIFY(frame.isValid()); - QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); - QCOMPARE(frame.pixelFormat(), pixelFormat); - QCOMPARE(frame.size(), size); - QCOMPARE(frame.width(), size.width()); - QCOMPARE(frame.height(), size.height()); - QCOMPARE(frame.startTime(), qint64(-1)); - QCOMPARE(frame.endTime(), qint64(-1)); -} - -void tst_QVideoFrame::createFromIncompatibleImage() -{ - const QImage image(64, 64, QImage::Format_Mono); - - QVideoFrame frame(image); - - QVERIFY(!frame.isValid()); - QCOMPARE(frame.handleType(), QVideoFrame::NoHandle); - QCOMPARE(frame.pixelFormat(), QVideoFrameFormat::Format_Invalid); - QCOMPARE(frame.size(), QSize(64, 64)); - QCOMPARE(frame.width(), 64); - QCOMPARE(frame.height(), 64); - QCOMPARE(frame.startTime(), qint64(-1)); - QCOMPARE(frame.endTime(), qint64(-1)); -} - void tst_QVideoFrame::createNull() { // Default ctor @@ -586,29 +531,21 @@ void tst_QVideoFrame::assign() void tst_QVideoFrame::map_data() { QTest::addColumn<QSize>("size"); - QTest::addColumn<int>("mappedBytes"); - QTest::addColumn<int>("bytesPerLine"); QTest::addColumn<QVideoFrameFormat::PixelFormat>("pixelFormat"); QTest::addColumn<QVideoFrame::MapMode>("mode"); QTest::newRow("read-only") << QSize(64, 64) - << 16384 - << 256 << QVideoFrameFormat::Format_ARGB32 << QVideoFrame::ReadOnly; QTest::newRow("write-only") << QSize(64, 64) - << 16384 - << 256 << QVideoFrameFormat::Format_ARGB32 << QVideoFrame::WriteOnly; QTest::newRow("read-write") << QSize(64, 64) - << 16384 - << 256 << QVideoFrameFormat::Format_ARGB32 << QVideoFrame::ReadWrite; } @@ -616,12 +553,10 @@ void tst_QVideoFrame::map_data() void tst_QVideoFrame::map() { QFETCH(QSize, size); - QFETCH(int, mappedBytes); - QFETCH(int, bytesPerLine); QFETCH(QVideoFrameFormat::PixelFormat, pixelFormat); QFETCH(QVideoFrame::MapMode, mode); - QVideoFrame frame(mappedBytes, bytesPerLine, QVideoFrameFormat(size, pixelFormat)); + QVideoFrame frame(QVideoFrameFormat(size, pixelFormat)); QVERIFY(!frame.bits()); QCOMPARE(frame.mappedBytes(), 0); @@ -653,60 +588,6 @@ void tst_QVideoFrame::map() } QVERIFY(frame.bits()); - QCOMPARE(frame.mappedBytes(), mappedBytes); - QCOMPARE(frame.bytesPerLine(), bytesPerLine); - QCOMPARE(frame.mapMode(), mode); - - frame.unmap(); - - QVERIFY(!frame.bits()); - QCOMPARE(frame.mappedBytes(), 0); - QCOMPARE(frame.bytesPerLine(), 0); - QCOMPARE(frame.mapMode(), QVideoFrame::NotMapped); -} - -void tst_QVideoFrame::mapImage_data() -{ - QTest::addColumn<QSize>("size"); - QTest::addColumn<QImage::Format>("format"); - QTest::addColumn<QVideoFrame::MapMode>("mode"); - - QTest::newRow("read-only") - << QSize(64, 64) - << QImage::Format_ARGB32 - << QVideoFrame::ReadOnly; - - QTest::newRow("write-only") - << QSize(15, 106) - << QImage::Format_RGB32 - << QVideoFrame::WriteOnly; - - QTest::newRow("read-write") - << QSize(23, 111) - << QImage::Format_RGB16 - << QVideoFrame::ReadWrite; -} - -void tst_QVideoFrame::mapImage() -{ - QFETCH(QSize, size); - QFETCH(QImage::Format, format); - QFETCH(QVideoFrame::MapMode, mode); - - QImage image(size.width(), size.height(), format); - - QVideoFrame frame(image); - - QVERIFY(!frame.bits()); - QCOMPARE(frame.mappedBytes(), 0); - QCOMPARE(frame.bytesPerLine(), 0); - QCOMPARE(frame.mapMode(), QVideoFrame::NotMapped); - - QVERIFY(frame.map(mode)); - - QVERIFY(frame.bits()); - QCOMPARE(qsizetype(frame.mappedBytes()), image.sizeInBytes()); - QCOMPARE(frame.bytesPerLine(), image.bytesPerLine()); QCOMPARE(frame.mapMode(), mode); frame.unmap(); @@ -740,39 +621,39 @@ void tst_QVideoFrame::mapPlanes_data() << (QList<int>() << 64 << 36 << 36) << (QList<int>() << 512 << 765); QTest::newRow("Format_YUV420P") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_YUV420P)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_YUV420P)) << (QList<int>() << 64 << 62 << 62) << (QList<int>() << 4096 << 6080); QTest::newRow("Format_YV12") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_YV12)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_YV12)) << (QList<int>() << 64 << 62 << 62) << (QList<int>() << 4096 << 6080); QTest::newRow("Format_NV12") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_NV12)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_NV12)) << (QList<int>() << 64 << 64) << (QList<int>() << 4096); QTest::newRow("Format_NV21") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_NV21)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_NV21)) << (QList<int>() << 64 << 64) << (QList<int>() << 4096); QTest::newRow("Format_IMC2") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC2)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC2)) << (QList<int>() << 64 << 64) << (QList<int>() << 4096); QTest::newRow("Format_IMC4") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC4)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC4)) << (QList<int>() << 64 << 64) << (QList<int>() << 4096); QTest::newRow("Format_IMC1") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC1)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC1)) << (QList<int>() << 64 << 64 << 64) << (QList<int>() << 4096 << 6144); QTest::newRow("Format_IMC3") - << QVideoFrame(8096, 64, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC3)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_IMC3)) << (QList<int>() << 64 << 64 << 64) << (QList<int>() << 4096 << 6144); QTest::newRow("Format_ARGB32") - << QVideoFrame(8096, 256, QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_ARGB32)) + << QVideoFrame(QVideoFrameFormat(QSize(60, 64), QVideoFrameFormat::Format_ARGB32)) << (QList<int>() << 256) << (QList<int>()); } @@ -808,31 +689,6 @@ void tst_QVideoFrame::mapPlanes() frame.unmap(); } -void tst_QVideoFrame::imageDetach() -{ - const uint red = qRgb(255, 0, 0); - const uint blue = qRgb(0, 0, 255); - - QImage image(8, 8, QImage::Format_RGB32); - - image.fill(red); - QCOMPARE(image.pixel(4, 4), red); - - QVideoFrame frame(image); - - QVERIFY(frame.map(QVideoFrame::ReadWrite)); - - QImage frameImage(frame.bits(), 8, 8, frame.bytesPerLine(), QImage::Format_RGB32); - - QCOMPARE(frameImage.pixel(4, 4), red); - - frameImage.fill(blue); - QCOMPARE(frameImage.pixel(4, 4), blue); - - // Original image has detached and is therefore unchanged. - QCOMPARE(image.pixel(4, 4), red); -} - void tst_QVideoFrame::formatConversion_data() { QTest::addColumn<QImage::Format>("imageFormat"); @@ -958,7 +814,7 @@ do { \ void tst_QVideoFrame::isMapped() { - QVideoFrame frame(16384, 256, QVideoFrameFormat(QSize(64, 64), QVideoFrameFormat::Format_ARGB32)); + QVideoFrame frame(QVideoFrameFormat(QSize(64, 64), QVideoFrameFormat::Format_ARGB32)); const QVideoFrame& constFrame(frame); TEST_UNMAPPED(frame); @@ -988,7 +844,7 @@ void tst_QVideoFrame::isMapped() void tst_QVideoFrame::isReadable() { - QVideoFrame frame(16384, 256, QVideoFrameFormat(QSize(64, 64), QVideoFrameFormat::Format_ARGB32)); + QVideoFrame frame(QVideoFrameFormat(QSize(64, 64), QVideoFrameFormat::Format_ARGB32)); QVERIFY(!frame.isMapped()); QVERIFY(!frame.isReadable()); @@ -1011,7 +867,7 @@ void tst_QVideoFrame::isReadable() void tst_QVideoFrame::isWritable() { - QVideoFrame frame(16384, 256, QVideoFrameFormat(QSize(64, 64), QVideoFrameFormat::Format_ARGB32)); + QVideoFrame frame(QVideoFrameFormat(QSize(64, 64), QVideoFrameFormat::Format_ARGB32)); QVERIFY(!frame.isMapped()); QVERIFY(!frame.isWritable()); @@ -1036,99 +892,71 @@ void tst_QVideoFrame::image_data() { QTest::addColumn<QSize>("size"); QTest::addColumn<QVideoFrameFormat::PixelFormat>("pixelFormat"); - QTest::addColumn<int>("bytes"); - QTest::addColumn<int>("bytesPerLine"); QTest::addColumn<QImage::Format>("imageFormat"); QTest::newRow("64x64 ARGB32") << QSize(64, 64) << QVideoFrameFormat::Format_ARGB32 - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 ARGB32_Premultiplied") << QSize(64, 64) << QVideoFrameFormat::Format_ARGB32_Premultiplied - << 16384 - << 256 << QImage::Format_ARGB32_Premultiplied; QTest::newRow("64x64 RGB32") << QSize(64, 64) << QVideoFrameFormat::Format_RGB32 - << 16384 - << 256 << QImage::Format_RGB32; QTest::newRow("64x64 BGRA32") << QSize(64, 64) << QVideoFrameFormat::Format_BGRA32 - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 BGRA32_Premultiplied") << QSize(64, 64) << QVideoFrameFormat::Format_BGRA32_Premultiplied - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 BGR32") << QSize(64, 64) << QVideoFrameFormat::Format_BGR32 - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 AYUV444") << QSize(64, 64) << QVideoFrameFormat::Format_AYUV444 - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 YUV420P") << QSize(64, 64) << QVideoFrameFormat::Format_YUV420P - << 13288 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 YV12") << QSize(64, 64) << QVideoFrameFormat::Format_YV12 - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 UYVY") << QSize(64, 64) << QVideoFrameFormat::Format_UYVY - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 YUYV") << QSize(64, 64) << QVideoFrameFormat::Format_YUYV - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 NV12") << QSize(64, 64) << QVideoFrameFormat::Format_NV12 - << 16384 - << 256 << QImage::Format_ARGB32; QTest::newRow("64x64 NV21") << QSize(64, 64) << QVideoFrameFormat::Format_NV21 - << 16384 - << 256 << QImage::Format_ARGB32; } @@ -1136,17 +964,14 @@ void tst_QVideoFrame::image() { QFETCH(QSize, size); QFETCH(QVideoFrameFormat::PixelFormat, pixelFormat); - QFETCH(int, bytes); - QFETCH(int, bytesPerLine); QFETCH(QImage::Format, imageFormat); - QVideoFrame frame(bytes, bytesPerLine, QVideoFrameFormat(size, pixelFormat)); + QVideoFrame frame(QVideoFrameFormat(size, pixelFormat)); QImage img = frame.toImage(); QVERIFY(!img.isNull()); QCOMPARE(img.format(), imageFormat); QCOMPARE(img.size(), size); - QCOMPARE(img.bytesPerLine(), bytesPerLine); } void tst_QVideoFrame::emptyData() |