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
qmediaengineplayer_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QMEDIAENGINEPLAYER_P_H
5#define QMEDIAENGINEPLAYER_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 <qwindowsmfdefs_p.h>
19
20#include <QtMultimedia/qmediametadata.h>
21#include <QtMultimedia/qvideoframeformat.h>
22#include <QtMultimedia/private/qplatformmediaplayer_p.h>
23#include <QtCore/qchronotimer.h>
24#include <QtCore/qfuture.h>
25#include <QtCore/qurl.h>
26#include <QtCore/private/qcomptr_p.h>
27
28#include <d3d11.h>
29
30#include <array>
31#include <chrono>
32#include <memory>
33#include <vector>
34
35QT_BEGIN_NAMESPACE
36
37class QAudioOutput;
38class QMediaEngineNotify;
39class QMediaEngineTimedTextNotify;
40class QPlatformVideoSink;
41
42namespace QtMultimediaPrivate {
43class QWindowsD3D11RhiTextureImporter;
44}
45
47{
48public:
49 QMediaEnginePlayer(QMediaPlayer *player);
51
52 // QPlatformMediaPlayer interface
53 qint64 duration() const override;
54 qint64 position() const override;
55 void setPosition(qint64 position) override;
56 float bufferProgress() const override;
58 qreal playbackRate() const override;
59 void setPlaybackRate(qreal rate) override;
60 QUrl media() const override;
61 const QIODevice *mediaStream() const override;
62 void setMedia(const QUrl &media, QIODevice *stream) override;
63 void play() override;
64 void pause() override;
65 void stop() override;
66 bool streamPlaybackSupported() const override { return true; }
68 QMediaMetaData metaData() const override;
69 void setAudioOutput(QPlatformAudioOutput *output) override;
70 void setVideoSink(QVideoSink *sink) override;
71 void setActiveTrack(TrackType type, int index) override;
72 int activeTrack(TrackType type) override;
73 int trackCount(TrackType type) override;
74 QMediaMetaData trackMetaData(TrackType type, int trackNumber) override;
75
76private:
77 // Initialization and lifecycle
78 bool initD3D11();
79 bool initMediaEngine();
80 void releaseMediaEngine();
81
82 // Event handling
83 void handleMediaEngineEvent(DWORD event, DWORD_PTR param1, DWORD param2);
84
85 // Video rendering
86 void presentVideoFrame();
87 void updateVideoFrameFormat();
88 void updateNativeSize();
89
90 // Audio
91 void applyAudioOutput();
92 void applyVolume();
93 void applyAudioDevice();
94
95 // Metadata and tracks
96 void updateMetaData();
97 void updateTracks();
98 void updateSubtitleTracks();
99 void updateDuration();
100
101 // Timer helpers
102 void startPlaybackTimers();
103 void stopPlaybackTimers();
104
105 // Utilities
106 qint64 currentPositionMs() const;
107 QSize nativeVideoSize() const;
108
109 // Context object for QObject::connect / callOnTimeout (the player
110 // itself is not a QObject, so we use the position timer instead).
111 QObject *context() { return &m_positionUpdateTimer; }
112
113private:
114 // Media Foundation
115 ComPtr<IMFMediaEngine> m_mediaEngine;
116 ComPtr<IMFMediaEngineEx> m_mediaEngineEx;
117 ComPtr<IMFTimedText> m_timedText;
118 ComPtr<QMediaEngineTimedTextNotify> m_timedTextNotify;
119 ComPtr<QMediaEngineNotify> m_notify;
120
121 // D3D11
122 ComPtr<ID3D11Device> m_d3dDevice;
123 ComPtr<IMFDXGIDeviceManager> m_dxgiManager;
124 UINT m_resetToken = 0;
125
126 // Video rendering
127 ComPtr<ID3D11Texture2D> m_transferTexture;
128 QSize m_videoSize;
129 QVideoFrameFormat m_videoFormat;
130 std::chrono::microseconds m_frameDuration{};
131 std::shared_ptr<QtMultimediaPrivate::QWindowsD3D11RhiTextureImporter> m_textureImporter;
132 int m_deviceLostRetries = 0;
133 static constexpr int kMaxDeviceLostRetries = 3;
134
135 // Outputs
136 QPlatformVideoSink *m_videoSink = nullptr;
137 QPlatformAudioOutput *m_audioOutput = nullptr;
138
139 // Source
140 QUrl m_url;
141 QIODevice *m_stream = nullptr;
142
143 // Metadata and tracks
144 QMediaMetaData m_metaData;
145 QFuture<void> m_metadataFuture;
146 struct TrackInfo
147 {
153 std::vector<Entry> entries;
154 int currentIndex = -1;
155 };
156 TrackTypeMap<TrackInfo> m_tracks;
157
158 // Playback state
159 std::chrono::milliseconds m_duration{};
160 std::optional<std::chrono::milliseconds> m_seekTarget;
161 qreal m_playbackRate = 1.0;
162 bool m_pendingPlay = false;
163 QChronoTimer m_positionUpdateTimer{ std::chrono::milliseconds{ 100 } };
164 QChronoTimer m_videoRenderTimer{ std::chrono::milliseconds{ 16 } };
165 QChronoTimer m_seekTimeoutTimer{ std::chrono::milliseconds{ 5000 } };
166};
167
168QT_END_NAMESPACE
169
170#endif // QMEDIAENGINEPLAYER_P_H
bool canReadQrc() const override
void setAudioFormat(const QAudioFormat &format) override
bool bufferAvailable() const override
QUrl source() const override
void setSourceDevice(QIODevice *device) override
QAudioFormat audioFormat() const override
QAudioBuffer read() override
void setSource(const QUrl &fileName) override
QIODevice * sourceDevice() const override
float bufferProgress() const override
void setPlaybackRate(qreal rate) override
void setActiveTrack(TrackType type, int index) override
void setAudioOutput(QPlatformAudioOutput *output) override
qint64 duration() const override
void setMedia(const QUrl &media, QIODevice *stream) override
QMediaTimeRange availablePlaybackRanges() const override
qint64 position() const override
qreal playbackRate() const override
int activeTrack(TrackType type) override
QMediaEnginePlayer(QMediaPlayer *player)
void setVideoSink(QVideoSink *sink) override
QUrl media() const override
void setPosition(qint64 position) override
QMediaMetaData trackMetaData(TrackType type, int trackNumber) override
bool streamPlaybackSupported() const override
PitchCompensationAvailability pitchCompensationAvailability() const override
const QIODevice * mediaStream() const override
QMediaMetaData metaData() const override
int trackCount(TrackType type) override
virtual ~QWindowsCamera()
bool isActive() const override
void setCamera(const QCameraDevice &camera) override
void setCaptureSession(QPlatformMediaCaptureSession *) override
bool setCameraFormat(const QCameraFormat &format) override
void setActive(bool active) override
int capture(const QString &fileName) override
virtual ~QWindowsImageCapture()
QImageEncoderSettings imageSettings() const override
void setImageSettings(const QImageEncoderSettings &settings) override
void setCaptureSession(QPlatformMediaCaptureSession *session)
bool isReadyForCapture() const override
QPlatformImageCapture * imageCapture() override
void setCamera(QPlatformCamera *camera) override
void setAudioInput(QPlatformAudioInput *) override
void setVideoPreview(QVideoSink *sink) override
QPlatformCamera * camera() override
QPlatformMediaRecorder * mediaRecorder() override
void setImageCapture(QPlatformImageCapture *imageCapture) override
void setAudioOutput(QPlatformAudioOutput *output) override
void setMediaRecorder(QPlatformMediaRecorder *recorder) override
QWindowsMediaDeviceSession * session() const
void setMetaData(const QMediaMetaData &metaData) override
QMediaRecorder::RecorderState state() const override
void setCaptureSession(QPlatformMediaCaptureSession *session)
QMediaMetaData metaData() const override
bool isLocationWritable(const QUrl &location) const override
qint64 duration() const override
void record(QMediaEncoderSettings &settings) override
q23::expected< QPlatformVideoSink *, QString > createVideoSink(QVideoSink *sink) override
QPlatformMediaFormatInfo * createFormatInfo() override
q23::expected< QPlatformAudioDecoder *, QString > createAudioDecoder(QAudioDecoder *decoder) override
q23::expected< QPlatformCamera *, QString > createCamera(QCamera *camera) override
q23::expected< QPlatformImageCapture *, QString > createImageCapture(QImageCapture *imageCapture) override
QPlatformVideoDevices * createVideoDevices() override
q23::expected< QPlatformMediaRecorder *, QString > createRecorder(QMediaRecorder *recorder) override
q23::expected< QPlatformMediaPlayer *, QString > createPlayer(QMediaPlayer *parent) override
q23::expected< QPlatformMediaCaptureSession *, QString > createCaptureSession() override
ComPtr< IMFMediaSource > mediaSource() const
void mediaSourceReady()
void load(const QUrl &url, QIODevice *stream)
Combined button and popup list for selecting options.