mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
LibAudio: Remove the last occurrence of Core::File
in the Flac plugin
The design is deeply inspired from what is done in the Wav plugin.
This commit is contained in:
parent
f028930033
commit
597a614ce6
2 changed files with 8 additions and 20 deletions
|
@ -26,33 +26,21 @@
|
||||||
namespace Audio {
|
namespace Audio {
|
||||||
|
|
||||||
FlacLoaderPlugin::FlacLoaderPlugin(StringView path)
|
FlacLoaderPlugin::FlacLoaderPlugin(StringView path)
|
||||||
: m_file(Core::File::construct(path))
|
: m_path(path)
|
||||||
{
|
{
|
||||||
if (!m_file->open(Core::OpenMode::ReadOnly)) {
|
|
||||||
m_error = LoaderError { String::formatted("Can't open file: {}", m_file->error_string()) };
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto maybe_stream = Core::Stream::BufferedFile::create(MUST(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)), FLAC_BUFFER_SIZE);
|
|
||||||
if (maybe_stream.is_error())
|
|
||||||
m_error = LoaderError { "Can't open file stream" };
|
|
||||||
else
|
|
||||||
m_stream = maybe_stream.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FlacLoaderPlugin::FlacLoaderPlugin(Bytes& buffer)
|
FlacLoaderPlugin::FlacLoaderPlugin(Bytes& buffer)
|
||||||
|
: m_backing_memory(buffer)
|
||||||
{
|
{
|
||||||
auto maybe_stream = Core::Stream::MemoryStream::construct(buffer);
|
|
||||||
if (maybe_stream.is_error())
|
|
||||||
m_error = LoaderError { "Can't open memory stream" };
|
|
||||||
else
|
|
||||||
m_stream = maybe_stream.release_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeLoaderError FlacLoaderPlugin::initialize()
|
MaybeLoaderError FlacLoaderPlugin::initialize()
|
||||||
{
|
{
|
||||||
if (m_error.has_value())
|
if (m_backing_memory.has_value())
|
||||||
return m_error.release_value();
|
m_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(m_backing_memory.value()));
|
||||||
|
else
|
||||||
|
m_stream = LOADER_TRY(Core::Stream::File::open(m_path, Core::Stream::OpenMode::Read));
|
||||||
|
|
||||||
TRY(parse_header());
|
TRY(parse_header());
|
||||||
TRY(reset());
|
TRY(reset());
|
||||||
|
|
|
@ -95,8 +95,7 @@ private:
|
||||||
ALWAYS_INLINE ErrorOr<u32, LoaderError> convert_sample_rate_code(u8 sample_rate_code);
|
ALWAYS_INLINE ErrorOr<u32, LoaderError> convert_sample_rate_code(u8 sample_rate_code);
|
||||||
ALWAYS_INLINE ErrorOr<PcmSampleFormat, LoaderError> convert_bit_depth_code(u8 bit_depth_code);
|
ALWAYS_INLINE ErrorOr<PcmSampleFormat, LoaderError> convert_bit_depth_code(u8 bit_depth_code);
|
||||||
|
|
||||||
RefPtr<Core::File> m_file;
|
StringView m_path;
|
||||||
Optional<LoaderError> m_error {};
|
|
||||||
|
|
||||||
// Data obtained directly from the FLAC metadata: many values have specific bit counts
|
// Data obtained directly from the FLAC metadata: many values have specific bit counts
|
||||||
u32 m_sample_rate { 0 }; // 20 bit
|
u32 m_sample_rate { 0 }; // 20 bit
|
||||||
|
@ -115,6 +114,7 @@ private:
|
||||||
// keep track of the start of the data in the FLAC stream to seek back more easily
|
// keep track of the start of the data in the FLAC stream to seek back more easily
|
||||||
u64 m_data_start_location { 0 };
|
u64 m_data_start_location { 0 };
|
||||||
OwnPtr<Core::Stream::SeekableStream> m_stream;
|
OwnPtr<Core::Stream::SeekableStream> m_stream;
|
||||||
|
Optional<Bytes> m_backing_memory;
|
||||||
Optional<FlacFrameHeader> m_current_frame;
|
Optional<FlacFrameHeader> m_current_frame;
|
||||||
// Whatever the last get_more_samples() call couldn't return gets stored here.
|
// Whatever the last get_more_samples() call couldn't return gets stored here.
|
||||||
Vector<Sample, FLAC_BUFFER_SIZE> m_unread_data;
|
Vector<Sample, FLAC_BUFFER_SIZE> m_unread_data;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue