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

LibVideo: Implement Matroska Cues for faster keyframe lookup

This implements the fastest seeking mode available for tracks with cues
using an array of cue points for each track. It approximates the index
based on the seeking timestamp and then finds the earliest cue point
before the timestamp. The approximation assumes that cues will be on
a regular interval, which I don't believe is always the case, but it
should at least be faster than iterating the whole set of cue points
each time.

Cues are stored per track, but most videos will only have cue points
for the video track(s) that are present. For now, this assumes that it
should only seek based on the cue points for the selected track. To
seek audio in a video file, we should copy the seeked iterator over to
the audio track's iterator after seeking is complete. The iterator will
then skip to the next audio block.
This commit is contained in:
Zaggy1024 2022-11-13 19:28:56 -06:00 committed by Andreas Kling
parent 56d8b96c78
commit f6830eaf73
5 changed files with 288 additions and 2 deletions

View file

@ -203,4 +203,32 @@ private:
Time m_timestamp { Time::zero() };
};
class CueTrackPosition {
public:
u64 track_number() const { return m_track_number; }
void set_track_number(u64 track_number) { m_track_number = track_number; }
size_t cluster_position() const { return m_cluster_position; }
void set_cluster_position(size_t cluster_position) { m_cluster_position = cluster_position; }
size_t block_offset() const { return m_block_offset; }
void set_block_offset(size_t block_offset) { m_block_offset = block_offset; }
private:
u64 m_track_number { 0 };
size_t m_cluster_position { 0 };
size_t m_block_offset { 0 };
};
class CuePoint {
public:
Time timestamp() const { return m_timestamp; }
void set_timestamp(Time timestamp) { m_timestamp = timestamp; }
OrderedHashMap<u64, CueTrackPosition>& track_positions() { return m_track_positions; }
OrderedHashMap<u64, CueTrackPosition> const& track_positions() const { return m_track_positions; }
Optional<CueTrackPosition const&> position_for_track(u64 track_number) const { return m_track_positions.get(track_number); }
private:
Time m_timestamp = Time::min();
OrderedHashMap<u64, CueTrackPosition> m_track_positions;
};
}