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.
This commit is contained in:
Timothy Flynn 2023-04-08 21:22:15 -04:00 committed by Linus Groh
parent 3591a13e85
commit 519b79abde
Notes: sideshowbarker 2024-07-16 23:59:28 +09:00
2 changed files with 15 additions and 1 deletions

View file

@ -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);

View file

@ -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());