diff options
author | Zaggy1024 <zaggy1024@gmail.com> | 2023-04-14 12:30:38 -0500 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-05-23 05:17:48 -0600 |
commit | eae7422ebc549a6a8640867907d33b076ee96710 (patch) | |
tree | d301b8dee219ed4bd387ada80ae423a2c81afbd4 /Userland/Libraries/LibVideo | |
parent | c03152c5d23ae2fbf9d1af8c68bcca67e5b1be70 (diff) | |
download | serenity-eae7422ebc549a6a8640867907d33b076ee96710.zip |
LibVideo: Fallibly construct playback manager fields
Diffstat (limited to 'Userland/Libraries/LibVideo')
-rw-r--r-- | Userland/Libraries/LibVideo/PlaybackManager.cpp | 31 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/PlaybackManager.h | 6 |
2 files changed, 21 insertions, 16 deletions
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index 7587bf2321..d8973e155e 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -28,22 +28,22 @@ namespace Video { DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::from_file(StringView filename) { auto demuxer = TRY(Matroska::MatroskaDemuxer::from_file(filename)); - return create_with_demuxer(move(demuxer)); + return create(move(demuxer)); } DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file) { auto demuxer = TRY(Matroska::MatroskaDemuxer::from_mapped_file(move(mapped_file))); - return create_with_demuxer(move(demuxer)); + return create(move(demuxer)); } DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::from_data(ReadonlyBytes data) { auto demuxer = TRY(Matroska::MatroskaDemuxer::from_data(data)); - return create_with_demuxer(move(demuxer)); + return create(move(demuxer)); } -DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::create_with_demuxer(NonnullOwnPtr<Demuxer> demuxer) +DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::create(NonnullOwnPtr<Demuxer> demuxer) { auto video_tracks = TRY(demuxer->get_tracks_for_type(TrackType::Video)); if (video_tracks.is_empty()) @@ -52,20 +52,25 @@ DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::create_with_demu dbgln_if(PLAYBACK_MANAGER_DEBUG, "Selecting video track number {}", track.identifier()); - return make<PlaybackManager>(demuxer, track, make<VP9::Decoder>()); + auto decoder = DECODER_TRY_ALLOC(try_make<VP9::Decoder>()); + auto frame_queue = DECODER_TRY_ALLOC(try_make<VideoFrameQueue>()); + auto playback_manager = DECODER_TRY_ALLOC(try_make<PlaybackManager>(demuxer, track, move(decoder), move(frame_queue))); + + playback_manager->m_present_timer = DECODER_TRY_ALLOC(Core::Timer::create_single_shot(0, [&self = *playback_manager] { self.timer_callback(); })); + playback_manager->m_decode_timer = DECODER_TRY_ALLOC(Core::Timer::create_single_shot(0, [&self = *playback_manager] { self.on_decode_timer(); })); + + playback_manager->m_playback_handler = make<SeekingStateHandler>(*playback_manager, false, Time::zero(), SeekMode::Fast); + DECODER_TRY_ALLOC(playback_manager->m_playback_handler->on_enter()); + + return playback_manager; } -PlaybackManager::PlaybackManager(NonnullOwnPtr<Demuxer>& demuxer, Track video_track, NonnullOwnPtr<VideoDecoder>&& decoder) +PlaybackManager::PlaybackManager(NonnullOwnPtr<Demuxer>& demuxer, Track video_track, NonnullOwnPtr<VideoDecoder>&& decoder, NonnullOwnPtr<VideoFrameQueue>&& frame_queue) : m_demuxer(move(demuxer)) , m_selected_video_track(video_track) , m_decoder(move(decoder)) - , m_frame_queue(make<VideoFrameQueue>()) - , m_playback_handler(make<SeekingStateHandler>(*this, false, Time::zero(), SeekMode::Fast)) + , m_frame_queue(move(frame_queue)) { - m_present_timer = Core::Timer::create_single_shot(0, [&] { timer_callback(); }).release_value_but_fixme_should_propagate_errors(); - m_decode_timer = Core::Timer::create_single_shot(0, [&] { on_decode_timer(); }).release_value_but_fixme_should_propagate_errors(); - - TRY_OR_FATAL_ERROR(m_playback_handler->on_enter()); } PlaybackManager::~PlaybackManager() = default; @@ -286,7 +291,7 @@ ErrorOr<void> PlaybackManager::PlaybackStateHandler::stop() template<class T, class... Args> ErrorOr<void> PlaybackManager::PlaybackStateHandler::replace_handler_and_delete_this(Args... args) { - auto temp_handler = TRY(adopt_nonnull_own_or_enomem<PlaybackStateHandler>(new (nothrow) T(m_manager, args...))); + OwnPtr<PlaybackStateHandler> temp_handler = TRY(try_make<T>(m_manager, args...)); m_manager.m_playback_handler.swap(temp_handler); #if PLAYBACK_MANAGER_DEBUG m_has_exited = true; diff --git a/Userland/Libraries/LibVideo/PlaybackManager.h b/Userland/Libraries/LibVideo/PlaybackManager.h index 60e538212d..44f7a9022b 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.h +++ b/Userland/Libraries/LibVideo/PlaybackManager.h @@ -105,7 +105,7 @@ public: static DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> from_data(ReadonlyBytes data); - PlaybackManager(NonnullOwnPtr<Demuxer>& demuxer, Track video_track, NonnullOwnPtr<VideoDecoder>&& decoder); + PlaybackManager(NonnullOwnPtr<Demuxer>& demuxer, Track video_track, NonnullOwnPtr<VideoDecoder>&& decoder, NonnullOwnPtr<VideoFrameQueue>&& frame_queue); ~PlaybackManager(); void resume_playback(); @@ -143,7 +143,7 @@ private: class SeekingStateHandler; class StoppedStateHandler; - static DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> create_with_demuxer(NonnullOwnPtr<Demuxer> demuxer); + static DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> create(NonnullOwnPtr<Demuxer> demuxer); void start_timer(int milliseconds); void timer_callback(); @@ -172,7 +172,7 @@ private: RefPtr<Core::Timer> m_decode_timer; - NonnullOwnPtr<PlaybackStateHandler> m_playback_handler; + OwnPtr<PlaybackStateHandler> m_playback_handler; Optional<FrameQueueItem> m_next_frame; u64 m_skipped_frames { 0 }; |