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.cpp
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
5
7#include "common/qohosvideooutput_p.h"
8#include <QtMultimedia/private/qplatformvideosink_p.h>
9
10#include <private/qplatformaudiooutput_p.h>
11
12#include <QtMultimedia/qaudiooutput.h>
13#include <QtMultimedia/qmediaplayer.h>
14#include <QtMultimedia/qmediametadata.h>
15#include <QtMultimedia/qmediatimerange.h>
16#include <QtMultimedia/qvideosink.h>
17
18#include <QtCore/qfile.h>
19#include <QtCore/qtimer.h>
20#include <QtCore/qfileinfo.h>
21#include <QtCore/qtemporaryfile.h>
22#include <QtCore/qloggingcategory.h>
23#include <QtCore/qmetaobject.h>
24#include <QtCore/qpointer.h>
25
26#include <multimedia/player_framework/native_averrors.h>
27
29
30static constexpr int surfaceWaitTimeoutMs = 500;
31
32namespace {
33
34QMediaPlayer::MediaStatus mediaStatusFor(AVPlayerState state, bool atEnd)
35{
36 if (atEnd)
37 return QMediaPlayer::EndOfMedia;
38
39 switch (state) {
40 case AV_IDLE:
41 return QMediaPlayer::NoMedia;
42 case AV_INITIALIZED:
43 return QMediaPlayer::LoadingMedia;
44 case AV_PREPARED:
45 case AV_STOPPED:
46 return QMediaPlayer::LoadedMedia;
47 case AV_PLAYING:
48 case AV_PAUSED:
49 return QMediaPlayer::BufferedMedia;
50 case AV_COMPLETED:
51 return QMediaPlayer::EndOfMedia;
52 case AV_RELEASED:
53 case AV_ERROR:
54 return QMediaPlayer::InvalidMedia;
55 }
56 return QMediaPlayer::NoMedia;
57}
58
59QMediaPlayer::PlaybackState playbackStateFor(AVPlayerState state)
60{
61 switch (state) {
62 case AV_PLAYING:
63 return QMediaPlayer::PlayingState;
64 case AV_PAUSED:
65 return QMediaPlayer::PausedState;
66 case AV_IDLE:
67 case AV_INITIALIZED:
68 case AV_PREPARED:
69 case AV_STOPPED:
70 case AV_COMPLETED:
71 case AV_RELEASED:
72 case AV_ERROR:
73 break;
74 }
75 return QMediaPlayer::StoppedState;
76}
77
78AVPlaybackSpeed playbackSpeedFor(qreal rate)
79{
80 // Map onto the closest discrete OH speed enum (SetPlaybackRate is API 20+).
81 if (rate <= 0.1875)
82 return AV_SPEED_FORWARD_0_125_X;
83 if (rate <= 0.375)
84 return AV_SPEED_FORWARD_0_25_X;
85 if (rate <= 0.625)
86 return AV_SPEED_FORWARD_0_50_X;
87 if (rate <= 0.875)
88 return AV_SPEED_FORWARD_0_75_X;
89 if (rate < 1.125)
90 return AV_SPEED_FORWARD_1_00_X;
91 if (rate < 1.375)
92 return AV_SPEED_FORWARD_1_25_X;
93 if (rate < 1.625)
94 return AV_SPEED_FORWARD_1_50_X;
95 if (rate < 1.875)
96 return AV_SPEED_FORWARD_1_75_X;
97 if (rate < 2.5)
98 return AV_SPEED_FORWARD_2_00_X;
99 return AV_SPEED_FORWARD_3_00_X;
100}
101
102} // namespace
103
104QOhosMediaPlayer::QOhosMediaPlayer(QMediaPlayer *parent)
105 : QObject(parent), QPlatformMediaPlayer(parent)
106{
107}
108
110{
111 releasePlayer();
112}
113
115{
116 return m_duration;
117}
118
120{
121 return m_position.load();
122}
123
124void QOhosMediaPlayer::setPosition(qint64 position)
125{
126 if (!m_player)
127 return;
128 if (m_stopPending) {
129 m_pendingPosition = position;
130 return;
131 }
132 if (m_avState == AV_PREPARED || m_avState == AV_PLAYING || m_avState == AV_PAUSED
133 || m_avState == AV_COMPLETED) {
134 m_pendingPosition.reset();
135 OH_AVPlayer_Seek(m_player, static_cast<int32_t>(position), AV_SEEK_NEXT_SYNC);
136 } else {
137 // Seeking is rejected until the player is prepared (again).
138 m_pendingPosition = position;
139 if (m_avState == AV_STOPPED)
140 reprepare();
141 }
142}
143
145{
146 return m_bufferProgress;
147}
148
150{
151 return m_seekable;
152}
153
155{
156 if (m_duration <= 0)
157 return {};
158 return QMediaTimeRange{ 0, m_duration };
159}
160
162{
163 return m_playbackRate;
164}
165
167{
168 if (qFuzzyCompare(m_playbackRate, rate))
169 return;
170 m_playbackRate = rate;
171 if (m_player)
172 OH_AVPlayer_SetPlaybackSpeed(m_player, playbackSpeedFor(rate));
173 playbackRateChanged(rate);
174}
175
177{
178 return m_media;
179}
180
182{
183 return m_stream;
184}
185
186void QOhosMediaPlayer::setMedia(const QUrl &media, QIODevice *stream)
187{
188 m_media = media;
189 m_stream = stream;
190
191 if (m_player)
192 OH_AVPlayer_Reset(m_player);
193 clearSource();
194 m_pendingPosition.reset();
195 m_stopPending = false;
196
197 if (media.isEmpty()) {
198 m_duration = 0;
199 m_position.store(0);
200 m_pendingSetMedia = false;
201 mediaStatusChanged(QMediaPlayer::NoMedia);
202 stateChanged(QMediaPlayer::StoppedState);
203 return;
204 }
205
206 // Reject obviously bad file-like sources synchronously so the test
207 // QMediaPlayer-style "invalid file" cases see ResourceError immediately
208 // instead of waiting forever on the deferred surface. QMediaPlayer's
209 // observable contract is "Loading -> Invalid", so emit Loading first even
210 // when the failure is immediate.
211 const QString scheme = media.scheme();
212 if (media.isLocalFile() || scheme.isEmpty() || scheme == QLatin1String("qrc")) {
213 QString openPath;
214 if (media.isLocalFile())
215 openPath = media.toLocalFile();
216 else if (scheme == QLatin1String("qrc"))
217 openPath = QLatin1Char(':') + media.path();
218 else
219 openPath = media.toString();
220 QFile probe(openPath);
221 if (!probe.open(QIODevice::ReadOnly)) {
222 mediaStatusChanged(QMediaPlayer::LoadingMedia);
223 setInvalidMediaWithError(QMediaPlayer::ResourceError,
224 QStringLiteral("Cannot open '%1'").arg(openPath));
225 return;
226 }
227 }
228
229 m_pendingSetMedia = false;
230 m_sourceApplied = false;
231 m_surfaceWaitStarted = false;
232 // Apply on the next event-loop cycle so a videoOutput assigned right after
233 // the source is in place before we pick a prepare path.
234 QMetaObject::invokeMethod(this, &QOhosMediaPlayer::tryApplyPendingSource,
235 Qt::QueuedConnection);
236}
237
238void QOhosMediaPlayer::tryApplyPendingSource()
239{
240 if (m_sourceApplied || m_media.isEmpty())
241 return;
242
243 // The surface can only be attached between SetSource and Prepare, so wait
244 // for it. A sink with no renderer never gets an RHI: give up and prepare
245 // without video rather than stall.
246 auto *rhiSink = m_videoSink ? qobject_cast<QRhiVideoSink *>(m_videoSink->platformVideoSink())
247 : nullptr;
248 const bool hasRhi = rhiSink && rhiSink->withRhi([](QRhi *rhi) {
249 return rhi != nullptr;
250 });
251 if (m_videoOutput && m_videoSink && !hasRhi) {
252 if (!m_surfaceWaitStarted) {
253 m_surfaceWaitStarted = true;
254 QTimer::singleShot(surfaceWaitTimeoutMs, this, [this] {
255 if (!m_sourceApplied && m_pendingSetMedia && !m_media.isEmpty()) {
256 m_pendingSetMedia = false;
257 m_sourceApplied = true;
258 applyPendingSource();
259 }
260 });
261 }
262 m_pendingSetMedia = true;
263 mediaStatusChanged(QMediaPlayer::LoadingMedia);
264 return;
265 }
266
267 m_sourceApplied = true;
268 applyPendingSource();
269}
270
271void QOhosMediaPlayer::applyPendingSource()
272{
273 if (!ensurePlayer()) {
274 setInvalidMediaWithError(QMediaPlayer::ResourceError,
275 QStringLiteral("Failed to create OH_AVPlayer"));
276 return;
277 }
278
279 m_videoSurfaceAttached = false;
280
281 // Surface the LoadingMedia status before we hand the source to OH_AVPlayer
282 // so any synchronous SetURLSource/SetFDSource rejection still produces the
283 // observable Loading -> Invalid transition QMediaPlayer guarantees.
284 mediaStatusChanged(QMediaPlayer::LoadingMedia);
285
286 OH_AVErrCode result = AV_ERR_OK;
287 const QString scheme = m_media.scheme();
288 const bool isQrc = scheme == QLatin1String("qrc");
289 const bool isFileLike = m_media.isLocalFile() || scheme.isEmpty() || isQrc;
290 if (isFileLike) {
291 QString openPath;
292 if (m_media.isLocalFile()) {
293 openPath = m_media.toLocalFile();
294 } else if (isQrc) {
295 // QFile understands ":/path" for embedded resources.
296 openPath = QLatin1Char(':') + m_media.path();
297 } else {
298 // Bare relative paths.
299 openPath = m_media.toString();
300 }
301 auto file = std::make_unique<QFile>(openPath);
302 if (!file->open(QIODevice::ReadOnly)) {
303 setInvalidMediaWithError(QMediaPlayer::ResourceError,
304 QStringLiteral("Cannot open '%1'").arg(openPath));
305 return;
306 }
307 const int fd = file->handle();
308 const qint64 size = file->size();
309 if (fd < 0) {
310 // Resource-backed QFile is mapped, not file-descriptor-backed —
311 // AVPlayer needs a real fd, so spool to a temp file before handing
312 // it off.
313 auto temp = std::make_unique<QTemporaryFile>();
314 if (!temp->open() || temp->write(file->readAll()) < 0) {
315 setInvalidMediaWithError(QMediaPlayer::ResourceError,
316 QStringLiteral("Cannot stage '%1'").arg(openPath));
317 return;
318 }
319 temp->flush();
320 temp->seek(0);
321 const int tempFd = temp->handle();
322 const qint64 tempSize = temp->size();
323 result = OH_AVPlayer_SetFDSource(m_player, tempFd, 0, tempSize);
324 m_sourceFile = std::move(temp);
325 } else {
326 result = OH_AVPlayer_SetFDSource(m_player, fd, 0, size);
327 m_sourceFile = std::move(file);
328 }
329 } else {
330 const QByteArray url = m_media.toString(QUrl::FullyEncoded).toUtf8();
331 result = OH_AVPlayer_SetURLSource(m_player, url.constData());
332 }
333
334 if (result != AV_ERR_OK) {
335 qCWarning(qLcOhosMediaPlugin) << "Source rejected, error" << int(result);
336 setInvalidMediaWithError(QMediaPlayer::ResourceError,
337 QStringLiteral("OH_AVPlayer rejected the source"));
338 clearSource();
339 return;
340 }
341
342 if (m_videoOutput) {
343 if (auto *window = m_videoOutput->nativeWindow()) {
344 if (OH_AVPlayer_SetVideoSurface(m_player, window) == AV_ERR_OK)
345 m_videoSurfaceAttached = true;
346 else
347 qCWarning(qLcOhosMediaPlugin) << "OH_AVPlayer_SetVideoSurface failed";
348 }
349 }
350
351 // Rejected before the source is set.
352 if (OH_AVPlayer_SetAudioRendererInfo(m_player, AUDIOSTREAM_USAGE_MOVIE) != AV_ERR_OK)
353 qCWarning(qLcOhosMediaPlugin) << "OH_AVPlayer_SetAudioRendererInfo failed";
354
355 result = OH_AVPlayer_Prepare(m_player);
356 if (result != AV_ERR_OK) {
357 qCWarning(qLcOhosMediaPlugin) << "Prepare failed, error" << int(result);
358 setInvalidMediaWithError(QMediaPlayer::ResourceError,
359 QStringLiteral("OH_AVPlayer_Prepare failed"));
360 clearSource();
361 }
362}
363
365{
366 if (!m_player) {
367 m_pendingPlay = !m_media.isEmpty();
368 return;
369 }
370
371 // OH_AVPlayer_Stop completes asynchronously, play once it has.
372 if (m_stopPending) {
373 m_pendingPlay = true;
374 return;
375 }
376
377 if (m_avState == AV_PLAYING) {
378 m_pendingPlay = false;
379 } else if (m_avState == AV_PREPARED || m_avState == AV_PAUSED
380 || m_avState == AV_COMPLETED) {
381 m_pendingPlay = false;
382 OH_AVPlayer_Play(m_player);
383 } else if (m_avState == AV_STOPPED) {
384 // A stopped OH_AVPlayer must be prepared again before it can play.
385 m_pendingPlay = true;
386 reprepare();
387 } else {
388 // Prepare hasn't finished yet — defer play to AV_INFO_TYPE_STATE_CHANGE
389 m_pendingPlay = true;
390 }
391}
392
394{
395 m_pendingPlay = false;
396 if (m_player && m_avState == AV_PLAYING)
397 OH_AVPlayer_Pause(m_player);
398}
399
401{
402 m_pendingPlay = false;
403 if (!m_player)
404 return;
405 if (m_avState == AV_PLAYING || m_avState == AV_PAUSED || m_avState == AV_PREPARED
406 || m_avState == AV_COMPLETED) {
407 m_pendingPosition.reset();
408 m_stopPending = OH_AVPlayer_Stop(m_player) == AV_ERR_OK;
409 }
410}
411
412void QOhosMediaPlayer::setAudioOutput(QPlatformAudioOutput *output)
413{
414 if (m_audioOutput == output)
415 return;
416 if (m_audioOutput)
417 m_audioOutput->q->disconnect(this);
418 m_audioOutput = output;
419 if (m_audioOutput) {
420 connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this,
421 &QOhosMediaPlayer::applyVolume);
422 connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this,
423 &QOhosMediaPlayer::applyVolume);
424 }
425 applyVolume();
426}
427
428void QOhosMediaPlayer::setVideoSink(QVideoSink *sink)
429{
430 m_videoSink = sink;
431
432 if (!sink) {
433 m_videoOutput.reset();
434 return;
435 }
436
437 if (!m_videoOutput) {
438 m_videoOutput = std::make_unique<QOhosVideoOutput>(
439 sink, QOhosVideoOutput::ContentSource::MediaPlayer, this);
440 connect(m_videoOutput.get(), &QOhosVideoOutput::surfaceReady, this,
441 &QOhosMediaPlayer::onVideoSurfaceReady);
442 }
443}
444
445int QOhosMediaPlayer::trackCount(TrackType type)
446{
447 // OH_AVPlayer doesn't enumerate per-stream metadata up front; expose the
448 // detected presence of audio/video as a single default track so QMediaPlayer
449 // consumers can ask for activeTrack(0) and get a sensible answer.
450 switch (type) {
451 case TrackType::VideoStream:
452 return m_hasVideoTrack ? 1 : 0;
453 case TrackType::AudioStream:
454 return m_hasAudioTrack ? 1 : 0;
455 case TrackType::SubtitleStream:
456 break;
457 }
458 return 0;
459}
460
461QMediaMetaData QOhosMediaPlayer::trackMetaData(TrackType type, int streamNumber)
462{
463 if (streamNumber != 0 || trackCount(type) == 0)
464 return {};
465 QMediaMetaData md;
466 md.insert(QMediaMetaData::Language, QVariant::fromValue(QLocale::AnyLanguage));
467 return md;
468}
469
471{
472 QMediaMetaData md;
473 if (m_duration > 0)
474 md.insert(QMediaMetaData::Duration, m_duration);
475 if (m_videoWidth > 0 && m_videoHeight > 0)
476 md.insert(QMediaMetaData::Resolution, QSize{ m_videoWidth, m_videoHeight });
477 return md;
478}
479
480int QOhosMediaPlayer::activeTrack(TrackType type)
481{
482 return trackCount(type) > 0 ? 0 : -1;
483}
484
485void QOhosMediaPlayer::onVideoSurfaceReady()
486{
487 if (m_pendingSetMedia && !m_media.isEmpty()) {
488 m_pendingSetMedia = false;
489 m_sourceApplied = true;
490 applyPendingSource();
491 }
492}
493
494void QOhosMediaPlayer::handleStateChange(AVPlayerState newState)
495{
496 if (m_avState == newState)
497 return;
498 m_avState = newState;
499 m_reprepareRequested = false;
500
501 // AV_IDLE is a transient state that OH_AVPlayer enters during Reset() as
502 // setMedia() is replacing the source. The user-facing NoMedia status is
503 // already emitted from setMedia(QUrl{}); leaking another NoMedia between a
504 // LoadingMedia/Invalid transition breaks observable status sequences.
505 if (newState == AV_IDLE)
506 return;
507
508 if (newState == AV_PREPARED) {
509 int32_t durationMs = 0;
510 if (OH_AVPlayer_GetDuration(m_player, &durationMs) == AV_ERR_OK) {
511 if (m_duration != durationMs) {
512 m_duration = durationMs;
513 durationChanged(m_duration);
514 }
515 }
516 m_seekable = m_duration > 0;
517 seekableChanged(m_seekable);
518
519 int32_t videoWidth = 0;
520 int32_t videoHeight = 0;
521 OH_AVPlayer_GetVideoWidth(m_player, &videoWidth);
522 OH_AVPlayer_GetVideoHeight(m_player, &videoHeight);
523 const bool hasVideo = videoWidth > 0 && videoHeight > 0;
524 if (hasVideo && m_videoOutput)
525 m_videoOutput->setVideoSize(QSize{ videoWidth, videoHeight });
526 videoAvailableChanged(hasVideo);
527 audioAvailableChanged(true);
528 const bool prevHasVideo = m_hasVideoTrack;
529 const bool prevHasAudio = m_hasAudioTrack;
530 m_hasVideoTrack = hasVideo;
531 m_hasAudioTrack = true;
532 if (prevHasVideo != m_hasVideoTrack || prevHasAudio != m_hasAudioTrack) {
533 tracksChanged();
534 activeTracksChanged();
535 }
536 m_videoWidth = videoWidth;
537 m_videoHeight = videoHeight;
538 metaDataChanged();
539
540 // OH_AVPlayer_SetVolume is rejected before the player is prepared.
541 applyVolume();
542 }
543
544 mediaStatusChanged(mediaStatusFor(newState, false));
545 stateChanged(playbackStateFor(newState));
546
547 if (newState == AV_STOPPED) {
548 m_stopPending = false;
549 if (m_pendingPlay || m_pendingPosition)
550 reprepare();
551 } else if (newState == AV_PREPARED) {
552 if (m_pendingPosition) {
553 OH_AVPlayer_Seek(m_player, static_cast<int32_t>(*m_pendingPosition),
554 AV_SEEK_NEXT_SYNC);
555 m_pendingPosition.reset();
556 }
557 if (m_pendingPlay) {
558 m_pendingPlay = false;
559 OH_AVPlayer_Play(m_player);
560 }
561 }
562}
563
564void QOhosMediaPlayer::handleEndOfStream()
565{
566 mediaStatusChanged(QMediaPlayer::EndOfMedia);
567 stateChanged(QMediaPlayer::StoppedState);
568}
569
570void QOhosMediaPlayer::handleSeekDone()
571{
572 // Position will refresh via AV_INFO_TYPE_POSITION_UPDATE.
573}
574
575void QOhosMediaPlayer::handleResolutionChange()
576{
577 if (!m_player)
578 return;
579 int32_t width = 0;
580 int32_t height = 0;
581 OH_AVPlayer_GetVideoWidth(m_player, &width);
582 OH_AVPlayer_GetVideoHeight(m_player, &height);
583 m_videoWidth = width;
584 m_videoHeight = height;
585 if (m_videoOutput && width > 0 && height > 0)
586 m_videoOutput->setVideoSize(QSize{ width, height });
587 videoAvailableChanged(width > 0 && height > 0);
588}
589
590void QOhosMediaPlayer::handleBufferingUpdate(int bufferingPercent)
591{
592 const float progress = std::clamp(bufferingPercent / 100.0f, 0.0f, 1.0f);
593 if (qFuzzyCompare(m_bufferProgress, progress))
594 return;
595 m_bufferProgress = progress;
596 bufferProgressChanged(progress);
597}
598
599void QOhosMediaPlayer::handleError(int32_t errorCode, const QString &errorMsg)
600{
601 qCWarning(qLcOhosMediaPlugin) << "OH_AVPlayer error" << errorCode << errorMsg;
602 setInvalidMediaWithError(QMediaPlayer::ResourceError,
603 errorMsg.isEmpty() ? QStringLiteral("AVPlayer error %1").arg(errorCode)
604 : errorMsg);
605}
606
607void QOhosMediaPlayer::releasePlayer()
608{
609 if (!m_player)
610 return;
611 OH_AVPlayer_SetOnInfoCallback(m_player, nullptr, nullptr);
612 OH_AVPlayer_SetOnErrorCallback(m_player, nullptr, nullptr);
613 OH_AVPlayer_ReleaseSync(m_player);
614 m_player = nullptr;
615 clearSource();
616}
617
618void QOhosMediaPlayer::clearSource()
619{
620 m_sourceFile.reset();
621 const bool changed = m_hasVideoTrack || m_hasAudioTrack;
622 m_hasVideoTrack = false;
623 m_hasAudioTrack = false;
624 const bool hadMetadata = m_duration > 0 || m_videoWidth > 0 || m_videoHeight > 0;
625 m_videoWidth = 0;
626 m_videoHeight = 0;
627 if (changed) {
628 tracksChanged();
629 activeTracksChanged();
630 }
631 if (hadMetadata)
632 metaDataChanged();
633}
634
635bool QOhosMediaPlayer::ensurePlayer()
636{
637 if (m_player)
638 return true;
639 m_player = OH_AVPlayer_Create();
640 if (!m_player) {
641 qCWarning(qLcOhosMediaPlugin) << "OH_AVPlayer_Create failed";
642 return false;
643 }
644 OH_AVPlayer_SetOnInfoCallback(m_player, &QOhosMediaPlayer::onInfoTrampoline, this);
645 OH_AVPlayer_SetOnErrorCallback(m_player, &QOhosMediaPlayer::onErrorTrampoline, this);
646 return true;
647}
648
649void QOhosMediaPlayer::reprepare()
650{
651 if (m_reprepareRequested)
652 return;
653 m_reprepareRequested = true;
654 OH_AVPlayer_Prepare(m_player);
655}
656
657void QOhosMediaPlayer::applyVolume()
658{
659 if (!m_player)
660 return;
661
662 float volume = 1.0f;
663 if (m_audioOutput)
664 volume = m_audioOutput->muted ? 0.0f : m_audioOutput->volume;
665
666 OH_AVPlayer_SetVolume(m_player, volume, volume);
667}
668
669void QOhosMediaPlayer::onInfoTrampoline(OH_AVPlayer *player, AVPlayerOnInfoType type,
670 OH_AVFormat *body, void *userData)
671{
672 Q_UNUSED(body)
673 Q_UNUSED(player)
674 auto *self = reinterpret_cast<QOhosMediaPlayer *>(userData);
675 if (!self)
676 return;
677
678 switch (type) {
679 case AV_INFO_TYPE_STATE_CHANGE: {
680 AVPlayerState state{ AV_IDLE };
681 OH_AVPlayer_GetState(player, &state);
682 QMetaObject::invokeMethod(
683 self, [self, state]() { self->handleStateChange(state); }, Qt::QueuedConnection);
684 break;
685 }
686 case AV_INFO_TYPE_POSITION_UPDATE: {
687 int32_t pos = 0;
688 OH_AVPlayer_GetCurrentTime(player, &pos);
689 self->m_position.store(pos);
690 QMetaObject::invokeMethod(
691 self, [self, pos]() { self->positionChanged(qint64{ pos }); },
692 Qt::QueuedConnection);
693 break;
694 }
695 case AV_INFO_TYPE_DURATION_UPDATE: {
696 int32_t dur = 0;
697 OH_AVPlayer_GetDuration(player, &dur);
698 QMetaObject::invokeMethod(
699 self,
700 [self, dur]() {
701 if (self->m_duration == dur)
702 return;
703 self->m_duration = dur;
704 self->durationChanged(qint64{ dur });
705 },
706 Qt::QueuedConnection);
707 break;
708 }
709 case AV_INFO_TYPE_EOS:
710 QMetaObject::invokeMethod(
711 self, [self]() { self->handleEndOfStream(); }, Qt::QueuedConnection);
712 break;
713 case AV_INFO_TYPE_SEEKDONE:
714 QMetaObject::invokeMethod(
715 self, [self]() { self->handleSeekDone(); }, Qt::QueuedConnection);
716 break;
717 case AV_INFO_TYPE_RESOLUTION_CHANGE:
718 QMetaObject::invokeMethod(
719 self, [self]() { self->handleResolutionChange(); }, Qt::QueuedConnection);
720 break;
721 default:
722 break;
723 }
724}
725
726void QOhosMediaPlayer::onErrorTrampoline(OH_AVPlayer *, int32_t errorCode, const char *errorMsg,
727 void *userData)
728{
729 auto *self = reinterpret_cast<QOhosMediaPlayer *>(userData);
730 if (!self)
731 return;
732 QString message = errorMsg ? QString::fromUtf8(errorMsg) : QString{};
733 QMetaObject::invokeMethod(
734 self, [self, errorCode, message]() { self->handleError(errorCode, message); },
735 Qt::QueuedConnection);
736}
737
738QT_END_NAMESPACE
739
740#include "moc_qohosmediaplayer_p.cpp"
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