diff options
author | Andreas Huber <andih@google.com> | 2009-10-12 15:48:51 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2009-10-12 16:04:30 -0700 |
commit | 0bf3921522461b1c7d321d0c667c1020ab3110bc (patch) | |
tree | fff4e450f8842c033b2f002d990acd0129b876ad /media/libstagefright/MP3Extractor.cpp | |
parent | 48c948b1137e7bbdb161b51908657ab72ac5e2da (diff) | |
download | frameworks_av-0bf3921522461b1c7d321d0c667c1020ab3110bc.zip frameworks_av-0bf3921522461b1c7d321d0c667c1020ab3110bc.tar.gz frameworks_av-0bf3921522461b1c7d321d0c667c1020ab3110bc.tar.bz2 |
Proper chunk size computation for Layer II/III V2 and V2.5, skip optional ID3 tag.
related-to-bug: 1986192
Diffstat (limited to 'media/libstagefright/MP3Extractor.cpp')
-rw-r--r-- | media/libstagefright/MP3Extractor.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp index ad53cc7..b7dd9ba 100644 --- a/media/libstagefright/MP3Extractor.cpp +++ b/media/libstagefright/MP3Extractor.cpp @@ -147,7 +147,12 @@ static bool get_mp3_frame_size( *out_bitrate = bitrate; } - *frame_size = 144000 * bitrate / sampling_rate + padding; + if (version == 3 /* V1 */) { + *frame_size = 144000 * bitrate / sampling_rate + padding; + } else { + // V2 or V2.5 + *frame_size = 72000 * bitrate / sampling_rate + padding; + } } if (out_sampling_rate) { @@ -166,6 +171,33 @@ static bool get_mp3_frame_size( static bool Resync( const sp<DataSource> &source, uint32_t match_header, off_t *inout_pos, uint32_t *out_header) { + if (*inout_pos == 0) { + // Skip an optional ID3 header if syncing at the very beginning + // of the datasource. + + uint8_t id3header[10]; + if (source->read_at(0, id3header, sizeof(id3header)) + < (ssize_t)sizeof(id3header)) { + // If we can't even read these 10 bytes, we might as well bail out, + // even if there _were_ 10 bytes of valid mp3 audio data... + return false; + } + + if (id3header[0] == 'I' && id3header[1] == 'D' && id3header[2] == '3') { + // Skip the ID3v2 header. + + size_t len = + ((id3header[6] & 0x7f) << 21) + | ((id3header[7] & 0x7f) << 14) + | ((id3header[8] & 0x7f) << 7) + | (id3header[9] & 0x7f); + + len += 10; + + *inout_pos += len; + } + } + // Everything must match except for // protection, bitrate, padding, private bits and mode extension. const uint32_t kMask = 0xfffe0ccf; |