Demuxer.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullOwnPtr.h>
  8. #include <LibCore/EventReceiver.h>
  9. #include <LibVideo/CodecID.h>
  10. #include <LibVideo/DecoderError.h>
  11. #include <LibVideo/Sample.h>
  12. #include <LibVideo/Track.h>
  13. namespace Video {
  14. class Demuxer {
  15. public:
  16. virtual ~Demuxer() = default;
  17. virtual DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) = 0;
  18. DecoderErrorOr<NonnullOwnPtr<VideoSample>> get_next_video_sample_for_track(Track track)
  19. {
  20. VERIFY(track.type() == TrackType::Video);
  21. auto sample = TRY(get_next_sample_for_track(track));
  22. VERIFY(sample->is_video_sample());
  23. return sample.release_nonnull<VideoSample>();
  24. }
  25. virtual DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) = 0;
  26. // Returns the timestamp of the keyframe that was seeked to.
  27. // The value is `Optional` to allow the demuxer to decide not to seek so that it can keep its position
  28. // in the case that the timestamp is closer to the current time than the nearest keyframe.
  29. virtual DecoderErrorOr<Optional<Duration>> seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone()) = 0;
  30. virtual DecoderErrorOr<Duration> duration() = 0;
  31. protected:
  32. virtual DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) = 0;
  33. };
  34. }