diff options
author | Magnus Holmgren <magnushol@gmail.com> | 2006-10-29 22:18:30 +0000 |
---|---|---|
committer | Magnus Holmgren <magnushol@gmail.com> | 2006-10-29 22:18:30 +0000 |
commit | 83abf50a83c1a6c2ba0f69cbdfd1668a7a1cc602 (patch) | |
tree | a9a0d9570f3be354a49470a32963cdabae8532dd | |
parent | 28918164891e7870f38994e6e053d52d1a39048e (diff) |
Moved the Ogg zero-length check to a better place. Also fixed so that really short files (< 1s) doesn't trigger the same problem. Applied the fixes on most other susceptible formats.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11387 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/metadata.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/apps/metadata.c b/apps/metadata.c index a4d8ef0f64..ee0100ecf7 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -760,13 +760,14 @@ static bool get_vorbis_metadata(int fd, struct mp3entry* id3) return false; } + id3->length = ((int64_t) id3->samples * 1000) / id3->frequency; + if (id3->length <= 0) { logf("ogg length invalid!"); return false; } - id3->length = (id3->samples / id3->frequency) * 1000; id3->bitrate = (((int64_t) id3->filesize - comment_size) * 8) / id3->length; id3->vbr = true; @@ -829,7 +830,14 @@ static bool get_flac_metadata(int fd, struct mp3entry* id3) | (buf[16] << 8) | buf[17]; /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ - id3->length = (totalsamples / id3->frequency) * 1000; + id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; + + if (id3->length <= 0) + { + logf("flac length invalid!"); + return false; + } + id3->bitrate = (id3->filesize * 8) / id3->length; } else if ((buf[0] & 0x7f) == 4) /* 4 is the VORBIS_COMMENT block */ @@ -957,7 +965,7 @@ static bool get_wave_metadata(int fd, struct mp3entry* id3) id3->filesize = filesize(fd); /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ - id3->length = (totalsamples / id3->frequency) * 1000; + id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; return true; } @@ -1329,7 +1337,14 @@ static bool get_mp4_metadata(int fd, struct mp3entry* id3) return false; } - id3->length = (id3->samples / id3->frequency) * 1000; + id3->length = ((int64_t) id3->samples * 1000) / id3->frequency; + + if (id3->length <= 0) + { + logf("mp4 length invalid!"); + return false; + } + id3->bitrate = ((int64_t) id3->filesize * 8) / id3->length; DEBUGF("MP4 bitrate %d, frequency %d Hz, length %d ms\n", id3->bitrate, id3->frequency, id3->length); @@ -1421,9 +1436,16 @@ static bool get_musepack_metadata(int fd, struct mp3entry *id3) id3->vbr = true; /* Estimate bitrate, we should probably subtract the various header sizes here for super-accurate results */ - id3->length = samples/id3->frequency*1000; + id3->length = ((int64_t) samples * 1000) / id3->frequency; + + if (id3->length <= 0) + { + logf("mpc length invalid!"); + return false; + } + id3->filesize = filesize(fd); - id3->bitrate = id3->filesize*8/id3->length; + id3->bitrate = id3->filesize * 8 / id3->length; return true; } @@ -1629,7 +1651,8 @@ static bool get_aiff_metadata(int fd, struct mp3entry* id3) /* save format infos */ id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; id3->frequency = sampleRate; - id3->length = (numSampleFrames / id3->frequency) * 1000; + id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency; + id3->vbr = false; /* AIFF files are CBR */ id3->filesize = filesize(fd); } |