ladybird/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h
Zaggy1024 3bfef8bfe0 LibVideo: Pass the current sample to demuxers to lazily seek better
In cases where the PlaybackManager's earliest buffered or displayed
sample is closer to the seek target than the demuxer's chosen keyframe,
we don't want to seek at all. To enable this, demuxers now receive an
optional parameter with the earliest timestamp that the caller can
still access.

The demuxer in turn returns an optional to indicate when a seek was not
needed, which allows PlaybackManager to avoid clearing its queue and
re-decoding frames.
2023-02-08 21:52:42 +01:00

51 lines
1.4 KiB
C++

/*
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <LibVideo/Containers/Demuxer.h>
#include "Reader.h"
namespace Video::Matroska {
class MatroskaDemuxer final : public Demuxer {
public:
// FIXME: We should instead accept some abstract data streaming type so that the demuxer
// can work with non-contiguous data.
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_file(StringView filename);
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_data(ReadonlyBytes data);
MatroskaDemuxer(Reader&& reader)
: m_reader(move(reader))
{
}
DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) override;
DecoderErrorOr<Optional<Time>> seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()) override;
DecoderErrorOr<Time> duration() override;
protected:
DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) override;
private:
struct TrackStatus {
SampleIterator iterator;
Optional<Block> block {};
size_t frame_index { 0 };
};
DecoderErrorOr<TrackStatus*> get_track_status(Track track);
Reader m_reader;
HashMap<Track, TrackStatus> m_track_statuses;
};
}