Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplatformmediaplayer_p.h
Go to the documentation of this file.
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/private/qglobal_p.h>
24#include <QtCore/qobject.h>
25
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 void setAudioBufferOutput(QAudioBufferOutput *) { }
68
69 virtual QMediaMetaData metaData() const { return {}; }
70
71 virtual void setVideoSink(QVideoSink * /*sink*/) = 0;
72
73 virtual bool canPlayQrc() const { return false; }
74
75 // media streams
76 enum TrackType : uint8_t { VideoStream, AudioStream, SubtitleStream, NTrackTypes };
77
78 virtual int trackCount(TrackType) { return 0; };
79 virtual QMediaMetaData trackMetaData(TrackType /*type*/, int /*streamNumber*/) { return QMediaMetaData(); }
80 virtual int activeTrack(TrackType) { return -1; }
81 virtual void setActiveTrack(TrackType, int /*streamNumber*/) {}
82
83 void durationChanged(std::chrono::milliseconds ms) { durationChanged(ms.count()); }
84 void durationChanged(qint64 duration) { emit player->durationChanged(duration); }
85 void positionChanged(std::chrono::milliseconds ms) { positionChanged(ms.count()); }
86 void positionChanged(qint64 position) {
87 if (m_position == position)
88 return;
89 m_position = position;
90 emit player->positionChanged(position);
91 }
92 void audioAvailableChanged(bool audioAvailable) {
93 if (m_audioAvailable == audioAvailable)
94 return;
95 m_audioAvailable = audioAvailable;
96 emit player->hasAudioChanged(audioAvailable);
97 }
98 void videoAvailableChanged(bool videoAvailable) {
99 if (m_videoAvailable == videoAvailable)
100 return;
101 m_videoAvailable = videoAvailable;
102 emit player->hasVideoChanged(videoAvailable);
103 }
104 void seekableChanged(bool seekable) {
105 if (m_seekable == seekable)
106 return;
107 m_seekable = seekable;
108 emit player->seekableChanged(seekable);
109 }
110 void playbackRateChanged(qreal rate) { emit player->playbackRateChanged(rate); }
111 void bufferProgressChanged(float progress) { emit player->bufferProgressChanged(progress); }
112 void metaDataChanged() { emit player->metaDataChanged(); }
113 void tracksChanged() { emit player->tracksChanged(); }
114 void activeTracksChanged() { emit player->activeTracksChanged(); }
115
116 void stateChanged(QMediaPlayer::PlaybackState newState);
117 void mediaStatusChanged(QMediaPlayer::MediaStatus status);
118 void error(QMediaPlayer::Error, const QString &errorString);
119
120 void resetCurrentLoop() { m_currentLoop = 0; }
121 bool doLoop() {
122 return isSeekable() && (m_loops < 0 || ++m_currentLoop < m_loops);
123 }
124 int loops() const { return m_loops; }
125 virtual void setLoops(int loops)
126 {
127 if (m_loops == loops)
128 return;
129 m_loops = loops;
130 Q_EMIT player->loopsChanged();
131 }
132
133 using PitchCompensationAvailability = QMediaPlayer::PitchCompensationAvailability;
134
135 virtual PitchCompensationAvailability pitchCompensationAvailability() const;
136 virtual void setPitchCompensation(bool enabled);
137 virtual bool pitchCompensation() const;
138 void pitchCompensationChanged(bool enabled) const;
139
140 QPlaybackOptions playbackOptions() const;
141
142 bool qmediaplayerDestructorCalled = false;
143
144protected:
145 explicit QPlatformMediaPlayer(QMediaPlayer *parent = nullptr);
146
147private:
148 QMediaPlayer *player = nullptr;
149 QMediaPlayer::MediaStatus m_status = QMediaPlayer::NoMedia;
150 QMediaPlayer::PlaybackState m_state = QMediaPlayer::StoppedState;
151 bool m_seekable = false;
152 bool m_videoAvailable = false;
153 bool m_audioAvailable = false;
154 int m_loops = 1;
155 int m_currentLoop = 0;
156 qint64 m_position = 0;
157};
158
159#ifndef QT_NO_DEBUG_STREAM
160inline QDebug operator<<(QDebug dbg, QPlatformMediaPlayer::TrackType type)
161{
162 QDebugStateSaver save(dbg);
163 dbg.nospace();
164
165 switch (type) {
166 case QPlatformMediaPlayer::TrackType::AudioStream:
167 return dbg << "AudioStream";
168 case QPlatformMediaPlayer::TrackType::VideoStream:
169 return dbg << "VideoStream";
170 case QPlatformMediaPlayer::TrackType::SubtitleStream:
171 return dbg << "SubtitleStream";
172 default:
173 Q_UNREACHABLE_RETURN(dbg);
174 }
175}
176#endif
177
178QT_END_NAMESPACE
179
180
181#endif // QMEDIAPLAYERCONTROL_H
\inmodule QtMultimedia
QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)