1// Copyright (C) 2021 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//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QMEDIAPLAYERCONTROL_H
16#define QMEDIAPLAYERCONTROL_H
17
18#include <QtMultimedia/qmediaplayer.h>
19#include <QtMultimedia/qmediatimerange.h>
20#include <QtMultimedia/qaudiodevice.h>
21#include <QtMultimedia/qmediametadata.h>
22
23#include <QtCore/qpair.h>
24#include <QtCore/private/qglobal_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QMediaStreamsControl;
29class QPlatformAudioOutput;
30
31class Q_MULTIMEDIA_EXPORT QPlatformMediaPlayer
32{
33public:
34 virtual ~QPlatformMediaPlayer();
35 virtual QMediaPlayer::PlaybackState state() const { return m_state; }
36 virtual QMediaPlayer::MediaStatus mediaStatus() const { return m_status; };
37
38 virtual qint64 duration() const = 0;
39
40 virtual qint64 position() const { return m_position; }
41 virtual void setPosition(qint64 position) = 0;
42
43 virtual float bufferProgress() const = 0;
44
45 virtual bool isAudioAvailable() const { return m_audioAvailable; }
46 virtual bool isVideoAvailable() const { return m_videoAvailable; }
47
48 virtual bool isSeekable() const { return m_seekable; }
49
50 virtual QMediaTimeRange availablePlaybackRanges() const = 0;
51
52 virtual qreal playbackRate() const = 0;
53 virtual void setPlaybackRate(qreal rate) = 0;
54
55 virtual QUrl media() const = 0;
56 virtual const QIODevice *mediaStream() const = 0;
57 virtual void setMedia(const QUrl &media, QIODevice *stream) = 0;
58
59 virtual void play() = 0;
60 virtual void pause() = 0;
61 virtual void stop() = 0;
62
63 virtual bool streamPlaybackSupported() const { return false; }
64
65 virtual void setAudioOutput(QPlatformAudioOutput *) {}
66
67 virtual QMediaMetaData metaData() const { return {}; }
68
69 virtual void setVideoSink(QVideoSink * /*sink*/) = 0;
70
71 // media streams
72 enum TrackType { VideoStream, AudioStream, SubtitleStream, NTrackTypes };
73
74 virtual int trackCount(TrackType) { return 0; };
75 virtual QMediaMetaData trackMetaData(TrackType /*type*/, int /*streamNumber*/) { return QMediaMetaData(); }
76 virtual int activeTrack(TrackType) { return -1; }
77 virtual void setActiveTrack(TrackType, int /*streamNumber*/) {}
78
79 void durationChanged(qint64 duration) { emit player->durationChanged(duration); }
80 void positionChanged(qint64 position) {
81 if (m_position == position)
82 return;
83 m_position = position;
84 emit player->positionChanged(position);
85 }
86 void audioAvailableChanged(bool audioAvailable) {
87 if (m_audioAvailable == audioAvailable)
88 return;
89 m_audioAvailable = audioAvailable;
90 emit player->hasAudioChanged(available: audioAvailable);
91 }
92 void videoAvailableChanged(bool videoAvailable) {
93 if (m_videoAvailable == videoAvailable)
94 return;
95 m_videoAvailable = videoAvailable;
96 emit player->hasVideoChanged(videoAvailable);
97 }
98 void seekableChanged(bool seekable) {
99 if (m_seekable == seekable)
100 return;
101 m_seekable = seekable;
102 emit player->seekableChanged(seekable);
103 }
104 void playbackRateChanged(qreal rate) { emit player->playbackRateChanged(rate); }
105 void bufferProgressChanged(float progress) { emit player->bufferProgressChanged(progress); }
106 void metaDataChanged() { emit player->metaDataChanged(); }
107 void tracksChanged() { emit player->tracksChanged(); }
108 void activeTracksChanged() { emit player->activeTracksChanged(); }
109
110 void stateChanged(QMediaPlayer::PlaybackState newState);
111 void mediaStatusChanged(QMediaPlayer::MediaStatus status);
112 void error(int error, const QString &errorString);
113
114 void resetCurrentLoop() { m_currentLoop = 0; }
115 bool doLoop() {
116 return isSeekable() && (m_loops < 0 || ++m_currentLoop < m_loops);
117 }
118 int loops() { return m_loops; }
119 virtual void setLoops(int loops)
120 {
121 if (m_loops == loops)
122 return;
123 m_loops = loops;
124 Q_EMIT player->loopsChanged();
125 }
126
127 virtual void *nativePipeline() { return nullptr; }
128
129 // private API, the purpose is getting GstPipeline
130 static void *nativePipeline(QMediaPlayer *player);
131
132protected:
133 explicit QPlatformMediaPlayer(QMediaPlayer *parent = nullptr);
134
135private:
136 QMediaPlayer *player = nullptr;
137 QMediaPlayer::MediaStatus m_status = QMediaPlayer::NoMedia;
138 QMediaPlayer::PlaybackState m_state = QMediaPlayer::StoppedState;
139 bool m_seekable = false;
140 bool m_videoAvailable = false;
141 bool m_audioAvailable = false;
142 int m_loops = 1;
143 int m_currentLoop = 0;
144 qint64 m_position = 0;
145};
146
147QT_END_NAMESPACE
148
149
150#endif // QMEDIAPLAYERCONTROL_H
151
152

source code of qtmultimedia/src/multimedia/platform/qplatformmediaplayer_p.h