summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/multimedia/CMakeLists.txt1
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp91
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h12
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstreamervideooutput.cpp146
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstreamervideooutput_p.h99
5 files changed, 255 insertions, 94 deletions
diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt
index fcd4aed4b..4c7b387c4 100644
--- a/src/multimedia/CMakeLists.txt
+++ b/src/multimedia/CMakeLists.txt
@@ -198,6 +198,7 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_gstreamer
platform/gstreamer/common/qgstreamermetadata.cpp platform/gstreamer/common/qgstreamermetadata_p.h
platform/gstreamer/common/qgstreamermessage.cpp platform/gstreamer/common/qgstreamermessage_p.h
platform/gstreamer/common/qgstreamermediaplayer.cpp platform/gstreamer/common/qgstreamermediaplayer_p.h
+ platform/gstreamer/common/qgstreamervideooutput.cpp platform/gstreamer/common/qgstreamervideooutput_p.h
platform/gstreamer/common/qgstreamervideooverlay.cpp platform/gstreamer/common/qgstreamervideooverlay_p.h
platform/gstreamer/common/qgstreamervideorenderer.cpp platform/gstreamer/common/qgstreamervideorenderer_p.h
platform/gstreamer/common/qgstreamervideowindow.cpp platform/gstreamer/common/qgstreamervideowindow_p.h
diff --git a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp
index e671e6194..f87008fec 100644
--- a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp
+++ b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp
@@ -43,6 +43,7 @@
#include <private/qgstreamermetadata_p.h>
#include <private/qgstreamerformatinfo_p.h>
#include <private/qgstreameraudiooutput_p.h>
+#include <private/qgstreamervideooutput_p.h>
#include <private/qaudiodeviceinfo_gstreamer_p.h>
#include <private/qgstappsrc_p.h>
#include <qaudiodeviceinfo.h>
@@ -76,12 +77,12 @@ QGstreamerMediaPlayer::QGstreamerMediaPlayer(QMediaPlayer *parent)
playerPipeline.add(inputSelector[AudioStream], gstAudioOutput->gstElement());
inputSelector[AudioStream].link(gstAudioOutput->gstElement());
+ gstVideoOutput = new QGstreamerVideoOutput(this);
+ gstVideoOutput->setPipeline(playerPipeline);
+
inputSelector[VideoStream] = QGstElement("input-selector", "videoInputSelector");
- videoQueue = QGstElement("queue", "videoQueue");
- videoConvert = QGstElement("videoconvert", "videoConvert");
- videoScale = QGstElement("videoscale", "videoScale");
- playerPipeline.add(inputSelector[VideoStream], videoQueue, videoConvert, videoScale);
- inputSelector[VideoStream].link(videoQueue, videoConvert, videoScale);
+ playerPipeline.add(inputSelector[VideoStream], gstVideoOutput->gstElement());
+ inputSelector[VideoStream].link(gstVideoOutput->gstElement());
inputSelector[SubtitleStream] = QGstElement("input-selector", "subTitleInputSelector");
playerPipeline.add(inputSelector[SubtitleStream]);
@@ -604,76 +605,6 @@ QMediaMetaData QGstreamerMediaPlayer::metaData() const
return m_metaData;
}
-void QGstreamerMediaPlayer::updateVideoSink()
-{
- qCDebug(qLcMediaPlayer) << "Video sink has changed, reload video output";
-
- QGstElement newSink;
- if (m_videoOutput && m_videoOutput->isReady())
- newSink = m_videoOutput->videoSink();
-
- if (newSink.isNull())
- newSink = QGstElement("fakesink", "fakevideosink");
-
- if (newSink == videoSink)
- return;
-
- qCDebug(qLcMediaPlayer) << "Reconfiguring video output";
-
- if (m_state == QMediaPlayer::StoppedState) {
- qCDebug(qLcMediaPlayer) << "The pipeline has not started yet";
-
- //the pipeline has not started yet
- playerPipeline.setState(GST_STATE_NULL);
- if (!videoSink.isNull()) {
- videoSink.setState(GST_STATE_NULL);
- playerPipeline.remove(videoSink);
- }
- videoSink = newSink;
- playerPipeline.add(videoSink);
- if (!videoScale.link(videoSink))
- qCWarning(qLcMediaPlayer) << "Linking new video output failed";
-
- if (g_object_class_find_property(G_OBJECT_GET_CLASS(videoSink.object()), "show-preroll-frame") != nullptr)
- videoSink.set("show-preroll-frame", true);
-
-// switch (m_pendingState) {
-// case QMediaPlayer::PausedState:
-// gst_element_set_state(m_playbin, GST_STATE_PAUSED);
-// break;
-// case QMediaPlayer::PlayingState:
-// gst_element_set_state(m_playbin, GST_STATE_PLAYING);
-// break;
-// default:
-// break;
-// }
-
- } else {
-// if (m_pendingVideoSink) {
-// qCDebug(qLcMediaPlayer) << "already waiting for pad to be blocked, just change the pending sink";
-// m_pendingVideoSink = videoSink;
-// return;
-// }
-
-// m_pendingVideoSink = videoSink;
-
-// qCDebug(qLcMediaPlayer) << "Blocking the video output pad...";
-
-// //block pads, async to avoid locking in paused state
-// GstPad *srcPad = gst_element_get_static_pad(m_videoIdentity, "src");
-// this->pad_probe_id = gst_pad_add_probe(srcPad, (GstPadProbeType)(GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BLOCKING), block_pad_cb, this, nullptr);
-// gst_object_unref(GST_OBJECT(srcPad));
-
-// //Unpause the sink to avoid waiting until the buffer is processed
-// //while the sink is paused. The pad will be blocked as soon as the current
-// //buffer is processed.
-// if (m_state == QMediaPlayer::PausedState) {
-// qCDebug(qLcMediaPlayer) << "Starting video output to avoid blocking in paused state...";
-// gst_element_set_state(m_videoSink, GST_STATE_PLAYING);
-// }
- }
-}
-
void QGstreamerMediaPlayer::setSeekable(bool seekable)
{
qCDebug(qLcMediaPlayer) << Q_FUNC_INFO << seekable;
@@ -759,15 +690,7 @@ void QGstreamerMediaPlayer::parseStreamsAndMetadata()
void QGstreamerMediaPlayer::setVideoSurface(QAbstractVideoSurface *surface)
{
- if (!m_videoOutput) {
- m_videoOutput = new QGstreamerVideoRenderer;
- qCDebug(qLcMediaPlayer) << Q_FUNC_INFO;
- connect(m_videoOutput, SIGNAL(sinkChanged()),
- this, SLOT(updateVideoRenderer()));
- }
-
- m_videoOutput->setSurface(surface);
- updateVideoSink();
+ gstVideoOutput->setVideoSurface(surface);
}
int QGstreamerMediaPlayer::trackCount(QPlatformMediaPlayer::TrackType type)
diff --git a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h
index c4248d8de..5aef3fe36 100644
--- a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h
+++ b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h
@@ -65,6 +65,7 @@ class QGstreamerBusHelper;
class QGstreamerMessage;
class QGstAppSrc;
class QGstreamerAudioOutput;
+class QGstreamerVideoOutput;
class Q_MULTIMEDIA_EXPORT QGstreamerMediaPlayer : public QObject, public QPlatformMediaPlayer
{
@@ -131,7 +132,6 @@ private:
void decoderPadAdded(const QGstElement &src, const QGstPad &pad);
void decoderPadRemoved(const QGstElement &src, const QGstPad &pad);
static void uridecodebinElementAddedCallback(GstElement *uridecodebin, GstElement *child, QGstreamerMediaPlayer *that);
- void updateVideoSink();
void setSeekable(bool seekable);
void parseStreamsAndMetadata();
@@ -152,10 +152,6 @@ private:
bool m_seekable = false;
qint64 m_duration = 0;
- QAudioDeviceInfo m_audioOutput;
- QAbstractVideoSurface *m_videoSurface = nullptr;
- QGstreamerVideoRenderer *m_videoOutput = nullptr;
-
QGstreamerBusHelper *busHelper;
QGstAppSrc *m_appSrc;
@@ -169,14 +165,10 @@ private:
QGstElement inputSelector[3];
QGstreamerAudioOutput *gstAudioOutput;
+ QGstreamerVideoOutput *gstVideoOutput;
// QGstElement streamSynchronizer;
- QGstElement videoQueue;
- QGstElement videoConvert;
- QGstElement videoScale;
- QGstElement videoSink;
-
QHash<QByteArray, QGstPad> decoderOutputMap;
};
diff --git a/src/multimedia/platform/gstreamer/common/qgstreamervideooutput.cpp b/src/multimedia/platform/gstreamer/common/qgstreamervideooutput.cpp
new file mode 100644
index 000000000..939e88599
--- /dev/null
+++ b/src/multimedia/platform/gstreamer/common/qgstreamervideooutput.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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 <private/qgstreamervideooutput_p.h>
+#include <private/qgstreamervideorenderer_p.h>
+
+#include <QtCore/qloggingcategory.h>
+#include <qthread.h>
+
+Q_LOGGING_CATEGORY(qLcMediaVideoOutput, "qt.multimedia.videooutput")
+
+QT_BEGIN_NAMESPACE
+
+QGstreamerVideoOutput::QGstreamerVideoOutput(QObject *parent)
+ : QObject(parent),
+ gstVideoOutput("videoOutput")
+{
+ videoQueue = QGstElement("queue", "videoQueue");
+ videoConvert = QGstElement("videoconvert", "videoConvert");
+ videoScale = QGstElement("videoscale", "videoScale");
+ videoSink = QGstElement("fakesink", "fakeVideoSink");
+ gstVideoOutput.add(videoQueue, videoConvert, videoScale, videoSink);
+ videoQueue.link(videoConvert, videoScale, videoSink);
+
+ gstVideoOutput.addGhostPad(videoQueue, "sink");
+}
+
+QGstreamerVideoOutput::~QGstreamerVideoOutput()
+{
+}
+
+static QGstElement getSink(QGstreamerVideoRenderer *output)
+{
+ QGstElement newSink;
+ if (output && output->isReady())
+ newSink = output->videoSink();
+
+ if (newSink.isNull())
+ newSink = QGstElement("fakesink", "fakevideosink");
+
+ return newSink;
+}
+
+void QGstreamerVideoOutput::setVideoSurface(QAbstractVideoSurface *surface)
+{
+ if (!m_videoOutput) {
+ m_videoOutput = new QGstreamerVideoRenderer;
+ qCDebug(qLcMediaVideoOutput) << Q_FUNC_INFO;
+ connect(m_videoOutput, SIGNAL(sinkChanged()),
+ this, SLOT(updateVideoRenderer()));
+ }
+
+ m_videoOutput->setSurface(surface);
+
+ newVideoSink = getSink(m_videoOutput);
+ if (newVideoSink == videoSink) {
+ newVideoSink = {};
+ return;
+ }
+ gstVideoOutput.add(newVideoSink);
+
+ qCDebug(qLcMediaVideoOutput) << "setVideoSurface: Reconfiguring video output" << QThread::currentThreadId();
+
+ auto state = gstPipeline.state();
+
+ if (state != GST_STATE_PLAYING) {
+ changeVideoOutput();
+ return;
+ }
+
+ // This doesn't quite work, as we're be getting the callback in another thread where state changes aren't allowed.
+ auto pad = videoScale.staticPad("src");
+ pad.addProbe<&QGstreamerVideoOutput::prepareVideoOutputChange>(this, GST_PAD_PROBE_TYPE_IDLE);
+}
+
+void QGstreamerVideoOutput::setIsPreview()
+{
+ // configures the queue to be fast and lightweight for camera preview
+ // also avoids blocking the queue in case we have an encodebin attached to the tee as well
+ videoQueue.set("leaky", 2 /*downstream*/);
+ videoQueue.set("silent", true);
+ videoQueue.set("max-size-buffers", 1);
+ videoQueue.set("max-size-bytes", 0);
+ videoQueue.set("max-size-time", 0);
+}
+
+void QGstreamerVideoOutput::changeVideoOutput()
+{
+ qCDebug(qLcMediaVideoOutput) << "Changing video output" << QThread::currentThreadId();
+
+ auto state = videoSink.state();
+ videoSink.setState(GST_STATE_NULL);
+ gstVideoOutput.remove(videoSink);
+ videoSink = newVideoSink;
+ videoScale.link(videoSink);
+ videoSink.setState(state);
+ newVideoSink = {};
+}
+
+void QGstreamerVideoOutput::prepareVideoOutputChange(const QGstPad &/*pad*/)
+{
+ qCDebug(qLcMediaVideoOutput) << "Reconfiguring video output" << QThread::currentThreadId();
+
+ gstPipeline.setState(GST_STATE_PAUSED);
+ changeVideoOutput();
+ gstPipeline.setState(GST_STATE_PLAYING);
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/platform/gstreamer/common/qgstreamervideooutput_p.h b/src/multimedia/platform/gstreamer/common/qgstreamervideooutput_p.h
new file mode 100644
index 000000000..d2612e76f
--- /dev/null
+++ b/src/multimedia/platform/gstreamer/common/qgstreamervideooutput_p.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGSTREAMERVIDEOOUTPUT_P_H
+#define QGSTREAMERVIDEOOUTPUT_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 <QtCore/qobject.h>
+#include <private/qtmultimediaglobal_p.h>
+#include <private/qgst_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QGstreamerVideoRenderer;
+class QAbstractVideoSurface;
+
+class Q_MULTIMEDIA_EXPORT QGstreamerVideoOutput : public QObject
+{
+ Q_OBJECT
+
+public:
+ QGstreamerVideoOutput(QObject *parent = 0);
+ ~QGstreamerVideoOutput();
+
+ void setVideoSurface(QAbstractVideoSurface *surface);
+
+ void setPipeline(const QGstPipeline &pipeline) { gstPipeline = pipeline; }
+
+ QGstElement gstElement() const { return gstVideoOutput; }
+
+ void setIsPreview();
+
+private:
+ void prepareVideoOutputChange(const QGstPad &pad);
+ void changeVideoOutput();
+
+ QAbstractVideoSurface *m_videoSurface = nullptr;
+ QGstreamerVideoRenderer *m_videoOutput = nullptr;
+
+ // Gst elements
+ QGstPipeline gstPipeline;
+
+ QGstBin gstVideoOutput;
+ QGstElement videoQueue;
+ QGstElement videoConvert;
+ QGstElement videoScale;
+ QGstElement videoSink;
+ QGstElement newVideoSink;
+};
+
+QT_END_NAMESPACE
+
+#endif