mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 12:47:34 +00:00
LibAudio: Allow the MP3 plugin to be constructed from a byte buffer
This commit is contained in:
parent
bb17ee8397
commit
754b129f4a
3 changed files with 14 additions and 2 deletions
|
@ -42,6 +42,9 @@ Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(Bytes& buffe
|
|||
if (auto initstate = plugin->initialize(); !initstate.is_error())
|
||||
return plugin;
|
||||
plugin = adopt_own(*new FlacLoaderPlugin(buffer));
|
||||
if (auto initstate = plugin->initialize(); !initstate.is_error())
|
||||
return plugin;
|
||||
plugin = adopt_own(*new MP3LoaderPlugin(buffer));
|
||||
if (auto initstate = plugin->initialize(); !initstate.is_error())
|
||||
return plugin;
|
||||
return LoaderError { "No loader plugin available" };
|
||||
|
|
|
@ -15,13 +15,19 @@ DSP::MDCT<12> MP3LoaderPlugin::s_mdct_12;
|
|||
DSP::MDCT<36> MP3LoaderPlugin::s_mdct_36;
|
||||
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(StringView path)
|
||||
: m_path(path)
|
||||
: LoaderPlugin(path)
|
||||
{
|
||||
}
|
||||
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(Bytes buffer)
|
||||
: m_backing_memory(buffer)
|
||||
{
|
||||
}
|
||||
|
||||
MaybeLoaderError MP3LoaderPlugin::initialize()
|
||||
{
|
||||
m_stream = LOADER_TRY(Core::Stream::File::open(m_path, Core::Stream::OpenMode::Read));
|
||||
LOADER_TRY(LoaderPlugin::initialize());
|
||||
|
||||
m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(*m_stream));
|
||||
|
||||
TRY(synchronize());
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <AK/MemoryStream.h>
|
||||
#include <AK/Tuple.h>
|
||||
#include <LibCore/InputBitStream.h>
|
||||
#include <LibCore/MemoryStream.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibDSP/MDCT.h>
|
||||
|
||||
|
@ -23,6 +24,7 @@ struct ScaleFactorBand;
|
|||
class MP3LoaderPlugin : public LoaderPlugin {
|
||||
public:
|
||||
explicit MP3LoaderPlugin(StringView path);
|
||||
explicit MP3LoaderPlugin(Bytes buffer);
|
||||
virtual ~MP3LoaderPlugin() = default;
|
||||
|
||||
virtual MaybeLoaderError initialize() override;
|
||||
|
@ -72,6 +74,7 @@ private:
|
|||
u32 m_current_frame_read;
|
||||
StringView m_path;
|
||||
OwnPtr<Core::Stream::SeekableStream> m_stream;
|
||||
Optional<Bytes const&> m_backing_memory;
|
||||
OwnPtr<Core::Stream::BigEndianInputBitStream> m_bitstream;
|
||||
DuplexMemoryStream m_bit_reservoir;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue