Handle optional frames field in bytes offset of MP3 header

custom
Tom Kirchner 4 months ago
parent 35f1246379
commit f8199bbd6d
  1. 14
      src/codecs/mad.cpp

@ -367,20 +367,26 @@ auto MadMp3Decoder::GetMp3Info(const mad_header& header)
uint32_t flags = ((uint32_t)flags_raw[0] << 24) +
((uint32_t)flags_raw[1] << 16) +
((uint32_t)flags_raw[2] << 8) + ((uint32_t)flags_raw[3]);
if (flags & 4) {
// TOC flag is set
auto toc_offset = 8;
auto bytes_offset = 8;
if (flags & 1) {
// Frames field is present
toc_offset += 4;
bytes_offset += 4;
}
if (flags & 2) {
// Bytes field is present
toc_offset += 4;
}
if (flags & 4) {
// TOC flag is set
if (flags & 2) {
// Bytes field
unsigned char const* bytes_raw = stream_->this_frame + xing_offset + 12;
unsigned char const* bytes_raw = stream_->this_frame + xing_offset + bytes_offset;
uint32_t num_bytes =
((uint32_t)bytes_raw[0] << 24) + ((uint32_t)bytes_raw[1] << 16) +
((uint32_t)bytes_raw[2] << 8) + ((uint32_t)bytes_raw[3]);
bytes.emplace(num_bytes);
toc_offset += 4;
}
// Read the table of contents in
toc.emplace((stream_->this_frame + xing_offset + toc_offset), 100);

Loading…
Cancel
Save