summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-07-18 15:21:45 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-07-18 15:21:45 +0000
commit60e7b20971ec10b5444fd43f32b88b91e40a3c22 (patch)
tree9c1ed205b862e7ecb5febef3e459b07deff24cb7
parentc7100372e1e683aab4418fbdec5d4968f1972fff (diff)
downloadrockbox-60e7b20971ec10b5444fd43f32b88b91e40a3c22.tar.gz
rockbox-60e7b20971ec10b5444fd43f32b88b91e40a3c22.zip
More detailed mp3 frame header check
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1383 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/id3.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/firmware/id3.c b/firmware/id3.c
index c2ae42e46d..16a155dd44 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -34,7 +34,6 @@
34#include "id3.h" 34#include "id3.h"
35 35
36/* Some utility macros used in getsonglength() */ 36/* Some utility macros used in getsonglength() */
37#define CHECKSYNC(x) (((x >> 21) & 0x07FF) == 0x7FF)
38#define BYTE0(x) ((x >> 24) & 0xFF) 37#define BYTE0(x) ((x >> 24) & 0xFF)
39#define BYTE1(x) ((x >> 16) & 0xFF) 38#define BYTE1(x) ((x >> 16) & 0xFF)
40#define BYTE2(x) ((x >> 8) & 0xFF) 39#define BYTE2(x) ((x >> 8) & 0xFF)
@@ -345,6 +344,29 @@ static int getid3v1len(int fd)
345 return offset; 344 return offset;
346} 345}
347 346
347/* check if 'head' is a valid mp3 frame header */
348static bool mp3frameheader(unsigned long head)
349{
350 if ((head & 0xffe00000) != 0xffe00000) /* bad sync? */
351 return false;
352 if (!((head >> 17) & 3)) /* no layer? */
353 return false;
354 if (((head >> 12) & 0xf) == 0xf) /* bad bitrate? */
355 return false;
356 if (!((head >> 12) & 0xf)) /* no bitrate? */
357 return false;
358 if (((head >> 10) & 0x3) == 0x3) /* bad sample rate? */
359 return false;
360 if (((head >> 19) & 1) == 1 &&
361 ((head >> 17) & 3) == 3 &&
362 ((head >> 16) & 1) == 1)
363 return false;
364 if ((head & 0xffff0000) == 0xfffe0000)
365 return false;
366
367 return true;
368}
369
348/* 370/*
349 * Calculates the length (in milliseconds) of an MP3 file. Currently this code 371 * Calculates the length (in milliseconds) of an MP3 file. Currently this code
350 * doesn't care about VBR (Variable BitRate) files since it would have to scan 372 * doesn't care about VBR (Variable BitRate) files since it would have to scan
@@ -397,7 +419,7 @@ static int getsonglength(int fd, struct mp3entry *entry)
397 if(!read(fd, &tmp, 1)) 419 if(!read(fd, &tmp, 1))
398 return -1; 420 return -1;
399 header |= tmp; 421 header |= tmp;
400 } while(!CHECKSYNC(header)); 422 } while(!mp3frameheader(header));
401 423
402 /* 424 /*
403 * Some files are filled with garbage in the beginning, 425 * Some files are filled with garbage in the beginning,