From b8cc86956ae45a6d07dfca04301e1b4905615ee7 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 25 Aug 2009 08:33:55 +1000 Subject: 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 --- configure | 25 +- doc/src/examples/videographicsitem.qdoc | 52 ++ doc/src/examples/videowidget.qdoc | 187 ++++++ doc/src/getting-started/examples.qdoc | 7 + doc/src/images/video-videographicsitem.png | Bin 0 -> 54436 bytes doc/src/images/video-videowidget.png | Bin 0 -> 54199 bytes examples/examples.pro | 7 +- examples/video/video.pro | 6 + examples/video/videographicsitem/main.cpp | 55 ++ .../video/videographicsitem/videographicsitem.pro | 16 + examples/video/videographicsitem/videoitem.cpp | 144 ++++ examples/video/videographicsitem/videoitem.h | 78 +++ examples/video/videographicsitem/videoplayer.cpp | 210 ++++++ examples/video/videographicsitem/videoplayer.h | 86 +++ examples/video/videowidget/main.cpp | 54 ++ examples/video/videowidget/videoplayer.cpp | 183 +++++ examples/video/videowidget/videoplayer.h | 79 +++ examples/video/videowidget/videowidget.cpp | 114 ++++ examples/video/videowidget/videowidget.h | 76 +++ examples/video/videowidget/videowidget.pro | 14 + examples/video/videowidget/videowidgetsurface.cpp | 175 +++++ examples/video/videowidget/videowidgetsurface.h | 81 +++ mkspecs/features/qt.prf | 2 +- src/multimedia/multimedia.pro | 13 +- src/multimedia/video/qabstractvideobuffer.cpp | 199 ++++++ src/multimedia/video/qabstractvideobuffer.h | 104 +++ src/multimedia/video/qabstractvideobuffer_p.h | 73 ++ src/multimedia/video/qabstractvideosurface.cpp | 268 ++++++++ src/multimedia/video/qabstractvideosurface.h | 110 +++ src/multimedia/video/qabstractvideosurface_p.h | 79 +++ src/multimedia/video/qimagevideobuffer.cpp | 102 +++ src/multimedia/video/qimagevideobuffer_p.h | 79 +++ src/multimedia/video/qmemoryvideobuffer.cpp | 129 ++++ src/multimedia/video/qmemoryvideobuffer_p.h | 83 +++ src/multimedia/video/qvideoframe.cpp | 742 ++++++++++++++++++++ src/multimedia/video/qvideoframe.h | 169 +++++ src/multimedia/video/qvideosurfaceformat.cpp | 742 ++++++++++++++++++++ src/multimedia/video/qvideosurfaceformat.h | 157 +++++ src/multimedia/video/video.pri | 21 + tests/auto/auto.pro | 4 + .../qabstractvideobuffer/qabstractvideobuffer.pro | 5 + .../tst_qabstractvideobuffer.cpp | 132 ++++ .../qabstractvideosurface.pro | 5 + .../tst_qabstractvideosurface.cpp | 292 ++++++++ tests/auto/qvideoframe/qvideoframe.pro | 5 + tests/auto/qvideoframe/tst_qvideoframe.cpp | 663 ++++++++++++++++++ .../qvideosurfaceformat/qvideosurfaceformat.pro | 5 + .../tst_qvideosurfaceformat.cpp | 745 +++++++++++++++++++++ tools/configure/configureapp.cpp | 2 +- 49 files changed, 6557 insertions(+), 22 deletions(-) create mode 100644 doc/src/examples/videographicsitem.qdoc create mode 100644 doc/src/examples/videowidget.qdoc create mode 100644 doc/src/images/video-videographicsitem.png create mode 100644 doc/src/images/video-videowidget.png create mode 100644 examples/video/video.pro create mode 100644 examples/video/videographicsitem/main.cpp create mode 100644 examples/video/videographicsitem/videographicsitem.pro create mode 100644 examples/video/videographicsitem/videoitem.cpp create mode 100644 examples/video/videographicsitem/videoitem.h create mode 100644 examples/video/videographicsitem/videoplayer.cpp create mode 100644 examples/video/videographicsitem/videoplayer.h create mode 100644 examples/video/videowidget/main.cpp create mode 100644 examples/video/videowidget/videoplayer.cpp create mode 100644 examples/video/videowidget/videoplayer.h create mode 100644 examples/video/videowidget/videowidget.cpp create mode 100644 examples/video/videowidget/videowidget.h create mode 100644 examples/video/videowidget/videowidget.pro create mode 100644 examples/video/videowidget/videowidgetsurface.cpp create mode 100644 examples/video/videowidget/videowidgetsurface.h create mode 100644 src/multimedia/video/qabstractvideobuffer.cpp create mode 100644 src/multimedia/video/qabstractvideobuffer.h create mode 100644 src/multimedia/video/qabstractvideobuffer_p.h create mode 100644 src/multimedia/video/qabstractvideosurface.cpp create mode 100644 src/multimedia/video/qabstractvideosurface.h create mode 100644 src/multimedia/video/qabstractvideosurface_p.h create mode 100644 src/multimedia/video/qimagevideobuffer.cpp create mode 100644 src/multimedia/video/qimagevideobuffer_p.h create mode 100644 src/multimedia/video/qmemoryvideobuffer.cpp create mode 100644 src/multimedia/video/qmemoryvideobuffer_p.h create mode 100644 src/multimedia/video/qvideoframe.cpp create mode 100644 src/multimedia/video/qvideoframe.h create mode 100644 src/multimedia/video/qvideosurfaceformat.cpp create mode 100644 src/multimedia/video/qvideosurfaceformat.h create mode 100644 src/multimedia/video/video.pri create mode 100644 tests/auto/qabstractvideobuffer/qabstractvideobuffer.pro create mode 100644 tests/auto/qabstractvideobuffer/tst_qabstractvideobuffer.cpp create mode 100644 tests/auto/qabstractvideosurface/qabstractvideosurface.pro create mode 100644 tests/auto/qabstractvideosurface/tst_qabstractvideosurface.cpp create mode 100644 tests/auto/qvideoframe/qvideoframe.pro create mode 100644 tests/auto/qvideoframe/tst_qvideoframe.cpp create mode 100644 tests/auto/qvideosurfaceformat/qvideosurfaceformat.pro create mode 100644 tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp diff --git a/configure b/configure index 06eed61..49b2e86 100755 --- a/configure +++ b/configure @@ -1216,7 +1216,7 @@ while [ "$#" -gt 0 ]; do fi fi ;; - + qvfb) # left for commandline compatibility, not documented if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then if [ "$VAL" = "yes" ]; then @@ -3202,9 +3202,8 @@ Usage: $relconf [-h] [-prefix ] [-prefix-install] [-bindir ] [-libdir [-no-separate-debug-info] [-no-mmx] [-no-3dnow] [-no-sse] [-no-sse2] [-qtnamespace ] [-qtlibinfix ] [-separate-debug-info] [-armfpa] [-no-optimized-qmake] [-optimized-qmake] [-no-xmlpatterns] [-xmlpatterns] - [-no-phonon] [-phonon] [-no-phonon-backend] [-phonon-backend] + [-no-multimedia] [-multimedia] [-no-phonon] [-phonon] [-no-phonon-backend] [-phonon-backend] [-no-openssl] [-openssl] [-openssl-linked] - [-no-multimedia] [-multimedia] [-no-gtkstyle] [-gtkstyle] [-no-svg] [-svg] [-no-webkit] [-webkit] [-no-script] [-script] [-no-scripttools] [-scripttools] @@ -3339,15 +3338,15 @@ fi QtXmlPatterns is built if a decent C++ compiler is used and exceptions are enabled. + -no-multimedia ..... Do not build the QtMultimedia module. + + -multimedia ........ Build the QtMultimedia module. + -no-phonon ......... Do not build the Phonon module. + -phonon ............ Build the Phonon module. Phonon is built if a decent C++ compiler is used. -no-phonon-backend.. Do not build the platform phonon plugin. + -phonon-backend..... Build the platform phonon plugin. - -no-multimedia ..... Do not build the multimedia module. - * -multimedia ........ Build the multimedia module. - -no-svg ............ Do not build the SVG module. + -svg ............... Build the SVG module. @@ -5817,7 +5816,7 @@ else fi fi; -# set the global Mac deployment target. This is overridden on an arch-by-arch basis +# set the global Mac deployment target. This is overridden on an arch-by-arch basis # in some cases, see code further down case "$PLATFORM,$CFG_MAC_COCOA" in macx*,yes) @@ -6322,6 +6321,12 @@ else QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_XMLPATTERNS" fi +if [ "$CFG_MULTIMEDIA" = "no" ]; then + QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_MULTIMEDIA" +else + QT_CONFIG="$QT_CONFIG multimedia" +fi + if [ "$CFG_SVG" = "yes" ]; then QT_CONFIG="$QT_CONFIG svg" else @@ -6367,12 +6372,6 @@ else QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_SCRIPTTOOLS" fi -if [ "$CFG_MULTIMEDIA" = "yes" ]; then - QT_CONFIG="$QT_CONFIG multimedia" -else - QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_MULTIMEDIA" -fi - if [ "$CFG_EXCEPTIONS" = "no" ]; then case "$COMPILER" in g++*) diff --git a/doc/src/examples/videographicsitem.qdoc b/doc/src/examples/videographicsitem.qdoc new file mode 100644 index 0000000..861b587 --- /dev/null +++ b/doc/src/examples/videographicsitem.qdoc @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example video/videographicsitem + \title Video Graphics Item Example + + The Video Graphics Item example shows how to implement a QGraphicsItem that displays video on a + graphics scene using QtMultimedia's QAbstractVideoSurface. + + \image video-videographicsitem.png + + \sa {Video Widget Example} +*/ diff --git a/doc/src/examples/videowidget.qdoc b/doc/src/examples/videowidget.qdoc new file mode 100644 index 0000000..27d5711 --- /dev/null +++ b/doc/src/examples/videowidget.qdoc @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example video/videowidget + \title Video Widget Example + + The Video Widget example shows how to implement a video widget using + QtMultimedia's QAbstractVideoSurface + + \image video-videowidget.png + + \section1 VideoWidgetSurface Class Definition + + \snippet examples/video/videowidget/videowidgetsurface.h 0 + + The VideoWidgetSurface class inherits QAbstractVideoSurface and paints + video frames on a QWidget. This is a separate class to VideoWidget as both + QAbstractVideoSurface and QWidget inherit QObject. + + In addition to the functions from QAbstractVideoSurface, VideoWidgetSurface + has functions for determining the video display rectangle, and painting + the video. + + \section1 VideoWidgetSurface Class Implementation + + \snippet examples/video/videowidget/videowidgetsurface.cpp 0 + + From the supportedPixelFormats() function we return a list of pixel formats + the surface can paint. The order of the list hints at which formats are + preferred by the surface. Assuming a 32-bit RGB backbuffer, we'd expect + that a 32-bit RGB type with no alpha to be fastest to paint so + QVideoFrame::Image_RGB32 is first in the list. + + Since we don't support rendering using any special frame handles we don't + return any pixel formats if handleType is not + QAbstractVideoBuffer::NoHandle. + + \snippet examples/video/videowidget/videowidgetsurface.cpp 1 + + In isFormatSupported() we test if the frame type of a surface format maps + to a valid QImage format, that the frame size is not empty, and the handle + type is QAbstractVideoBuffer::NoHandle. Note that the + QAbstractVideoSurface implementation of isFormatSupported() will verify + that the list of supported pixel formats returned by + \c supportedPixelFormats(format.handleType()) contains the pixel format and + that the size is not empty so a reimplementation wasn't strictly necessary + in this case. + + \snippet examples/video/videowidget/videowidgetsurface.cpp 2 + + To start our surface we'll extract the image format and size from the + selected video format and save it for use in the paint() function. If the + image format, or size are invalid then we'll set an error and return false. + Otherwise we'll save the format and confirm the surface has been started, + by calling QAbstractVideoSurface::start(). Finally since the video size may + have changed we'll trigger an update of the widget, and video geometry. + + \snippet examples/video/videowidget/videowidgetsurface.cpp 5 + + The updateVideoRect() function calculates the region within the widget the + video occupies. The \l {QVideoSurfaceFormat::sizeHint()}{size hint} of the + video format gives a suggested size for the video calculated from the + \l {QVideoSurfaceFormat::viewport()}{viewport} and + \l {QVideoSurfaceFormat::pixelAspectRatio()}{pixel aspect ratio}. If the + suggested size fits within the widget then we create a new rect of that + size in the center of the widget. Otherwise we shrink the size maintaining + the aspect ratio so that it does fit. + + \snippet examples/video/videowidget/videowidgetsurface.cpp 4 + + We can't paint from outside a paint event, so when a new frame is received + in present() we save a reference to it and force an immediate repaint of + the video region. We retain the saved reference to the frame after the + repaint so that the widget can be repainted between frame changes if + necessary. + + If the format of the frame doesn't match the surface format we can't paint + it or very likely any future frames. So we set an + \l {QAbstractVideoSurface::UnsupportedFormatError}{UnsupportedFormatError} + on our surface and stop it immediately. + + \snippet examples/video/videowidget/videowidgetsurface.cpp 6 + + The paint() function is called by the video widget to paint the current + video frame. Before we draw the frame first we'll check the format for + the scan line direction and if the scan lines are arranged from bottom to + top we'll flip the painter so the frame isn't drawn upside down. Then + using the image format information saved in the start() function we'll + construct a new QImage from the current video frame, and draw it to the + the widget. + + \snippet examples/video/videowidget/videowidgetsurface.cpp 3 + + When the surface is stopped we need to release the current frame and + invalidate the video region. Then we confirm the surface has been + stopped by calling QAbstractVideoSurface::stop() which sets the started + state to false and finally we update so the video widget so paints over + the last frame. + + \section1 VideoWidget Class Definition + + The VideoWidget class uses the VideoWidgetSurface class to implement a + video widget. + + \snippet examples/video/videowidget/videowidget.h 0 + + The VideoWidget QWidget implementation is minimal with just the sizeHint(), + paintEvent(), and resizeEvent() functions in addition to the constructor, + destructor and an instance of VideoWidgetSurface. + + \section1 VideoWidget Class Implementation + + \snippet examples/video/videowidget/videowidget.cpp 0 + + In the VideoWidget constructor we set some flags to speed up re-paints a + little. Setting the Qt::WA_NoSystemBackground flag and disabling automatic + background fills will stop Qt from a painting a background that'll be + completely obscured by the video. The Qt::WA_PaintOnScreen flag will + allow us to paint to the screen instead of the back buffer where supported. + + Next we set the background color to black, so that any borders around the + video are filled in black rather the default background color. + + Finally we construct an instance of the VideoWidgetSurface class. + + \snippet examples/video/videowidget/videowidget.cpp 1 + + In the destructor we simply delete the VideoWidgetSurface instance. + + \snippet examples/video/videowidget/videowidget.cpp 2 + + We get the size hint for the widget from the video format of the surface + which is calculated from viewport and pixel aspect ratio of the video + format. + + \snippet examples/video/videowidget/videowidget.cpp 3 + + When the video widget receives a paint event we first check if the surface + is started, if not then we simply fill the widget with the background + color. If it is then we draw a border around the video region clipped + by the paint region, before calling paint on the video surface to draw the + current frame. + + \snippet examples/video/videowidget/videowidget.cpp 4 + + The resizeEvent() function is reimplemented to trigger an update of the + video region when the widget is resized. +*/ diff --git a/doc/src/getting-started/examples.qdoc b/doc/src/getting-started/examples.qdoc index 253a4e4..b0d6bf6 100644 --- a/doc/src/getting-started/examples.qdoc +++ b/doc/src/getting-started/examples.qdoc @@ -796,6 +796,13 @@ \o \l{multimedia/audio/audioinput}{Audio Input} \endlist + \section1 Video Output + + \list + \o \l{video/videowidget}{Video Widget}\raisedaster + \o \l{video/videographicsitem}{Video Graphics Item} + \endlist + \section1 Phonon The Phonon Multimedia Framework brings multimedia support to Qt applications. diff --git a/doc/src/images/video-videographicsitem.png b/doc/src/images/video-videographicsitem.png new file mode 100644 index 0000000..e333c54 Binary files /dev/null and b/doc/src/images/video-videographicsitem.png differ diff --git a/doc/src/images/video-videowidget.png b/doc/src/images/video-videowidget.png new file mode 100644 index 0000000..a3c7bcb Binary files /dev/null and b/doc/src/images/video-videowidget.png differ diff --git a/examples/examples.pro b/examples/examples.pro index dc3b40f..6658fd3 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -39,8 +39,13 @@ symbian: SUBDIRS = \ uitools \ xml +contains(QT_CONFIG, multimedia) { + SUBDIRS += video + !static: SUBDIRS += multimedia +} + contains(QT_CONFIG, script): SUBDIRS += script -contains(QT_CONFIG, multimedia):!static: SUBDIRS += multimedia + contains(QT_CONFIG, phonon):!static: SUBDIRS += phonon contains(QT_CONFIG, webkit): SUBDIRS += webkit embedded:SUBDIRS += qws diff --git a/examples/video/video.pro b/examples/video/video.pro new file mode 100644 index 0000000..f0b63b6 --- /dev/null +++ b/examples/video/video.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + videographicsitem \ + videowidget + diff --git a/examples/video/videographicsitem/main.cpp b/examples/video/videographicsitem/main.cpp new file mode 100644 index 0000000..b80ac47 --- /dev/null +++ b/examples/video/videographicsitem/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videoplayer.h" + +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + VideoPlayer player; + player.show(); + + return app.exec(); +} + diff --git a/examples/video/videographicsitem/videographicsitem.pro b/examples/video/videographicsitem/videographicsitem.pro new file mode 100644 index 0000000..7e0b4c5 --- /dev/null +++ b/examples/video/videographicsitem/videographicsitem.pro @@ -0,0 +1,16 @@ +QT += multimedia + +contains(QT_CONFIG, opengl): QT += opengl + +HEADERS += videoplayer.h \ + videoitem.h + +SOURCES += main.cpp \ + videoplayer.cpp \ + videoitem.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/video/videographicsitem +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images +sources.path = $$[QT_INSTALL_EXAMPLES]/video/videographicsitem +INSTALLS += target sources diff --git a/examples/video/videographicsitem/videoitem.cpp b/examples/video/videographicsitem/videoitem.cpp new file mode 100644 index 0000000..6c17d6a --- /dev/null +++ b/examples/video/videographicsitem/videoitem.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videoitem.h" + +#include + +VideoItem::VideoItem(QGraphicsItem *parent) + : QGraphicsItem(parent) + , imageFormat(QImage::Format_Invalid) + , framePainted(false) +{ +} + +VideoItem::~VideoItem() +{ +} + +QRectF VideoItem::boundingRect() const +{ + return QRectF(QPointF(0,0), surfaceFormat().sizeHint()); +} + +void VideoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) { + const QTransform oldTransform = painter->transform(); + + if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) { + painter->scale(1, -1); + painter->translate(0, -boundingRect().height()); + } + + painter->drawImage(boundingRect(), QImage( + currentFrame.bits(), + imageSize.width(), + imageSize.height(), + imageFormat)); + + painter->setTransform(oldTransform); + + framePainted = true; + + currentFrame.unmap(); + } +} + +QList VideoItem::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + if (handleType == QAbstractVideoBuffer::NoHandle) { + return QList() + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_ARGB32_Premultiplied + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_RGB555; + } else { + return QList(); + } +} + +bool VideoItem::start(const QVideoSurfaceFormat &format) +{ + if (isFormatSupported(format)) { + imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); + imageSize = format.frameSize(); + framePainted = true; + + QAbstractVideoSurface::start(format); + + prepareGeometryChange(); + + return true; + } else { + return false; + } +} + +void VideoItem::stop() +{ + currentFrame = QVideoFrame(); + framePainted = false; + + QAbstractVideoSurface::stop(); +} + +bool VideoItem::present(const QVideoFrame &frame) +{ + if (!framePainted) { + if (!isStarted()) + setError(StoppedError); + + return false; + } else { + currentFrame = frame; + framePainted = false; + + update(); + + return true; + } +} diff --git a/examples/video/videographicsitem/videoitem.h b/examples/video/videographicsitem/videoitem.h new file mode 100644 index 0000000..868cd54 --- /dev/null +++ b/examples/video/videographicsitem/videoitem.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#ifndef VIDEOITEM_H +#define VIDEOITEM_H + +#include +#include + +class VideoItem + : public QAbstractVideoSurface, + public QGraphicsItem +{ + Q_OBJECT +public: + explicit VideoItem(QGraphicsItem *parentItem = 0); + ~VideoItem(); + + QRectF boundingRect() const; + void paint( + QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + + //video surface + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; + + bool start(const QVideoSurfaceFormat &format); + void stop(); + bool present(const QVideoFrame &frame); + +private: + QImage::Format imageFormat; + QSize imageSize; + + QVideoFrame currentFrame; + bool framePainted; +}; + +#endif + diff --git a/examples/video/videographicsitem/videoplayer.cpp b/examples/video/videographicsitem/videoplayer.cpp new file mode 100644 index 0000000..85a5527 --- /dev/null +++ b/examples/video/videographicsitem/videoplayer.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videoplayer.h" +#include "videoitem.h" + +#include + +#ifndef QT_NO_OPENGL +# include +#endif + +VideoPlayer::VideoPlayer(QWidget *parent, Qt::WindowFlags flags) + : QWidget(parent, flags) + , videoItem(0) + , playButton(0) + , positionSlider(0) +{ + connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(movieStateChanged(QMovie::MovieState))); + connect(&movie, SIGNAL(frameChanged(int)), + this, SLOT(frameChanged(int))); + + videoItem = new VideoItem; + + QGraphicsScene *scene = new QGraphicsScene(this); + QGraphicsView *graphicsView = new QGraphicsView(scene); + +#ifndef QT_NO_OPENGL + graphicsView->setViewport(new QGLWidget); +#endif + + scene->addItem(videoItem); + + QSlider *rotateSlider = new QSlider(Qt::Horizontal); + rotateSlider->setRange(-180, 180); + rotateSlider->setValue(0); + + connect(rotateSlider, SIGNAL(valueChanged(int)), + this, SLOT(rotateVideo(int))); + + QAbstractButton *openButton = new QPushButton(tr("Open...")); + connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + + playButton = new QPushButton; + playButton->setEnabled(false); + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + + connect(playButton, SIGNAL(clicked()), + this, SLOT(play())); + + positionSlider = new QSlider(Qt::Horizontal); + positionSlider->setRange(0, 0); + + connect(positionSlider, SIGNAL(sliderMoved(int)), + this, SLOT(setPosition(int))); + + connect(&movie, SIGNAL(frameChanged(int)), + positionSlider, SLOT(setValue(int))); + + QBoxLayout *controlLayout = new QHBoxLayout; + controlLayout->setMargin(0); + controlLayout->addWidget(openButton); + controlLayout->addWidget(playButton); + controlLayout->addWidget(positionSlider); + + QBoxLayout *layout = new QVBoxLayout; + layout->addWidget(graphicsView); + layout->addWidget(rotateSlider); + layout->addLayout(controlLayout); + + setLayout(layout); +} + +VideoPlayer::~VideoPlayer() +{ +} + +void VideoPlayer::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); + + if (!fileName.isEmpty()) { + if (videoItem->isStarted()) + videoItem->stop(); + + movie.setFileName(fileName); + + playButton->setEnabled(true); + positionSlider->setMaximum(movie.frameCount()); + + movie.jumpToFrame(0); + } +} + +void VideoPlayer::play() +{ + switch(movie.state()) { + case QMovie::NotRunning: + movie.start(); + break; + case QMovie::Paused: + movie.setPaused(false); + break; + case QMovie::Running: + movie.setPaused(true); + break; + } +} + +void VideoPlayer::movieStateChanged(QMovie::MovieState state) +{ + switch(state) { + case QMovie::NotRunning: + case QMovie::Paused: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + break; + case QMovie::Running: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + break; + } +} + +void VideoPlayer::frameChanged(int frame) +{ + if (!presentImage(movie.currentImage())) { + movie.stop(); + playButton->setEnabled(false); + positionSlider->setMaximum(0); + } else { + positionSlider->setValue(frame); + } +} + +void VideoPlayer::setPosition(int frame) +{ + movie.jumpToFrame(frame); +} + +void VideoPlayer::rotateVideo(int angle) +{ + //rotate around the center of video element + qreal x = videoItem->boundingRect().width() / 2.0; + qreal y = videoItem->boundingRect().height() / 2.0; + videoItem->setTransform(QTransform().translate(x, y).rotate(angle).translate(-x, -y)); +} + +bool VideoPlayer::presentImage(const QImage &image) +{ + QVideoFrame frame(image); + + if (!frame.isValid()) + return false; + + QVideoSurfaceFormat currentFormat = videoItem->surfaceFormat(); + + if (frame.pixelFormat() != currentFormat.pixelFormat() + || frame.size() != currentFormat.frameSize()) { + QVideoSurfaceFormat format(frame.size(), frame.pixelFormat()); + + if (!videoItem->start(format)) + return false; + } + + if (!videoItem->present(frame)) { + videoItem->stop(); + + return false; + } else { + return true; + } +} diff --git a/examples/video/videographicsitem/videoplayer.h b/examples/video/videographicsitem/videoplayer.h new file mode 100644 index 0000000..246f727 --- /dev/null +++ b/examples/video/videographicsitem/videoplayer.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#ifndef VIDEOPLAYER_H +#define VIDEOPLAYER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QAbstractButton; +class QAbstractVideoSurface; +class QSlider; +QT_END_NAMESPACE + + +class VideoItem; + +class VideoPlayer : public QWidget +{ + Q_OBJECT +public: + VideoPlayer(QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~VideoPlayer(); + + QSize sizeHint() const { return QSize(800, 600); } + +public slots: + void openFile(); + void play(); + +private slots: + void movieStateChanged(QMovie::MovieState state); + void frameChanged(int frame); + void setPosition(int frame); + void rotateVideo(int angle); + +private: + bool presentImage(const QImage &image); + + QMovie movie; + VideoItem *videoItem; + QAbstractButton *playButton; + QSlider *positionSlider; +}; + +#endif + diff --git a/examples/video/videowidget/main.cpp b/examples/video/videowidget/main.cpp new file mode 100644 index 0000000..4fba301 --- /dev/null +++ b/examples/video/videowidget/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videoplayer.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + VideoPlayer player; + player.show(); + + return app.exec(); +} diff --git a/examples/video/videowidget/videoplayer.cpp b/examples/video/videowidget/videoplayer.cpp new file mode 100644 index 0000000..2e4c758 --- /dev/null +++ b/examples/video/videowidget/videoplayer.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videoplayer.h" + +#include "videowidget.h" + +#include + +VideoPlayer::VideoPlayer(QWidget *parent) + : QWidget(parent) + , surface(0) + , playButton(0) + , positionSlider(0) +{ + connect(&movie, SIGNAL(stateChanged(QMovie::MovieState)), + this, SLOT(movieStateChanged(QMovie::MovieState))); + connect(&movie, SIGNAL(frameChanged(int)), + this, SLOT(frameChanged(int))); + + VideoWidget *videoWidget = new VideoWidget; + surface = videoWidget->videoSurface(); + + QAbstractButton *openButton = new QPushButton(tr("Open...")); + connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + + playButton = new QPushButton; + playButton->setEnabled(false); + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + + connect(playButton, SIGNAL(clicked()), + this, SLOT(play())); + + positionSlider = new QSlider(Qt::Horizontal); + positionSlider->setRange(0, 0); + + connect(positionSlider, SIGNAL(sliderMoved(int)), + this, SLOT(setPosition(int))); + + connect(&movie, SIGNAL(frameChanged(int)), + positionSlider, SLOT(setValue(int))); + + QBoxLayout *controlLayout = new QHBoxLayout; + controlLayout->setMargin(0); + controlLayout->addWidget(openButton); + controlLayout->addWidget(playButton); + controlLayout->addWidget(positionSlider); + + QBoxLayout *layout = new QVBoxLayout; + layout->addWidget(videoWidget); + layout->addLayout(controlLayout); + + setLayout(layout); +} + +VideoPlayer::~VideoPlayer() +{ +} + +void VideoPlayer::openFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie")); + + if (!fileName.isEmpty()) { + if (surface->isStarted()) + surface->stop(); + + movie.setFileName(fileName); + + playButton->setEnabled(true); + positionSlider->setMaximum(movie.frameCount()); + + movie.jumpToFrame(0); + } +} + +void VideoPlayer::play() +{ + switch(movie.state()) { + case QMovie::NotRunning: + movie.start(); + break; + case QMovie::Paused: + movie.setPaused(false); + break; + case QMovie::Running: + movie.setPaused(true); + break; + } +} + +void VideoPlayer::movieStateChanged(QMovie::MovieState state) +{ + switch(state) { + case QMovie::NotRunning: + case QMovie::Paused: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay)); + break; + case QMovie::Running: + playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause)); + break; + } +} + +void VideoPlayer::frameChanged(int frame) +{ + if (!presentImage(movie.currentImage())) { + movie.stop(); + playButton->setEnabled(false); + positionSlider->setMaximum(0); + } else { + positionSlider->setValue(frame); + } +} + +void VideoPlayer::setPosition(int frame) +{ + movie.jumpToFrame(frame); +} + +bool VideoPlayer::presentImage(const QImage &image) +{ + QVideoFrame frame(image); + + if (!frame.isValid()) + return false; + + QVideoSurfaceFormat currentFormat = surface->surfaceFormat(); + + if (frame.pixelFormat() != currentFormat.pixelFormat() + || frame.size() != currentFormat.frameSize()) { + QVideoSurfaceFormat format(frame.size(), frame.pixelFormat()); + + if (!surface->start(format)) + return false; + } + + if (!surface->present(frame)) { + surface->stop(); + + return false; + } else { + return true; + } +} diff --git a/examples/video/videowidget/videoplayer.h b/examples/video/videowidget/videoplayer.h new file mode 100644 index 0000000..76f3e9e --- /dev/null +++ b/examples/video/videowidget/videoplayer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#ifndef VIDEOPLAYER_H +#define VIDEOPLAYER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QAbstractButton; +class QAbstractVideoSurface; +class QSlider; +QT_END_NAMESPACE + +class VideoPlayer : public QWidget +{ + Q_OBJECT +public: + VideoPlayer(QWidget *parent = 0); + ~VideoPlayer(); + +public slots: + void openFile(); + void play(); + +private slots: + void movieStateChanged(QMovie::MovieState state); + void frameChanged(int frame); + void setPosition(int frame); + +private: + bool presentImage(const QImage &image); + + QMovie movie; + QAbstractVideoSurface *surface; + QAbstractButton *playButton; + QSlider *positionSlider; +}; + +#endif diff --git a/examples/video/videowidget/videowidget.cpp b/examples/video/videowidget/videowidget.cpp new file mode 100644 index 0000000..b29d2ae --- /dev/null +++ b/examples/video/videowidget/videowidget.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videowidget.h" + +#include "videowidgetsurface.h" + +#include + +//! [0] +VideoWidget::VideoWidget(QWidget *parent) + : QWidget(parent) + , surface(0) +{ + setAutoFillBackground(false); + setAttribute(Qt::WA_NoSystemBackground, true); + setAttribute(Qt::WA_PaintOnScreen, true); + + QPalette palette = this->palette(); + palette.setColor(QPalette::Background, Qt::black); + setPalette(palette); + + setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + + surface = new VideoWidgetSurface(this); +} +//! [0] + +//! [1] +VideoWidget::~VideoWidget() +{ + delete surface; +} +//! [1] + +//! [2] +QSize VideoWidget::sizeHint() const +{ + return surface->surfaceFormat().sizeHint(); +} +//! [2] + + +//! [3] +void VideoWidget::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + + if (surface->isStarted()) { + const QRect videoRect = surface->videoRect(); + + if (!videoRect.contains(event->rect())) { + QRegion region = event->region(); + region.subtract(videoRect); + + QBrush brush = palette().background(); + + foreach (const QRect &rect, region.rects()) + painter.fillRect(rect, brush); + } + + surface->paint(&painter); + } else { + painter.fillRect(event->rect(), palette().background()); + } +} +//! [3] + +//! [4] +void VideoWidget::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); + + surface->updateVideoRect(); +} +//! [4] diff --git a/examples/video/videowidget/videowidget.h b/examples/video/videowidget/videowidget.h new file mode 100644 index 0000000..737d32d --- /dev/null +++ b/examples/video/videowidget/videowidget.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#ifndef VIDEOWIDGET_H +#define VIDEOWIDGET_H + +#include "videowidgetsurface.h" + +#include + +QT_BEGIN_NAMESPACE +class QAbstractVideoSurface; +QT_END_NAMESPACE + +class VideoWidgetSurface; + +//! [0] +class VideoWidget : public QWidget +{ + Q_OBJECT +public: + VideoWidget(QWidget *parent = 0); + ~VideoWidget(); + + QAbstractVideoSurface *videoSurface() const { return surface; } + + QSize sizeHint() const; + +protected: + void paintEvent(QPaintEvent *event); + void resizeEvent(QResizeEvent *event); + +private: + VideoWidgetSurface *surface; +}; +//! [0] + +#endif diff --git a/examples/video/videowidget/videowidget.pro b/examples/video/videowidget/videowidget.pro new file mode 100644 index 0000000..a006f2f --- /dev/null +++ b/examples/video/videowidget/videowidget.pro @@ -0,0 +1,14 @@ +TEMPLATE = app + +QT += multimedia + +HEADERS = \ + videoplayer.h \ + videowidget.h \ + videowidgetsurface.h + +SOURCES = \ + main.cpp \ + videoplayer.cpp \ + videowidget.cpp \ + videowidgetsurface.cpp diff --git a/examples/video/videowidget/videowidgetsurface.cpp b/examples/video/videowidget/videowidgetsurface.cpp new file mode 100644 index 0000000..6089b6f --- /dev/null +++ b/examples/video/videowidget/videowidgetsurface.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "videowidgetsurface.h" + +#include + +VideoWidgetSurface::VideoWidgetSurface(QWidget *widget, QObject *parent) + : QAbstractVideoSurface(parent) + , widget(widget) + , imageFormat(QImage::Format_Invalid) +{ +} + +//! [0] +QList VideoWidgetSurface::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + if (handleType == QAbstractVideoBuffer::NoHandle) { + return QList() + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_ARGB32_Premultiplied + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_RGB555; + } else { + return QList(); + } +} +//! [0] + +//! [1] +bool VideoWidgetSurface::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const +{ + Q_UNUSED(similar); + + const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); + const QSize size = format.frameSize(); + + return imageFormat != QImage::Format_Invalid + && !size.isEmpty() + && format.handleType() == QAbstractVideoBuffer::NoHandle; +} +//! [1] + +//! [2] +bool VideoWidgetSurface::start(const QVideoSurfaceFormat &format) +{ + const QImage::Format imageFormat = QVideoFrame::equivalentImageFormat(format.pixelFormat()); + const QSize size = format.frameSize(); + + if (imageFormat != QImage::Format_Invalid && !size.isEmpty()) { + this->imageFormat = imageFormat; + imageSize = size; + sourceRect = format.viewport(); + + QAbstractVideoSurface::start(format); + + widget->updateGeometry(); + updateVideoRect(); + + return true; + } else { + return false; + } +} +//! [2] + +//! [3] +void VideoWidgetSurface::stop() +{ + currentFrame = QVideoFrame(); + targetRect = QRect(); + + QAbstractVideoSurface::stop(); + + widget->update(); +} +//! [3] + +//! [4] +bool VideoWidgetSurface::present(const QVideoFrame &frame) +{ + if (surfaceFormat().pixelFormat() != frame.pixelFormat() + || surfaceFormat().frameSize() != frame.size()) { + setError(IncorrectFormatError); + stop(); + + return false; + } else { + currentFrame = frame; + + widget->repaint(targetRect); + + return true; + } +} +//! [4] + +//! [5] +void VideoWidgetSurface::updateVideoRect() +{ + QSize size = surfaceFormat().sizeHint(); + size.scale(widget->size().boundedTo(size), Qt::KeepAspectRatio); + + targetRect = QRect(QPoint(0, 0), size); + targetRect.moveCenter(widget->rect().center()); +} +//! [5] + +//! [6] +void VideoWidgetSurface::paint(QPainter *painter) +{ + if (currentFrame.map(QAbstractVideoBuffer::ReadOnly)) { + const QTransform oldTransform = painter->transform(); + + if (surfaceFormat().scanLineDirection() == QVideoSurfaceFormat::BottomToTop) { + painter->scale(1, -1); + painter->translate(0, -widget->height()); + } + + QImage image( + currentFrame.bits(), + currentFrame.width(), + currentFrame.height(), + currentFrame.bytesPerLine(), + imageFormat); + + painter->drawImage(targetRect, image, sourceRect); + + painter->setTransform(oldTransform); + + currentFrame.unmap(); + } +} +//! [6] diff --git a/examples/video/videowidget/videowidgetsurface.h b/examples/video/videowidget/videowidgetsurface.h new file mode 100644 index 0000000..56ba329 --- /dev/null +++ b/examples/video/videowidget/videowidgetsurface.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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$ +** +****************************************************************************/ + +#ifndef VIDEOWIDGETSURFACE_H +#define VIDEOWIDGETSURFACE_H + +#include +#include +#include +#include + +//! [0] +class VideoWidgetSurface : public QAbstractVideoSurface +{ + Q_OBJECT +public: + VideoWidgetSurface(QWidget *widget, QObject *parent = 0); + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; + bool isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; + + bool start(const QVideoSurfaceFormat &format); + void stop(); + + bool present(const QVideoFrame &frame); + + QRect videoRect() const { return targetRect; } + void updateVideoRect(); + + void paint(QPainter *painter); + +private: + QWidget *widget; + QImage::Format imageFormat; + QRect targetRect; + QSize imageSize; + QRect sourceRect; + QVideoFrame currentFrame; +}; +//! [0] + +#endif diff --git a/mkspecs/features/qt.prf b/mkspecs/features/qt.prf index 6de19c3..b3d6a5f 100644 --- a/mkspecs/features/qt.prf +++ b/mkspecs/features/qt.prf @@ -36,7 +36,7 @@ INCLUDEPATH = $$QMAKE_INCDIR_QT $$INCLUDEPATH #prepending prevents us from picki win32:INCLUDEPATH += $$QMAKE_INCDIR_QT/ActiveQt # As order does matter for static libs, we reorder the QT variable here -TMPLIBS = multimedia webkit phonon dbus testlib script scripttools svg qt3support sql xmlpatterns xml egl opengl openvg gui network core +TMPLIBS = webkit phonon multimedia dbus testlib script scripttools svg qt3support sql xmlpatterns xml egl opengl openvg gui network core for(QTLIB, $$list($$TMPLIBS)) { contains(QT, $$QTLIB): QT_ORDERED += $$QTLIB } diff --git a/src/multimedia/multimedia.pro b/src/multimedia/multimedia.pro index 7d38afa..53fcb49 100644 --- a/src/multimedia/multimedia.pro +++ b/src/multimedia/multimedia.pro @@ -1,11 +1,12 @@ -TARGET = QtMultimedia -QPRO_PWD = $$PWD -QT = core -DEFINES += QT_BUILD_MULTIMEDIA_LIB +TARGET = QtMultimedia +QPRO_PWD = $$PWD +QT = core gui -win32-msvc*:QMAKE_LIBS += $$QMAKE_LIBS_CORE +DEFINES += QT_BUILD_MULTIMEDIA_LIB QT_NO_USING_NAMESPACE -unix:QMAKE_PKGCONFIG_REQUIRES = QtCore +unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui include(../qbase.pri) + include(audio/audio.pri) +include(video/video.pri) diff --git a/src/multimedia/video/qabstractvideobuffer.cpp b/src/multimedia/video/qabstractvideobuffer.cpp new file mode 100644 index 0000000..702b9a0 --- /dev/null +++ b/src/multimedia/video/qabstractvideobuffer.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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 "qabstractvideobuffer_p.h" + +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QAbstractVideoBuffer + \brief The QAbstractVideoBuffer class is an abstraction for video data. + \preliminary + \since 4.6 + + The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of + video data. Creating a subclass of QAbstractVideoBuffer will allow you to construct video + frames from preallocated or static buffers. + + The contents of a buffer can be accessed by mapping the buffer to memory using the map() + function which returns a pointer to memory containing the contents of the the video buffer. + The memory returned by map() is released by calling the unmap() function. + + The handle() of a buffer may also be used to manipulate it's contents using type specific APIs. + The type of a buffer's handle is given by the handleType() function. + + \sa QVideoFrame +*/ + +/*! + \enum QAbstractVideoBuffer::HandleType + + Identifies the type of a video buffers handle. + + \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer. + \value GLTextureHandle The handle of the buffer is an OpenGL texture ID. + \value UserHandle Start value for user defined handle types. + + \sa handleType() +*/ + +/*! + \enum QAbstractVideoBuffer::MapMode + + Enumerates how a video buffer's data is mapped to memory. + + \value NotMapped The video buffer has is not mapped to memory. + \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but + the content of the mapped memory may be discarded when unmapped. + \value WriteOnly The mapped memory in unitialized when mapped, and the content will be used to + populate the video buffer when unmapped. + \value ReadWrite The mapped memory is populated with data from the video buffer, and the + video buffer is repopulated with the content of the mapped memory. + + \sa mapMode(), map() +*/ + +/*! + Constructs an abstract video buffer of the given \a type. +*/ + +QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type) + : d_ptr(new QAbstractVideoBufferPrivate) +{ + Q_D(QAbstractVideoBuffer); + + d->handleType = type; +} + +/*! + \internal +*/ + +QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type) + : d_ptr(&dd) +{ + Q_D(QAbstractVideoBuffer); + + d->handleType = type; +} + +/*! + Destroys an abstract video buffer. +*/ + +QAbstractVideoBuffer::~QAbstractVideoBuffer() +{ + delete d_ptr; +} + +/*! + Returns the type of a video buffer's handle. + + \sa handle() +*/ + +QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const +{ + return d_func()->handleType; +} + +/*! + \fn QAbstractVideoBuffer::mapMode() const + + Returns the mode a video buffer is mapped in. + + \sa map() +*/ + +/*! + \fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) + + Maps the contents of a video buffer to memory. + + The map \a mode indicates whether the contents of the mapped memory should be read from and/or + written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the + mapped memory will be populated with the content of the video buffer when mapped. If the map + mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be + persisted in the buffer when unmapped. + + When access to the data is no longer needed be sure to call the unmap() function to release the + mapped memory. + + Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The + size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a + bytesPerLine. + + When access to the data is no longer needed be sure to unmap() the buffer. + + \note Writing to memory that is mapped as read-only is undefined, and may result in changes + to shared data. + + \sa unmap(), mapMode() +*/ + +/*! + \fn QAbstractVideoBuffer::unmap() + + Releases the memory mapped by the map() function + + If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly + flag this will persist the current content of the mapped memory to the video frame. + + \sa map() +*/ + +/*! + Returns a type specific handle to the data buffer. + + The type of the handle is given by handleType() function. + + \sa handleType() +*/ + +QVariant QAbstractVideoBuffer::handle() const +{ + return QVariant(); +} + + +QT_END_NAMESPACE diff --git a/src/multimedia/video/qabstractvideobuffer.h b/src/multimedia/video/qabstractvideobuffer.h new file mode 100644 index 0000000..3ffb87a --- /dev/null +++ b/src/multimedia/video/qabstractvideobuffer.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOBUFFER_H +#define QABSTRACTVIDEOBUFFER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QVariant; + +class QAbstractVideoBufferPrivate; + +class Q_MULTIMEDIA_EXPORT QAbstractVideoBuffer +{ +public: + enum HandleType + { + NoHandle, + GLTextureHandle, + UserHandle = 1000 + }; + + enum MapMode + { + NotMapped = 0x00, + ReadOnly = 0x01, + WriteOnly = 0x02, + ReadWrite = ReadOnly | WriteOnly + }; + + QAbstractVideoBuffer(HandleType type); + virtual ~QAbstractVideoBuffer(); + + HandleType handleType() const; + + virtual MapMode mapMode() const = 0; + + virtual uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) = 0; + virtual void unmap() = 0; + + virtual QVariant handle() const; + +protected: + QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type); + + QAbstractVideoBufferPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QAbstractVideoBuffer) + Q_DISABLE_COPY(QAbstractVideoBuffer) +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QAbstractVideoBuffer::HandleType) +Q_DECLARE_METATYPE(QAbstractVideoBuffer::MapMode) + +QT_END_HEADER + +#endif diff --git a/src/multimedia/video/qabstractvideobuffer_p.h b/src/multimedia/video/qabstractvideobuffer_p.h new file mode 100644 index 0000000..afe22b3 --- /dev/null +++ b/src/multimedia/video/qabstractvideobuffer_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOBUFFER_P_H +#define QABSTRACTVIDEOBUFFER_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 +#include + +QT_BEGIN_NAMESPACE + +class QAbstractVideoBufferPrivate +{ +public: + QAbstractVideoBufferPrivate() + : handleType(QAbstractVideoBuffer::NoHandle) + {} + + QAbstractVideoBuffer::HandleType handleType; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/video/qabstractvideosurface.cpp b/src/multimedia/video/qabstractvideosurface.cpp new file mode 100644 index 0000000..5309e57 --- /dev/null +++ b/src/multimedia/video/qabstractvideosurface.cpp @@ -0,0 +1,268 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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 "qabstractvideosurface_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QAbstractVideoSurface + \brief The QAbstractVideoSurface class is a base class for video presentation surfaces. + \preliminary + \since 4.6 + + The QAbstractVideoSurface class defines the standard interface that video producers use to + inter-operate with video presentation surfaces. It is not supposed to be instantiated directly. + Instead, you should subclass it to create new video surfaces. + + A video surface presents a continuous stream of identically formatted frames, where the format + of each frame is compatible with a stream format supplied when starting a presentation. + + A list of pixel formats a surface can present is given by the supportedPixelFormats() function, + and the isFormatSupported() function will test if a complete video format is supported. In + some cases when a format is not supported; isFormatSupported() may suggest a similar format. + For example if a surface supports fixed set of resolutions it may suggest the smallest + supported resolution that contains the proposed resolution. + + The start() function takes a supported format and enables a video surface. Once started a + surface will begin displaying the frames it receives in the present() function. Surfaces may + hold a reference to the buffer of a presented video frame until a new frame is presented or + streaming is stopped. The stop() function will disable a surface and a release any video + buffers it holds references to. +*/ + +/*! + \enum QAbstractVideoSurface::Error + This enum describes the errors that may be returned by the error() function. + + \value NoError No error occurred. + \value UnsupportedFormatError A video format was not supported. + \value IncorrectFormatError A video frame was not compatible with the format of the surface. + \value StoppedError The surface has not been started. + \value ResourceError The surface could not allocate some resource. +*/ + +/*! + Constructs a video surface with the given \a parent. +*/ + +QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent) + : QObject(*new QAbstractVideoSurfacePrivate, parent) +{ +} + +/*! + \internal +*/ + +QAbstractVideoSurface::QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + +/*! + Destroys a video surface. +*/ + +QAbstractVideoSurface::~QAbstractVideoSurface() +{ +} + +/*! + \fn QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const + + Returns a list of pixel formats a video surface can present for a given handle \a type. + + The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer + that can be mapped in read-only mode. + + Types that are first in the list can be assumed to be faster to render. +*/ + +/*! + Tests a video \a format to determine if a surface can accept it. If the format isn't supported + the surface may suggest a \a similar format that is supported. + + Returns true if the format is supported by the surface, and false otherwise. +*/ + +bool QAbstractVideoSurface::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const +{ + Q_UNUSED(similar); + + return supportedPixelFormats(format.handleType()).contains(format.pixelFormat()); +} + +/*! + \fn QAbstractVideoSurface::supportedFormatsChanged() + + Signals that the set of formats supported by a video surface has changed. + + \sa supportedPixelFormats(), isFormatSupported() +*/ + +/*! + Returns the format of a video surface. +*/ + +QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const +{ + return d_func()->format; +} + +/*! + \fn QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format) + + Signals that the configured \a format of a video surface has changed. + + \sa surfaceFormat(), start() +*/ + +/*! + Starts a video surface presenting \a format frames. + + Returns true if the surface was started, and false if an error occurred. + + \sa isStarted(), stop() +*/ + +bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) +{ + Q_D(QAbstractVideoSurface); + + bool wasStarted = d->started; + + d->started = true; + d->format = format; + d->error = NoError; + + emit surfaceFormatChanged(d->format); + + if (!wasStarted) + emit startedChanged(true); + + return true; +} + +/*! + Stops a video surface presenting frames and releases any resources acquired in start(). + + \sa isStarted(), start() +*/ + +void QAbstractVideoSurface::stop() +{ + Q_D(QAbstractVideoSurface); + + if (d->started) { + d->format = QVideoSurfaceFormat(); + d->started = false; + + emit startedChanged(false); + emit surfaceFormatChanged(d->format); + } +} + +/*! + Indicates whether a video surface has been started. + + Returns true if the surface has been started, and false otherwise. +*/ + +bool QAbstractVideoSurface::isStarted() const +{ + return d_func()->started; +} + +/*! + \fn QAbstractVideoSurface::startedChanged(bool started) + + Signals that the \a started state of a video surface has changed. + + \sa isStarted(), start(), stop() +*/ + +/*! + \fn QAbstractVideoSurface::present(const QVideoFrame &frame) + + Presents a video \a frame. + + Returns true if the frame was presented, and false if an error occurred. + + Not all surfaces will block until the presentation of a frame has completed. Calling present() + on a non-blocking surface may fail if called before the presentation of a previous frame has + completed. In such cases the surface may not return to a ready state until it's had an + opportunity to process events. + + If present() fails for any other reason the surface will immediately enter the stopped state + and an error() value will be set. + + A video surface must be in the started state for present() to succeed, and the format of the + video frame must be compatible with the current video surface format. + + \sa error() +*/ + +/*! + Returns the last error that occurred. + + If a surface fails to start(), or stops unexpectedly this function can be called to discover + what error occurred. +*/ + +QAbstractVideoSurface::Error QAbstractVideoSurface::error() const +{ + return d_func()->error; +} + +/*! + Sets the value of error() to \a error. +*/ + +void QAbstractVideoSurface::setError(Error error) +{ + Q_D(QAbstractVideoSurface); + + d->error = error; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/video/qabstractvideosurface.h b/src/multimedia/video/qabstractvideosurface.h new file mode 100644 index 0000000..78831f0 --- /dev/null +++ b/src/multimedia/video/qabstractvideosurface.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOSURFACE_H +#define QABSTRACTVIDEOSURFACE_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QRectF; +class QVideoSurfaceFormat; + +class QAbstractVideoSurfacePrivate; + +class Q_MULTIMEDIA_EXPORT QAbstractVideoSurface : public QObject +{ + Q_OBJECT + +public: + enum Error + { + NoError, + UnsupportedFormatError, + IncorrectFormatError, + StoppedError, + ResourceError + }; + + explicit QAbstractVideoSurface(QObject *parent = 0); + ~QAbstractVideoSurface(); + + virtual QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const = 0; + virtual bool isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar = 0) const; + + QVideoSurfaceFormat surfaceFormat() const; + + virtual bool start(const QVideoSurfaceFormat &format); + virtual void stop(); + + bool isStarted() const; + + virtual bool present(const QVideoFrame &frame) = 0; + + Error error() const; + +Q_SIGNALS: + void startedChanged(bool started); + void surfaceFormatChanged(const QVideoSurfaceFormat &format); + void supportedFormatsChanged(); + +protected: + QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent); + + void setError(Error error); + +private: + Q_DECLARE_PRIVATE(QAbstractVideoSurface) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/video/qabstractvideosurface_p.h b/src/multimedia/video/qabstractvideosurface_p.h new file mode 100644 index 0000000..e401102 --- /dev/null +++ b/src/multimedia/video/qabstractvideosurface_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOSURFACE_P_H +#define QABSTRACTVIDEOSURFACE_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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QAbstractVideoSurfacePrivate : public QObjectPrivate +{ +public: + QAbstractVideoSurfacePrivate() + : error(QAbstractVideoSurface::NoError) + , started(false) + { + } + + mutable QAbstractVideoSurface::Error error; + QVideoSurfaceFormat format; + bool started; + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp new file mode 100644 index 0000000..d63f145 --- /dev/null +++ b/src/multimedia/video/qimagevideobuffer.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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 "qimagevideobuffer_p.h" + +#include + +#include +#include + +class QImageVideoBufferPrivate : public QAbstractVideoBufferPrivate +{ +public: + QImageVideoBufferPrivate() + : mapMode(QAbstractVideoBuffer::NotMapped) + { + } + + QAbstractVideoBuffer::MapMode mapMode; + QImage image; +}; + +QImageVideoBuffer::QImageVideoBuffer(const QImage &image) + : QAbstractVideoBuffer(*new QImageVideoBufferPrivate, NoHandle) +{ + Q_D(QImageVideoBuffer); + + d->image = image; +} + +QImageVideoBuffer::~QImageVideoBuffer() +{ +} + +QAbstractVideoBuffer::MapMode QImageVideoBuffer::mapMode() const +{ + return d_func()->mapMode; +} + +uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) +{ + Q_D(QImageVideoBuffer); + + if (d->mapMode == NotMapped && d->image.bits() && mode != NotMapped) { + d->mapMode = mode; + + if (numBytes) + *numBytes = d->image.numBytes(); + + if (bytesPerLine) + *bytesPerLine = d->image.bytesPerLine(); + + return d->image.bits(); + } else { + return 0; + } +} + +void QImageVideoBuffer::unmap() +{ + Q_D(QImageVideoBuffer); + + d->mapMode = NotMapped; +} diff --git a/src/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/video/qimagevideobuffer_p.h new file mode 100644 index 0000000..dcbc0b3 --- /dev/null +++ b/src/multimedia/video/qimagevideobuffer_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#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 + +QT_BEGIN_NAMESPACE + +class QImage; + +class QImageVideoBufferPrivate; + +class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer +{ + Q_DECLARE_PRIVATE(QImageVideoBuffer) +public: + QImageVideoBuffer(const QImage &image); + ~QImageVideoBuffer(); + + MapMode mapMode() const; + + uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); + void unmap(); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/video/qmemoryvideobuffer.cpp b/src/multimedia/video/qmemoryvideobuffer.cpp new file mode 100644 index 0000000..f457820 --- /dev/null +++ b/src/multimedia/video/qmemoryvideobuffer.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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 "qmemoryvideobuffer_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QMemoryVideoBufferPrivate : public QAbstractVideoBufferPrivate +{ +public: + QMemoryVideoBufferPrivate() + : bytesPerLine(0) + , mapMode(QAbstractVideoBuffer::NotMapped) + { + } + + int bytesPerLine; + QAbstractVideoBuffer::MapMode mapMode; + QByteArray data; +}; + +/*! + \class QMemoryVideoBuffer + \brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer. + \internal + + QMemoryVideoBuffer is the default video buffer for allocating system memory. It may be used to + allocate memory for a QVideoFrame without implementing your own QAbstractVideoBuffer. +*/ + +/*! + Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array. +*/ +QMemoryVideoBuffer::QMemoryVideoBuffer(const QByteArray &array, int bytesPerLine) + : QAbstractVideoBuffer(*new QMemoryVideoBufferPrivate, NoHandle) +{ + Q_D(QMemoryVideoBuffer); + + d->data = array; + d->bytesPerLine = bytesPerLine; +} + +/*! + Destroys a system memory allocated video buffer. +*/ +QMemoryVideoBuffer::~QMemoryVideoBuffer() +{ +} + +/*! + \reimp +*/ +QAbstractVideoBuffer::MapMode QMemoryVideoBuffer::mapMode() const +{ + return d_func()->mapMode; +} + +/*! + \reimp +*/ +uchar *QMemoryVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) +{ + Q_D(QMemoryVideoBuffer); + + if (d->mapMode == NotMapped && d->data.data() && mode != NotMapped) { + d->mapMode = mode; + + if (numBytes) + *numBytes = d->data.size(); + + if (bytesPerLine) + *bytesPerLine = d->bytesPerLine; + + return reinterpret_cast(d->data.data()); + } else { + return 0; + } +} + +/*! + \reimp +*/ +void QMemoryVideoBuffer::unmap() +{ + d_func()->mapMode = NotMapped; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/video/qmemoryvideobuffer_p.h b/src/multimedia/video/qmemoryvideobuffer_p.h new file mode 100644 index 0000000..e84c4a1 --- /dev/null +++ b/src/multimedia/video/qmemoryvideobuffer_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QMEMORYVIDEOBUFFER_P_H +#define QMEMORYVIDEOBUFFER_P_H + +#include + +// +// 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. +// + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMemoryVideoBufferPrivate; + +class Q_MULTIMEDIA_EXPORT QMemoryVideoBuffer : public QAbstractVideoBuffer +{ + Q_DECLARE_PRIVATE(QMemoryVideoBuffer) +public: + QMemoryVideoBuffer(const QByteArray &data, int bytesPerLine); + ~QMemoryVideoBuffer(); + + MapMode mapMode() const; + + uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); + void unmap(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp new file mode 100644 index 0000000..c3584b7 --- /dev/null +++ b/src/multimedia/video/qvideoframe.cpp @@ -0,0 +1,742 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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 "qvideoframe.h" + +#include +#include + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QVideoFramePrivate : public QSharedData +{ +public: + QVideoFramePrivate() + : startTime(-1) + , endTime(-1) + , data(0) + , numBytes(0) + , bytesPerLine(0) + , pixelFormat(QVideoFrame::Format_Invalid) + , fieldType(QVideoFrame::ProgressiveFrame) + , buffer(0) + { + } + + QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format) + : size(size) + , startTime(-1) + , endTime(-1) + , data(0) + , numBytes(0) + , bytesPerLine(0) + , pixelFormat(format) + , fieldType(QVideoFrame::ProgressiveFrame) + , buffer(0) + { + } + + ~QVideoFramePrivate() + { + delete buffer; + } + + QSize size; + qint64 startTime; + qint64 endTime; + uchar *data; + int numBytes; + int bytesPerLine; + QVideoFrame::PixelFormat pixelFormat; + QVideoFrame::FieldType fieldType; + QAbstractVideoBuffer *buffer; + +private: + Q_DISABLE_COPY(QVideoFramePrivate) +}; + +/*! + \class QVideoFrame + \brief The QVideoFrame class provides a representation of a frame of video data. + \preliminary + \since 4.6 + + A QVideoFrame encapsulates the data of a video frame, and information about the frame. + + The contents of a video frame can be mapped to memory using the map() function. While + mapped the video data can accessed using the bits() function which returns a pointer to a + buffer, the total size of which is given by the numBytes(), and the size of each line is given + by bytesPerLine(). The return value of the handle() function may be used to access frame data + using the internal buffer's native APIs. + + The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame + may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class. + + \note QVideoFrame is explicitly shared, any change made to video frame will also apply to any + copies. +*/ + +/*! + \enum QVideoFrame::PixelFormat + + Enumerates video data types. + + \value Format_Invalid + The frame is invalid. + + \value Format_ARGB32 + The frame is stored using a 32-bit ARGB format (0xAARRGGBB). This is equivalent to + QImage::Format_ARGB32. + + \value Format_ARGB32_Premultiplied + The frame stored using a premultiplied 32-bit ARGB format (0xAARRGGBB). This is equivalent + to QImage::Format_ARGB32_Premultiplied. + + \value Format_RGB32 + The frame stored using a 32-bit RGB format (0xffRRGGBB). This is equivalent to + QImage::Format_RGB32 + + \value Format_RGB24 + The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to + QImage::Format_RGB888 + + \value Format_RGB565 + The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to + QImage::Format_RGB16. + + \value Format_RGB555 + The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to + QImage::Format_RGB555. + + \value Format_ARGB8565_Premultiplied + The frame is stored using a 24-bit premultiplied ARGB format (8-6-6-5). + + \value Format_BGRA32 + The frame is stored using a 32-bit ARGB format (0xBBGGRRAA). + + \value Format_BGRA32_Premultiplied + The frame is stored using a premultiplied 32bit BGRA format. + + \value Format_BGR32 + The frame is stored using a 32-bit BGR format (0xBBGGRRff). + + \value Format_BGR24 + The frame is stored using a 24-bit BGR format (0xBBGGRR). + + \value Format_BGR565 + The frame is stored using a 16-bit BGR format (5-6-5). + + \value Format_BGR555 + The frame is stored using a 16-bit BGR format (5-5-5). + + \value Format_BGRA5658_Premultiplied + The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8). + + \value Format_AYUV444 + The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV). + + \value Format_AYUV444_Premultiplied + The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV). + + \value Format_YUV444 + The frame is stored using a 24-bit packed YUV format (8-8-8). + + \value Format_YUV420P + The frame is stored using an 8-bit per component planar YUV format with the U and V planes + horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are + half that of the Y plane. + + \value Format_YV12 + The frame is stored using an 8-bit per component planar YVU format with the V and U planes + horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are + half that of the Y plane. + + \value Format_UYVY + The frame is stored using an 8-bit per component packed YUV format with the U and V planes + horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit + macropixel which has a Y value for each pixel and common U and V values. + + \value Format_YUYV + The frame is stored using an 8-bit per component packed YUV format with the U and V planes + horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit + macropixel which has a Y value for each pixel and common U and V values. + + \value Format_NV12 + The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) + followed by a horizontally and vertically sub-sampled, packed UV plane (U-V). + + \value Format_NV21 + The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) + followed by a horizontally and vertically sub-sampled, packed VU plane (V-U). + + \value Format_IMC1 + The frame is stored using an 8-bit per component planar YUV format with the U and V planes + horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except + that the bytes per line of the U and V planes are padded out to the same stride as the Y plane. + + \value Format_IMC2 + The frame is stored using an 8-bit per component planar YUV format with the U and V planes + horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except + that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a + line of V data creating a single line of the same stride as the Y data. + + \value Format_IMC3 + The frame is stored using an 8-bit per component planar YVU format with the V and U planes + horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that + the bytes per line of the V and U planes are padded out to the same stride as the Y plane. + + \value Format_IMC4 + The frame is stored using an 8-bit per component planar YVU format with the V and U planes + horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that + the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line + of U data creating a single line of the same stride as the Y data. + + \value Format_Y8 + The frame is stored using an 8-bit greyscale format. + + \value Format_Y16 + The frame is stored using a 16-bit linear greyscale format. Little endian. + + \value Format_User + Start value for user defined pixel formats. +*/ + +/*! + \enum QVideoFrame::FieldType + + Specifies the field an interlaced video frame belongs to. + + \value ProgressiveFrame The frame is not interlaced. + \value TopField The frame contains a top field. + \value BottomField The frame contains a bottom field. + \value InterlacedFrame The frame contains a merged top and bottom field. +*/ + +/*! + Constructs a null video frame. +*/ + +QVideoFrame::QVideoFrame() + : d(new QVideoFramePrivate) +{ +} + +/*! + Constructs a video frame from a \a buffer of the given pixel \a format and \a size in pixels. + + \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)) +{ + d->buffer = buffer; +} + +/*! + Constructs a video frame of the given pixel \a format and \a size in pixels. + + 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)) +{ + if (bytes > 0) { + QByteArray data; + data.resize(bytes); + + // Check the memory was successfully allocated. + if (!data.isEmpty()) + d->buffer = new QMemoryVideoBuffer(data, bytesPerLine); + } +} + +/*! + 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 equivalentPixelFormat() +*/ + +QVideoFrame::QVideoFrame(const QImage &image) + : d(new QVideoFramePrivate( + image.size(), equivalentPixelFormat(image.format()))) +{ + if (d->pixelFormat != Format_Invalid) + d->buffer = new QImageVideoBuffer(image); +} + +/*! + Constructs a copy of \a other. +*/ + +QVideoFrame::QVideoFrame(const QVideoFrame &other) + : d(other.d) +{ +} + +/*! + Assigns the contents of \a other to a video frame. +*/ + +QVideoFrame &QVideoFrame::operator =(const QVideoFrame &other) +{ + d = other.d; + + return *this; +} + +/*! + Destroys a video frame. +*/ + +QVideoFrame::~QVideoFrame() +{ +} + +/*! + Identifies whether a video frame is valid. + + An invalid frame has no video buffer associated with it. + + Returns true if the frame is valid, and false if it is not. +*/ + +bool QVideoFrame::isValid() const +{ + return d->buffer != 0; +} + +/*! + Returns the color format of a video frame. +*/ + +QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const +{ + return d->pixelFormat; +} + +/*! + Returns the type of a video frame's handle. +*/ + +QAbstractVideoBuffer::HandleType QVideoFrame::handleType() const +{ + return d->buffer ? d->buffer->handleType() : QAbstractVideoBuffer::NoHandle; +} + +/*! + Returns the size of a video frame. +*/ + +QSize QVideoFrame::size() const +{ + return d->size; +} + +/*! + Returns the width of a video frame. +*/ + +int QVideoFrame::width() const +{ + return d->size.width(); +} + +/*! + Returns the height of a video frame. +*/ + +int QVideoFrame::height() const +{ + return d->size.height(); +} + +/*! + Returns the field an interlaced video frame belongs to. + + If the video is not interlaced this will return WholeFrame. +*/ + +QVideoFrame::FieldType QVideoFrame::fieldType() const +{ + return d->fieldType; +} + +/*! + Sets the \a field an interlaced video frame belongs to. +*/ + +void QVideoFrame::setFieldType(QVideoFrame::FieldType field) +{ + d->fieldType = field; +} + +/*! + Identifies if a video frame's contents are currently mapped to system memory. + + This is a convenience function which checks that the \l {QAbstractVideoBuffer::MapMode}{MapMode} + of the frame is not equal to QAbstractVideoBuffer::NotMapped. + + Returns true if the contents of the video frame are mapped to system memory, and false + otherwise. + + \sa mapMode() QAbstractVideoBuffer::MapMode +*/ + +bool QVideoFrame::isMapped() const +{ + return d->buffer != 0 && d->buffer->mapMode() != QAbstractVideoBuffer::NotMapped; +} + +/*! + Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped. + + This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode} + contains the QAbstractVideoBuffer::WriteOnly flag. + + Returns true if the video frame will be updated when unmapped, and false otherwise. + + \note The result of altering the data of a frame that is mapped in read-only mode is undefined. + Depending on the buffer implementation the changes may be persisted, or worse alter a shared + buffer. + + \sa mapMode(), QAbstractVideoBuffer::MapMode +*/ + +bool QVideoFrame::isWritable() const +{ + return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::WriteOnly); +} + +/*! + Identifies if the mapped contents of a video frame were read from the frame when it was mapped. + + This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode} + contains the QAbstractVideoBuffer::WriteOnly flag. + + Returns true if the contents of the mapped memory were read from the video frame, and false + otherwise. + + \sa mapMode(), QAbstractVideoBuffer::MapMode +*/ + +bool QVideoFrame::isReadable() const +{ + return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::ReadOnly); +} + +/*! + Returns the mode a video frame was mapped to system memory in. + + \sa map(), QAbstractVideoBuffer::MapMode +*/ + +QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const +{ + return d->buffer != 0 ? d->buffer->mapMode() : QAbstractVideoBuffer::NotMapped; +} + +/*! + Maps the contents of a video frame to memory. + + The map \a mode indicates whether the contents of the mapped memory should be read from and/or + written to the frame. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the + mapped memory will be populated with the content of the video frame when mapped. If the map + mode inclues the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be + persisted in the frame when unmapped. + + While mapped the contents of a video frame can be accessed directly through the pointer returned + by the bits() function. + + When access to the data is no longer needed be sure to call the unmap() function to release the + mapped memory. + + Returns true if the buffer was mapped to memory in the given \a mode and false otherwise. + + \sa unmap(), mapMode(), bits() +*/ + +bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) +{ + if (d->buffer != 0 && d->data == 0) { + Q_ASSERT(d->bytesPerLine == 0); + Q_ASSERT(d->numBytes == 0); + + d->data = d->buffer->map(mode, &d->numBytes, &d->bytesPerLine); + + return d->data != 0; + } + + return false; +} + +/*! + Releases the memory mapped by the map() function. + + If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly + flag this will persist the current content of the mapped memory to the video frame. + + \sa map() +*/ + +void QVideoFrame::unmap() +{ + if (d->data != 0) { + d->numBytes = 0; + d->bytesPerLine = 0; + d->data = 0; + + d->buffer->unmap(); + } +} + +/*! + Returns the number of bytes in a scan line. + + \note This is the bytes per line of the first plane only. The bytes per line of subsequent + planes should be calculated as per the frame type. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa bits(), map(), numBytes() +*/ + +int QVideoFrame::bytesPerLine() const +{ + return d->bytesPerLine; +} + +/*! + Returns a pointer to the start of the frame data buffer. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa map(), numBytes(), bytesPerLine() +*/ + +uchar *QVideoFrame::bits() +{ + return d->data; +} + +/*! + Returns a pointer to the start of the frame data buffer. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa map(), numBytes(), bytesPerLine() +*/ + +const uchar *QVideoFrame::bits() const +{ + return d->data; +} + +/*! + Returns the number of bytes occupied by the frame data. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa map() +*/ + +int QVideoFrame::numBytes() const +{ + return d->numBytes; +} + +/*! + Returns a type specific handle to a video frame's buffer. + + For an OpenGL texture this would be the texture ID. + + \sa QAbstractVideoBuffer::handle() +*/ + +QVariant QVideoFrame::handle() const +{ + return d->buffer != 0 ? d->buffer->handle() : QVariant(); +} + +/*! + Returns the presentation time when the frame should be displayed. +*/ + +qint64 QVideoFrame::startTime() const +{ + return d->startTime; +} + +/*! + Sets the presentation \a time when the frame should be displayed. +*/ + +void QVideoFrame::setStartTime(qint64 time) +{ + d->startTime = time; +} + +/*! + Returns the presentation time when a frame should stop being displayed. +*/ + +qint64 QVideoFrame::endTime() const +{ + return d->endTime; +} + +/*! + Sets the presentation \a time when a frame should stop being displayed. +*/ + +void QVideoFrame::setEndTime(qint64 time) +{ + d->endTime = time; +} + +/*! + Returns an video pixel format equivalent to an image \a format. If there is no equivalent + format QVideoFrame::InvalidType is returned instead. +*/ + +QVideoFrame::PixelFormat QVideoFrame::equivalentPixelFormat(QImage::Format format) +{ + switch (format) { + case QImage::Format_Invalid: + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + case QImage::Format_Indexed8: + return Format_Invalid; + case QImage::Format_RGB32: + return Format_RGB32; + case QImage::Format_ARGB32: + return Format_ARGB32; + case QImage::Format_ARGB32_Premultiplied: + return Format_ARGB32_Premultiplied; + case QImage::Format_RGB16: + return Format_RGB565; + case QImage::Format_ARGB8565_Premultiplied: + case QImage::Format_RGB666: + case QImage::Format_ARGB6666_Premultiplied: + return Format_Invalid; + case QImage::Format_RGB555: + return Format_RGB555; + case QImage::Format_ARGB8555_Premultiplied: + return Format_Invalid; + case QImage::Format_RGB888: + return Format_RGB24; + case QImage::Format_RGB444: + case QImage::Format_ARGB4444_Premultiplied: + return Format_Invalid; + case QImage::NImageFormats: + return Format_Invalid; + } + return Format_Invalid; +} + +/*! + Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent + format QImage::Format_Invalid is returned instead. +*/ + +QImage::Format QVideoFrame::equivalentImageFormat(PixelFormat format) +{ + switch (format) { + case Format_Invalid: + return QImage::Format_Invalid; + case Format_ARGB32: + return QImage::Format_ARGB32; + case Format_ARGB32_Premultiplied: + return QImage::Format_ARGB32_Premultiplied; + case Format_RGB32: + return QImage::Format_RGB32; + case Format_RGB24: + return QImage::Format_RGB888; + case Format_RGB565: + return QImage::Format_RGB16; + case Format_RGB555: + return QImage::Format_RGB555; + case Format_ARGB8565_Premultiplied: + return QImage::Format_ARGB8565_Premultiplied; + case Format_BGRA32: + case Format_BGRA32_Premultiplied: + case Format_BGR32: + case Format_BGR24: + return QImage::Format_Invalid; + case Format_BGR565: + case Format_BGR555: + case Format_BGRA5658_Premultiplied: + case Format_AYUV444: + case Format_AYUV444_Premultiplied: + case Format_YUV444: + case Format_YUV420P: + case Format_YV12: + case Format_UYVY: + case Format_YUYV: + case Format_NV12: + case Format_NV21: + case Format_IMC1: + case Format_IMC2: + case Format_IMC3: + case Format_IMC4: + case Format_Y8: + case Format_Y16: + return QImage::Format_Invalid; + case Format_User: + return QImage::Format_Invalid; + } + return QImage::Format_Invalid; +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h new file mode 100644 index 0000000..5bd9ac3 --- /dev/null +++ b/src/multimedia/video/qvideoframe.h @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QVIDEOFRAME_H +#define QVIDEOFRAME_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QSize; +class QVariant; + +class QVideoFramePrivate; + +class Q_MULTIMEDIA_EXPORT QVideoFrame +{ +public: + enum FieldType + { + ProgressiveFrame, + TopField, + BottomField, + InterlacedFrame + }; + + enum PixelFormat + { + Format_Invalid, + Format_ARGB32, + Format_ARGB32_Premultiplied, + Format_RGB32, + Format_RGB24, + Format_RGB565, + Format_RGB555, + Format_ARGB8565_Premultiplied, + Format_BGRA32, + Format_BGRA32_Premultiplied, + Format_BGR32, + Format_BGR24, + Format_BGR565, + Format_BGR555, + Format_BGRA5658_Premultiplied, + + Format_AYUV444, + Format_AYUV444_Premultiplied, + Format_YUV444, + Format_YUV420P, + Format_YV12, + Format_UYVY, + Format_YUYV, + Format_NV12, + Format_NV21, + Format_IMC1, + Format_IMC2, + Format_IMC3, + Format_IMC4, + Format_Y8, + Format_Y16, + + Format_User = 1000 + }; + + QVideoFrame(); + QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format); + QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format); + QVideoFrame(const QImage &image); + QVideoFrame(const QVideoFrame &other); + ~QVideoFrame(); + + QVideoFrame &operator =(const QVideoFrame &other); + + bool isValid() const; + + PixelFormat pixelFormat() const; + + QAbstractVideoBuffer::HandleType handleType() const; + + QSize size() const; + int width() const; + int height() const; + + FieldType fieldType() const; + void setFieldType(FieldType); + + bool isMapped() const; + bool isReadable() const; + bool isWritable() const; + + QAbstractVideoBuffer::MapMode mapMode() const; + + bool map(QAbstractVideoBuffer::MapMode mode); + void unmap(); + + int bytesPerLine() const; + + uchar *bits(); + const uchar *bits() const; + int numBytes() const; + + QVariant handle() const; + + qint64 startTime() const; + void setStartTime(qint64 time); + + qint64 endTime() const; + void setEndTime(qint64 time); + + static PixelFormat equivalentPixelFormat(QImage::Format format); + static QImage::Format equivalentImageFormat(PixelFormat format); + +private: + QExplicitlySharedDataPointer d; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QVideoFrame::FieldType) +Q_DECLARE_METATYPE(QVideoFrame::PixelFormat) + +QT_END_HEADER + +#endif + diff --git a/src/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/video/qvideosurfaceformat.cpp new file mode 100644 index 0000000..7e18dda --- /dev/null +++ b/src/multimedia/video/qvideosurfaceformat.cpp @@ -0,0 +1,742 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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 "qvideosurfaceformat.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QVideoSurfaceFormatPrivate : public QSharedData +{ +public: + QVideoSurfaceFormatPrivate() + : pixelFormat(QVideoFrame::Format_Invalid) + , handleType(QAbstractVideoBuffer::NoHandle) + , scanLineDirection(QVideoSurfaceFormat::TopToBottom) + , pixelAspectRatio(1, 1) + , yuvColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , frameRate(0, 0) + { + } + + QVideoSurfaceFormatPrivate( + const QSize &size, + QVideoFrame::PixelFormat format, + QAbstractVideoBuffer::HandleType type) + : pixelFormat(format) + , handleType(type) + , scanLineDirection(QVideoSurfaceFormat::TopToBottom) + , frameSize(size) + , pixelAspectRatio(1, 1) + , yuvColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , viewport(QPoint(0, 0), size) + , frameRate(0, 0) + { + } + + QVideoSurfaceFormatPrivate(const QVideoSurfaceFormatPrivate &other) + : QSharedData(other) + , pixelFormat(other.pixelFormat) + , handleType(other.handleType) + , scanLineDirection(other.scanLineDirection) + , frameSize(other.frameSize) + , pixelAspectRatio(other.pixelAspectRatio) + , yuvColorSpace(other.yuvColorSpace) + , viewport(other.viewport) + , frameRate(other.frameRate) + , propertyNames(other.propertyNames) + , propertyValues(other.propertyValues) + { + } + + bool operator ==(const QVideoSurfaceFormatPrivate &other) const + { + if (pixelFormat == other.pixelFormat + && handleType == other.handleType + && scanLineDirection == other.scanLineDirection + && frameSize == other.frameSize + && pixelAspectRatio == other.pixelAspectRatio + && viewport == other.viewport + && frameRate == other.frameRate + && yuvColorSpace == other.yuvColorSpace + && propertyNames.count() == other.propertyNames.count()) { + for (int i = 0; i < propertyNames.count(); ++i) { + int j = other.propertyNames.indexOf(propertyNames.at(i)); + + if (j == -1 || propertyValues.at(i) != other.propertyValues.at(j)) + return false; + } + return true; + } else { + return false; + } + } + + QVideoFrame::PixelFormat pixelFormat; + QAbstractVideoBuffer::HandleType handleType; + QVideoSurfaceFormat::Direction scanLineDirection; + QSize frameSize; + QSize pixelAspectRatio; + QVideoSurfaceFormat::YuvColorSpace yuvColorSpace; + QRect viewport; + QVideoSurfaceFormat::FrameRate frameRate; + QList propertyNames; + QList propertyValues; +}; + +/*! + \class QVideoSurfaceFormat + \brief The QVideoSurfaceFormat class specifies the stream format of a video presentation + surface. + \preliminary + \since 4.6 + + A video surface presents a stream of video frames. The surface's format describes the type of + the frames and determines how they should be presented. + + The core properties of a video stream required to setup a video surface are the pixel format + given by pixelFormat(), and the frame dimensions given by frameSize(). + + If the surface is to present frames using a frame's handle a surface format will also include + a handle type which is given by the handleType() function. + + The region of a frame that is actually displayed on a video surface is given by the viewport(). + A stream may have a viewport less than the entire region of a frame to allow for videos smaller + than the nearest optimal size of a video frame. For example the width of a frame may be + extended so that the start of each scan line is eight byte aligned. + + Other common properties are the pixelAspectRatio(), scanLineDirection(), and frameRate(). + Additionally a stream may have some additional type specific properties which are listed by the + dynamicPropertyNames() function and can be accessed using the property(), and setProperty() + functions. +*/ + +/*! + \enum QVideoSurfaceFormat::Direction + + Enumerates the layout direction of video scan lines. + + \value TopToBottom Scan lines are arranged from the top of the frame to the bottom. + \value BottomToTop Scan lines are arranged from the bottom of the frame to the top. +*/ + +/*! + \enum QVideoSurfaceFormat::ViewportMode + + Enumerates the methods for updating the stream viewport when the frame size is changed. + + \value ResetViewport The viewport is reset to cover an entire frame. + \value KeepViewport The viewport is kept within the bounds the frame. +*/ + +/*! + \enum QVideoSurfaceFormat::YuvColorSpace + + Enumerates the YUV color space of video frames. + + \value YCbCr_Undefined + No color space is specified. + + \value YCbCr_BT601 + A Y'CbCr color space defined by ITU-R recommendation BT.601 + with Y value range from 16 to 235, and Cb/Cr range from 16 to 240. + Used in standard definition video. + + \value YCbCr_BT709 + A Y'CbCr color space defined by ITU-R BT.709 with the same values range as YCbCr_BT601. Used + for HDTV. + + \value YCbCr_xvYCC601 + The BT.601 color space with the value range extended to 0 to 255. + It is backward compatibile with BT.601 and uses values outside BT.601 range to represent + wider colors range. + + \value YCbCr_xvYCC709 + The BT.709 color space with the value range extended to 0 to 255. + + \value YCbCr_JPEG + The full range Y'CbCr color space used in JPEG files. +*/ + + +/*! + \typedef QVideoSurfaceFormat::FrameRate + + A pair of integers representing the frame rate of a video stream. + + The first number is the numerator and the second the denominator. +*/ + +/*! + Constructs a null video stream format. +*/ + +QVideoSurfaceFormat::QVideoSurfaceFormat() + : d(new QVideoSurfaceFormatPrivate) +{ +} + +/*! + Contructs a description of stream which receives stream of \a type buffers with given frame + \a size and pixel \a format. +*/ + +QVideoSurfaceFormat::QVideoSurfaceFormat( + const QSize& size, QVideoFrame::PixelFormat format, QAbstractVideoBuffer::HandleType type) + : d(new QVideoSurfaceFormatPrivate(size, format, type)) +{ +} + +/*! + Constructs a copy of \a other. +*/ + +QVideoSurfaceFormat::QVideoSurfaceFormat(const QVideoSurfaceFormat &other) + : d(other.d) +{ +} + +/*! + Assigns the values of \a other to a video stream description. +*/ + +QVideoSurfaceFormat &QVideoSurfaceFormat::operator =(const QVideoSurfaceFormat &other) +{ + d = other.d; + + return *this; +} + +/*! + Destroys a video stream description. +*/ + +QVideoSurfaceFormat::~QVideoSurfaceFormat() +{ +} + +/*! + Identifies if a video surface format has a valid pixel format and frame size. + + Returns true if the format is valid, and false otherwise. +*/ + +bool QVideoSurfaceFormat::isValid() const +{ + return d->pixelFormat == QVideoFrame::Format_Invalid && d->frameSize.isValid(); +} + +/*! + Returns true if \a other is the same as a video format, and false if they are the different. +*/ + +bool QVideoSurfaceFormat::operator ==(const QVideoSurfaceFormat &other) const +{ + return d == other.d || *d == *other.d; +} + +/*! + Returns true if \a other is different to a video format, and false if they are the same. +*/ + +bool QVideoSurfaceFormat::operator !=(const QVideoSurfaceFormat &other) const +{ + return d != other.d && !(*d == *other.d); +} + +/*! + Returns the pixel format of frames in a video stream. +*/ + +QVideoFrame::PixelFormat QVideoSurfaceFormat::pixelFormat() const +{ + return d->pixelFormat; +} + +/*! + Returns the type of handle the surface uses to present the frame data. + + If the handle type is QAbstractVideoBuffer::NoHandle buffers with any handle type are valid + provided they can be \l {QAbstractVideoBuffer::map()}{mapped} with the + QAbstractVideoBuffer::ReadOnly flag. If the handleType() is not QAbstractVideoBuffer::NoHandle + then the handle type of the buffer be the same as that of the surface format. +*/ + +QAbstractVideoBuffer::HandleType QVideoSurfaceFormat::handleType() const +{ + return d->handleType; +} + +/*! + Returns the size of frames in a video stream. + + \sa frameWidth(), frameHeight() +*/ + +QSize QVideoSurfaceFormat::frameSize() const +{ + return d->frameSize; +} + +/*! + Returns the width of frames in a video stream. + + \sa frameSize(), frameHeight() +*/ + +int QVideoSurfaceFormat::frameWidth() const +{ + return d->frameSize.width(); +} + +/*! + Returns the height of frame in a video stream. +*/ + +int QVideoSurfaceFormat::frameHeight() const +{ + return d->frameSize.height(); +} + +/*! + Sets the size of frames in a video stream to \a size. + + The viewport \a mode indicates how the view port should be updated. +*/ + +void QVideoSurfaceFormat::setFrameSize(const QSize &size, ViewportMode mode) +{ + d->frameSize = size; + + switch (mode) { + case ResetViewport: + d->viewport = QRect(QPoint(0, 0), size); + break; + case KeepViewport: + d->viewport = QRect(QPoint(0, 0), size).intersected(d->viewport); + break; + } +} + +/*! + \overload + + Sets the \a width and \a height of frames in a video stream. + + The viewport \a mode indicates how the view port should be updated. +*/ + +void QVideoSurfaceFormat::setFrameSize(int width, int height, ViewportMode mode) +{ + setFrameSize(QSize(width, height), mode); +} + +/*! + Returns the viewport of a video stream. + + The viewport is the region of a video frame that is actually displayed. + + By default the viewport covers an entire frame. +*/ + +QRect QVideoSurfaceFormat::viewport() const +{ + return d->viewport; +} + +/*! + Sets the viewport of a video stream to \a viewport. +*/ + +void QVideoSurfaceFormat::setViewport(const QRect &viewport) +{ + d->viewport = viewport; +} + +/*! + Returns the direction of scan lines. +*/ + +QVideoSurfaceFormat::Direction QVideoSurfaceFormat::scanLineDirection() const +{ + return d->scanLineDirection; +} + +/*! + Sets the \a direction of scan lines. +*/ + +void QVideoSurfaceFormat::setScanLineDirection(Direction direction) +{ + d->scanLineDirection = direction; +} + +/*! + Returns the frame rate of a video stream. + + The frame rate is a rational number represented by a pair of integers. + The first integer is the numerator and the second the denominator. +*/ + +QVideoSurfaceFormat::FrameRate QVideoSurfaceFormat::frameRate() const +{ + return d->frameRate; +} + +/*! + Sets the frame \a rate of a video stream. + + The frame rate is a rational number represented by a pair of integers. + The first integer is the numerator and the second the denominator. +*/ + +void QVideoSurfaceFormat::setFrameRate(const FrameRate &rate) +{ + d->frameRate = rate; +} + +/*! + \overload + + Sets the \a numerator and \a denominator of the frame rate of a video stream. +*/ + +void QVideoSurfaceFormat::setFrameRate(int numerator, int denominator) +{ + d->frameRate = qMakePair(numerator, denominator); +} + +/*! + Returns a video stream's pixel aspect ratio. +*/ + +QSize QVideoSurfaceFormat::pixelAspectRatio() const +{ + return d->pixelAspectRatio; +} + +/*! + Sets a video stream's pixel aspect \a ratio. +*/ + +void QVideoSurfaceFormat::setPixelAspectRatio(const QSize &ratio) +{ + d->pixelAspectRatio = ratio; +} + +/*! + \overload + + Sets the \a horizontal and \a vertical elements of a video stream's pixel aspect ratio. +*/ + +void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical) +{ + d->pixelAspectRatio = QSize(horizontal, vertical); +} + +/*! + Returns a YUV color space of a video stream. +*/ + +QVideoSurfaceFormat::YuvColorSpace QVideoSurfaceFormat::yuvColorSpace() const +{ + return d->yuvColorSpace; +} + +/*! + Sets a YUV color \a space of a video stream. + It is only used with raw YUV frame types. +*/ + +void QVideoSurfaceFormat::setYuvColorSpace(QVideoSurfaceFormat::YuvColorSpace space) +{ + d->yuvColorSpace = space; +} + +/*! + Returns a suggested size in pixels for the video stream. + + This is the size of the viewport scaled according to the pixel aspect ratio. +*/ + +QSize QVideoSurfaceFormat::sizeHint() const +{ + QSize size = d->viewport.size(); + + if (d->pixelAspectRatio.height() != 0) + size.setWidth(size.width() * d->pixelAspectRatio.width() / d->pixelAspectRatio.height()); + + return size; +} + +/*! + Returns a list of video format dynamic property names. +*/ + +QList QVideoSurfaceFormat::propertyNames() const +{ + return (QList() + << "handleType" + << "pixelFormat" + << "frameSize" + << "frameWidth" + << "viewport" + << "scanLineDirection" + << "frameRate" + << "pixelAspectRatio" + << "sizeHint" + << "yuvColorSpace") + + d->propertyNames; +} + +/*! + Returns the value of the video format's \a name property. +*/ + +QVariant QVideoSurfaceFormat::property(const char *name) const +{ + if (qstrcmp(name, "handleType") == 0) { + return qVariantFromValue(d->handleType); + } else if (qstrcmp(name, "pixelFormat") == 0) { + return qVariantFromValue(d->pixelFormat); + } else if (qstrcmp(name, "handleType") == 0) { + return qVariantFromValue(d->handleType); + } else if (qstrcmp(name, "frameSize") == 0) { + return d->frameSize; + } else if (qstrcmp(name, "frameWidth") == 0) { + return d->frameSize.width(); + } else if (qstrcmp(name, "frameHeight") == 0) { + return d->frameSize.height(); + } else if (qstrcmp(name, "viewport") == 0) { + return d->viewport; + } else if (qstrcmp(name, "scanLineDirection") == 0) { + return qVariantFromValue(d->scanLineDirection); + } else if (qstrcmp(name, "frameRate") == 0) { + return qVariantFromValue(d->frameRate); + } else if (qstrcmp(name, "pixelAspectRatio") == 0) { + return qVariantFromValue(d->pixelAspectRatio); + } else if (qstrcmp(name, "sizeHint") == 0) { + return sizeHint(); + } else if (qstrcmp(name, "yuvColorSpace") == 0) { + return qVariantFromValue(d->yuvColorSpace); + } else { + int id = 0; + for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} + + return id < d->propertyValues.count() + ? d->propertyValues.at(id) + : QVariant(); + } +} + +/*! + Sets the video format's \a name property to \a value. +*/ + +void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value) +{ + if (qstrcmp(name, "handleType") == 0) { + // read only. + } else if (qstrcmp(name, "pixelFormat") == 0) { + // read only. + } else if (qstrcmp(name, "frameSize") == 0) { + if (qVariantCanConvert(value)) { + d->frameSize = qvariant_cast(value); + d->viewport = QRect(QPoint(0, 0), d->frameSize); + } + } else if (qstrcmp(name, "frameWidth") == 0) { + // read only. + } else if (qstrcmp(name, "frameHeight") == 0) { + // read only. + } else if (qstrcmp(name, "viewport") == 0) { + if (qVariantCanConvert(value)) + d->viewport = qvariant_cast(value); + } else if (qstrcmp(name, "scanLineDirection") == 0) { + if (qVariantCanConvert(value)) + d->scanLineDirection = qvariant_cast(value); + } else if (qstrcmp(name, "frameRate") == 0) { + if (qVariantCanConvert(value)) + d->frameRate = qvariant_cast(value); + } else if (qstrcmp(name, "pixelAspectRatio") == 0) { + if (qVariantCanConvert(value)) + d->pixelAspectRatio = qvariant_cast(value); + } else if (qstrcmp(name, "sizeHint") == 0) { + // read only. + } else if (qstrcmp(name, "yuvColorSpace") == 0) { + if (qVariantCanConvert(value)) + d->yuvColorSpace = qvariant_cast(value); + } else { + int id = 0; + for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} + + if (id < d->propertyValues.count()) { + if (value.isNull()) { + d->propertyNames.removeAt(id); + d->propertyValues.removeAt(id); + } else { + d->propertyValues[id] = value; + } + } else if (!value.isNull()) { + d->propertyNames.append(QByteArray(name)); + d->propertyValues.append(value); + } + } +} + + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f) +{ + QString typeName; + switch (f.pixelFormat()) { + case QVideoFrame::Format_Invalid: + typeName = QLatin1String("Format_Invalid"); + break; + case QVideoFrame::Format_ARGB32: + typeName = QLatin1String("Format_ARGB32"); + break; + case QVideoFrame::Format_ARGB32_Premultiplied: + typeName = QLatin1String("Format_ARGB32_Premultiplied"); + break; + case QVideoFrame::Format_RGB32: + typeName = QLatin1String("Format_RGB32"); + break; + case QVideoFrame::Format_RGB24: + typeName = QLatin1String("Format_RGB24"); + break; + case QVideoFrame::Format_RGB565: + typeName = QLatin1String("Format_RGB565"); + break; + case QVideoFrame::Format_RGB555: + typeName = QLatin1String("Format_RGB555"); + break; + case QVideoFrame::Format_ARGB8565_Premultiplied: + typeName = QLatin1String("Format_ARGB8565_Premultiplied"); + break; + case QVideoFrame::Format_BGRA32: + typeName = QLatin1String("Format_BGRA32"); + break; + case QVideoFrame::Format_BGRA32_Premultiplied: + typeName = QLatin1String("Format_BGRA32_Premultiplied"); + break; + case QVideoFrame::Format_BGR32: + typeName = QLatin1String("Format_BGR32"); + break; + case QVideoFrame::Format_BGR24: + typeName = QLatin1String("Format_BGR24"); + break; + case QVideoFrame::Format_BGR565: + typeName = QLatin1String("Format_BGR565"); + break; + case QVideoFrame::Format_BGR555: + typeName = QLatin1String("Format_BGR555"); + break; + case QVideoFrame::Format_BGRA5658_Premultiplied: + typeName = QLatin1String("Format_BGRA5658_Premultiplied"); + break; + case QVideoFrame::Format_AYUV444: + typeName = QLatin1String("Format_AYUV444"); + break; + case QVideoFrame::Format_AYUV444_Premultiplied: + typeName = QLatin1String("Format_AYUV444_Premultiplied"); + break; + case QVideoFrame::Format_YUV444: + typeName = QLatin1String("Format_YUV444"); + break; + case QVideoFrame::Format_YUV420P: + typeName = QLatin1String("Format_YUV420P"); + break; + case QVideoFrame::Format_YV12: + typeName = QLatin1String("Format_YV12"); + break; + case QVideoFrame::Format_UYVY: + typeName = QLatin1String("Format_UYVY"); + break; + case QVideoFrame::Format_YUYV: + typeName = QLatin1String("Format_YUYV"); + break; + case QVideoFrame::Format_NV12: + typeName = QLatin1String("Format_NV12"); + break; + case QVideoFrame::Format_NV21: + typeName = QLatin1String("Format_NV21"); + break; + case QVideoFrame::Format_IMC1: + typeName = QLatin1String("Format_IMC1"); + break; + case QVideoFrame::Format_IMC2: + typeName = QLatin1String("Format_IMC2"); + break; + case QVideoFrame::Format_IMC3: + typeName = QLatin1String("Format_IMC3"); + break; + case QVideoFrame::Format_IMC4: + typeName = QLatin1String("Format_IMC4"); + break; + case QVideoFrame::Format_Y8: + typeName = QLatin1String("Format_Y8"); + break; + case QVideoFrame::Format_Y16: + typeName = QLatin1String("Format_Y16"); + default: + typeName = QString(QLatin1String("UserType(%1)" )).arg(int(f.pixelFormat())); + } + + dbg.nospace() << "QVideoSurfaceFormat(" << typeName; + dbg.nospace() << ", " << f.frameSize(); + dbg.nospace() << ", viewport=" << f.viewport(); + dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio(); + dbg.nospace() << ")"; + + foreach(const QByteArray& propertyName, f.propertyNames()) + dbg << "\n " << propertyName.data() << " = " << f.property(propertyName.data()); + + return dbg.space(); +} +#endif + +QT_END_NAMESPACE diff --git a/src/multimedia/video/qvideosurfaceformat.h b/src/multimedia/video/qvideosurfaceformat.h new file mode 100644 index 0000000..72a2452 --- /dev/null +++ b/src/multimedia/video/qvideosurfaceformat.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module 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$ +** +****************************************************************************/ + +#ifndef QVIDEOSURFACEFORMAT_H +#define QVIDEOSURFACEFORMAT_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QDebug; + +class QVideoSurfaceFormatPrivate; + +class Q_MULTIMEDIA_EXPORT QVideoSurfaceFormat +{ +public: + enum Direction + { + TopToBottom, + BottomToTop + }; + + enum ViewportMode + { + ResetViewport, + KeepViewport + }; + + enum YuvColorSpace + { + YCbCr_Undefined, + YCbCr_BT601, + YCbCr_BT709, + YCbCr_xvYCC601, + YCbCr_xvYCC709, + YCbCr_JPEG, +#ifndef qdoc + YCbCr_CustomMatrix +#endif + }; + + typedef QPair FrameRate; + + QVideoSurfaceFormat(); + QVideoSurfaceFormat( + const QSize &size, + QVideoFrame::PixelFormat pixelFormat, + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle); + QVideoSurfaceFormat(const QVideoSurfaceFormat &format); + ~QVideoSurfaceFormat(); + + QVideoSurfaceFormat &operator =(const QVideoSurfaceFormat &format); + + bool operator ==(const QVideoSurfaceFormat &format) const; + bool operator !=(const QVideoSurfaceFormat &format) const; + + bool isValid() const; + + QVideoFrame::PixelFormat pixelFormat() const; + QAbstractVideoBuffer::HandleType handleType() const; + + QSize frameSize() const; + void setFrameSize(const QSize &size, ViewportMode mode = ResetViewport); + void setFrameSize(int width, int height, ViewportMode mode = ResetViewport); + + int frameWidth() const; + int frameHeight() const; + + QRect viewport() const; + void setViewport(const QRect &viewport); + + Direction scanLineDirection() const; + void setScanLineDirection(Direction direction); + + FrameRate frameRate() const; + void setFrameRate(const FrameRate &rate); + void setFrameRate(int numerator, int denominator = 1); + + QSize pixelAspectRatio() const; + void setPixelAspectRatio(const QSize &ratio); + void setPixelAspectRatio(int width, int height); + + YuvColorSpace yuvColorSpace() const; + void setYuvColorSpace(YuvColorSpace colorSpace); + + QSize sizeHint() const; + + QList propertyNames() const; + QVariant property(const char *name) const; + void setProperty(const char *name, const QVariant &value); + +private: + QSharedDataPointer d; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &); +#endif + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QVideoSurfaceFormat::FrameRate); +Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction) +Q_DECLARE_METATYPE(QVideoSurfaceFormat::YuvColorSpace) + +QT_END_HEADER + +#endif + diff --git a/src/multimedia/video/video.pri b/src/multimedia/video/video.pri new file mode 100644 index 0000000..0547a4c --- /dev/null +++ b/src/multimedia/video/video.pri @@ -0,0 +1,21 @@ + +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qabstractvideobuffer.h \ + $$PWD/qabstractvideobuffer_p.h \ + $$PWD/qabstractvideosurface.h \ + $$PWD/qabstractvideosurface_p.h \ + $$PWD/qimagevideobuffer_p.h \ + $$PWD/qmemoryvideobuffer_p.h \ + $$PWD/qvideoframe.h \ + $$PWD/qvideosurfaceformat.h + +SOURCES += \ + $$PWD/qabstractvideobuffer.cpp \ + $$PWD/qabstractvideosurface.cpp \ + $$PWD/qimagevideobuffer.cpp \ + $$PWD/qmemoryvideobuffer.cpp \ + $$PWD/qvideoframe.cpp \ + $$PWD/qvideosurfaceformat.cpp + 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 + +#include + +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("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 + +#include +#include + +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 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 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(); + + 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("supportedFormats"); + QTest::addColumn("format"); + QTest::addColumn("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("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(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(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 + +#include +#include +#include + +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("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("bytes"); + QTest::addColumn("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("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("bytes"); + QTest::addColumn("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("handleType"); + QTest::addColumn("size"); + QTest::addColumn("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("size"); + QTest::addColumn("imageFormat"); + QTest::addColumn("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 buffer = new QtTestVideoBuffer; + + { + QVideoFrame frame(buffer, QSize(4, 1), QVideoFrame::Format_ARGB32); + } + + QVERIFY(buffer.isNull()); +} + +void tst_QVideoFrame::copy_data() +{ + QTest::addColumn("handleType"); + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("fieldType"); + QTest::addColumn("startTime"); + QTest::addColumn("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 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("handleType"); + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("fieldType"); + QTest::addColumn("startTime"); + QTest::addColumn("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 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("size"); + QTest::addColumn("numBytes"); + QTest::addColumn("bytesPerLine"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("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("size"); + QTest::addColumn("format"); + QTest::addColumn("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 + +#include + +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("frameSize"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("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("initialSize"); + QTest::addColumn("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("initialSize"); + QTest::addColumn("viewport"); + QTest::addColumn("newSize"); + QTest::addColumn("viewportMode"); + QTest::addColumn("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("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(format.property("scanLineDirection")), + direction); + } + { + QVideoSurfaceFormat format(QSize(16, 16), QVideoFrame::Format_RGB32); + + format.setProperty("scanLineDirection", qVariantFromValue(direction)); + + QCOMPARE(format.scanLineDirection(), direction); + QCOMPARE( + qvariant_cast(format.property("scanLineDirection")), + direction); + } +} + +void tst_QVideoSurfaceFormat::frameRate_data() +{ + QTest::addColumn("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(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(format.property("frameRate")), + frameRate); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + format.setFrameRate(frameRate); + format.setProperty( + "frameRate", qVariantFromValue(frameRate)); + + QCOMPARE(format.frameRate(), frameRate); + QCOMPARE(qvariant_cast(format.property("frameRate")), + frameRate); + } +} + +void tst_QVideoSurfaceFormat::yuvColorSpace_data() +{ + QTest::addColumn("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(format.property("yuvColorSpace")), + colorspace); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setProperty("yuvColorSpace", qVariantFromValue(colorspace)); + + QCOMPARE(format.yuvColorSpace(), colorspace); + QCOMPARE(qvariant_cast(format.property("yuvColorSpace")), + colorspace); + } +} + +void tst_QVideoSurfaceFormat::pixelAspectRatio_data() +{ + QTest::addColumn("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("frameSize"); + QTest::addColumn("viewport"); + QTest::addColumn("aspectRatio"); + QTest::addColumn("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 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 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" diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 365167e..4fe70e3 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -3154,7 +3154,7 @@ void Configure::displayConfig() cout << "QtDBus support.............." << dictionary[ "DBUS" ] << endl; cout << "QtXmlPatterns support......." << dictionary[ "XMLPATTERNS" ] << endl; cout << "Phonon support.............." << dictionary[ "PHONON" ] << endl; - cout << "Multimedia support.........." << dictionary[ "MULTIMEDIA" ] << endl; + cout << "QtMultimedia support........" << dictionary[ "MULTIMEDIA" ] << endl; cout << "WebKit support.............." << dictionary[ "WEBKIT" ] << endl; cout << "QtScript support............" << dictionary[ "SCRIPT" ] << endl; cout << "QtScriptTools support......." << dictionary[ "SCRIPTTOOLS" ] << endl; -- cgit v0.12