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
qohosmediaplayer_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 QOHOSMEDIAPLAYER_P_H
5#define QOHOSMEDIAPLAYER_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 <private/qplatformmediaplayer_p.h>
19
20#include <QtCore/qmutex.h>
21#include <QtCore/qpointer.h>
22#include <QtCore/qurl.h>
23#include <QtCore/qfile.h>
24
25#include <multimedia/player_framework/avplayer.h>
26#include <multimedia/player_framework/avplayer_base.h>
27
28#include <atomic>
29#include <memory>
30
31QT_BEGIN_NAMESPACE
32
33class QAudioOutput;
34class QVideoSink;
35class QPlatformAudioOutput;
37class QOhosVideoSink;
38
40{
42
43public:
46
47 // QPlatformMediaPlayer interface
48 qint64 duration() const override;
49 qint64 position() const override;
50 void setPosition(qint64 position) override;
51 float bufferProgress() const override;
52 bool isSeekable() const override;
54 qreal playbackRate() const override;
55 void setPlaybackRate(qreal rate) override;
56 QUrl media() const override;
57 const QIODevice *mediaStream() const override;
58 void setMedia(const QUrl &media, QIODevice *stream) override;
59 void play() override;
60 void pause() override;
61 void stop() override;
62 void setAudioOutput(QPlatformAudioOutput *) override;
63 void setVideoSink(QVideoSink *sink) override;
64
65 int trackCount(TrackType type) override;
66 QMediaMetaData trackMetaData(TrackType type, int streamNumber) override;
67 int activeTrack(TrackType type) override;
68 QMediaMetaData metaData() const override;
69
70private:
71 // Called from Qt thread, dispatched from native callbacks.
72 void handleStateChange(AVPlayerState newState);
73 void handleEndOfStream();
74 void handleSeekDone();
75 void handleResolutionChange();
76 void handleBufferingUpdate(int bufferingPercent);
77 void handleError(int32_t errorCode, const QString &errorMsg);
78
79 void releasePlayer();
80 void clearSource();
81 bool ensurePlayer();
82 void applyVolume();
83
84 void onVideoSurfaceReady();
85 void tryApplyPendingSource();
86 void applyPendingSource();
87
88 // Native trampoline callbacks. Run on system threads — must marshal to Qt thread.
89 static void onInfoTrampoline(OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat *body,
90 void *userData);
91 static void onErrorTrampoline(OH_AVPlayer *player, int32_t errorCode, const char *errorMsg,
92 void *userData);
93
94 OH_AVPlayer *m_player{ nullptr };
95 QUrl m_media;
96 QPointer<QIODevice> m_stream;
97 // Local-file sources require the QFile to outlive the AVPlayer because
98 // OH_AVPlayer_SetFDSource only borrows the descriptor. Mirrors the gotcha
99 // documented in the Qt 5 OHOS port.
100 std::unique_ptr<QFileDevice> m_sourceFile;
101
102 QPointer<QVideoSink> m_videoSink;
103 QPlatformAudioOutput *m_audioOutput{ nullptr };
104 std::unique_ptr<QOhosVideoOutput> m_videoOutput;
105 bool m_videoSurfaceAttached{ false };
106 bool m_pendingSetMedia{ false };
107 bool m_sourceApplied{ false };
108 bool m_surfaceWaitStarted{ false };
109
110 std::atomic<qint64> m_position{ 0 };
111 qint64 m_duration{ 0 };
112 int m_videoWidth{ 0 };
113 int m_videoHeight{ 0 };
114 float m_bufferProgress{ 0.0f };
115 bool m_hasVideoTrack{ false };
116 bool m_hasAudioTrack{ false };
117 qreal m_playbackRate{ 1.0 };
118 bool m_seekable{ false };
119 bool m_pendingPlay{ false };
120
121 AVPlayerState m_avState{ AV_IDLE };
122};
123
124QT_END_NAMESPACE
125
126#endif // QOHOSMEDIAPLAYER_P_H
void stop() override
int activeTrack(TrackType type) override
qint64 position() const override
float bufferProgress() const override
void pause() override
void setAudioOutput(QPlatformAudioOutput *) override
void setPlaybackRate(qreal rate) override
void play() override
const QIODevice * mediaStream() const override
int trackCount(TrackType type) override
qreal playbackRate() const override
qint64 duration() const override
QUrl media() const override
void setVideoSink(QVideoSink *sink) override
void setPosition(qint64 position) override
QMediaMetaData trackMetaData(TrackType type, int streamNumber) override
QMediaTimeRange availablePlaybackRanges() const override
bool isSeekable() const override
void setMedia(const QUrl &media, QIODevice *stream) override
QMediaMetaData metaData() const override
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE constexpr int surfaceWaitTimeoutMs