1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +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

@ -24,22 +24,16 @@ QOALoaderPlugin::QOALoaderPlugin(NonnullOwnPtr<AK::SeekableStream> stream)
{
}
Result<NonnullOwnPtr<QOALoaderPlugin>, LoaderError> QOALoaderPlugin::create(StringView path)
bool QOALoaderPlugin::sniff(SeekableStream& stream)
{
auto stream = LOADER_TRY(Core::InputBufferedFile::create(LOADER_TRY(Core::File::open(path, Core::File::OpenMode::Read))));
auto loader = make<QOALoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
return loader;
auto maybe_qoa = stream.read_value<BigEndian<u32>>();
return !maybe_qoa.is_error() && maybe_qoa.value() == QOA::magic;
}
Result<NonnullOwnPtr<QOALoaderPlugin>, LoaderError> QOALoaderPlugin::create(Bytes buffer)
ErrorOr<NonnullOwnPtr<LoaderPlugin>, LoaderError> QOALoaderPlugin::create(NonnullOwnPtr<SeekableStream> stream)
{
auto loader = make<QOALoaderPlugin>(make<FixedMemoryStream>(buffer));
auto loader = make<QOALoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
return loader;
}