diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp index bac8f7d65d..e01da0cc6f 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp +++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp @@ -14,6 +14,11 @@ DecoderErrorOr> MatroskaDemuxer::from_file(String return make(TRY(Reader::from_file(filename))); } +DecoderErrorOr> MatroskaDemuxer::from_mapped_file(NonnullRefPtr mapped_file) +{ + return make(TRY(Reader::from_mapped_file(move(mapped_file)))); +} + DecoderErrorOr> MatroskaDemuxer::from_data(ReadonlyBytes data) { return make(TRY(Reader::from_data(data))); diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h index 660175ca2c..eeddd16630 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h +++ b/Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h @@ -18,6 +18,8 @@ public: // FIXME: We should instead accept some abstract data streaming type so that the demuxer // can work with non-contiguous data. static DecoderErrorOr> from_file(StringView filename); + static DecoderErrorOr> from_mapped_file(NonnullRefPtr mapped_file); + static DecoderErrorOr> from_data(ReadonlyBytes data); MatroskaDemuxer(Reader&& reader) diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp index 5b8dd12671..b6a87b194d 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp @@ -81,8 +81,13 @@ constexpr u32 CUE_REFERENCE_ID = 0xDB; DecoderErrorOr Reader::from_file(StringView path) { auto mapped_file = DECODER_TRY(DecoderErrorCategory::IO, Core::MappedFile::map(path)); + return from_mapped_file(mapped_file); +} + +DecoderErrorOr Reader::from_mapped_file(NonnullRefPtr mapped_file) +{ auto reader = TRY(from_data(mapped_file->bytes())); - reader.m_mapped_file = mapped_file; + reader.m_mapped_file = move(mapped_file); return reader; } diff --git a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h index 030ce7ef95..ccfd54ca75 100644 --- a/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h +++ b/Userland/Libraries/LibVideo/Containers/Matroska/Reader.h @@ -25,6 +25,8 @@ public: typedef Function(TrackEntry const&)> TrackEntryCallback; static DecoderErrorOr from_file(StringView path); + static DecoderErrorOr from_mapped_file(NonnullRefPtr mapped_file); + static DecoderErrorOr from_data(ReadonlyBytes data); EBMLHeader const& header() const { return m_header.value(); } diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index 8af53cbce8..7587bf2321 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -31,6 +31,12 @@ DecoderErrorOr> PlaybackManager::from_file(String return create_with_demuxer(move(demuxer)); } +DecoderErrorOr> PlaybackManager::from_mapped_file(NonnullRefPtr mapped_file) +{ + auto demuxer = TRY(Matroska::MatroskaDemuxer::from_mapped_file(move(mapped_file))); + return create_with_demuxer(move(demuxer)); +} + DecoderErrorOr> PlaybackManager::from_data(ReadonlyBytes data) { auto demuxer = TRY(Matroska::MatroskaDemuxer::from_data(data)); diff --git a/Userland/Libraries/LibVideo/PlaybackManager.h b/Userland/Libraries/LibVideo/PlaybackManager.h index 01f55e29e7..60e538212d 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.h +++ b/Userland/Libraries/LibVideo/PlaybackManager.h @@ -101,6 +101,8 @@ public: static constexpr SeekMode DEFAULT_SEEK_MODE = SeekMode::Accurate; static DecoderErrorOr> from_file(StringView file); + static DecoderErrorOr> from_mapped_file(NonnullRefPtr file); + static DecoderErrorOr> from_data(ReadonlyBytes data); PlaybackManager(NonnullOwnPtr& demuxer, Track video_track, NonnullOwnPtr&& decoder);