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