diff options
Diffstat (limited to 'firmware/id3.c')
-rw-r--r-- | firmware/id3.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/firmware/id3.c b/firmware/id3.c index 1b6a6920ae..b101aee407 100644 --- a/firmware/id3.c +++ b/firmware/id3.c | |||
@@ -40,9 +40,9 @@ | |||
40 | #define BYTE2(x) ((x >> 8) & 0xFF) | 40 | #define BYTE2(x) ((x >> 8) & 0xFF) |
41 | #define BYTE3(x) ((x >> 0) & 0xFF) | 41 | #define BYTE3(x) ((x >> 0) & 0xFF) |
42 | 42 | ||
43 | #define UNSYNC(b1,b2,b3,b4) (((b1 & 0x7F) << (3*7)) + \ | 43 | #define UNSYNC(b1,b2,b3,b4) (((b1 & 0x7F) << (3*7)) | \ |
44 | ((b2 & 0x7F) << (2*7)) + \ | 44 | ((b2 & 0x7F) << (2*7)) | \ |
45 | ((b3 & 0x7F) << (1*7)) + \ | 45 | ((b3 & 0x7F) << (1*7)) | \ |
46 | ((b4 & 0x7F) << (0*7))) | 46 | ((b4 & 0x7F) << (0*7))) |
47 | 47 | ||
48 | #define HASID3V2(entry) entry->id3v2len > 0 | 48 | #define HASID3V2(entry) entry->id3v2len > 0 |
@@ -92,7 +92,7 @@ stripspaces(char *buffer) | |||
92 | int i = 0; | 92 | int i = 0; |
93 | while(*(buffer + i) != '\0') | 93 | while(*(buffer + i) != '\0') |
94 | i++; | 94 | i++; |
95 | 95 | ||
96 | for(;i >= 0; i--) { | 96 | for(;i >= 0; i--) { |
97 | if(*(buffer + i) == ' ') | 97 | if(*(buffer + i) == ' ') |
98 | *(buffer + i) = '\0'; | 98 | *(buffer + i) = '\0'; |
@@ -111,8 +111,7 @@ stripspaces(char *buffer) | |||
111 | * | 111 | * |
112 | * Returns: true if a title was found and created, else false | 112 | * Returns: true if a title was found and created, else false |
113 | */ | 113 | */ |
114 | static bool | 114 | static bool setid3v1title(int fd, struct mp3entry *entry) |
115 | setid3v1title(int fd, struct mp3entry *entry) | ||
116 | { | 115 | { |
117 | char buffer[31]; | 116 | char buffer[31]; |
118 | int offsets[3] = {-95,-65,-125}; | 117 | int offsets[3] = {-95,-65,-125}; |
@@ -156,8 +155,7 @@ setid3v1title(int fd, struct mp3entry *entry) | |||
156 | * | 155 | * |
157 | * Returns: true if a title was found and created, else false | 156 | * Returns: true if a title was found and created, else false |
158 | */ | 157 | */ |
159 | static void | 158 | static void setid3v2title(int fd, struct mp3entry *entry) |
160 | setid3v2title(int fd, struct mp3entry *entry) | ||
161 | { | 159 | { |
162 | unsigned int minframesize; | 160 | unsigned int minframesize; |
163 | int size; | 161 | int size; |
@@ -292,8 +290,7 @@ setid3v2title(int fd, struct mp3entry *entry) | |||
292 | * | 290 | * |
293 | * Returns: the size of the tag or 0 if none was found | 291 | * Returns: the size of the tag or 0 if none was found |
294 | */ | 292 | */ |
295 | static int | 293 | static int getid3v2len(int fd) |
296 | getid3v2len(int fd) | ||
297 | { | 294 | { |
298 | char buf[6]; | 295 | char buf[6]; |
299 | int offset; | 296 | int offset; |
@@ -303,17 +300,17 @@ getid3v2len(int fd) | |||
303 | (read(fd, buf, 6) != 6) || | 300 | (read(fd, buf, 6) != 6) || |
304 | (strncmp(buf, "ID3", strlen("ID3")) != 0)) | 301 | (strncmp(buf, "ID3", strlen("ID3")) != 0)) |
305 | offset = 0; | 302 | offset = 0; |
303 | |||
306 | /* Now check what the ID3v2 size field says */ | 304 | /* Now check what the ID3v2 size field says */ |
307 | else if(read(fd, buf, 4) != 4) | 305 | else if(read(fd, buf, 4) != 4) |
308 | offset = 0; | 306 | offset = 0; |
309 | else | 307 | else |
310 | offset = UNSYNC(buf[0], buf[1], buf[2], buf[3]) + 10; | 308 | offset = UNSYNC(buf[0], buf[1], buf[2], buf[3]) + 10; |
311 | 309 | ||
312 | return offset; | 310 | return offset; |
313 | } | 311 | } |
314 | 312 | ||
315 | static int | 313 | static int getfilesize(int fd) |
316 | getfilesize(int fd) | ||
317 | { | 314 | { |
318 | int size; | 315 | int size; |
319 | 316 | ||
@@ -332,8 +329,7 @@ getfilesize(int fd) | |||
332 | * | 329 | * |
333 | * Returns: the size of the tag or 0 if none was found | 330 | * Returns: the size of the tag or 0 if none was found |
334 | */ | 331 | */ |
335 | static int | 332 | static int getid3v1len(int fd) |
336 | getid3v1len(int fd) | ||
337 | { | 333 | { |
338 | char buf[3]; | 334 | char buf[3]; |
339 | int offset; | 335 | int offset; |
@@ -363,8 +359,7 @@ getid3v1len(int fd) | |||
363 | * Returns: the song length in milliseconds, | 359 | * Returns: the song length in milliseconds, |
364 | * -1 means that it couldn't be calculated | 360 | * -1 means that it couldn't be calculated |
365 | */ | 361 | */ |
366 | static int | 362 | static int getsonglength(int fd, struct mp3entry *entry) |
367 | getsonglength(int fd, struct mp3entry *entry) | ||
368 | { | 363 | { |
369 | unsigned int filetime = 0; | 364 | unsigned int filetime = 0; |
370 | unsigned long header=0; | 365 | unsigned long header=0; |
@@ -530,8 +525,7 @@ getsonglength(int fd, struct mp3entry *entry) | |||
530 | * | 525 | * |
531 | * Returns: void | 526 | * Returns: void |
532 | */ | 527 | */ |
533 | bool | 528 | bool mp3info(struct mp3entry *entry, char *filename) |
534 | mp3info(struct mp3entry *entry, char *filename) | ||
535 | { | 529 | { |
536 | int fd; | 530 | int fd; |
537 | fd = open(filename, O_RDONLY); | 531 | fd = open(filename, O_RDONLY); |
@@ -547,6 +541,10 @@ mp3info(struct mp3entry *entry, char *filename) | |||
547 | entry->id3v2len = getid3v2len(fd); | 541 | entry->id3v2len = getid3v2len(fd); |
548 | entry->tracknum = 0; | 542 | entry->tracknum = 0; |
549 | 543 | ||
544 | /* Ignore the tag if it is too big */ | ||
545 | if(entry->id3v2len > sizeof(entry->id3v2buf)) | ||
546 | entry->id3v2len = 0; | ||
547 | |||
550 | if(HASID3V2(entry)) | 548 | if(HASID3V2(entry)) |
551 | setid3v2title(fd, entry); | 549 | setid3v2title(fd, entry); |
552 | entry->length = getsonglength(fd, entry); | 550 | entry->length = getsonglength(fd, entry); |