ladybird/Libraries/LibMedia/Demuxer.h
Zaggy1024 ae7f82591b LibMedia: Separate file duration from track duration in Demuxer
Most users will only care about the total file duration, and shouldn't
be required to determine the file duration from multiple track
durations. To facilitate that, add a total_duration() function that
returns the demuxer's duration not associated to any particular track.
2025-09-12 11:23:47 +02:00

44 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullOwnPtr.h>
#include <LibCore/EventReceiver.h>
#include "CodecID.h"
#include "DecoderError.h"
#include "Sample.h"
#include "Track.h"
namespace Media {
class Demuxer {
public:
virtual ~Demuxer() = default;
virtual DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) = 0;
// Returns the container's preferred track for a given track type. This must return a value if any track of the
// given type is present.
virtual DecoderErrorOr<Optional<Track>> get_preferred_track_for_type(TrackType type) = 0;
virtual DecoderErrorOr<Sample> get_next_sample_for_track(Track track) = 0;
virtual DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) = 0;
virtual DecoderErrorOr<ReadonlyBytes> get_codec_initialization_data_for_track(Track track) = 0;
// Returns the timestamp of the keyframe that was seeked to.
// The value is `Optional` to allow the demuxer to decide not to seek so that it can keep its position
// in the case that the timestamp is closer to the current time than the nearest keyframe.
virtual DecoderErrorOr<Optional<AK::Duration>> seek_to_most_recent_keyframe(Track track, AK::Duration timestamp, Optional<AK::Duration> earliest_available_sample = OptionalNone()) = 0;
virtual DecoderErrorOr<AK::Duration> duration_of_track(Track const&) = 0;
virtual DecoderErrorOr<AK::Duration> total_duration() = 0;
};
}