From 33140095c4364feea17623e2ab20f76784086ae0 Mon Sep 17 00:00:00 2001 From: Vladislav Mikhalin Date: Sat, 22 Feb 2025 20:55:14 +0300 Subject: [PATCH] avplayer: removed all waits from GetVideoData --- src/core/libraries/avplayer/avplayer.cpp | 8 ++++---- src/core/libraries/avplayer/avplayer_common.h | 4 ++++ src/core/libraries/avplayer/avplayer_source.cpp | 14 +++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/libraries/avplayer/avplayer.cpp b/src/core/libraries/avplayer/avplayer.cpp index 3feef5e5b..8d5a76199 100644 --- a/src/core/libraries/avplayer/avplayer.cpp +++ b/src/core/libraries/avplayer/avplayer.cpp @@ -19,7 +19,7 @@ s32 PS4_SYSV_ABI sceAvPlayerAddSource(AvPlayerHandle handle, const char* filenam s32 PS4_SYSV_ABI sceAvPlayerAddSourceEx(AvPlayerHandle handle, AvPlayerUriType uri_type, AvPlayerSourceDetails* source_details) { - LOG_TRACE(Lib_AvPlayer, "(STUBBED) called"); + LOG_TRACE(Lib_AvPlayer, "called"); if (handle == nullptr || uri_type != AvPlayerUriType::Source) { return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS; } @@ -159,7 +159,7 @@ s32 PS4_SYSV_ABI sceAvPlayerJumpToTime(AvPlayerHandle handle, uint64_t time) { } s32 PS4_SYSV_ABI sceAvPlayerPause(AvPlayerHandle handle) { - LOG_TRACE(Lib_AvPlayer, "(STUBBED) called"); + LOG_TRACE(Lib_AvPlayer, "called"); if (handle == nullptr) { return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS; } @@ -180,7 +180,7 @@ s32 PS4_SYSV_ABI sceAvPlayerPrintf(const char* format, ...) { } s32 PS4_SYSV_ABI sceAvPlayerResume(AvPlayerHandle handle) { - LOG_TRACE(Lib_AvPlayer, "(STUBBED) called"); + LOG_TRACE(Lib_AvPlayer, "called"); if (handle == nullptr) { return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS; } @@ -188,7 +188,7 @@ s32 PS4_SYSV_ABI sceAvPlayerResume(AvPlayerHandle handle) { } s32 PS4_SYSV_ABI sceAvPlayerSetAvSyncMode(AvPlayerHandle handle, AvPlayerAvSyncMode sync_mode) { - LOG_TRACE(Lib_AvPlayer, "(STUBBED) called"); + LOG_TRACE(Lib_AvPlayer, "called"); if (handle == nullptr) { return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS; } diff --git a/src/core/libraries/avplayer/avplayer_common.h b/src/core/libraries/avplayer/avplayer_common.h index 2c5f4ec13..1e5715009 100644 --- a/src/core/libraries/avplayer/avplayer_common.h +++ b/src/core/libraries/avplayer/avplayer_common.h @@ -65,6 +65,10 @@ public: m_queue.emplace(std::forward(value)); } + T& Front() { + return m_queue.front(); + } + std::optional Pop() { if (Size() == 0) { return std::nullopt; diff --git a/src/core/libraries/avplayer/avplayer_source.cpp b/src/core/libraries/avplayer/avplayer_source.cpp index d65e5e3d8..4f637f1ba 100644 --- a/src/core/libraries/avplayer/avplayer_source.cpp +++ b/src/core/libraries/avplayer/avplayer_source.cpp @@ -291,10 +291,6 @@ void AvPlayerSource::Resume() { } bool AvPlayerSource::GetVideoData(AvPlayerFrameInfo& video_info) { - if (!IsActive()) { - return false; - } - AvPlayerFrameInfoEx info{}; if (!GetVideoData(info)) { return false; @@ -317,18 +313,18 @@ bool AvPlayerSource::GetVideoData(AvPlayerFrameInfoEx& video_info) { return false; } - auto frame = m_video_frames.Pop(); + const auto& last_frame = m_video_frames.Front(); if (m_state.GetSyncMode() == AvPlayerAvSyncMode::Default) { const auto current_time = m_audio_stream_index.has_value() ? m_last_audio_packet_time : CurrentTime(); - if (0 < current_time && current_time < frame->info.timestamp) { - std::this_thread::sleep_for( - std::chrono::milliseconds(frame->info.timestamp - current_time)); + if (0 < current_time && current_time < last_frame.info.timestamp) { + return false; } } - // return the buffer to the queue + auto frame = m_video_frames.Pop(); if (m_current_video_frame.has_value()) { + // return the buffer to the queue m_video_buffers.Push(std::move(m_current_video_frame.value())); m_video_buffers_cv.Notify(); }