ladybird/Userland/Libraries/LibAudio/Loader.cpp

71 lines
1.7 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2018-2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibAudio/FlacLoader.h>
2021-11-27 17:00:19 +01:00
#include <LibAudio/Loader.h>
#include <LibAudio/MP3Loader.h>
#include <LibAudio/WavLoader.h>
namespace Audio {
LoaderPlugin::LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream)
: m_stream(move(stream))
{
}
2021-11-27 17:00:19 +01:00
Loader::Loader(NonnullOwnPtr<LoaderPlugin> plugin)
: m_plugin(move(plugin))
{
}
2021-11-27 17:00:19 +01:00
Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(StringView path)
{
{
auto plugin = WavLoaderPlugin::create(path);
if (!plugin.is_error())
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
}
2021-11-27 17:00:19 +01:00
{
auto plugin = FlacLoaderPlugin::create(path);
if (!plugin.is_error())
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
}
2021-11-27 17:00:19 +01:00
{
auto plugin = MP3LoaderPlugin::create(path);
if (!plugin.is_error())
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
}
2021-11-27 17:00:19 +01:00
return LoaderError { "No loader plugin available" };
}
Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(Bytes buffer)
2021-11-27 17:00:19 +01:00
{
{
auto plugin = WavLoaderPlugin::create(buffer);
if (!plugin.is_error())
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
}
{
auto plugin = FlacLoaderPlugin::create(buffer);
if (!plugin.is_error())
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
}
{
auto plugin = MP3LoaderPlugin::create(buffer);
if (!plugin.is_error())
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
}
2021-11-27 17:00:19 +01:00
return LoaderError { "No loader plugin available" };
}
}