1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:57:35 +00:00

LibVideo: Implement accurate seeking to inter frames in PlaybackManager

This implements the PlaybackManager portion of seeking, so that it can
seek to any frame in the video by dropping all preceding frames until
it reaches the seek point.

MatroskaDemuxer currently will only seek to the start of the video.
That means that every seek has to drop all the frames until it comes
across the target timestamp.
This commit is contained in:
Zaggy1024 2022-11-14 00:54:21 -06:00 committed by Andreas Kling
parent 9a9fe08449
commit 5c2cede2c9
3 changed files with 65 additions and 24 deletions

View file

@ -28,7 +28,8 @@ enum class PlaybackStatus {
Playing,
Paused,
Buffering,
Seeking,
SeekingPlaying,
SeekingPaused,
Stopped,
Corrupted,
};
@ -102,7 +103,8 @@ public:
void pause_playback();
void restart_playback();
void seek_to_timestamp(Time);
bool is_playing() const { return m_status == PlaybackStatus::Playing || m_status == PlaybackStatus::Buffering; }
bool is_playing() const { return m_status == PlaybackStatus::Playing || m_status == PlaybackStatus::SeekingPlaying || m_status == PlaybackStatus::Buffering; }
bool is_seeking() const { return m_status == PlaybackStatus::SeekingPlaying || m_status == PlaybackStatus::SeekingPaused; }
bool is_buffering() const { return m_status == PlaybackStatus::Buffering; }
bool is_stopped() const { return m_status == PlaybackStatus::Stopped || m_status == PlaybackStatus::Corrupted; }
@ -118,7 +120,7 @@ public:
private:
void set_playback_status(PlaybackStatus status);
bool prepare_next_frame();
void end_seek();
void update_presented_frame();
// May run off the main thread
@ -133,6 +135,8 @@ private:
Time m_last_present_in_media_time = Time::zero();
Time m_last_present_in_real_time = Time::zero();
Time m_seek_to_media_time = Time::min();
NonnullOwnPtr<Demuxer> m_demuxer;
Track m_selected_video_track;
NonnullOwnPtr<VideoDecoder> m_decoder;
@ -213,8 +217,10 @@ inline StringView playback_status_to_string(PlaybackStatus status)
return "Paused"sv;
case PlaybackStatus::Buffering:
return "Buffering"sv;
case PlaybackStatus::Seeking:
return "Seeking"sv;
case PlaybackStatus::SeekingPlaying:
return "SeekingPlaying"sv;
case PlaybackStatus::SeekingPaused:
return "SeekingPaused"sv;
case PlaybackStatus::Stopped:
return "Stopped"sv;
case PlaybackStatus::Corrupted: