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 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
107 std::atomic<qint64> m_position{ 0 };
108 qint64 m_duration{ 0 };
109 int m_videoWidth{ 0 };
110 int m_videoHeight{ 0 };
111 float m_bufferProgress{ 0.0f };
112 bool m_hasVideoTrack{ false };
113 bool m_hasAudioTrack{ false };
114 qreal m_playbackRate{ 1.0 };
115 bool m_seekable{ false };
116 bool m_pendingPlay{ false };
117
118 AVPlayerState m_avState{ AV_IDLE };
119};
120
121QT_END_NAMESPACE
122
123#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.
QMediaPlayer::MediaStatus mediaStatusFor(AVPlayerState state, bool atEnd)
AVPlaybackSpeed playbackSpeedFor(qreal rate)
QMediaPlayer::PlaybackState playbackStateFor(AVPlayerState state)