diff options
Diffstat (limited to 'lib/rbcodec/metadata/mp3data.c')
-rw-r--r-- | lib/rbcodec/metadata/mp3data.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/rbcodec/metadata/mp3data.c b/lib/rbcodec/metadata/mp3data.c index 8a134dd534..49f9786c29 100644 --- a/lib/rbcodec/metadata/mp3data.c +++ b/lib/rbcodec/metadata/mp3data.c | |||
@@ -39,6 +39,9 @@ | |||
39 | #include "mp3data.h" | 39 | #include "mp3data.h" |
40 | #include "platform.h" | 40 | #include "platform.h" |
41 | 41 | ||
42 | #include "metadata.h" | ||
43 | #include "metadata/metadata_parsers.h" | ||
44 | |||
42 | //#define DEBUG_VERBOSE | 45 | //#define DEBUG_VERBOSE |
43 | 46 | ||
44 | #ifdef DEBUG_VERBOSE | 47 | #ifdef DEBUG_VERBOSE |
@@ -340,7 +343,7 @@ static int buf_getbyte(int fd, unsigned char *c) | |||
340 | static int buf_seek(int fd, int len) | 343 | static int buf_seek(int fd, int len) |
341 | { | 344 | { |
342 | fnf_read_index += len; | 345 | fnf_read_index += len; |
343 | if(fnf_read_index > fnf_buf_len) | 346 | if(fnf_read_index >= fnf_buf_len) |
344 | { | 347 | { |
345 | len = fnf_read_index - fnf_buf_len; | 348 | len = fnf_read_index - fnf_buf_len; |
346 | 349 | ||
@@ -348,23 +351,22 @@ static int buf_seek(int fd, int len) | |||
348 | if(fnf_buf_len < 0) | 351 | if(fnf_buf_len < 0) |
349 | return -1; | 352 | return -1; |
350 | 353 | ||
351 | fnf_read_index = 0; | 354 | fnf_read_index = len; |
352 | fnf_read_index += len; | ||
353 | } | 355 | } |
354 | 356 | ||
355 | if(fnf_read_index > fnf_buf_len) | 357 | if(fnf_read_index >= fnf_buf_len) |
356 | { | 358 | { |
357 | return -1; | 359 | return -1; |
358 | } | 360 | } |
359 | else | 361 | |
360 | return 0; | 362 | return 0; |
361 | } | 363 | } |
362 | 364 | ||
363 | static void buf_init(unsigned char* buf, size_t buflen) | 365 | static void buf_init(unsigned char* buf, size_t buflen) |
364 | { | 366 | { |
365 | fnf_buf = buf; | 367 | fnf_buf = buf; |
366 | fnf_buf_len = buflen; | 368 | fnf_buf_len = buflen; |
367 | fnf_read_index = 0; | 369 | fnf_read_index = buflen; |
368 | } | 370 | } |
369 | 371 | ||
370 | static unsigned long buf_find_next_frame(int fd, long *offset, long max_offset) | 372 | static unsigned long buf_find_next_frame(int fd, long *offset, long max_offset) |
@@ -601,14 +603,18 @@ int get_mp3file_info(int fd, struct mp3info *info) | |||
601 | } | 603 | } |
602 | else | 604 | else |
603 | { | 605 | { |
606 | long offset; | ||
607 | |||
604 | VDEBUGF("-- No VBR header --\n"); | 608 | VDEBUGF("-- No VBR header --\n"); |
605 | 609 | ||
606 | /* There was no VBR header found. So, we seek back to beginning and | 610 | /* There was no VBR header found. So, we seek back to beginning and |
607 | * search for the first MPEG frame header of the mp3 stream. */ | 611 | * search for the first MPEG frame header of the mp3 stream. */ |
608 | lseek(fd, -info->frame_size, SEEK_CUR); | 612 | offset = lseek(fd, -info->frame_size, SEEK_CUR); |
609 | result = get_next_header_info(fd, &bytecount, info, false); | 613 | result = get_next_header_info(fd, &bytecount, info, false); |
610 | if(result) | 614 | if(result) |
611 | return result; | 615 | return result; |
616 | |||
617 | info->byte_count = filesize(fd) - getid3v1len(fd) - offset - bytecount; | ||
612 | } | 618 | } |
613 | 619 | ||
614 | return bytecount; | 620 | return bytecount; |
@@ -647,7 +653,7 @@ int count_mp3_frames(int fd, int startpos, int filesize, | |||
647 | num_frames = 0; | 653 | num_frames = 0; |
648 | cnt = 0; | 654 | cnt = 0; |
649 | 655 | ||
650 | while((header = buf_find_next_frame(fd, &bytes, header_template))) { | 656 | while((header = buf_find_next_frame(fd, &bytes, startpos + filesize))) { |
651 | mp3headerinfo(&info, header); | 657 | mp3headerinfo(&info, header); |
652 | 658 | ||
653 | if(!header_template) | 659 | if(!header_template) |
@@ -723,7 +729,7 @@ int create_xing_header(int fd, long startpos, long filesize, | |||
723 | /* Advance from the last seek point to this one */ | 729 | /* Advance from the last seek point to this one */ |
724 | for(j = 0;j < pos - last_pos;j++) | 730 | for(j = 0;j < pos - last_pos;j++) |
725 | { | 731 | { |
726 | header = buf_find_next_frame(fd, &bytes, header_template); | 732 | header = buf_find_next_frame(fd, &bytes, startpos + filesize); |
727 | filepos += bytes; | 733 | filepos += bytes; |
728 | mp3headerinfo(&info, header); | 734 | mp3headerinfo(&info, header); |
729 | buf_seek(fd, info.frame_size-4); | 735 | buf_seek(fd, info.frame_size-4); |