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

LibAudio: Extract loader stream creation from the plugins

This removes a lot of duplicated stream creation code from the plugins,
and also simplifies the way that the appropriate plugin is found. This
mirrors the ImageDecoderPlugin design and necessitates new sniffing
methods on the loaders.
This commit is contained in:
kleines Filmröllchen 2023-06-24 17:04:38 +02:00 committed by Sam Atkins
parent dfd48ab643
commit 5f1dbbaaa6
15 changed files with 124 additions and 131 deletions

View file

@ -12,6 +12,7 @@
#include <AK/IntegralMath.h>
#include <AK/Math.h>
#include <AK/MemoryStream.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/ScopeGuard.h>
#include <AK/StdLibExtras.h>
#include <AK/Try.h>
@ -34,23 +35,10 @@ FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr<SeekableStream> stream)
{
}
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(StringView path)
ErrorOr<NonnullOwnPtr<LoaderPlugin>, LoaderError> FlacLoaderPlugin::create(NonnullOwnPtr<SeekableStream> stream)
{
auto stream = LOADER_TRY(Core::InputBufferedFile::create(LOADER_TRY(Core::File::open(path, Core::File::OpenMode::Read))));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
return loader;
}
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(Bytes buffer)
{
auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
TRY(loader->initialize());
return loader;
}
@ -61,6 +49,13 @@ MaybeLoaderError FlacLoaderPlugin::initialize()
return {};
}
bool FlacLoaderPlugin::sniff(SeekableStream& stream)
{
BigEndianInputBitStream bit_input { MaybeOwned<Stream>(stream) };
auto maybe_flac = bit_input.read_bits<u32>(32);
return !maybe_flac.is_error() && maybe_flac.value() == 0x664C6143; // "flaC"
}
// 11.5 STREAM
MaybeLoaderError FlacLoaderPlugin::parse_header()
{