diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2009-08-24 22:33:55 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2009-08-24 23:02:27 (GMT) |
commit | b8cc86956ae45a6d07dfca04301e1b4905615ee7 (patch) | |
tree | 3587b6d2c66a5ad2505732e5f67df56dcccd5673 /tests | |
parent | e4002434bfde5c8206463ea3a0d4140835619944 (diff) | |
download | Qt-b8cc86956ae45a6d07dfca04301e1b4905615ee7.zip Qt-b8cc86956ae45a6d07dfca04301e1b4905615ee7.tar.gz Qt-b8cc86956ae45a6d07dfca04301e1b4905615ee7.tar.bz2 |
Integrate QAbstractVideoSurface API.
This introduces a QAbstractVideoSurface interface for implementing arbitrary
video outputs, and a QVideoFrame type. Also included is the
QVideoSurfaceFormat class which is used to configure the input to a video
surface, and the QAbstractVideoBuffer class which allows QVideoFrames
to be constructed from non-native frame types.
Reviewed-by: Dmytro Poplavskiy
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 4 | ||||
-rw-r--r-- | tests/auto/qabstractvideobuffer/qabstractvideobuffer.pro | 5 | ||||
-rw-r--r-- | tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp | 132 | ||||
-rw-r--r-- | tests/auto/qabstractvideosurface/qabstractvideosurface.pro | 5 | ||||
-rw-r--r-- | tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp | 292 | ||||
-rw-r--r-- | tests/auto/qvideoframe/qvideoframe.pro | 5 | ||||
-rw-r--r-- | tests/auto/qvideoframe/tst_qvideoframe.cpp | 663 | ||||
-rw-r--r-- | tests/auto/qvideosurfaceformat/qvideosurfaceformat.pro | 5 | ||||
-rw-r--r-- | tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp | 745 |
9 files changed, 1856 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 80d540f..6a5ac9e 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -72,6 +72,8 @@ SUBDIRS += \ qabstractsocket \ qabstractspinbox \ qabstracttextdocumentlayout \ + qabstractvideobuffer \ + qabstractvideosurface \ qaccessibility \ qaction \ qactiongroup \ @@ -368,6 +370,8 @@ SUBDIRS += \ qvariant \ qvarlengtharray \ qvector \ + qvideoframe \ + qvideosurfaceformat \ qvectornd \ qwaitcondition \ qwidget \ diff --git a/tests/auto/qabstractvideobuffer/qabstractvideobuffer.pro b/tests/auto/qabstractvideobuffer/qabstractvideobuffer.pro new file mode 100644 index 0000000..080719a --- /dev/null +++ b/tests/auto/qabstractvideobuffer/qabstractvideobuffer.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +SOURCES += tst_qabstractvideobuffer.cpp + +QT += multimedia +requires(contains(QT_CONFIG, multimedia)) diff --git a/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp b/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp new file mode 100644 index 0000000..2f376d5 --- /dev/null +++ b/tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtMultimedia/QAbstractVideoBuffer> + +class tst_QAbstractVideoBuffer : public QObject +{ + Q_OBJECT +public: + tst_QAbstractVideoBuffer(); + ~tst_QAbstractVideoBuffer(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void handleType_data(); + void handleType(); + void handle(); +}; + +class QtTestVideoBuffer : public QAbstractVideoBuffer +{ +public: + QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) : QAbstractVideoBuffer(type) {} + + MapMode mapMode() const { return NotMapped; } + + uchar *map(MapMode, int *, int *) { return 0; } + void unmap() {} +}; + +tst_QAbstractVideoBuffer::tst_QAbstractVideoBuffer() +{ +} + +tst_QAbstractVideoBuffer::~tst_QAbstractVideoBuffer() +{ +} + +void tst_QAbstractVideoBuffer::initTestCase() +{ +} + +void tst_QAbstractVideoBuffer::cleanupTestCase() +{ +} + +void tst_QAbstractVideoBuffer::init() +{ +} + +void tst_QAbstractVideoBuffer::cleanup() +{ +} + +void tst_QAbstractVideoBuffer::handleType_data() +{ + QTest::addColumn<QAbstractVideoBuffer::HandleType>("type"); + + QTest::newRow("none") + << QAbstractVideoBuffer::NoHandle; + QTest::newRow("opengl") + << QAbstractVideoBuffer::GLTextureHandle; + QTest::newRow("user1") + << QAbstractVideoBuffer::UserHandle; + QTest::newRow("user2") + << QAbstractVideoBuffer::HandleType(QAbstractVideoBuffer::UserHandle + 1); +} + +void tst_QAbstractVideoBuffer::handleType() +{ + QFETCH(QAbstractVideoBuffer::HandleType, type); + + QtTestVideoBuffer buffer(type); + + QCOMPARE(buffer.handleType(), type); +} + +void tst_QAbstractVideoBuffer::handle() +{ + QtTestVideoBuffer buffer(QAbstractVideoBuffer::NoHandle); + + QVERIFY(buffer.handle().isNull()); +} + +QTEST_MAIN(tst_QAbstractVideoBuffer) + +#include "tst_qabstractvideobuffer.moc" diff --git a/tests/auto/qabstractvideosurface/qabstractvideosurface.pro b/tests/auto/qabstractvideosurface/qabstractvideosurface.pro new file mode 100644 index 0000000..4e14542 --- /dev/null +++ b/tests/auto/qabstractvideosurface/qabstractvideosurface.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +SOURCES += tst_qabstractvideosurface.cpp + +QT += multimedia +requires(contains(QT_CONFIG, multimedia)) diff --git a/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp b/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp new file mode 100644 index 0000000..0c46ff1 --- /dev/null +++ b/tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp @@ -0,0 +1,292 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtMultimedia/QAbstractVideoSurface> +#include <QtMultimedia/QVideoSurfaceFormat> + +class tst_QAbstractVideoSurface : public QObject +{ + Q_OBJECT +public: + tst_QAbstractVideoSurface(); + ~tst_QAbstractVideoSurface(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void setError(); + void isFormatSupported_data(); + void isFormatSupported(); + void start_data(); + void start(); +}; + +typedef QMap<QAbstractVideoBuffer::HandleType, QVideoFrame::PixelFormat> SupportedFormatMap; + +Q_DECLARE_METATYPE(SupportedFormatMap) +Q_DECLARE_METATYPE(QVideoSurfaceFormat) +Q_DECLARE_METATYPE(QAbstractVideoSurface::Error); + +class QtTestVideoSurface : public QAbstractVideoSurface +{ + Q_OBJECT +public: + explicit QtTestVideoSurface(QObject *parent = 0) : QAbstractVideoSurface(parent) {} + explicit QtTestVideoSurface(SupportedFormatMap formats, QObject *parent = 0) + : QAbstractVideoSurface(parent), supportedFormats(formats) {} + + QList<QVideoFrame::PixelFormat> supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const + { + return supportedFormats.values(handleType); + } + + bool present(const QVideoFrame &) { return false; } + + using QAbstractVideoSurface::setError; + +private: + SupportedFormatMap supportedFormats; +}; + +tst_QAbstractVideoSurface::tst_QAbstractVideoSurface() +{ +} + +tst_QAbstractVideoSurface::~tst_QAbstractVideoSurface() +{ +} + +void tst_QAbstractVideoSurface::initTestCase() +{ +} + +void tst_QAbstractVideoSurface::cleanupTestCase() +{ +} + +void tst_QAbstractVideoSurface::init() +{ +} + +void tst_QAbstractVideoSurface::cleanup() +{ +} + +void tst_QAbstractVideoSurface::setError() +{ + qRegisterMetaType<QAbstractVideoSurface::Error>(); + + QtTestVideoSurface surface; + + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + + surface.setError(QAbstractVideoSurface::StoppedError); + QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); + + surface.setError(QAbstractVideoSurface::ResourceError); + QCOMPARE(surface.error(), QAbstractVideoSurface::ResourceError); + + surface.setError(QAbstractVideoSurface::NoError); + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); +} + +void tst_QAbstractVideoSurface::isFormatSupported_data() +{ + QTest::addColumn<SupportedFormatMap>("supportedFormats"); + QTest::addColumn<QVideoSurfaceFormat>("format"); + QTest::addColumn<bool>("supported"); + + SupportedFormatMap formats; + + QTest::newRow("no formats: rgb32") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32) + << false; + QTest::newRow("no formats: yv12") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) + << false; + QTest::newRow("no formats: rgb32 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32, + QAbstractVideoBuffer::GLTextureHandle) + << false; + QTest::newRow("no formats: rgb24 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB24, + QAbstractVideoBuffer::GLTextureHandle) + << false; + + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB32); + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB24); + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YUV444); + formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB32); + + QTest::newRow("supported: rgb32") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32) + << true; + QTest::newRow("supported: rgb24") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB24) + << true; + QTest::newRow("unsupported: yv12") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) + << false; + QTest::newRow("supported: rgb32 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32, + QAbstractVideoBuffer::GLTextureHandle) + << true; + QTest::newRow("unsupported: rgb24 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB24, + QAbstractVideoBuffer::GLTextureHandle) + << false; + QTest::newRow("unsupported: yv12 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_YV12, + QAbstractVideoBuffer::GLTextureHandle) + << false; + + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YV12); + formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB24); + + QTest::newRow("supported: yv12") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) + << true; + QTest::newRow("supported: rgb24 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB24, + QAbstractVideoBuffer::GLTextureHandle) + << true; +} + +void tst_QAbstractVideoSurface::isFormatSupported() +{ + QFETCH(SupportedFormatMap, supportedFormats); + QFETCH(QVideoSurfaceFormat, format); + QFETCH(bool, supported); + + QtTestVideoSurface surface(supportedFormats); + + QCOMPARE(surface.isFormatSupported(format), supported); +} + +void tst_QAbstractVideoSurface::start_data() +{ + QTest::addColumn<QVideoSurfaceFormat>("format"); + + QTest::newRow("rgb32") << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32); + QTest::newRow("yv12") << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_YV12); + QTest::newRow("rgb32 gl") << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32, + QAbstractVideoBuffer::GLTextureHandle); +} + +void tst_QAbstractVideoSurface::start() +{ + QFETCH(QVideoSurfaceFormat, format); + + QtTestVideoSurface surface; + surface.setError(QAbstractVideoSurface::ResourceError); + + QSignalSpy formatSpy(&surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat))); + QSignalSpy startedSpy(&surface, SIGNAL(startedChanged(bool))); + + QVERIFY(!surface.isStarted()); + QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); + + QVERIFY(surface.start(format)); + + QVERIFY(surface.isStarted()); + QCOMPARE(surface.surfaceFormat(), format); + + QCOMPARE(formatSpy.count(), 1); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat>(formatSpy.at(0).at(0)), format); + + QCOMPARE(startedSpy.count(), 1); + QCOMPARE(startedSpy.at(0).at(0).toBool(), true); + + // error() is reset on a successful start. + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + + surface.stop(); + + QVERIFY(!surface.isStarted()); + QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); + + QCOMPARE(formatSpy.count(), 2); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat>(formatSpy.at(1).at(0)), QVideoSurfaceFormat()); + + QCOMPARE(startedSpy.count(), 2); + QCOMPARE(startedSpy.at(1).at(0).toBool(), false); +} + +QTEST_MAIN(tst_QAbstractVideoSurface) + +#include "tst_qabstractvideosurface.moc" diff --git a/tests/auto/qvideoframe/qvideoframe.pro b/tests/auto/qvideoframe/qvideoframe.pro new file mode 100644 index 0000000..a735352 --- /dev/null +++ b/tests/auto/qvideoframe/qvideoframe.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +SOURCES += tst_qvideoframe.cpp + +QT += multimedia +requires(contains(QT_CONFIG, multimedia)) diff --git a/tests/auto/qvideoframe/tst_qvideoframe.cpp b/tests/auto/qvideoframe/tst_qvideoframe.cpp new file mode 100644 index 0000000..4fa89ee --- /dev/null +++ b/tests/auto/qvideoframe/tst_qvideoframe.cpp @@ -0,0 +1,663 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtMultimedia/QVideoFrame> +#include <QtGui/QImage> +#include <QtCore/QPointer> + +class tst_QVideoFrame : public QObject +{ + Q_OBJECT +public: + tst_QVideoFrame(); + ~tst_QVideoFrame(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void create_data(); + void create(); + void createInvalid_data(); + void createInvalid(); + void createFromBuffer_data(); + void createFromBuffer(); + void createFromImage_data(); + void createFromImage(); + void createFromIncompatibleImage(); + void createNull(); + void destructor(); + void copy_data(); + void copy(); + void assign_data(); + void assign(); + void map_data(); + void map(); + void mapImage_data(); + void mapImage(); + void imageDetach(); +}; + +Q_DECLARE_METATYPE(QImage::Format) +Q_DECLARE_METATYPE(QVideoFrame) + +class QtTestVideoBuffer : public QObject, public QAbstractVideoBuffer +{ + Q_OBJECT +public: + QtTestVideoBuffer() + : QAbstractVideoBuffer(NoHandle) {} + explicit QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) + : QAbstractVideoBuffer(type) {} + + MapMode mapMode() const { return NotMapped; } + + uchar *map(MapMode, int *, int *) { return 0; } + void unmap() {} +}; + +tst_QVideoFrame::tst_QVideoFrame() +{ +} + +tst_QVideoFrame::~tst_QVideoFrame() +{ +} + +void tst_QVideoFrame::initTestCase() +{ +} + +void tst_QVideoFrame::cleanupTestCase() +{ +} + +void tst_QVideoFrame::init() +{ +} + +void tst_QVideoFrame::cleanup() +{ +} + +void tst_QVideoFrame::create_data() +{ + QTest::addColumn<QSize>("size"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + QTest::addColumn<int>("bytes"); + QTest::addColumn<int>("bytesPerLine"); + + QTest::newRow("64x64 ARGB32") + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << 16384 + << 256; + QTest::newRow("32x256 YUV420P") + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << 13288 + << 32; +} + +void tst_QVideoFrame::create() +{ + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(int, bytes); + QFETCH(int, bytesPerLine); + + QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createInvalid_data() +{ + QTest::addColumn<QSize>("size"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + QTest::addColumn<int>("bytes"); + QTest::addColumn<int>("bytesPerLine"); + + QTest::newRow("64x64 ARGB32 0 size") + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << 0 + << 45; + QTest::newRow("32x256 YUV420P negative size") + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << -13288 + << 32; +} + +void tst_QVideoFrame::createInvalid() +{ + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(int, bytes); + QFETCH(int, bytesPerLine); + + QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createFromBuffer_data() +{ + QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); + QTest::addColumn<QSize>("size"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + + QTest::newRow("64x64 ARGB32 no handle") + << QAbstractVideoBuffer::NoHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32; + QTest::newRow("64x64 ARGB32 gl handle") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32; + QTest::newRow("64x64 ARGB32 user handle") + << QAbstractVideoBuffer::UserHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32; +} + +void tst_QVideoFrame::createFromBuffer() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + + QVideoFrame frame(new QtTestVideoBuffer(handleType), size, pixelFormat); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createFromImage_data() +{ + QTest::addColumn<QSize>("size"); + QTest::addColumn<QImage::Format>("imageFormat"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + + QTest::newRow("64x64 RGB32") + << QSize(64, 64) + << QImage::Format_RGB32 + << QVideoFrame::Format_RGB32; + QTest::newRow("12x45 RGB16") + << QSize(12, 45) + << QImage::Format_RGB16 + << QVideoFrame::Format_RGB565; + QTest::newRow("19x46 ARGB32_Premultiplied") + << QSize(19, 46) + << QImage::Format_ARGB32_Premultiplied + << QVideoFrame::Format_ARGB32_Premultiplied; +} + +void tst_QVideoFrame::createFromImage() +{ + QFETCH(QSize, size); + QFETCH(QImage::Format, imageFormat); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + + const QImage image(size.width(), size.height(), imageFormat); + + QVideoFrame frame(image); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + 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(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(frame.size(), QSize(64, 64)); + QCOMPARE(frame.width(), 64); + QCOMPARE(frame.height(), 64); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createNull() +{ + QVideoFrame frame; + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(frame.size(), QSize()); + QCOMPARE(frame.width(), -1); + QCOMPARE(frame.height(), -1); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::destructor() +{ + QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer; + + { + QVideoFrame frame(buffer, QSize(4, 1), QVideoFrame::Format_ARGB32); + } + + QVERIFY(buffer.isNull()); +} + +void tst_QVideoFrame::copy_data() +{ + QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); + QTest::addColumn<QSize>("size"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + QTest::addColumn<QVideoFrame::FieldType>("fieldType"); + QTest::addColumn<qint64>("startTime"); + QTest::addColumn<qint64>("endTime"); + + QTest::newRow("64x64 ARGB32") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::TopField + << qint64(63641740) + << qint64(63641954); + QTest::newRow("32x256 YUV420P") + << QAbstractVideoBuffer::UserHandle + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << QVideoFrame::InterlacedFrame + << qint64(12345) + << qint64(12389); +} + +void tst_QVideoFrame::copy() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QVideoFrame::FieldType, fieldType); + QFETCH(qint64, startTime); + QFETCH(qint64, endTime); + + QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer(handleType); + + { + QVideoFrame frame(buffer, size, pixelFormat); + frame.setFieldType(QVideoFrame::FieldType(fieldType)); + frame.setStartTime(startTime); + frame.setEndTime(endTime); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), fieldType); + QCOMPARE(frame.startTime(), startTime); + QCOMPARE(frame.endTime(), endTime); + + { + QVideoFrame otherFrame(frame); + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), startTime); + QCOMPARE(otherFrame.endTime(), endTime); + + otherFrame.setEndTime(-1); + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), startTime); + QCOMPARE(otherFrame.endTime(), qint64(-1)); + } + + QVERIFY(!buffer.isNull()); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), fieldType); + QCOMPARE(frame.startTime(), startTime); + QCOMPARE(frame.endTime(), qint64(-1)); // Explicitly shared. + } + + QVERIFY(buffer.isNull()); +} + +void tst_QVideoFrame::assign_data() +{ + QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); + QTest::addColumn<QSize>("size"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + QTest::addColumn<QVideoFrame::FieldType>("fieldType"); + QTest::addColumn<qint64>("startTime"); + QTest::addColumn<qint64>("endTime"); + + QTest::newRow("64x64 ARGB32") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::TopField + << qint64(63641740) + << qint64(63641954); + QTest::newRow("32x256 YUV420P") + << QAbstractVideoBuffer::UserHandle + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << QVideoFrame::InterlacedFrame + << qint64(12345) + << qint64(12389); +} + +void tst_QVideoFrame::assign() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QVideoFrame::FieldType, fieldType); + QFETCH(qint64, startTime); + QFETCH(qint64, endTime); + + QPointer<QtTestVideoBuffer> buffer = new QtTestVideoBuffer(handleType); + + QVideoFrame frame; + { + QVideoFrame otherFrame(buffer, size, pixelFormat); + otherFrame.setFieldType(fieldType); + otherFrame.setStartTime(startTime); + otherFrame.setEndTime(endTime); + + frame = otherFrame; + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), startTime); + QCOMPARE(otherFrame.endTime(), endTime); + + otherFrame.setStartTime(-1); + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), qint64(-1)); + QCOMPARE(otherFrame.endTime(), endTime); + } + + QVERIFY(!buffer.isNull()); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), fieldType); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), endTime); + + frame = QVideoFrame(); + + QVERIFY(buffer.isNull()); + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(frame.size(), QSize()); + QCOMPARE(frame.width(), -1); + QCOMPARE(frame.height(), -1); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::map_data() +{ + QTest::addColumn<QSize>("size"); + QTest::addColumn<int>("numBytes"); + QTest::addColumn<int>("bytesPerLine"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + QTest::addColumn<QAbstractVideoBuffer::MapMode>("mode"); + + QTest::newRow("read-only") + << QSize(64, 64) + << 16384 + << 256 + << QVideoFrame::Format_ARGB32 + << QAbstractVideoBuffer::ReadOnly; + + QTest::newRow("write-only") + << QSize(64, 64) + << 16384 + << 256 + << QVideoFrame::Format_ARGB32 + << QAbstractVideoBuffer::WriteOnly; + + QTest::newRow("read-write") + << QSize(64, 64) + << 16384 + << 256 + << QVideoFrame::Format_ARGB32 + << QAbstractVideoBuffer::ReadWrite; +} + +void tst_QVideoFrame::map() +{ + QFETCH(QSize, size); + QFETCH(int, numBytes); + QFETCH(int, bytesPerLine); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QAbstractVideoBuffer::MapMode, mode); + + QVideoFrame frame(numBytes, size, bytesPerLine, pixelFormat); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.numBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); + + QVERIFY(frame.map(mode)); + + QVERIFY(frame.bits()); + QCOMPARE(frame.numBytes(), numBytes); + QCOMPARE(frame.bytesPerLine(), bytesPerLine); + QCOMPARE(frame.mapMode(), mode); + + frame.unmap(); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.numBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); +} + +void tst_QVideoFrame::mapImage_data() +{ + QTest::addColumn<QSize>("size"); + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<QAbstractVideoBuffer::MapMode>("mode"); + + QTest::newRow("read-only") + << QSize(64, 64) + << QImage::Format_ARGB32 + << QAbstractVideoBuffer::ReadOnly; + + QTest::newRow("write-only") + << QSize(15, 106) + << QImage::Format_RGB32 + << QAbstractVideoBuffer::WriteOnly; + + QTest::newRow("read-write") + << QSize(23, 111) + << QImage::Format_RGB16 + << QAbstractVideoBuffer::ReadWrite; +} + +void tst_QVideoFrame::mapImage() +{ + QFETCH(QSize, size); + QFETCH(QImage::Format, format); + QFETCH(QAbstractVideoBuffer::MapMode, mode); + + QImage image(size.width(), size.height(), format); + + QVideoFrame frame(image); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.numBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); + + QVERIFY(frame.map(mode)); + + QVERIFY(frame.bits()); + QCOMPARE(frame.numBytes(), image.numBytes()); + QCOMPARE(frame.bytesPerLine(), image.bytesPerLine()); + QCOMPARE(frame.mapMode(), mode); + + frame.unmap(); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.numBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); +} + +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(QAbstractVideoBuffer::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); +} + +QTEST_MAIN(tst_QVideoFrame) + +#include "tst_qvideoframe.moc" diff --git a/tests/auto/qvideosurfaceformat/qvideosurfaceformat.pro b/tests/auto/qvideosurfaceformat/qvideosurfaceformat.pro new file mode 100644 index 0000000..830b3d7 --- /dev/null +++ b/tests/auto/qvideosurfaceformat/qvideosurfaceformat.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +SOURCES += tst_qvideosurfaceformat.cpp + +QT += multimedia +requires(contains(QT_CONFIG, multimedia)) diff --git a/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp b/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp new file mode 100644 index 0000000..1bab37b --- /dev/null +++ b/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp @@ -0,0 +1,745 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtMultimedia/QVideoSurfaceFormat> + +class tst_QVideoSurfaceFormat : public QObject +{ + Q_OBJECT +public: + tst_QVideoSurfaceFormat(); + ~tst_QVideoSurfaceFormat(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void constructNull(); + void construct_data(); + void construct(); + void frameSize_data(); + void frameSize(); + void viewport_data(); + void viewport(); + void scanLineDirection_data(); + void scanLineDirection(); + void frameRate_data(); + void frameRate(); + void yuvColorSpace_data(); + void yuvColorSpace(); + void pixelAspectRatio_data(); + void pixelAspectRatio(); + void sizeHint_data(); + void sizeHint(); + void staticPropertyNames(); + void dynamicProperty(); + void compare(); + void copy(); + void assign(); +}; + +Q_DECLARE_METATYPE(QVideoSurfaceFormat::ViewportMode) + + +tst_QVideoSurfaceFormat::tst_QVideoSurfaceFormat() +{ +} + +tst_QVideoSurfaceFormat::~tst_QVideoSurfaceFormat() +{ +} + +void tst_QVideoSurfaceFormat::initTestCase() +{ +} + +void tst_QVideoSurfaceFormat::cleanupTestCase() +{ +} + +void tst_QVideoSurfaceFormat::init() +{ +} + +void tst_QVideoSurfaceFormat::cleanup() +{ +} + +void tst_QVideoSurfaceFormat::constructNull() +{ + QVideoSurfaceFormat format; + + QVERIFY(!format.isValid()); + QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(format.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(format.frameSize(), QSize()); + QCOMPARE(format.frameWidth(), -1); + QCOMPARE(format.frameHeight(), -1); + QCOMPARE(format.viewport(), QRect()); + QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + QCOMPARE(format.frameRate(), QVideoSurfaceFormat::FrameRate()); + QCOMPARE(format.pixelAspectRatio(), QSize(1, 1)); + QCOMPARE(format.yuvColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined); +} + +void tst_QVideoSurfaceFormat::construct_data() +{ + QTest::addColumn<QSize>("frameSize"); + QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); + QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); + + QTest::newRow("32x32 rgb32 no handle") + << QSize(32, 32) + << QVideoFrame::Format_RGB32 + << QAbstractVideoBuffer::NoHandle; + + QTest::newRow("1024x768 YUV444 GL texture") + << QSize(32, 32) + << QVideoFrame::Format_YUV444 + << QAbstractVideoBuffer::GLTextureHandle; +} + +void tst_QVideoSurfaceFormat::construct() +{ + QFETCH(QSize, frameSize); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + + QRect viewport(QPoint(0, 0), frameSize); + + QVideoSurfaceFormat format(frameSize, pixelFormat, handleType); + + QCOMPARE(format.handleType(), handleType); + QCOMPARE(format.pixelFormat(), pixelFormat); + QCOMPARE(format.frameSize(), frameSize); + QCOMPARE(format.frameWidth(), frameSize.width()); + QCOMPARE(format.frameHeight(), frameSize.height()); + QCOMPARE(format.viewport(), viewport); + QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + QCOMPARE(format.frameRate(), QVideoSurfaceFormat::FrameRate()); + QCOMPARE(format.pixelAspectRatio(), QSize(1, 1)); + QCOMPARE(format.yuvColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined); +} + +void tst_QVideoSurfaceFormat::frameSize_data() +{ + QTest::addColumn<QSize>("initialSize"); + QTest::addColumn<QSize>("newSize"); + + QTest::newRow("grow") + << QSize(64, 64) + << QSize(1024, 1024); + QTest::newRow("shrink") + << QSize(1024, 1024) + << QSize(64, 64); + QTest::newRow("unchanged") + << QSize(512, 512) + << QSize(512, 512); +} + +void tst_QVideoSurfaceFormat::frameSize() +{ + QFETCH(QSize, initialSize); + QFETCH(QSize, newSize); + + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setFrameSize(newSize); + + QCOMPARE(format.frameSize(), newSize); + QCOMPARE(format.property("frameSize").toSize(), newSize); + QCOMPARE(format.frameWidth(), newSize.width()); + QCOMPARE(format.property("frameWidth").toInt(), newSize.width()); + QCOMPARE(format.frameHeight(), newSize.height()); + QCOMPARE(format.property("frameHeight").toInt(), newSize.height()); +} + +void tst_QVideoSurfaceFormat::viewport_data() +{ + QTest::addColumn<QSize>("initialSize"); + QTest::addColumn<QRect>("viewport"); + QTest::addColumn<QSize>("newSize"); + QTest::addColumn<QVideoSurfaceFormat::ViewportMode>("viewportMode"); + QTest::addColumn<QRect>("expectedViewport"); + + QTest::newRow("grow reset") + << QSize(64, 64) + << QRect(8, 8, 48, 48) + << QSize(1024, 1024) + << QVideoSurfaceFormat::ResetViewport + << QRect(0, 0, 1024, 1024); + QTest::newRow("grow keep") + << QSize(64, 64) + << QRect(8, 8, 48, 48) + << QSize(1024, 1024) + << QVideoSurfaceFormat::KeepViewport + << QRect(8, 8, 48, 48); + QTest::newRow("shrink reset") + << QSize(1024, 1024) + << QRect(8, 8, 1008, 1008) + << QSize(64, 64) + << QVideoSurfaceFormat::ResetViewport + << QRect(0, 0, 64, 64); + QTest::newRow("shrink keep") + << QSize(1024, 1024) + << QRect(8, 8, 1008, 1008) + << QSize(64, 64) + << QVideoSurfaceFormat::KeepViewport + << QRect(8, 8, 56, 56); + QTest::newRow("unchanged reset") + << QSize(512, 512) + << QRect(8, 8, 496, 496) + << QSize(512, 512) + << QVideoSurfaceFormat::ResetViewport + << QRect(0, 0, 512, 512); + QTest::newRow("unchanged keep") + << QSize(512, 512) + << QRect(8, 8, 496, 496) + << QSize(512, 512) + << QVideoSurfaceFormat::KeepViewport + << QRect(8, 8, 496, 496); +} + +void tst_QVideoSurfaceFormat::viewport() +{ + QFETCH(QSize, initialSize); + QFETCH(QRect, viewport); + QFETCH(QSize, newSize); + QFETCH(QVideoSurfaceFormat::ViewportMode, viewportMode); + QFETCH(QRect, expectedViewport); + + { + QRect initialViewport(QPoint(0, 0), initialSize); + + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setViewport(viewport); + + QCOMPARE(format.viewport(), viewport); + QCOMPARE(format.property("viewport").toRect(), viewport); + + format.setFrameSize(newSize, viewportMode); + + QCOMPARE(format.viewport(), expectedViewport); + QCOMPARE(format.property("viewport").toRect(), expectedViewport); + } + { + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setProperty("viewport", viewport); + + QCOMPARE(format.viewport(), viewport); + QCOMPARE(format.property("viewport").toRect(), viewport); + } +} + +void tst_QVideoSurfaceFormat::scanLineDirection_data() +{ + QTest::addColumn<QVideoSurfaceFormat::Direction>("direction"); + + QTest::newRow("top to bottom") + << QVideoSurfaceFormat::TopToBottom; + + QTest::newRow("bottom to top") + << QVideoSurfaceFormat::BottomToTop; +} + +void tst_QVideoSurfaceFormat::scanLineDirection() +{ + QFETCH(QVideoSurfaceFormat::Direction, direction); + + { + QVideoSurfaceFormat format(QSize(16, 16), QVideoFrame::Format_RGB32); + + format.setScanLineDirection(direction); + + QCOMPARE(format.scanLineDirection(), direction); + QCOMPARE( + qvariant_cast<QVideoSurfaceFormat::Direction>(format.property("scanLineDirection")), + direction); + } + { + QVideoSurfaceFormat format(QSize(16, 16), QVideoFrame::Format_RGB32); + + format.setProperty("scanLineDirection", qVariantFromValue(direction)); + + QCOMPARE(format.scanLineDirection(), direction); + QCOMPARE( + qvariant_cast<QVideoSurfaceFormat::Direction>(format.property("scanLineDirection")), + direction); + } +} + +void tst_QVideoSurfaceFormat::frameRate_data() +{ + QTest::addColumn<QVideoSurfaceFormat::FrameRate>("frameRate"); + + QTest::newRow("null") + << QVideoSurfaceFormat::FrameRate(0, 0); + QTest::newRow("1/1") + << QVideoSurfaceFormat::FrameRate(1, 1); + QTest::newRow("24/1") + << QVideoSurfaceFormat::FrameRate(24, 1); + QTest::newRow("15/2") + << QVideoSurfaceFormat::FrameRate(15, 2); +} + +void tst_QVideoSurfaceFormat::frameRate() +{ + QFETCH(QVideoSurfaceFormat::FrameRate, frameRate); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + format.setFrameRate(frameRate); + + QCOMPARE(format.frameRate(), frameRate); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat::FrameRate>(format.property("frameRate")), + frameRate); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + format.setFrameRate(frameRate.first, frameRate.second); + + QCOMPARE(format.frameRate(), frameRate); + QCOMPARE( + qvariant_cast<QVideoSurfaceFormat::FrameRate>(format.property("frameRate")), + frameRate); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + format.setFrameRate(frameRate); + format.setProperty( + "frameRate", qVariantFromValue<QVideoSurfaceFormat::FrameRate>(frameRate)); + + QCOMPARE(format.frameRate(), frameRate); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat::FrameRate>(format.property("frameRate")), + frameRate); + } +} + +void tst_QVideoSurfaceFormat::yuvColorSpace_data() +{ + QTest::addColumn<QVideoSurfaceFormat::YuvColorSpace>("colorspace"); + + QTest::newRow("undefined") + << QVideoSurfaceFormat::YCbCr_Undefined; + QTest::newRow("bt709") + << QVideoSurfaceFormat::YCbCr_BT709; + QTest::newRow("xvYCC601") + << QVideoSurfaceFormat::YCbCr_xvYCC601; + QTest::newRow("JPEG") + << QVideoSurfaceFormat::YCbCr_JPEG; +} + +void tst_QVideoSurfaceFormat::yuvColorSpace() +{ + QFETCH(QVideoSurfaceFormat::YuvColorSpace, colorspace); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setYuvColorSpace(colorspace); + + QCOMPARE(format.yuvColorSpace(), colorspace); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat::YuvColorSpace>(format.property("yuvColorSpace")), + colorspace); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setProperty("yuvColorSpace", qVariantFromValue(colorspace)); + + QCOMPARE(format.yuvColorSpace(), colorspace); + QCOMPARE(qvariant_cast<QVideoSurfaceFormat::YuvColorSpace>(format.property("yuvColorSpace")), + colorspace); + } +} + +void tst_QVideoSurfaceFormat::pixelAspectRatio_data() +{ + QTest::addColumn<QSize>("aspectRatio"); + + QTest::newRow("1:1") + << QSize(1, 1); + QTest::newRow("4:3") + << QSize(4, 3); + QTest::newRow("16:9") + << QSize(16, 9); +} + +void tst_QVideoSurfaceFormat::pixelAspectRatio() +{ + QFETCH(QSize, aspectRatio); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setPixelAspectRatio(aspectRatio); + + QCOMPARE(format.pixelAspectRatio(), aspectRatio); + QCOMPARE(format.property("pixelAspectRatio").toSize(), aspectRatio); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setPixelAspectRatio(aspectRatio.width(), aspectRatio.height()); + + QCOMPARE(format.pixelAspectRatio(), aspectRatio); + QCOMPARE(format.property("pixelAspectRatio").toSize(), aspectRatio); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setProperty("pixelAspectRatio", aspectRatio); + + QCOMPARE(format.pixelAspectRatio(), aspectRatio); + QCOMPARE(format.property("pixelAspectRatio").toSize(), aspectRatio); + } +} + +void tst_QVideoSurfaceFormat::sizeHint_data() +{ + QTest::addColumn<QSize>("frameSize"); + QTest::addColumn<QRect>("viewport"); + QTest::addColumn<QSize>("aspectRatio"); + QTest::addColumn<QSize>("sizeHint"); + + QTest::newRow("(0, 0, 1024x768), 1:1") + << QSize(1024, 768) + << QRect(0, 0, 1024, 768) + << QSize(1, 1) + << QSize(1024, 768); + QTest::newRow("0, 0, 1024x768), 4:3") + << QSize(1024, 768) + << QRect(0, 0, 1024, 768) + << QSize(4, 3) + << QSize(1365, 768); + QTest::newRow("(168, 84, 800x600), 1:1") + << QSize(1024, 768) + << QRect(168, 84, 800, 600) + << QSize(1, 1) + << QSize(800, 600); + QTest::newRow("(168, 84, 800x600), 4:3") + << QSize(1024, 768) + << QRect(168, 84, 800, 600) + << QSize(4, 3) + << QSize(1066, 600); +} + +void tst_QVideoSurfaceFormat::sizeHint() +{ + QFETCH(QSize, frameSize); + QFETCH(QRect, viewport); + QFETCH(QSize, aspectRatio); + QFETCH(QSize, sizeHint); + + QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_RGB32); + format.setViewport(viewport); + format.setPixelAspectRatio(aspectRatio); + + QCOMPARE(format.sizeHint(), sizeHint); + QCOMPARE(format.property("sizeHint").toSize(), sizeHint); +} + +void tst_QVideoSurfaceFormat::staticPropertyNames() +{ + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + QList<QByteArray> propertyNames = format.propertyNames(); + + QVERIFY(propertyNames.contains("handleType")); + QVERIFY(propertyNames.contains("pixelFormat")); + QVERIFY(propertyNames.contains("frameSize")); + QVERIFY(propertyNames.contains("frameWidth")); + QVERIFY(propertyNames.contains("viewport")); + QVERIFY(propertyNames.contains("scanLineDirection")); + QVERIFY(propertyNames.contains("frameRate")); + QVERIFY(propertyNames.contains("pixelAspectRatio")); + QVERIFY(propertyNames.contains("yuvColorSpace")); + QVERIFY(propertyNames.contains("sizeHint")); + QCOMPARE(propertyNames.count(), 10); +} + +void tst_QVideoSurfaceFormat::dynamicProperty() +{ + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + QCOMPARE(format.property("integer"), QVariant()); + QCOMPARE(format.property("size"), QVariant()); + QCOMPARE(format.property("string"), QVariant()); + QCOMPARE(format.property("null"), QVariant()); + + QList<QByteArray> propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 0); + QCOMPARE(propertyNames.count(QByteArray("string")), 0); + QCOMPARE(propertyNames.count(QByteArray("size")), 0); + QCOMPARE(propertyNames.count(QByteArray("null")), 0); + + format.setProperty("string", QString::fromLatin1("Hello")); + format.setProperty("integer", 198); + format.setProperty("size", QSize(43, 65)); + + QCOMPARE(format.property("integer").toInt(), 198); + QCOMPARE(format.property("size").toSize(), QSize(43, 65)); + QCOMPARE(format.property("string").toString(), QString::fromLatin1("Hello")); + + propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 1); + QCOMPARE(propertyNames.count(QByteArray("string")), 1); + QCOMPARE(propertyNames.count(QByteArray("size")), 1); + + format.setProperty("integer", 125423); + format.setProperty("size", QSize(1, 986)); + + QCOMPARE(format.property("integer").toInt(), 125423); + QCOMPARE(format.property("size").toSize(), QSize(1, 986)); + QCOMPARE(format.property("string").toString(), QString::fromLatin1("Hello")); + + propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 1); + QCOMPARE(propertyNames.count(QByteArray("string")), 1); + QCOMPARE(propertyNames.count(QByteArray("size")), 1); + + format.setProperty("string", QVariant()); + format.setProperty("size", QVariant()); + format.setProperty("null", QVariant()); + + QCOMPARE(format.property("integer").toInt(), 125423); + QCOMPARE(format.property("size"), QVariant()); + QCOMPARE(format.property("string"), QVariant()); + QCOMPARE(format.property("null"), QVariant()); + + propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 1); + QCOMPARE(propertyNames.count(QByteArray("string")), 0); + QCOMPARE(propertyNames.count(QByteArray("size")), 0); + QCOMPARE(propertyNames.count(QByteArray("null")), 0); +} + +void tst_QVideoSurfaceFormat::compare() +{ + QVideoSurfaceFormat format1( + QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); + QVideoSurfaceFormat format2( + QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); + QVideoSurfaceFormat format3( + QSize(32, 32), QVideoFrame::Format_YUV444, QAbstractVideoBuffer::GLTextureHandle); + QVideoSurfaceFormat format4( + QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::UserHandle); + + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + QCOMPARE(format1 == format3, false); + QCOMPARE(format1 != format3, true); + QCOMPARE(format1 == format4, false); + QCOMPARE(format1 != format4, true); + + format2.setFrameSize(1024, 768, QVideoSurfaceFormat::ResetViewport); + + // Not equal, frame size differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setFrameSize(1024, 768, QVideoSurfaceFormat::KeepViewport); + + // Not equal, viewport differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setViewport(QRect(0, 0, 1024, 768)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format2.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + // Not equal scan line direction differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setFrameRate(QVideoSurfaceFormat::FrameRate(15, 2)); + + // Not equal frame rate differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setFrameRate(15, 2); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format2.setPixelAspectRatio(4, 3); + + // Not equal pixel aspect ratio differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setPixelAspectRatio(QSize(4, 3)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format2.setYuvColorSpace(QVideoSurfaceFormat::YCbCr_xvYCC601); + + // Not equal yuv color space differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setYuvColorSpace(QVideoSurfaceFormat::YCbCr_xvYCC601); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setProperty("integer", 12); + + // Not equal, property mismatch. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setProperty("integer", 45); + + // Not equal, integer differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setProperty("integer", 12); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setProperty("string", QString::fromLatin1("Hello")); + format2.setProperty("size", QSize(12, 54)); + + // Not equal, property mismatch. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setProperty("string", QString::fromLatin1("Hello")); + format1.setProperty("size", QSize(12, 54)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setProperty("string", QVariant()); + + // Not equal, property mismatch. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); +} + + +void tst_QVideoSurfaceFormat::copy() +{ + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + QVideoSurfaceFormat copy(original); + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + copy.setScanLineDirection(QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(original.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, false); + QCOMPARE(original != copy, true); +} + +void tst_QVideoSurfaceFormat::assign() +{ + QVideoSurfaceFormat copy( + QSize(64, 64), QVideoFrame::Format_AYUV444, QAbstractVideoBuffer::UserHandle); + + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + copy = original; + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + copy.setScanLineDirection(QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(original.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, false); + QCOMPARE(original != copy, true); +} + +QTEST_MAIN(tst_QVideoSurfaceFormat) + +#include "tst_qvideosurfaceformat.moc" |