mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:47:46 +00:00
LibVideo: Read Matroska lazily so that large files can start quickly
The Demuxer class was changed to return errors for more functions so that all of the underlying reading can be done lazily. Other than that, the demuxer interface is unchanged, and only the underlying reader was modified. The MatroskaDocument class is no more, and MatroskaReader's getter functions replace it. Every MatroskaReader getter beyond the Segment element's position is parsed lazily from the file as needed. This means that all getter functions can return DecoderErrors which must be handled by callers.
This commit is contained in:
parent
f4c476b26f
commit
393cfdd5c5
11 changed files with 576 additions and 310 deletions
|
@ -20,30 +20,30 @@ public:
|
|||
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_file(StringView filename);
|
||||
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_data(ReadonlyBytes data);
|
||||
|
||||
MatroskaDemuxer(NonnullOwnPtr<MatroskaDocument>&& document)
|
||||
: m_document(move(document))
|
||||
MatroskaDemuxer(Reader&& reader)
|
||||
: m_reader(move(reader))
|
||||
{
|
||||
}
|
||||
|
||||
Vector<Track> get_tracks_for_type(TrackType type) override;
|
||||
DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) override;
|
||||
|
||||
DecoderErrorOr<void> seek_to_most_recent_keyframe(Track track, size_t timestamp) override;
|
||||
|
||||
Time duration() override;
|
||||
DecoderErrorOr<Time> duration() override;
|
||||
|
||||
protected:
|
||||
DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) override;
|
||||
|
||||
private:
|
||||
struct TrackStatus {
|
||||
size_t m_cluster_index { 0 };
|
||||
size_t m_block_index { 0 };
|
||||
size_t m_frame_index { 0 };
|
||||
SampleIterator iterator;
|
||||
Optional<Block> block {};
|
||||
size_t frame_index { 0 };
|
||||
};
|
||||
|
||||
ErrorOr<TrackStatus*> get_track_status(Track track);
|
||||
DecoderErrorOr<TrackStatus*> get_track_status(Track track);
|
||||
|
||||
NonnullOwnPtr<MatroskaDocument> m_document;
|
||||
Reader m_reader;
|
||||
|
||||
HashMap<Track, TrackStatus> m_track_statuses;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue