1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QGSTREAMERPLAYERSESSION_P_H
41#define QGSTREAMERPLAYERSESSION_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtMultimedia/private/qtmultimediaglobal_p.h>
55#include <QObject>
56#include <QtCore/qmutex.h>
57#include <QtNetwork/qnetworkrequest.h>
58#include <private/qgstreamerplayercontrol_p.h>
59#include <private/qgstreamerbushelper_p.h>
60#include <qmediaplayer.h>
61#include <qmediastreamscontrol.h>
62#include <qaudioformat.h>
63
64#if QT_CONFIG(gstreamer_app)
65#include <private/qgstappsrc_p.h>
66#endif
67
68#include <gst/gst.h>
69
70QT_BEGIN_NAMESPACE
71
72class QGstreamerBusHelper;
73class QGstreamerMessage;
74
75class QGstreamerVideoRendererInterface;
76class QGstreamerVideoProbeControl;
77class QGstreamerAudioProbeControl;
78
79typedef enum {
80 GST_AUTOPLUG_SELECT_TRY,
81 GST_AUTOPLUG_SELECT_EXPOSE,
82 GST_AUTOPLUG_SELECT_SKIP
83} GstAutoplugSelectResult;
84
85class Q_GSTTOOLS_EXPORT QGstreamerPlayerSession
86 : public QObject
87 , public QGstreamerBusMessageFilter
88{
89Q_OBJECT
90Q_INTERFACES(QGstreamerBusMessageFilter)
91
92public:
93 QGstreamerPlayerSession(QObject *parent);
94 virtual ~QGstreamerPlayerSession();
95
96 GstElement *playbin() const;
97 GstElement *pipeline() const { return m_pipeline; }
98 QGstreamerBusHelper *bus() const { return m_busHelper; }
99
100 QNetworkRequest request() const;
101
102 QMediaPlayer::State state() const { return m_state; }
103 QMediaPlayer::State pendingState() const { return m_pendingState; }
104
105 qint64 duration() const;
106 qint64 position() const;
107
108 int volume() const;
109 bool isMuted() const;
110
111 bool isAudioAvailable() const;
112
113 void setVideoRenderer(QObject *renderer);
114 QGstreamerVideoRendererInterface *renderer() const { return m_renderer; }
115 bool isVideoAvailable() const;
116
117 bool isSeekable() const;
118
119 qreal playbackRate() const;
120 void setPlaybackRate(qreal rate);
121
122 QMediaTimeRange availablePlaybackRanges() const;
123
124 QMap<QByteArray ,QVariant> tags() const { return m_tags; }
125 QMap<QString,QVariant> streamProperties(int streamNumber) const { return m_streamProperties[streamNumber]; }
126 int streamCount() const { return m_streamProperties.count(); }
127 QMediaStreamsControl::StreamType streamType(int streamNumber) { return m_streamTypes.value(i: streamNumber, defaultValue: QMediaStreamsControl::UnknownStream); }
128
129 int activeStream(QMediaStreamsControl::StreamType streamType) const;
130 void setActiveStream(QMediaStreamsControl::StreamType streamType, int streamNumber);
131
132 bool processBusMessage(const QGstreamerMessage &message) override;
133
134#if QT_CONFIG(gstreamer_app)
135 QGstAppSrc *appsrc() const { return m_appSrc; }
136 static void configureAppSrcElement(GObject*, GObject*, GParamSpec*,QGstreamerPlayerSession* _this);
137#endif
138
139 bool isLiveSource() const;
140
141 void addProbe(QGstreamerVideoProbeControl* probe);
142 void removeProbe(QGstreamerVideoProbeControl* probe);
143
144 void addProbe(QGstreamerAudioProbeControl* probe);
145 void removeProbe(QGstreamerAudioProbeControl* probe);
146
147 void endOfMediaReset();
148
149public slots:
150 void loadFromUri(const QNetworkRequest &url);
151 void loadFromStream(const QNetworkRequest &url, QIODevice *stream);
152 bool play();
153 bool pause();
154 void stop();
155
156 bool seek(qint64 pos);
157
158 void setVolume(int volume);
159 void setMuted(bool muted);
160
161 void showPrerollFrames(bool enabled);
162
163signals:
164 void durationChanged(qint64 duration);
165 void positionChanged(qint64 position);
166 void stateChanged(QMediaPlayer::State state);
167 void volumeChanged(int volume);
168 void mutedStateChanged(bool muted);
169 void audioAvailableChanged(bool audioAvailable);
170 void videoAvailableChanged(bool videoAvailable);
171 void bufferingProgressChanged(int percentFilled);
172 void playbackFinished();
173 void tagsChanged();
174 void streamsChanged();
175 void seekableChanged(bool);
176 void error(int error, const QString &errorString);
177 void invalidMedia();
178 void playbackRateChanged(qreal);
179 void rendererChanged();
180 void pipelineChanged();
181
182private slots:
183 void getStreamsInfo();
184 void setSeekable(bool);
185 void finishVideoOutputChange();
186 void updateVideoRenderer();
187 void updateVideoResolutionTag();
188 void updateVolume();
189 void updateMuted();
190 void updateDuration();
191
192private:
193 static void playbinNotifySource(GObject *o, GParamSpec *p, gpointer d);
194 static void handleVolumeChange(GObject *o, GParamSpec *p, gpointer d);
195 static void handleMutedChange(GObject *o, GParamSpec *p, gpointer d);
196#if !GST_CHECK_VERSION(1,0,0)
197 static void insertColorSpaceElement(GstElement *element, gpointer data);
198#endif
199 static void handleElementAdded(GstBin *bin, GstElement *element, QGstreamerPlayerSession *session);
200 static void handleStreamsChange(GstBin *bin, gpointer user_data);
201 static GstAutoplugSelectResult handleAutoplugSelect(GstBin *bin, GstPad *pad, GstCaps *caps, GstElementFactory *factory, QGstreamerPlayerSession *session);
202
203 void processInvalidMedia(QMediaPlayer::Error errorCode, const QString& errorString);
204
205 void removeVideoBufferProbe();
206 void addVideoBufferProbe();
207 void removeAudioBufferProbe();
208 void addAudioBufferProbe();
209 void flushVideoProbes();
210 void resumeVideoProbes();
211 bool parsePipeline();
212 bool setPipeline(GstElement *pipeline);
213 void resetElements();
214 void initPlaybin();
215 void setBus(GstBus *bus);
216
217 QNetworkRequest m_request;
218 QMediaPlayer::State m_state = QMediaPlayer::StoppedState;
219 QMediaPlayer::State m_pendingState = QMediaPlayer::StoppedState;
220 QGstreamerBusHelper *m_busHelper = nullptr;
221 GstElement *m_playbin = nullptr;
222 GstElement *m_pipeline = nullptr;
223
224 GstElement *m_videoSink = nullptr;
225
226 GstElement *m_videoOutputBin = nullptr;
227 GstElement *m_videoIdentity = nullptr;
228#if !GST_CHECK_VERSION(1,0,0)
229 GstElement *m_colorSpace = nullptr;
230 bool m_usingColorspaceElement = false;
231#endif
232 GstElement *m_pendingVideoSink = nullptr;
233 GstElement *m_nullVideoSink = nullptr;
234
235 GstElement *m_audioSink = nullptr;
236 GstElement *m_volumeElement = nullptr;
237
238 GstBus *m_bus = nullptr;
239 QObject *m_videoOutput = nullptr;
240 QGstreamerVideoRendererInterface *m_renderer = nullptr;
241
242#if QT_CONFIG(gstreamer_app)
243 QGstAppSrc *m_appSrc = nullptr;
244#endif
245
246 QMap<QByteArray, QVariant> m_tags;
247 QList< QMap<QString,QVariant> > m_streamProperties;
248 QList<QMediaStreamsControl::StreamType> m_streamTypes;
249 QMap<QMediaStreamsControl::StreamType, int> m_playbin2StreamOffset;
250
251 QGstreamerVideoProbeControl *m_videoProbe = nullptr;
252 QGstreamerAudioProbeControl *m_audioProbe = nullptr;
253
254 int m_volume = 100;
255 qreal m_playbackRate = 1.0;
256 bool m_muted = false;
257 bool m_audioAvailable = false;
258 bool m_videoAvailable = false;
259 bool m_seekable = false;
260
261 mutable qint64 m_lastPosition = 0;
262 qint64 m_duration = 0;
263 int m_durationQueries = 0;
264
265 bool m_displayPrerolledFrame = true;
266
267 enum SourceType
268 {
269 UnknownSrc,
270 SoupHTTPSrc,
271 UDPSrc,
272 MMSSrc,
273 RTSPSrc,
274 };
275 SourceType m_sourceType = UnknownSrc;
276 bool m_everPlayed = false;
277 bool m_isLiveSource = false;
278
279 gulong pad_probe_id = 0;
280};
281
282QT_END_NAMESPACE
283
284#endif // QGSTREAMERPLAYERSESSION_H
285

source code of qtmultimedia/src/gsttools/qgstreamerplayersession_p.h