1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:17:46 +00:00

LibAudio: Switch LoaderPlugin to a more traditional constructor pattern

This now prepares all the needed (fallible) components before actually
constructing a LoaderPlugin object, so we are no longer filling them in
at an arbitrary later point in time.
This commit is contained in:
Tim Schumacher 2022-12-05 00:41:23 +01:00 committed by Andreas Kling
parent 3cf93d0dd2
commit c57be0f474
12 changed files with 132 additions and 86 deletions

View file

@ -25,20 +25,33 @@
namespace Audio {
FlacLoaderPlugin::FlacLoaderPlugin(StringView path)
: LoaderPlugin(path)
FlacLoaderPlugin::FlacLoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream)
: LoaderPlugin(move(stream))
{
}
FlacLoaderPlugin::FlacLoaderPlugin(Bytes buffer)
: LoaderPlugin(buffer)
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::try_create(StringView path)
{
auto stream = LOADER_TRY(Core::Stream::BufferedFile::create(LOADER_TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read))));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
return loader;
}
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::try_create(Bytes buffer)
{
auto stream = LOADER_TRY(Core::Stream::MemoryStream::construct(buffer));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
return loader;
}
MaybeLoaderError FlacLoaderPlugin::initialize()
{
LOADER_TRY(LoaderPlugin::initialize());
TRY(parse_header());
TRY(reset());
return {};