diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-08 21:22:15 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-09 23:55:05 +0200 |
commit | 519b79abde3424854457b575604db6fd1dccfeb2 (patch) | |
tree | 6e372b84a459bef5bc8eae7cb93c8ffe8959b56e /Userland | |
parent | 3591a13e85ffd76682e26888ff5f0bc27b87aa2c (diff) | |
download | serenity-519b79abde3424854457b575604db6fd1dccfeb2.zip |
LibVideo: Add a factory to create a PlaybackManager from in-memory data
The demuxer already has such a factory, so this just exposes the same
factory in the PlaybackManager.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibVideo/PlaybackManager.cpp | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/PlaybackManager.h | 3 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index 21aa997fbc..4db877e1f2 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -47,7 +47,18 @@ private: DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::from_file(StringView filename, PlaybackTimerCreator playback_timer_creator) { - NonnullOwnPtr<Demuxer> demuxer = TRY(Matroska::MatroskaDemuxer::from_file(filename)); + auto demuxer = TRY(Matroska::MatroskaDemuxer::from_file(filename)); + return create_with_demuxer(move(demuxer), move(playback_timer_creator)); +} + +DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::from_data(ReadonlyBytes data, PlaybackTimerCreator playback_timer_creator) +{ + auto demuxer = TRY(Matroska::MatroskaDemuxer::from_data(data)); + return create_with_demuxer(move(demuxer), move(playback_timer_creator)); +} + +DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> PlaybackManager::create_with_demuxer(NonnullOwnPtr<Demuxer> demuxer, PlaybackTimerCreator playback_timer_creator) +{ auto video_tracks = TRY(demuxer->get_tracks_for_type(TrackType::Video)); if (video_tracks.is_empty()) return DecoderError::with_description(DecoderErrorCategory::Invalid, "No video track is present"sv); diff --git a/Userland/Libraries/LibVideo/PlaybackManager.h b/Userland/Libraries/LibVideo/PlaybackManager.h index 43657e193f..29fae14f2b 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.h +++ b/Userland/Libraries/LibVideo/PlaybackManager.h @@ -102,6 +102,7 @@ public: using PlaybackTimerCreator = Function<ErrorOr<NonnullOwnPtr<PlaybackTimer>>(int, Function<void()>)>; static DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> from_file(StringView file, PlaybackTimerCreator = nullptr); + static DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> from_data(ReadonlyBytes data, PlaybackTimerCreator = nullptr); PlaybackManager(NonnullOwnPtr<Demuxer>& demuxer, Track video_track, NonnullOwnPtr<VideoDecoder>&& decoder, PlaybackTimerCreator); @@ -135,6 +136,8 @@ private: class SeekingStateHandler; class StoppedStateHandler; + static DecoderErrorOr<NonnullOwnPtr<PlaybackManager>> create_with_demuxer(NonnullOwnPtr<Demuxer> demuxer, PlaybackTimerCreator playback_timer_creator); + void start_timer(int milliseconds); void timer_callback(); Optional<Time> seek_demuxer_to_most_recent_keyframe(Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()); |