summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVideo/Containers
diff options
context:
space:
mode:
authorCaoimhe <caoimhebyrne06@gmail.com>2023-05-11 12:25:52 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-05-14 15:56:49 -0600
commit465fa3460f7cdbfb1fbd38267e29b2190c068e71 (patch)
treef0ff75000ecf6e7feae80802cbe5de2cb10265a3 /Userland/Libraries/LibVideo/Containers
parent69396d4c4d6aab71fde06a261ba8fab92a884b5f (diff)
downloadserenity-465fa3460f7cdbfb1fbd38267e29b2190c068e71.zip
LibVideo: Add `PlaybackManager::from_mapped_file`
This allows us to create a PlaybackManager from a file which has already been mapped, instead of passing a file name. This means that anyone who uses `PlaybackManager` can now use LibFSAC :)
Diffstat (limited to 'Userland/Libraries/LibVideo/Containers')
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.cpp5
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/MatroskaDemuxer.h2
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Reader.cpp7
-rw-r--r--Userland/Libraries/LibVideo/Containers/Matroska/Reader.h2
4 files changed, 15 insertions, 1 deletions
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<NonnullOwnPtr<MatroskaDemuxer>> MatroskaDemuxer::from_file(String
return make<MatroskaDemuxer>(TRY(Reader::from_file(filename)));
}
+DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> MatroskaDemuxer::from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file)
+{
+ return make<MatroskaDemuxer>(TRY(Reader::from_mapped_file(move(mapped_file))));
+}
+
DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> MatroskaDemuxer::from_data(ReadonlyBytes data)
{
return make<MatroskaDemuxer>(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<NonnullOwnPtr<MatroskaDemuxer>> from_file(StringView filename);
+ static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file);
+
static DecoderErrorOr<NonnullOwnPtr<MatroskaDemuxer>> 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> Reader::from_file(StringView path)
{
auto mapped_file = DECODER_TRY(DecoderErrorCategory::IO, Core::MappedFile::map(path));
+ return from_mapped_file(mapped_file);
+}
+
+DecoderErrorOr<Reader> Reader::from_mapped_file(NonnullRefPtr<Core::MappedFile> 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<DecoderErrorOr<IterationDecision>(TrackEntry const&)> TrackEntryCallback;
static DecoderErrorOr<Reader> from_file(StringView path);
+ static DecoderErrorOr<Reader> from_mapped_file(NonnullRefPtr<Core::MappedFile> mapped_file);
+
static DecoderErrorOr<Reader> from_data(ReadonlyBytes data);
EBMLHeader const& header() const { return m_header.value(); }