/* * Copyright (c) 2022, Gregory Bertilson * * SPDX-License-Identifier: BSD-2-Clause */ #include "MatroskaDemuxer.h" namespace Video::Matroska { DecoderErrorOr> MatroskaDemuxer::from_file(StringView filename) { return make(TRY(Reader::from_file(filename))); } DecoderErrorOr> MatroskaDemuxer::from_data(ReadonlyBytes data) { return make(TRY(Reader::from_data(data))); } DecoderErrorOr> MatroskaDemuxer::get_tracks_for_type(TrackType type) { TrackEntry::TrackType matroska_track_type; switch (type) { case TrackType::Video: matroska_track_type = TrackEntry::TrackType::Video; break; case TrackType::Audio: matroska_track_type = TrackEntry::TrackType::Audio; break; case TrackType::Subtitles: matroska_track_type = TrackEntry::TrackType::Subtitle; break; } Vector tracks; TRY(m_reader.for_each_track_of_type(matroska_track_type, [&](TrackEntry const& track_entry) -> DecoderErrorOr { VERIFY(track_entry.track_type() == matroska_track_type); DECODER_TRY_ALLOC(tracks.try_append(Track(type, track_entry.track_number()))); return IterationDecision::Continue; })); return tracks; } DecoderErrorOr MatroskaDemuxer::get_track_status(Track track) { if (!m_track_statuses.contains(track)) { auto iterator = TRY(m_reader.create_sample_iterator(track.identifier())); DECODER_TRY_ALLOC(m_track_statuses.try_set(track, { iterator })); } return &m_track_statuses.get(track).release_value(); } DecoderErrorOr