From 51fde20c1e5ad8ef31c874ab7990827e9fdfa9c3 Mon Sep 17 00:00:00 2001 From: beveloper Date: Sun, 9 Nov 2003 22:13:50 +0000 Subject: [PATCH] added info header parsing (to be able to skip it), fixed lyrics header parsing git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5295 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../plugins/mp3_reader/MP3ReaderPlugin.cpp | 30 +++++++++++++++++-- .../plugins/mp3_reader/MP3ReaderPlugin.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.cpp b/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.cpp index d7d78ad0bf..456f826707 100644 --- a/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.cpp +++ b/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.cpp @@ -295,6 +295,12 @@ mp3Reader::ParseFile() goto skip_header; } + hdr_length = GetInfoCbrLength(&buf[pos]); + if (hdr_length > 0) { + TRACE("mp3ReaderPlugin::ParseFile found a Info CBR header of %d bytes at position %Ld\n", hdr_length, offset + pos); + goto skip_header; + } + hdr_length = GetFraunhoferVbrLength(&buf[pos]); if (hdr_length > 0) { TRACE("mp3ReaderPlugin::ParseFile found a Fraunhofer VBR header of %d bytes at position %Ld\n", hdr_length, offset + pos); @@ -374,7 +380,7 @@ mp3Reader::ParseFile() continue; if (0 == memcmp(&buf[pos], "LYRICSBEGIN", 11)) { TRACE("mp3ReaderPlugin::ParseFile found a Lyrics header at position %Ld\n", offset + pos); - fDataSize = fDataStart - offset + pos; + fDataSize = offset + pos + fDataStart; } } @@ -398,7 +404,6 @@ mp3Reader::GetXingVbrLength(uint8 *header) else // mpeg2 xing_header = (h_mode != 3) ? (header + 21) : (header + 13); - // note: in CBR files, there is an 'Info' tag of the same format if (xing_header[0] != 'X') return -1; if (xing_header[1] != 'i') return -1; if (xing_header[2] != 'n') return -1; @@ -407,6 +412,27 @@ mp3Reader::GetXingVbrLength(uint8 *header) return GetFrameLength(header); } +int +mp3Reader::GetInfoCbrLength(uint8 *header) +{ + int h_id = (header[1] >> 3) & 1; + int h_mode = (header[3] >> 6) & 3; + uint8 *info_header; + + // determine offset of header + if(h_id) // mpeg1 + info_header = (h_mode != 3) ? (header + 36) : (header + 21); + else // mpeg2 + info_header = (h_mode != 3) ? (header + 21) : (header + 13); + + if (info_header[0] != 'I') return -1; + if (info_header[1] != 'n') return -1; + if (info_header[2] != 'f') return -1; + if (info_header[3] != 'o') return -1; + + return GetFrameLength(header); +} + int mp3Reader::GetLameVbrLength(uint8 *header) { diff --git a/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.h b/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.h index 57f018460e..d5adb6cf8a 100644 --- a/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.h +++ b/src/add-ons/media/plugins/mp3_reader/MP3ReaderPlugin.h @@ -43,6 +43,7 @@ private: int GetFraunhoferVbrLength(uint8 *header); int GetLameVbrLength(uint8 *header); int GetId3v2Length(uint8 *header); + int GetInfoCbrLength(uint8 *header); bool FindData();