1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QGSTREAMERMEDIAPLAYER_P_H
5#define QGSTREAMERMEDIAPLAYER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qstack.h>
19#include <private/qplatformmediaplayer_p.h>
20#include <private/qtmultimediaglobal_p.h>
21#include <private/qmultimediautils_p.h>
22#include <qurl.h>
23#include <qgst_p.h>
24#include <qgstpipeline_p.h>
25
26#include <QtCore/qtimer.h>
27
28#include <array>
29
30QT_BEGIN_NAMESPACE
31
32class QNetworkAccessManager;
33class QGstreamerMessage;
34class QGstAppSrc;
35class QGstreamerAudioOutput;
36class QGstreamerVideoOutput;
37
38class Q_MULTIMEDIA_EXPORT QGstreamerMediaPlayer
39 : public QObject,
40 public QPlatformMediaPlayer,
41 public QGstreamerBusMessageFilter,
42 public QGstreamerSyncMessageFilter
43{
44 Q_OBJECT
45
46public:
47 static QMaybe<QPlatformMediaPlayer *> create(QMediaPlayer *parent = nullptr);
48 ~QGstreamerMediaPlayer();
49
50 qint64 position() const override;
51 qint64 duration() const override;
52
53 float bufferProgress() const override;
54
55 QMediaTimeRange availablePlaybackRanges() const override;
56
57 qreal playbackRate() const override;
58 void setPlaybackRate(qreal rate) override;
59
60 QUrl media() const override;
61 const QIODevice *mediaStream() const override;
62 void setMedia(const QUrl&, QIODevice *) override;
63
64 bool streamPlaybackSupported() const override { return true; }
65
66 void setAudioOutput(QPlatformAudioOutput *output) override;
67
68 QMediaMetaData metaData() const override;
69
70 void setVideoSink(QVideoSink *sink) override;
71
72 int trackCount(TrackType) override;
73 QMediaMetaData trackMetaData(TrackType /*type*/, int /*streamNumber*/) override;
74 int activeTrack(TrackType) override;
75 void setActiveTrack(TrackType, int /*streamNumber*/) override;
76
77 void setPosition(qint64 pos) override;
78
79 void play() override;
80 void pause() override;
81 void stop() override;
82
83 void *nativePipeline() override;
84
85 bool processBusMessage(const QGstreamerMessage& message) override;
86 bool processSyncMessage(const QGstreamerMessage& message) override;
87public Q_SLOTS:
88 void updatePosition() { positionChanged(position: position()); }
89
90private:
91 QGstreamerMediaPlayer(QGstreamerVideoOutput *videoOutput, QGstElement decodebin,
92 QGstElement videoInputSelector, QGstElement audioInputSelector,
93 QGstElement subTitleInputSelector, QMediaPlayer *parent);
94
95 struct TrackSelector {
96 TrackSelector(TrackType, QGstElement selector);
97 QGstPad createInputPad();
98 void removeInputPad(QGstPad pad);
99 void removeAllInputPads();
100 QGstPad inputPad(int index);
101 int activeInputIndex() const { return isConnected ? tracks.indexOf(t: activeInputPad()) : -1; }
102 QGstPad activeInputPad() const { return isConnected ? selector.getObject(property: "active-pad") : QGstPad{}; }
103 void setActiveInputPad(QGstPad input) { selector.set(property: "active-pad", o: input); }
104 int trackCount() const { return tracks.count(); }
105
106 QGstElement selector;
107 TrackType type;
108 QList<QGstPad> tracks;
109 bool isConnected = false;
110 };
111
112 friend class QGstreamerStreamsControl;
113 void decoderPadAdded(const QGstElement &src, const QGstPad &pad);
114 void decoderPadRemoved(const QGstElement &src, const QGstPad &pad);
115 static void uridecodebinElementAddedCallback(GstElement *uridecodebin, GstElement *child, QGstreamerMediaPlayer *that);
116 static void sourceSetupCallback(GstElement *uridecodebin, GstElement *source, QGstreamerMediaPlayer *that);
117 void parseStreamsAndMetadata();
118 void connectOutput(TrackSelector &ts);
119 void removeOutput(TrackSelector &ts);
120 void removeAllOutputs();
121 void stopOrEOS(bool eos);
122
123 std::array<TrackSelector, NTrackTypes> trackSelectors;
124 TrackSelector &trackSelector(TrackType type);
125
126 QMediaMetaData m_metaData;
127
128 int m_bufferProgress = -1;
129 QUrl m_url;
130 QIODevice *m_stream = nullptr;
131
132 bool prerolling = false;
133 bool m_requiresSeekOnPlay = false;
134 qint64 m_duration = 0;
135 QTimer positionUpdateTimer;
136
137 QGstAppSrc *m_appSrc = nullptr;
138
139 GType decodebinType;
140 QGstStructure topology;
141
142 // Gst elements
143 QGstPipeline playerPipeline;
144 QGstElement src;
145 QGstElement decoder;
146
147 QGstreamerAudioOutput *gstAudioOutput = nullptr;
148 QGstreamerVideoOutput *gstVideoOutput = nullptr;
149
150 // QGstElement streamSynchronizer;
151
152 QHash<QByteArray, QGstPad> decoderOutputMap;
153};
154
155QT_END_NAMESPACE
156
157#endif
158

source code of qtmultimedia/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer_p.h