diff options
Diffstat (limited to 'src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h')
-rw-r--r-- | src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h | 139 |
1 files changed, 75 insertions, 64 deletions
diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h index cfc576643..cf337f32c 100644 --- a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h +++ b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QGSTREAMERMEDIAPLAYER_P_H #define QGSTREAMERMEDIAPLAYER_P_H @@ -54,9 +18,10 @@ #include <QtCore/qstack.h> #include <private/qplatformmediaplayer_p.h> #include <private/qtmultimediaglobal_p.h> +#include <private/qmultimediautils_p.h> #include <qurl.h> -#include <qgst_p.h> -#include <qgstpipeline_p.h> +#include <common/qgst_p.h> +#include <common/qgstpipeline_p.h> #include <QtCore/qtimer.h> @@ -66,23 +31,19 @@ QT_BEGIN_NAMESPACE class QNetworkAccessManager; class QGstreamerMessage; -class QGstAppSrc; +class QGstAppSource; class QGstreamerAudioOutput; class QGstreamerVideoOutput; -class Q_MULTIMEDIA_EXPORT QGstreamerMediaPlayer - : public QObject, - public QPlatformMediaPlayer, - public QGstreamerBusMessageFilter, - public QGstreamerSyncMessageFilter +class QGstreamerMediaPlayer : public QObject, + public QPlatformMediaPlayer, + public QGstreamerBusMessageFilter, + public QGstreamerSyncMessageFilter { - Q_OBJECT - public: - QGstreamerMediaPlayer(QMediaPlayer *parent = 0); + static QMaybe<QPlatformMediaPlayer *> create(QMediaPlayer *parent = nullptr); ~QGstreamerMediaPlayer(); - qint64 position() const override; qint64 duration() const override; float bufferProgress() const override; @@ -94,7 +55,7 @@ public: QUrl media() const override; const QIODevice *mediaStream() const override; - void setMedia(const QUrl&, QIODevice *) override; + void setMedia(const QUrl &, QIODevice *) override; bool streamPlaybackSupported() const override { return true; } @@ -110,26 +71,32 @@ public: void setActiveTrack(TrackType, int /*streamNumber*/) override; void setPosition(qint64 pos) override; + void setPosition(std::chrono::milliseconds pos); void play() override; void pause() override; void stop() override; + const QGstPipeline &pipeline() const; + bool processBusMessage(const QGstreamerMessage& message) override; bool processSyncMessage(const QGstreamerMessage& message) override; -public Q_SLOTS: - void updatePosition() { positionChanged(position()); } - private: - struct TrackSelector { - TrackSelector(TrackType, const char *name); + QGstreamerMediaPlayer(QGstreamerVideoOutput *videoOutput, QMediaPlayer *parent); + + struct TrackSelector + { + TrackSelector(TrackType, QGstElement selector); QGstPad createInputPad(); void removeInputPad(QGstPad pad); void removeAllInputPads(); QGstPad inputPad(int index); int activeInputIndex() const { return isConnected ? tracks.indexOf(activeInputPad()) : -1; } - QGstPad activeInputPad() const { return isConnected ? selector.getObject("active-pad") : QGstPad{}; } + QGstPad activeInputPad() const + { + return isConnected ? QGstPad{ selector.getObject("active-pad") } : QGstPad{}; + } void setActiveInputPad(QGstPad input) { selector.set("active-pad", input); } int trackCount() const { return tracks.count(); } @@ -142,31 +109,56 @@ private: friend class QGstreamerStreamsControl; 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 disconnectDecoderHandlers(); + static void uridecodebinElementAddedCallback(GstElement *uridecodebin, GstElement *child, + QGstreamerMediaPlayer *that); + static void sourceSetupCallback(GstElement *uridecodebin, GstElement *source, + QGstreamerMediaPlayer *that); + static void unknownTypeCallback(GstElement *decodebin, GstPad *pad, GstCaps *caps, + QGstreamerMediaPlayer *self); + static void decodebinElementAddedCallback(GstBin *decodebin, GstBin *sub_bin, + GstElement *element, QGstreamerMediaPlayer *self); + static void decodebinElementRemovedCallback(GstBin *decodebin, GstBin *sub_bin, + GstElement *element, QGstreamerMediaPlayer *self); + void parseStreamsAndMetadata(); void connectOutput(TrackSelector &ts); void removeOutput(TrackSelector &ts); + void removeDynamicPipelineElements(); void removeAllOutputs(); void stopOrEOS(bool eos); + bool canTrackProgress() const { return decodeBinQueues > 0; } + void detectPipelineIsSeekable(); + + std::chrono::nanoseconds pipelinePosition() const; + void updatePositionFromPipeline(); std::array<TrackSelector, NTrackTypes> trackSelectors; TrackSelector &trackSelector(TrackType type); QMediaMetaData m_metaData; - int m_bufferProgress = -1; + int m_bufferProgress = 0; QUrl m_url; QIODevice *m_stream = nullptr; + enum class ResourceErrorState : uint8_t { + NoError, + ErrorOccurred, + ErrorReported, + }; + bool prerolling = false; bool m_requiresSeekOnPlay = false; - qint64 m_duration = 0; + bool m_initialBufferProgressSent = false; + ResourceErrorState m_resourceErrorState = ResourceErrorState::NoError; + float m_rate = 1.f; + std::chrono::milliseconds m_duration{}; QTimer positionUpdateTimer; - QGstAppSrc *m_appSrc = nullptr; + QGstAppSource *m_appSrc = nullptr; - GType decodebinType; - QGstStructure topology; + QUniqueGstStructureHandle topology; // Gst elements QGstPipeline playerPipeline; @@ -178,7 +170,26 @@ private: // QGstElement streamSynchronizer; - QHash<QByteArray, QGstPad> decoderOutputMap; + struct QGstPadLess + { + bool operator()(const QGstPad &lhs, const QGstPad &rhs) const + { + return lhs.pad() < rhs.pad(); + } + }; + + std::map<QGstPad, QGstPad, QGstPadLess> decoderOutputMap; + + // decoder connections + QGObjectHandlerScopedConnection padAdded; + QGObjectHandlerScopedConnection padRemoved; + QGObjectHandlerScopedConnection sourceSetup; + QGObjectHandlerScopedConnection uridecodebinElementAdded; + QGObjectHandlerScopedConnection unknownType; + QGObjectHandlerScopedConnection elementAdded; + QGObjectHandlerScopedConnection elementRemoved; + + int decodeBinQueues = 0; }; QT_END_NAMESPACE |