diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2022-10-13 16:05:57 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-14 23:11:23 +0200 |
commit | c837a1a8de492f42d5b5fd0e4b61da4681328ccf (patch) | |
tree | 4ed84c69ea49da1842a24ed43b08eef0b3248880 /Userland/Libraries/LibAudio/Loader.cpp | |
parent | 754b129f4a4428ed9a3bb378c2a23f9e6e731ff6 (diff) | |
download | serenity-c837a1a8de492f42d5b5fd0e4b61da4681328ccf.zip |
LibAudio: Factorize stream initialisation to base class `LoaderPlugin`
All actual plugins follow the same logic to initialize their stream,
this commit factorizes all of this to their base class: `LoaderPlugin`.
Diffstat (limited to 'Userland/Libraries/LibAudio/Loader.cpp')
-rw-r--r-- | Userland/Libraries/LibAudio/Loader.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibAudio/Loader.cpp b/Userland/Libraries/LibAudio/Loader.cpp index f98212f0ab..163d48e20e 100644 --- a/Userland/Libraries/LibAudio/Loader.cpp +++ b/Userland/Libraries/LibAudio/Loader.cpp @@ -11,6 +11,26 @@ namespace Audio { +LoaderPlugin::LoaderPlugin(StringView path) + : m_path(path) +{ +} + +LoaderPlugin::LoaderPlugin(Bytes buffer) + : m_backing_memory(buffer) +{ +} + +MaybeLoaderError LoaderPlugin::initialize() +{ + if (m_backing_memory.has_value()) + m_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(m_backing_memory.value())); + else + m_stream = LOADER_TRY(Core::Stream::File::open(m_path, Core::Stream::OpenMode::Read)); + + return {}; +} + Loader::Loader(NonnullOwnPtr<LoaderPlugin> plugin) : m_plugin(move(plugin)) { |