1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 18:35:09 +00:00
serenity/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h
Zaggy1024 fd3ffd88ce LibVideo: Add a fast seeking mode to seek only to keyframes
Now that we're able to find the nearest keyframe, we can have a fast
seeking mode that only seeks to keyframes, so that it doesn't have to
also decode inter frames until it reaches the timestamp.

The default is still accurate seeking, so that the entire seeking
implementation can be tested.
2022-11-25 23:28:39 +01:00

51 lines
1.3 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<Time> seek_to_most_recent_keyframe(Track track, Time timestamp) 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;
};
}