Demuxer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/Object.h>
  9. #include <LibVideo/DecoderError.h>
  10. #include <LibVideo/Sample.h>
  11. #include <LibVideo/Track.h>
  12. namespace Video {
  13. class Demuxer {
  14. public:
  15. virtual ~Demuxer() = default;
  16. virtual DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) = 0;
  17. DecoderErrorOr<NonnullOwnPtr<VideoSample>> get_next_video_sample_for_track(Track track)
  18. {
  19. VERIFY(track.type() == TrackType::Video);
  20. auto sample = TRY(get_next_sample_for_track(track));
  21. VERIFY(sample->is_video_sample());
  22. return sample.release_nonnull<VideoSample>();
  23. }
  24. // Returns the timestamp of the keyframe that was seeked to.
  25. // The value is `Optional` to allow the demuxer to decide not to seek so that it can keep its position
  26. // in the case that the timestamp is closer to the current time than the nearest keyframe.
  27. virtual DecoderErrorOr<Optional<Time>> seek_to_most_recent_keyframe(Track track, Time timestamp, Optional<Time> earliest_available_sample = OptionalNone()) = 0;
  28. virtual DecoderErrorOr<Time> duration() = 0;
  29. protected:
  30. virtual DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) = 0;
  31. };
  32. }