mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 02:59:45 +00:00
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`.
This commit is contained in:
parent
754b129f4a
commit
c837a1a8de
Notes:
sideshowbarker
2024-07-17 05:47:13 +09:00
Author: https://github.com/LucasChollet
Commit: c837a1a8de
Pull-request: https://github.com/SerenityOS/serenity/pull/15568
Reviewed-by: https://github.com/linusg ✅
Reviewed-by: https://github.com/sin-ack ✅
10 changed files with 42 additions and 31 deletions
|
@ -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))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue