MatroskaDemuxer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/HashMap.h>
  8. #include <LibVideo/Containers/Demuxer.h>
  9. #include "Reader.h"
  10. namespace Video::Matroska {
  11. class MatroskaDemuxer final : public Demuxer {
  12. public:
  13. // FIXME: We should instead accept some abstract data streaming type so that the demuxer
  14. // can work with non-contiguous data.
  15. static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_file(StringView filename);
  16. static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_mapped_file(NonnullOwnPtr<Core::MappedFile> mapped_file);
  17. static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_data(ReadonlyBytes data);
  18. MatroskaDemuxer(Reader&& reader)
  19. : m_reader(move(reader))
  20. {
  21. }
  22. DecoderErrorOr<Vector<Track>> get_tracks_for_type(TrackType type) override;
  23. DecoderErrorOr<Optional<Duration>> seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample = OptionalNone()) override;
  24. DecoderErrorOr<Duration> duration() override;
  25. DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) override;
  26. protected:
  27. DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) override;
  28. private:
  29. struct TrackStatus {
  30. SampleIterator iterator;
  31. Optional<Block> block {};
  32. size_t frame_index { 0 };
  33. };
  34. DecoderErrorOr<TrackStatus*> get_track_status(Track track);
  35. CodecID get_codec_id_for_string(FlyString const& codec_id);
  36. Reader m_reader;
  37. HashMap<Track, TrackStatus> m_track_statuses;
  38. };
  39. }