mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +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:
parent
3cf93d0dd2
commit
c57be0f474
Notes:
sideshowbarker
2024-07-17 03:43:33 +09:00
Author: https://github.com/timschumi
Commit: c57be0f474
Pull-request: https://github.com/SerenityOS/serenity/pull/16316
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
12 changed files with 132 additions and 86 deletions
|
@ -14,20 +14,33 @@ namespace Audio {
|
|||
DSP::MDCT<12> MP3LoaderPlugin::s_mdct_12;
|
||||
DSP::MDCT<36> MP3LoaderPlugin::s_mdct_36;
|
||||
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(StringView path)
|
||||
: LoaderPlugin(path)
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream)
|
||||
: LoaderPlugin(move(stream))
|
||||
{
|
||||
}
|
||||
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(Bytes buffer)
|
||||
: LoaderPlugin(buffer)
|
||||
Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::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<MP3LoaderPlugin>(move(stream));
|
||||
|
||||
LOADER_TRY(loader->initialize());
|
||||
|
||||
return loader;
|
||||
}
|
||||
|
||||
Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::try_create(Bytes buffer)
|
||||
{
|
||||
auto stream = LOADER_TRY(Core::Stream::MemoryStream::construct(buffer));
|
||||
auto loader = make<MP3LoaderPlugin>(move(stream));
|
||||
|
||||
LOADER_TRY(loader->initialize());
|
||||
|
||||
return loader;
|
||||
}
|
||||
|
||||
MaybeLoaderError MP3LoaderPlugin::initialize()
|
||||
{
|
||||
LOADER_TRY(LoaderPlugin::initialize());
|
||||
|
||||
m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(*m_stream));
|
||||
|
||||
TRY(synchronize());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue