summaryrefslogtreecommitdiffstats
path: root/examples/multimediawidgets/customvideosurface
diff options
context:
space:
mode:
Diffstat (limited to 'examples/multimediawidgets/customvideosurface')
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideoitem/customvideoitem.pro16
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideoitem/main.cpp54
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.cpp145
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.h78
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.cpp174
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.h84
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideosurface.pro4
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/customvideowidget.pro18
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/main.cpp53
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.cpp143
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.h77
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.cpp113
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.h70
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.cpp173
-rw-r--r--examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.h81
15 files changed, 1283 insertions, 0 deletions
diff --git a/examples/multimediawidgets/customvideosurface/customvideoitem/customvideoitem.pro b/examples/multimediawidgets/customvideosurface/customvideoitem/customvideoitem.pro
new file mode 100644
index 000000000..387e494c9
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideoitem/customvideoitem.pro
@@ -0,0 +1,16 @@
+TEMPLATE = app
+TARGET = customvideoitem
+
+QT += multimedia multimediawidgets widgets
+
+contains(QT_CONFIG, opengl): QT += opengl
+
+HEADERS += videoplayer.h \
+ videoitem.h
+
+SOURCES += main.cpp \
+ videoplayer.cpp \
+ videoitem.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/multimediawidgets/customvideosurface/customvideoitem
+INSTALLS += target
diff --git a/examples/multimediawidgets/customvideosurface/customvideoitem/main.cpp b/examples/multimediawidgets/customvideosurface/customvideoitem/main.cpp
new file mode 100644
index 000000000..18f602f88
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideoitem/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoplayer.h"
+
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ VideoPlayer player;
+ player.show();
+
+ return app.exec();
+}
+
diff --git a/examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.cpp b/examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.cpp
new file mode 100644
index 000000000..db6651efd
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoitem.h"
+
+#include <QPainter>
+#include <QTransform>
+#include <QVideoSurfaceFormat>
+
+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<QVideoFrame::PixelFormat> VideoItem::supportedPixelFormats(
+ QAbstractVideoBuffer::HandleType handleType) const
+{
+ if (handleType == QAbstractVideoBuffer::NoHandle) {
+ return QList<QVideoFrame::PixelFormat>()
+ << QVideoFrame::Format_RGB32
+ << QVideoFrame::Format_ARGB32
+ << QVideoFrame::Format_ARGB32_Premultiplied
+ << QVideoFrame::Format_RGB565
+ << QVideoFrame::Format_RGB555;
+ } else {
+ return QList<QVideoFrame::PixelFormat>();
+ }
+}
+
+bool VideoItem::start(const QVideoSurfaceFormat &format)
+{
+ if (isFormatSupported(format)) {
+ imageFormat = QVideoFrame::imageFormatFromPixelFormat(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 (!QAbstractVideoSurface::isActive())
+ setError(StoppedError);
+
+ return false;
+ } else {
+ currentFrame = frame;
+ framePainted = false;
+
+ update();
+
+ return true;
+ }
+}
diff --git a/examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.h b/examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.h
new file mode 100644
index 000000000..28360577b
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideoitem/videoitem.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOITEM_H
+#define VIDEOITEM_H
+
+#include <QAbstractVideoSurface>
+#include <QGraphicsItem>
+
+class VideoItem
+ : public QAbstractVideoSurface,
+ public QGraphicsItem
+{
+ Q_OBJECT
+ Q_INTERFACES(QGraphicsItem)
+
+public:
+ explicit VideoItem(QGraphicsItem *parentItem = 0);
+ ~VideoItem();
+
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+ //video surface
+ QList<QVideoFrame::PixelFormat> 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 // VIDEOITEM_H
+
diff --git a/examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.cpp b/examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.cpp
new file mode 100644
index 000000000..c76160da3
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.cpp
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoplayer.h"
+#include "videoitem.h"
+
+#include <QtWidgets>
+#include <QVideoSurfaceFormat>
+
+#if !defined(QT_NO_OPENGL)
+# include <QGLWidget>
+#endif
+
+VideoPlayer::VideoPlayer(QWidget *parent)
+ : QWidget(parent)
+ , mediaPlayer(0, QMediaPlayer::VideoSurface)
+ , videoItem(0)
+ , playButton(0)
+ , positionSlider(0)
+{
+ videoItem = new VideoItem;
+
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ QGraphicsView *graphicsView = new QGraphicsView(scene);
+
+#if !defined(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)));
+
+ 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);
+
+ mediaPlayer.setVideoOutput(videoItem);
+ connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)),
+ this, SLOT(mediaStateChanged(QMediaPlayer::State)));
+ connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
+ connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged(qint64)));
+}
+
+VideoPlayer::~VideoPlayer()
+{
+}
+
+
+void VideoPlayer::openFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath());
+
+ if (!fileName.isEmpty()) {
+ mediaPlayer.setMedia(QUrl::fromLocalFile(fileName));
+
+ playButton->setEnabled(true);
+ }
+}
+
+void VideoPlayer::play()
+{
+ switch(mediaPlayer.state()) {
+ case QMediaPlayer::PlayingState:
+ mediaPlayer.pause();
+ break;
+ default:
+ mediaPlayer.play();
+ break;
+ }
+}
+
+void VideoPlayer::mediaStateChanged(QMediaPlayer::State state)
+{
+ switch(state) {
+ case QMediaPlayer::PlayingState:
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
+ break;
+ default:
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ break;
+ }
+}
+
+void VideoPlayer::positionChanged(qint64 position)
+{
+ positionSlider->setValue(position);
+}
+
+void VideoPlayer::durationChanged(qint64 duration)
+{
+ positionSlider->setRange(0, duration);
+}
+
+void VideoPlayer::setPosition(int position)
+{
+ mediaPlayer.setPosition(position);
+}
+
+
+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));
+}
diff --git a/examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.h b/examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.h
new file mode 100644
index 000000000..5b4db4e4d
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideoitem/videoplayer.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOPLAYER_H
+#define VIDEOPLAYER_H
+
+#include <QMediaPlayer>
+#include <QMovie>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractButton;
+class QSlider;
+QT_END_NAMESPACE
+
+class VideoItem;
+
+class VideoPlayer : public QWidget
+{
+ Q_OBJECT
+
+public:
+ VideoPlayer(QWidget *parent = 0);
+ ~VideoPlayer();
+
+ QSize sizeHint() const { return QSize(800, 600); }
+
+public slots:
+ void openFile();
+ void play();
+
+private slots:
+ void mediaStateChanged(QMediaPlayer::State state);
+ void positionChanged(qint64 position);
+ void durationChanged(qint64 duration);
+ void setPosition(int position);
+ void rotateVideo(int angle);
+
+private:
+ QMediaPlayer mediaPlayer;
+ VideoItem *videoItem;
+ QAbstractButton *playButton;
+ QSlider *positionSlider;
+};
+
+#endif // VIDEOPLAYER_H
+
diff --git a/examples/multimediawidgets/customvideosurface/customvideosurface.pro b/examples/multimediawidgets/customvideosurface/customvideosurface.pro
new file mode 100644
index 000000000..baffdaba7
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideosurface.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+
+SUBDIRS += customvideoitem customvideowidget
+
diff --git a/examples/multimediawidgets/customvideosurface/customvideowidget/customvideowidget.pro b/examples/multimediawidgets/customvideosurface/customvideowidget/customvideowidget.pro
new file mode 100644
index 000000000..b4476dfb7
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/customvideowidget.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET = customvideowidget
+
+QT += multimedia multimediawidgets widgets
+
+HEADERS = \
+ videoplayer.h \
+ videowidget.h \
+ videowidgetsurface.h
+
+SOURCES = \
+ main.cpp \
+ videoplayer.cpp \
+ videowidget.cpp \
+ videowidgetsurface.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/multimediawidgets/customvideosurface/customvideowidget
+INSTALLS += target
diff --git a/examples/multimediawidgets/customvideosurface/customvideowidget/main.cpp b/examples/multimediawidgets/customvideosurface/customvideowidget/main.cpp
new file mode 100644
index 000000000..8b7aba641
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoplayer.h"
+
+#include <QtWidgets/QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ VideoPlayer player;
+ player.show();
+
+ return app.exec();
+}
diff --git a/examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.cpp b/examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.cpp
new file mode 100644
index 000000000..639c32461
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videoplayer.h"
+
+#include "videowidget.h"
+
+#include <QtWidgets>
+#include <qvideosurfaceformat.h>
+
+VideoPlayer::VideoPlayer(QWidget *parent)
+ : QWidget(parent)
+ , mediaPlayer(0, QMediaPlayer::VideoSurface)
+ , playButton(0)
+ , positionSlider(0)
+{
+ VideoWidget *videoWidget = new VideoWidget;
+
+ 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)));
+
+ 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);
+
+ mediaPlayer.setVideoOutput(videoWidget->videoSurface());
+ connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)),
+ this, SLOT(mediaStateChanged(QMediaPlayer::State)));
+ connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
+ connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged(qint64)));
+}
+
+VideoPlayer::~VideoPlayer()
+{
+}
+
+void VideoPlayer::openFile()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath());
+
+ if (!fileName.isEmpty()) {
+ mediaPlayer.setMedia(QUrl::fromLocalFile(fileName));
+
+ playButton->setEnabled(true);
+ }
+}
+
+void VideoPlayer::play()
+{
+ switch(mediaPlayer.state()) {
+ case QMediaPlayer::PlayingState:
+ mediaPlayer.pause();
+ break;
+ default:
+ mediaPlayer.play();
+ break;
+ }
+}
+
+void VideoPlayer::mediaStateChanged(QMediaPlayer::State state)
+{
+ switch(state) {
+ case QMediaPlayer::PlayingState:
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
+ break;
+ default:
+ playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
+ break;
+ }
+}
+
+void VideoPlayer::positionChanged(qint64 position)
+{
+ positionSlider->setValue(position);
+}
+
+void VideoPlayer::durationChanged(qint64 duration)
+{
+ positionSlider->setRange(0, duration);
+}
+
+void VideoPlayer::setPosition(int position)
+{
+ mediaPlayer.setPosition(position);
+}
diff --git a/examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.h b/examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.h
new file mode 100644
index 000000000..7aff44fbb
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/videoplayer.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOPLAYER_H
+#define VIDEOPLAYER_H
+
+#include <QMediaPlayer>
+#include <QMovie>
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QAbstractButton;
+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 mediaStateChanged(QMediaPlayer::State state);
+ void positionChanged(qint64 position);
+ void durationChanged(qint64 duration);
+ void setPosition(int position);
+
+private:
+ QMediaPlayer mediaPlayer;
+ QAbstractButton *playButton;
+ QSlider *positionSlider;
+};
+
+#endif // VIDEOPLAYER_H
diff --git a/examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.cpp b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.cpp
new file mode 100644
index 000000000..38c386e6e
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videowidget.h"
+
+#include "videowidgetsurface.h"
+
+#include <QtWidgets>
+#include <qvideosurfaceformat.h>
+
+//! [0]
+VideoWidget::VideoWidget(QWidget *parent)
+ : QWidget(parent)
+ , surface(0)
+{
+ setAutoFillBackground(false);
+ setAttribute(Qt::WA_NoSystemBackground, 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->isActive()) {
+ const QRect videoRect = surface->videoRect();
+
+ if (!videoRect.contains(event->rect())) {
+ QRegion region = event->region();
+ region = region.subtracted(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/multimediawidgets/customvideosurface/customvideowidget/videowidget.h b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.h
new file mode 100644
index 000000000..9b9bd0f38
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidget.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOWIDGET_H
+#define VIDEOWIDGET_H
+
+#include "videowidgetsurface.h"
+
+#include <QWidget>
+
+//! [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 // VIDEOWIDGET_H
diff --git a/examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.cpp b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.cpp
new file mode 100644
index 000000000..df157206b
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.cpp
@@ -0,0 +1,173 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "videowidgetsurface.h"
+
+#include <QtWidgets>
+#include <qabstractvideosurface.h>
+#include <qvideosurfaceformat.h>
+
+VideoWidgetSurface::VideoWidgetSurface(QWidget *widget, QObject *parent)
+ : QAbstractVideoSurface(parent)
+ , widget(widget)
+ , imageFormat(QImage::Format_Invalid)
+{
+}
+
+//! [0]
+QList<QVideoFrame::PixelFormat> VideoWidgetSurface::supportedPixelFormats(
+ QAbstractVideoBuffer::HandleType handleType) const
+{
+ if (handleType == QAbstractVideoBuffer::NoHandle) {
+ return QList<QVideoFrame::PixelFormat>()
+ << QVideoFrame::Format_RGB32
+ << QVideoFrame::Format_ARGB32
+ << QVideoFrame::Format_ARGB32_Premultiplied
+ << QVideoFrame::Format_RGB565
+ << QVideoFrame::Format_RGB555;
+ } else {
+ return QList<QVideoFrame::PixelFormat>();
+ }
+}
+//! [0]
+
+//! [1]
+bool VideoWidgetSurface::isFormatSupported(const QVideoSurfaceFormat &format) const
+{
+ const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(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::imageFormatFromPixelFormat(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/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.h b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.h
new file mode 100644
index 000000000..3e9c40bd2
--- /dev/null
+++ b/examples/multimediawidgets/customvideosurface/customvideowidget/videowidgetsurface.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef VIDEOWIDGETSURFACE_H
+#define VIDEOWIDGETSURFACE_H
+
+#include <QAbstractVideoSurface>
+#include <QImage>
+#include <QRect>
+#include <QVideoFrame>
+
+//! [0]
+class VideoWidgetSurface : public QAbstractVideoSurface
+{
+ Q_OBJECT
+
+public:
+ VideoWidgetSurface(QWidget *widget, QObject *parent = 0);
+
+ QList<QVideoFrame::PixelFormat> supportedPixelFormats(
+ QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
+ bool isFormatSupported(const QVideoSurfaceFormat &format) 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