1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27: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:
Lucas CHOLLET 2022-10-13 16:05:57 +02:00 committed by Linus Groh
parent 754b129f4a
commit c837a1a8de
10 changed files with 42 additions and 31 deletions

View file

@ -18,6 +18,7 @@
#include <LibAudio/LoaderError.h>
#include <LibAudio/Sample.h>
#include <LibAudio/SampleFormats.h>
#include <LibCore/Stream.h>
namespace Audio {
@ -28,6 +29,8 @@ using MaybeLoaderError = Result<void, LoaderError>;
class LoaderPlugin {
public:
explicit LoaderPlugin(StringView path);
explicit LoaderPlugin(Bytes buffer);
virtual ~LoaderPlugin() = default;
virtual MaybeLoaderError initialize() = 0;
@ -53,6 +56,12 @@ public:
// Human-readable name of the file format, of the form <full abbreviation> (.<ending>)
virtual String format_name() = 0;
virtual PcmSampleFormat pcm_format() = 0;
protected:
StringView m_path;
OwnPtr<Core::Stream::SeekableStream> m_stream;
// The constructor might set this so that we can initialize the data stream later.
Optional<Bytes> m_backing_memory;
};
class Loader : public RefCounted<Loader> {