mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibAudio: Extract MP3 synchronize to static helper function
This comes in handy when we want to sniff an MP3 file with a stream outside of the loader.
This commit is contained in:
parent
aec3d9d84e
commit
dfd48ab643
2 changed files with 11 additions and 5 deletions
|
@ -188,21 +188,26 @@ ErrorOr<MP3::Header, LoaderError> MP3LoaderPlugin::read_header()
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeLoaderError MP3LoaderPlugin::synchronize()
|
MaybeLoaderError MP3LoaderPlugin::synchronize(BigEndianInputBitStream& stream, size_t sample_index)
|
||||||
{
|
{
|
||||||
size_t one_counter = 0;
|
size_t one_counter = 0;
|
||||||
while (one_counter < 12 && !m_bitstream->is_eof()) {
|
while (one_counter < 12 && !stream.is_eof()) {
|
||||||
bool const bit = LOADER_TRY(m_bitstream->read_bit());
|
bool const bit = LOADER_TRY(stream.read_bit());
|
||||||
one_counter = bit ? one_counter + 1 : 0;
|
one_counter = bit ? one_counter + 1 : 0;
|
||||||
if (!bit) {
|
if (!bit) {
|
||||||
m_bitstream->align_to_byte_boundary();
|
stream.align_to_byte_boundary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (one_counter != 12)
|
if (one_counter != 12)
|
||||||
return LoaderError { LoaderError::Category::Format, m_loaded_samples, "Failed to synchronize." };
|
return LoaderError { LoaderError::Category::Format, sample_index, "Failed to synchronize." };
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MaybeLoaderError MP3LoaderPlugin::synchronize()
|
||||||
|
{
|
||||||
|
return MP3LoaderPlugin::synchronize(*m_bitstream, m_loaded_samples);
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_next_frame()
|
ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_next_frame()
|
||||||
{
|
{
|
||||||
// Note: This will spin until we find a correct frame, or we reach eof.
|
// Note: This will spin until we find a correct frame, or we reach eof.
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MaybeLoaderError initialize();
|
MaybeLoaderError initialize();
|
||||||
|
static MaybeLoaderError synchronize(BigEndianInputBitStream& stream, size_t sample_index);
|
||||||
MaybeLoaderError synchronize();
|
MaybeLoaderError synchronize();
|
||||||
MaybeLoaderError build_seek_table();
|
MaybeLoaderError build_seek_table();
|
||||||
ErrorOr<MP3::Header, LoaderError> read_header();
|
ErrorOr<MP3::Header, LoaderError> read_header();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue