From 2a228e8a6eec2646c55d1c1dbfbf59459e16508d Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 12 Feb 2023 00:44:16 -0600 Subject: [PATCH] LibVideo: Deduplicate logic for dispatching video frame queue items Previously we had dispatch_decoder_error and on_decoder_error serving the same function, with one not handling the end of stream properly. There is also a new function to dispatch either an error or a frame to the owner of this playback manager, so that PlaybackStateHandlers don't have to duplicate this logic. --- .../Libraries/LibVideo/PlaybackManager.cpp | 44 +++++++++++-------- Userland/Libraries/LibVideo/PlaybackManager.h | 4 +- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index 0024fd4a0f..522a6d2bd2 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -75,7 +75,7 @@ Time PlaybackManager::duration() { auto duration_result = m_demuxer->duration(); if (duration_result.is_error()) - on_decoder_error(duration_result.release_error()); + dispatch_decoder_error(duration_result.release_error()); return duration_result.release_value(); } @@ -89,7 +89,7 @@ void PlaybackManager::dispatch_fatal_error(Error error) m_event_handler.dispatch_event(event); } -void PlaybackManager::on_decoder_error(DecoderError error) +void PlaybackManager::dispatch_decoder_error(DecoderError error) { switch (error.category()) { case DecoderErrorCategory::EndOfStream: @@ -104,6 +104,23 @@ void PlaybackManager::on_decoder_error(DecoderError error) } } +void PlaybackManager::dispatch_new_frame(RefPtr frame) +{ + m_main_loop.post_event(m_event_handler, make(frame)); +} + +bool PlaybackManager::dispatch_frame_queue_item(FrameQueueItem&& item) +{ + if (item.is_error()) { + dispatch_decoder_error(item.release_error()); + return true; + } + + dbgln_if(PLAYBACK_MANAGER_DEBUG, "Sent frame for presentation"); + dispatch_new_frame(item.bitmap()); + return false; +} + void PlaybackManager::timer_callback() { TRY_OR_FATAL_ERROR(m_playback_handler->on_timer_callback()); @@ -120,7 +137,7 @@ Optional