mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:07:45 +00:00
FlacLoader: Parse SEEKTABLE header
Populates m_seektable attribute with FlacSeekPoints. For more information see: https://datatracker.ietf.org/doc/html/draft-ietf-cellar-flac#section-11.13 Co-authored-by: kleines Filmröllchen <filmroellchen@serenityos.org>
This commit is contained in:
parent
d7c7e6e496
commit
346696ffbb
3 changed files with 32 additions and 2 deletions
|
@ -118,13 +118,20 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
|
|||
md5_checksum.bytes().copy_to({ m_md5_checksum, sizeof(m_md5_checksum) });
|
||||
|
||||
// Parse other blocks
|
||||
// TODO: For a simple first implementation, all other blocks are skipped as allowed by the FLAC specification.
|
||||
// Especially the SEEKTABLE block may become useful in a more sophisticated version.
|
||||
[[maybe_unused]] u16 meta_blocks_parsed = 1;
|
||||
[[maybe_unused]] u16 total_meta_blocks = meta_blocks_parsed;
|
||||
FlacRawMetadataBlock block = streaminfo;
|
||||
while (!block.is_last_block) {
|
||||
block = TRY(next_meta_block(*bit_input));
|
||||
switch (block.type) {
|
||||
case (FlacMetadataBlockType::SEEKTABLE):
|
||||
TRY(load_seektable(block));
|
||||
break;
|
||||
default:
|
||||
// TODO: Parse the remaining metadata block types.
|
||||
// Currently only STREAMINFO and SEEKTABLE are handled.
|
||||
break;
|
||||
}
|
||||
++total_meta_blocks;
|
||||
}
|
||||
|
||||
|
@ -133,6 +140,21 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
|
|||
return {};
|
||||
}
|
||||
|
||||
MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block)
|
||||
{
|
||||
auto memory_stream = LOADER_TRY(Core::Stream::MemoryStream::construct(block.data.bytes()));
|
||||
auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(*memory_stream));
|
||||
for (size_t i = 0; i < block.length / 18; ++i) {
|
||||
FlacSeekPoint seekpoint {
|
||||
.sample_index = LOADER_TRY(seektable_bytes->read_bits<u64>(64)),
|
||||
.byte_offset = LOADER_TRY(seektable_bytes->read_bits<u64>(64)),
|
||||
.num_samples = LOADER_TRY(seektable_bytes->read_bits<u16>(16))
|
||||
};
|
||||
m_seektable.append(seekpoint);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<FlacRawMetadataBlock, LoaderError> FlacLoaderPlugin::next_meta_block(BigEndianInputBitStream& bit_input)
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue