diff options
author | Magnus Holmgren <magnushol@gmail.com> | 2006-01-08 08:58:58 +0000 |
---|---|---|
committer | Magnus Holmgren <magnushol@gmail.com> | 2006-01-08 08:58:58 +0000 |
commit | e8b1787296dae2a69893bd0fe97b2361fb6180ba (patch) | |
tree | 5fb1ab112c52a240c577c9d0570c88efbc36e6fb /firmware | |
parent | c78b019944a1e79116855355a10f120be52668ff (diff) |
Discard some LAME header fields if the file length has changed since the header was written. Fixes some NPR podcasts.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8307 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/id3.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/firmware/id3.c b/firmware/id3.c index 89864a659b..a2b6521b67 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -882,6 +882,32 @@ static int getsonglength(int fd, struct mp3entry *entry) bytecount += entry->id3v2len; + /* Validate byte count, in case the file has been edited without + * updating the header. + */ + if (info.byte_count) + { + const unsigned long expected = entry->filesize - entry->id3v1len + - entry->id3v2len; + const unsigned long diff = MAX(10240, info.byte_count / 20); + + if ((info.byte_count > expected + diff) + || (info.byte_count < expected - diff)) + { + DEBUGF("Note: info.byte_count differs from expected value by " + "%d bytes\n", labs((long) (expected - info.byte_count))); + info.byte_count = 0; + info.frame_count = 0; + info.file_time = 0; + info.enc_padding = 0; + + /* Even if the bitrate was based on "known bad" values, it + * should still be better for VBR files than using the bitrate + * of the first audio frame. + */ + } + } + entry->bitrate = info.bitrate; entry->frequency = info.frequency; entry->version = info.version; |