Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
mfplayersession_p.h
Go to the documentation of this file.
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 MFPLAYERSESSION_H
5#define MFPLAYERSESSION_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 <mfapi.h>
19#include <mfidl.h>
20
21#include "qmediaplayer.h"
22#include "qmediatimerange.h"
23
24#include <QtCore/qcoreevent.h>
25#include <QtCore/qmutex.h>
26#include <QtCore/qurl.h>
27#include <QtCore/qwaitcondition.h>
28#include <QtMultimedia/qaudioformat.h>
29#include <QtMultimedia/qvideoframeformat.h>
30#include <qaudiodevice.h>
31#include <qtimer.h>
32#include "mfplayercontrol_p.h"
33#include <private/qcomptr_p.h>
34#include <evrhelpers_p.h>
35
37
38class QUrl;
39
40class SourceResolver;
42class MFPlayerControl;
43class MFPlayerService;
44class AudioSampleGrabberCallback;
45class MFTransform;
46
47class MFPlayerSession : public QObject, public IMFAsyncCallback
48{
50 friend class SourceResolver;
51public:
52 MFPlayerSession(MFPlayerControl *playerControl = 0);
53
54 STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override;
55
56 STDMETHODIMP_(ULONG) AddRef(void) override;
57
58 STDMETHODIMP_(ULONG) Release(void) override;
59
60 STDMETHODIMP Invoke(IMFAsyncResult *pResult) override;
61
62 STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue) override
63 {
64 Q_UNUSED(pdwFlags);
65 Q_UNUSED(pdwQueue);
66 return E_NOTIMPL;
67 }
68
69 void load(const QUrl &media, QIODevice *stream);
70 void stop(bool immediate = false);
71 void start();
72 void pause();
73
77 qreal playbackRate() const;
79 float bufferProgress();
81
83
84 void close();
85
87
88 QMediaMetaData metaData() const { return m_metaData; }
89
91
96
97 void setPlayerControl(MFPlayerControl *playerControl) { m_playerControl = playerControl; }
98
99 void statusChanged() { if (m_playerControl) m_playerControl->handleStatusChanged(); }
100 void tracksChanged() { if (m_playerControl) m_playerControl->handleTracksChanged(); }
101 void audioAvailable() { if (m_playerControl) m_playerControl->handleAudioAvailable(); }
102 void videoAvailable() { if (m_playerControl) m_playerControl->handleVideoAvailable(); }
103 void durationUpdate(qint64 duration) { if (m_playerControl) m_playerControl->handleDurationUpdate(duration); }
104 void seekableUpdate(bool seekable) { if (m_playerControl) m_playerControl->handleSeekableUpdate(seekable); }
105 void error(QMediaPlayer::Error error, QString errorString, bool isFatal) { if (m_playerControl) m_playerControl->handleError(error, errorString, isFatal); }
106 void playbackRateChanged(qreal rate) { if (m_playerControl) m_playerControl->playbackRateChanged(rate); }
107 void bufferProgressChanged(float percentFilled) { if (m_playerControl) m_playerControl->bufferProgressChanged(percentFilled); }
108 void metaDataChanged() { if (m_playerControl) m_playerControl->metaDataChanged(); }
109 void positionChanged(qint64 position) { if (m_playerControl) m_playerControl->positionChanged(position); }
110
111public Q_SLOTS:
112 void setVolume(float volume);
113 void setMuted(bool muted);
114 void updateOutputRouting();
115
117 void sessionEvent(const ComPtr<IMFMediaEvent> &sessionEvent);
118
119private Q_SLOTS:
120 void handleMediaSourceReady();
121 void handleSessionEvent(const ComPtr<IMFMediaEvent> &sessionEvent);
122 void handleSourceError(long hr);
123 void timeout();
124
125private:
126 long m_cRef;
127 MFPlayerControl *m_playerControl = nullptr;
128 MFVideoRendererControl *m_videoRendererControl = nullptr;
129 ComPtr<IMFMediaSession> m_session;
130 ComPtr<IMFPresentationClock> m_presentationClock;
131 ComPtr<IMFRateControl> m_rateControl;
132 ComPtr<IMFRateSupport> m_rateSupport;
133 ComPtr<IMFAudioStreamVolume> m_volumeControl;
134 ComPtr<IPropertyStore> m_netsourceStatistics;
135 qint64 m_position = 0;
136 qint64 m_restorePosition = -1;
137 qint64 m_timeCounter = 0;
138 UINT64 m_duration = 0;
139 bool m_updatingTopology = false;
140 bool m_updateRoutingOnStart = false;
141
142 enum Command
143 {
144 CmdNone = 0,
145 CmdStop,
146 CmdStart,
147 CmdPause,
148 CmdSeek,
149 CmdSeekResume,
150 CmdStartAndSeek
151 };
152
153 void clear();
154 void setPositionInternal(qint64 position, Command requestCmd);
155 void setPlaybackRateInternal(qreal rate);
156 void commitRateChange(qreal rate, BOOL isThin);
157 bool canScrub() const;
158 void scrub(bool enableScrub);
159 bool m_scrubbing;
160 float m_restoreRate;
161
162 ComPtr<SourceResolver> m_sourceResolver;
163 EventHandle m_hCloseEvent;
164 bool m_closing;
165
166 enum MediaType
167 {
168 Unknown = 0,
169 Audio = 1,
170 Video = 2,
171 };
172 DWORD m_mediaTypes;
173
174 enum PendingState
175 {
176 NoPending = 0,
177 CmdPending,
178 SeekPending,
179 };
180
181 struct SeekState
182 {
183 void setCommand(Command cmd) {
184 prevCmd = command;
185 command = cmd;
186 }
187 Command command;
188 Command prevCmd;
189 float rate; // Playback rate
190 BOOL isThin; // Thinned playback?
191 qint64 start; // Start position
192 };
193 SeekState m_state; // Current nominal state.
194 SeekState m_request; // Pending request.
195 PendingState m_pendingState;
196 float m_pendingRate;
197 void updatePendingCommands(Command command);
198
199 struct TrackInfo
200 {
201 QList<QMediaMetaData> metaData;
202 QList<int> nativeIndexes;
203 int currentIndex = -1;
204 TOPOID sourceNodeId = -1;
205 TOPOID outputNodeId = -1;
206 GUID format = GUID_NULL;
207 };
208 TrackInfo m_trackInfo[QPlatformMediaPlayer::NTrackTypes];
209
211 bool m_canScrub;
212 float m_volume = 1.;
213 bool m_muted = false;
214
215 QPlatformAudioOutput *m_audioOutput = nullptr;
216 QMediaMetaData m_metaData;
217
218 void setVolumeInternal(float volume);
219
220 bool createSession();
221 void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD);
222 bool getStreamInfo(IMFStreamDescriptor *stream, MFPlayerSession::MediaType *type, QString *name, QString *language, GUID *format) const;
223 ComPtr<IMFTopologyNode> addSourceNode(IMFTopology *topology, IMFMediaSource *source,
224 IMFPresentationDescriptor *presentationDesc,
225 IMFStreamDescriptor *streamDesc);
226 ComPtr<IMFTopologyNode> addOutputNode(MediaType mediaType, IMFTopology *topology, DWORD sinkID);
227
228 QAudioFormat audioFormatForMFMediaType(IMFMediaType *mediaType) const;
229
230 ComPtr<IMFTopology> insertMFT(const ComPtr<IMFTopology> &topology, TOPOID outputNodeId);
231 bool insertResizer(IMFTopology *topology);
232 void insertColorConverter(IMFTopology *topology, TOPOID outputNodeId);
233
234 QTimer m_signalPositionChangeTimer;
235 qint64 m_lastPosition = -1;
236};
237
239
240#endif
AVFCameraSession * m_session
IOBluetoothDevice * device
void handleError(QMediaPlayer::Error errorCode, const QString &errorString, bool isFatal)
void handleSeekableUpdate(bool seekable)
void handleDurationUpdate(qint64 duration)
void seekableUpdate(bool seekable)
void setPlaybackRate(qreal rate)
QMediaMetaData metaData() const
void setAudioOutput(QPlatformAudioOutput *device)
void setVideoSink(QVideoSink *sink)
void bufferProgressChanged(float percentFilled)
void setActiveTrack(QPlatformMediaPlayer::TrackType type, int index)
void playbackRateChanged(qreal rate)
STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObject) override
void positionChanged(qint64 position)
MFPlayerSession(MFPlayerControl *playerControl=0)
void sessionEvent(const ComPtr< IMFMediaEvent > &sessionEvent)
void setPlayerControl(MFPlayerControl *playerControl)
void durationUpdate(qint64 duration)
qreal playbackRate() const
void stop(bool immediate=false)
void setVolume(float volume)
QMediaMetaData trackMetaData(QPlatformMediaPlayer::TrackType type, int trackNumber)
STDMETHODIMP Invoke(IMFAsyncResult *pResult) override
void load(const QUrl &media, QIODevice *stream)
int activeTrack(QPlatformMediaPlayer::TrackType type)
QMediaPlayer::MediaStatus status() const
void changeStatus(QMediaPlayer::MediaStatus newStatus)
QMediaTimeRange availablePlaybackRanges()
STDMETHODIMP_(ULONG) Release(void) override
void setMuted(bool muted)
STDMETHODIMP_(ULONG) AddRef(void) override
void error(QMediaPlayer::Error error, QString errorString, bool isFatal)
STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue) override
int trackCount(QPlatformMediaPlayer::TrackType)
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtMultimedia
MediaStatus
\qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState
Error
\qmlproperty enumeration QtMultimedia::MediaPlayer::mediaStatus
The QMediaTimeRange class represents a set of zero or more disjoint time intervals.
\inmodule QtCore
Definition qobject.h:103
void positionChanged(qint64 position)
void playbackRateChanged(qreal rate)
void bufferProgressChanged(float progress)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qtimer.h:20
\inmodule QtCore
Definition qurl.h:94
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
b clear()
static bool isFatal(QtMsgType msgType)
Definition qlogging.cpp:202
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLStreamKHR stream
n void setPosition(void) \n\
GLuint index
[2]
GLbitfield GLuint64 timeout
[4]
GLenum type
GLuint start
GLuint name
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
GLuint GLenum * rate
GLsizei GLenum GLboolean sink
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
#define Q_UNUSED(x)
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
IUIViewSettingsInterop __RPC__in REFIID riid