summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/video.cpp23
-rw-r--r--src/multimedia/playback/qmediaplayer.cpp21
-rw-r--r--src/multimedia/playback/qmediaplayer.h1
-rw-r--r--src/multimedia/qmediaserviceprovider.cpp6
-rw-r--r--src/multimedia/video/qvideoframe.cpp8
-rw-r--r--src/multimedia/video/qvideoframe.h2
-rw-r--r--src/multimedia/video/qvideosurfaces.cpp103
-rw-r--r--src/multimedia/video/qvideosurfaces_p.h (renamed from src/multimedia/video/qvideoframe_p.h)30
-rw-r--r--src/multimedia/video/video.pri7
9 files changed, 182 insertions, 19 deletions
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/video.cpp b/src/multimedia/doc/snippets/multimedia-snippets/video.cpp
index 3c14f7009..46327e3d6 100644
--- a/src/multimedia/doc/snippets/multimedia-snippets/video.cpp
+++ b/src/multimedia/doc/snippets/multimedia-snippets/video.cpp
@@ -117,6 +117,7 @@ public:
void VideoWidget();
void VideoWindowControl();
void VideoWidgetControl();
+ void VideoSurface();
private:
// Common naming
@@ -163,6 +164,28 @@ void VideoExample::VideoWidget()
//! [Setting surface in player]
}
+void VideoExample::VideoSurface()
+{
+ //! [Widget Surface]
+ QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);
+ QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32);
+ videoWidget = new QVideoWidget;
+ videoWidget->videoSurface()->start(format);
+ videoWidget->videoSurface()->present(img);
+ videoWidget->show();
+ //! [Widget Surface]
+
+ //! [GraphicsVideoItem Surface]
+ QGraphicsVideoItem *item = new QGraphicsVideoItem;
+ graphicsView->scene()->addItem(item);
+ graphicsView->show();
+ QImage img = QImage("images/qt-logo.png").convertToFormat(QImage::Format_ARGB32);
+ QVideoSurfaceFormat format(img.size(), QVideoFrame::Format_ARGB32);
+ item->videoSurface()->start(format);
+ item->videoSurface()->present(img);
+ //! [GraphicsVideoItem Surface]
+}
+
void VideoExample::VideoWidgetControl()
{
//! [Video widget control]
diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp
index 48db0335e..9b51bcddf 100644
--- a/src/multimedia/playback/qmediaplayer.cpp
+++ b/src/multimedia/playback/qmediaplayer.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qmediaplayer.h"
+#include "qvideosurfaces_p.h"
#include "qvideosurfaceoutput_p.h"
#include "qmediaobject_p.h"
@@ -555,7 +556,7 @@ static QMediaService *playerService(QMediaPlayer::Flags flags)
{
QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
if (flags) {
- QMediaServiceProviderHint::Features features = 0;
+ QMediaServiceProviderHint::Features features;
if (flags & QMediaPlayer::LowLatency)
features |= QMediaServiceProviderHint::LowLatencyPlayback;
@@ -1168,6 +1169,24 @@ void QMediaPlayer::setVideoOutput(QAbstractVideoSurface *surface)
}
}
+/*!
+ \since 5.15
+ Sets multiple video surfaces as the video output of a media player.
+ This allows the media player to render video frames on different surfaces.
+
+ All video surfaces must support at least one shared \c QVideoFrame::PixelFormat.
+
+ If a video output has already been set on the media player the new surfaces
+ will replace it.
+
+ \sa QAbstractVideoSurface::supportedPixelFormats
+*/
+
+void QMediaPlayer::setVideoOutput(const QVector<QAbstractVideoSurface *> &surfaces)
+{
+ setVideoOutput(new QVideoSurfaces(surfaces, this));
+}
+
/*! \reimp */
QMultimedia::AvailabilityStatus QMediaPlayer::availability() const
{
diff --git a/src/multimedia/playback/qmediaplayer.h b/src/multimedia/playback/qmediaplayer.h
index 5d9a393e1..7ebed84da 100644
--- a/src/multimedia/playback/qmediaplayer.h
+++ b/src/multimedia/playback/qmediaplayer.h
@@ -131,6 +131,7 @@ public:
void setVideoOutput(QVideoWidget *);
void setVideoOutput(QGraphicsVideoItem *);
void setVideoOutput(QAbstractVideoSurface *surface);
+ void setVideoOutput(const QVector<QAbstractVideoSurface *> &surfaces);
QMediaContent media() const;
const QIODevice *mediaStream() const;
diff --git a/src/multimedia/qmediaserviceprovider.cpp b/src/multimedia/qmediaserviceprovider.cpp
index d8ffe42ae..93b560d8c 100644
--- a/src/multimedia/qmediaserviceprovider.cpp
+++ b/src/multimedia/qmediaserviceprovider.cpp
@@ -56,7 +56,7 @@ class QMediaServiceProviderHintPrivate : public QSharedData
{
public:
QMediaServiceProviderHintPrivate(QMediaServiceProviderHint::Type type)
- :type(type), cameraPosition(QCamera::UnspecifiedPosition), features(nullptr)
+ : type(type)
{
}
@@ -77,7 +77,7 @@ public:
QMediaServiceProviderHint::Type type;
QByteArray device;
- QCamera::Position cameraPosition;
+ QCamera::Position cameraPosition = QCamera::UnspecifiedPosition;
QString mimeType;
QStringList codecs;
QMediaServiceProviderHint::Features features;
@@ -712,7 +712,7 @@ QMediaServiceProviderHint::Features QMediaServiceProvider::supportedFeatures(con
{
Q_UNUSED(service);
- return QMediaServiceProviderHint::Features(nullptr);
+ return {};
}
/*!
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index 5e2d6df39..fd7b74075 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -39,7 +39,6 @@
#include "qvideoframe.h"
-#include "qvideoframe_p.h"
#include "qimagevideobuffer_p.h"
#include "qmemoryvideobuffer_p.h"
#include "qvideoframeconversionhelper_p.h"
@@ -1112,11 +1111,12 @@ static void qInitConvertFuncsAsm()
}
/*!
- \internal
+ Based on the pixel format converts current video frame to image.
+ \since 5.15
*/
-QImage qt_imageFromVideoFrame(const QVideoFrame &f)
+QImage QVideoFrame::image() const
{
- QVideoFrame &frame = const_cast<QVideoFrame&>(f);
+ QVideoFrame frame = *this;
QImage result;
if (!frame.isValid() || !frame.map(QAbstractVideoBuffer::ReadOnly))
diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h
index 8fcf47fc4..d043442a3 100644
--- a/src/multimedia/video/qvideoframe.h
+++ b/src/multimedia/video/qvideoframe.h
@@ -166,6 +166,8 @@ public:
QVariant metaData(const QString &key) const;
void setMetaData(const QString &key, const QVariant &value);
+ QImage image() const;
+
static PixelFormat pixelFormatFromImageFormat(QImage::Format format);
static QImage::Format imageFormatFromPixelFormat(PixelFormat format);
diff --git a/src/multimedia/video/qvideosurfaces.cpp b/src/multimedia/video/qvideosurfaces.cpp
new file mode 100644
index 000000000..793879382
--- /dev/null
+++ b/src/multimedia/video/qvideosurfaces.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qvideosurfaces_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QVideoSurfaces::QVideoSurfaces(const QVector<QAbstractVideoSurface *> &s, QObject *parent)
+ : QAbstractVideoSurface(parent)
+ , m_surfaces(s)
+{
+ for (auto a : s) {
+ connect(a, &QAbstractVideoSurface::supportedFormatsChanged, this, [this, a] {
+ auto context = property("GLContext").value<QObject *>();
+ if (!context)
+ setProperty("GLContext", a->property("GLContext"));
+
+ emit supportedFormatsChanged();
+ });
+ }
+}
+
+QVideoSurfaces::~QVideoSurfaces()
+{
+}
+
+QList<QVideoFrame::PixelFormat> QVideoSurfaces::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const
+{
+ QList<QVideoFrame::PixelFormat> result;
+ QMap<QVideoFrame::PixelFormat, int> formats;
+ for (auto &s : m_surfaces) {
+ for (auto &p : s->supportedPixelFormats(type)) {
+ if (++formats[p] == m_surfaces.size())
+ result << p;
+ }
+ }
+
+ return result;
+}
+
+bool QVideoSurfaces::start(const QVideoSurfaceFormat &format)
+{
+ bool result = true;
+ for (auto &s : m_surfaces)
+ result &= s->start(format);
+
+ return result && QAbstractVideoSurface::start(format);
+}
+
+void QVideoSurfaces::stop()
+{
+ for (auto &s : m_surfaces)
+ s->stop();
+
+ QAbstractVideoSurface::stop();
+}
+
+bool QVideoSurfaces::present(const QVideoFrame &frame)
+{
+ bool result = true;
+ for (auto &s : m_surfaces)
+ result &= s->present(frame);
+
+ return result;
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/video/qvideoframe_p.h b/src/multimedia/video/qvideosurfaces_p.h
index d7b9dd348..67831e74e 100644
--- a/src/multimedia/video/qvideoframe_p.h
+++ b/src/multimedia/video/qvideosurfaces_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -37,10 +37,8 @@
**
****************************************************************************/
-#ifndef QVIDEOFRAME_P_H
-#define QVIDEOFRAME_P_H
-
-#include <QtMultimedia/qvideoframe.h>
+#ifndef QVIDEOSURFACES_P_H
+#define QVIDEOSURFACES_P_H
//
// W A R N I N G
@@ -53,11 +51,27 @@
// We mean it.
//
+#include <QAbstractVideoSurface>
+#include <QVector>
+
QT_BEGIN_NAMESPACE
-Q_MULTIMEDIA_EXPORT QImage qt_imageFromVideoFrame(const QVideoFrame &frame);
+class QVideoSurfaces : public QAbstractVideoSurface
+{
+public:
+ QVideoSurfaces(const QVector<QAbstractVideoSurface *> &surfaces, QObject *parent = nullptr);
+ ~QVideoSurfaces();
-QT_END_NAMESPACE
+ QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const override;
+ bool start(const QVideoSurfaceFormat &format) override;
+ void stop() override;
+ bool present(const QVideoFrame &frame) override;
-#endif // QVIDEOFRAME_P_H
+private:
+ QVector<QAbstractVideoSurface *> m_surfaces;
+ Q_DISABLE_COPY(QVideoSurfaces)
+};
+
+QT_END_NAMESPACE
+#endif // QVIDEOSURFACES_P_H
diff --git a/src/multimedia/video/video.pri b/src/multimedia/video/video.pri
index e5fa697ce..a3668ba4a 100644
--- a/src/multimedia/video/video.pri
+++ b/src/multimedia/video/video.pri
@@ -15,8 +15,8 @@ PRIVATE_HEADERS += \
video/qmemoryvideobuffer_p.h \
video/qvideooutputorientationhandler_p.h \
video/qvideosurfaceoutput_p.h \
- video/qvideoframe_p.h \
- video/qvideoframeconversionhelper_p.h
+ video/qvideoframeconversionhelper_p.h \
+ video/qvideosurfaces_p.h
SOURCES += \
video/qabstractvideobuffer.cpp \
@@ -29,7 +29,8 @@ SOURCES += \
video/qvideosurfaceoutput.cpp \
video/qvideoprobe.cpp \
video/qabstractvideofilter.cpp \
- video/qvideoframeconversionhelper.cpp
+ video/qvideoframeconversionhelper.cpp \
+ video/qvideosurfaces.cpp
SSE2_SOURCES += video/qvideoframeconversionhelper_sse2.cpp
SSSE3_SOURCES += video/qvideoframeconversionhelper_ssse3.cpp