diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2002-07-22 16:05:46 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2002-07-22 16:05:46 +0000 |
commit | 4e69f82c8f0feb124710ac1f6ce44040cb1acc2c (patch) | |
tree | 52e234d7ba34665a9884b46f252194444a48c3e8 /firmware/id3.c | |
parent | 6f75d1739fa6e1f76753a62e4417761df812c072 (diff) |
Now continues searching for good frames if a bad one is found. Patch by Hardeep Sidhu
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1398 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/id3.c')
-rw-r--r-- | firmware/id3.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/firmware/id3.c b/firmware/id3.c index 16a155dd44..021b817704 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -396,6 +396,7 @@ static int getsonglength(int fd, struct mp3entry *entry) int freqindex; int frequency; int chmode; + int bytecount; long bpf; long tpf; @@ -413,12 +414,18 @@ static int getsonglength(int fd, struct mp3entry *entry) } /* Loop trough file until we find a frame header */ + bytecount = 0; restart: do { header <<= 8; if(!read(fd, &tmp, 1)) return -1; header |= tmp; + + /* Quit if we haven't found a valid header within 128K */ + bytecount++; + if(bytecount > 0x20000) + return -1; } while(!mp3frameheader(header)); /* @@ -444,7 +451,7 @@ static int getsonglength(int fd, struct mp3entry *entry) version = 1; break; default: - return -1; + goto restart; } /* Layer */ @@ -459,20 +466,20 @@ static int getsonglength(int fd, struct mp3entry *entry) layer = 1; break; default: - return -1; + goto restart; } /* Bitrate */ bitindex = (header & 0xF000) >> 12; bitrate = bitrate_table[version-1][layer-1][bitindex]; if(bitrate == 0) - return -1; + goto restart; /* Sampling frequency */ freqindex = (header & 0x0C00) >> 10; frequency = freqtab[version-1][freqindex]; if(frequency == 0) - return -1; + goto restart; #ifdef DEBUG_VERBOSE DEBUGF( "Version %i, lay %i, biti %i, bitr %i, freqi %i, freq %i, chmode %d\n", @@ -500,7 +507,7 @@ static int getsonglength(int fd, struct mp3entry *entry) } /* Calculate time per frame */ - tpf = bs[layer] / freqtab[version-1][freqindex] << (version - 1); + tpf = bs[layer] / (freqtab[version-1][freqindex] << (version - 1)); /* OK, we have found a frame. Let's see if it has a Xing header */ if(read(fd, frame, sizeof frame) < 0) |