diff options
Diffstat (limited to 'apps/mp3data.c')
-rw-r--r-- | apps/mp3data.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/apps/mp3data.c b/apps/mp3data.c index 9fed727609..53f13f4f64 100644 --- a/apps/mp3data.c +++ b/apps/mp3data.c | |||
@@ -311,17 +311,18 @@ unsigned long find_next_frame(int fd, | |||
311 | #ifndef __PCTOOL__ | 311 | #ifndef __PCTOOL__ |
312 | static int fnf_read_index; | 312 | static int fnf_read_index; |
313 | static int fnf_buf_len; | 313 | static int fnf_buf_len; |
314 | static unsigned char *fnf_buf; | ||
314 | 315 | ||
315 | static int buf_getbyte(int fd, unsigned char *c) | 316 | static int buf_getbyte(int fd, unsigned char *c) |
316 | { | 317 | { |
317 | if(fnf_read_index < fnf_buf_len) | 318 | if(fnf_read_index < fnf_buf_len) |
318 | { | 319 | { |
319 | *c = audiobuf[fnf_read_index++]; | 320 | *c = fnf_buf[fnf_read_index++]; |
320 | return 1; | 321 | return 1; |
321 | } | 322 | } |
322 | else | 323 | else |
323 | { | 324 | { |
324 | fnf_buf_len = read(fd, audiobuf, audiobufend - audiobuf); | 325 | fnf_buf_len = read(fd, fnf_buf, fnf_buf_len); |
325 | if(fnf_buf_len < 0) | 326 | if(fnf_buf_len < 0) |
326 | return -1; | 327 | return -1; |
327 | 328 | ||
@@ -329,7 +330,7 @@ static int buf_getbyte(int fd, unsigned char *c) | |||
329 | 330 | ||
330 | if(fnf_buf_len > 0) | 331 | if(fnf_buf_len > 0) |
331 | { | 332 | { |
332 | *c = audiobuf[fnf_read_index++]; | 333 | *c = fnf_buf[fnf_read_index++]; |
333 | return 1; | 334 | return 1; |
334 | } | 335 | } |
335 | else | 336 | else |
@@ -345,7 +346,7 @@ static int buf_seek(int fd, int len) | |||
345 | { | 346 | { |
346 | len = fnf_read_index - fnf_buf_len; | 347 | len = fnf_read_index - fnf_buf_len; |
347 | 348 | ||
348 | fnf_buf_len = read(fd, audiobuf, audiobufend - audiobuf); | 349 | fnf_buf_len = read(fd, fnf_buf, fnf_buf_len); |
349 | if(fnf_buf_len < 0) | 350 | if(fnf_buf_len < 0) |
350 | return -1; | 351 | return -1; |
351 | 352 | ||
@@ -361,9 +362,10 @@ static int buf_seek(int fd, int len) | |||
361 | return 0; | 362 | return 0; |
362 | } | 363 | } |
363 | 364 | ||
364 | static void buf_init(void) | 365 | static void buf_init(unsigned char* buf, size_t buflen) |
365 | { | 366 | { |
366 | fnf_buf_len = 0; | 367 | fnf_buf = buf; |
368 | fnf_buf_len = buflen; | ||
367 | fnf_read_index = 0; | 369 | fnf_read_index = 0; |
368 | } | 370 | } |
369 | 371 | ||
@@ -372,8 +374,9 @@ static unsigned long buf_find_next_frame(int fd, long *offset, long max_offset) | |||
372 | return __find_next_frame(fd, offset, max_offset, 0, buf_getbyte, true); | 374 | return __find_next_frame(fd, offset, max_offset, 0, buf_getbyte, true); |
373 | } | 375 | } |
374 | 376 | ||
375 | static int audiobuflen; | 377 | static size_t mem_buflen; |
376 | static int mem_pos; | 378 | static unsigned char* mem_buf; |
379 | static size_t mem_pos; | ||
377 | static int mem_cnt; | 380 | static int mem_cnt; |
378 | static int mem_maxlen; | 381 | static int mem_maxlen; |
379 | 382 | ||
@@ -381,8 +384,8 @@ static int mem_getbyte(int dummy, unsigned char *c) | |||
381 | { | 384 | { |
382 | dummy = dummy; | 385 | dummy = dummy; |
383 | 386 | ||
384 | *c = audiobuf[mem_pos++]; | 387 | *c = mem_buf[mem_pos++]; |
385 | if(mem_pos >= audiobuflen) | 388 | if(mem_pos >= mem_buflen) |
386 | mem_pos = 0; | 389 | mem_pos = 0; |
387 | 390 | ||
388 | if(mem_cnt++ >= mem_maxlen) | 391 | if(mem_cnt++ >= mem_maxlen) |
@@ -394,9 +397,11 @@ static int mem_getbyte(int dummy, unsigned char *c) | |||
394 | unsigned long mem_find_next_frame(int startpos, | 397 | unsigned long mem_find_next_frame(int startpos, |
395 | long *offset, | 398 | long *offset, |
396 | long max_offset, | 399 | long max_offset, |
397 | unsigned long reference_header) | 400 | unsigned long reference_header, |
401 | unsigned char* buf, size_t buflen) | ||
398 | { | 402 | { |
399 | audiobuflen = audiobufend - audiobuf; | 403 | mem_buf = buf; |
404 | mem_buflen = buflen; | ||
400 | mem_pos = startpos; | 405 | mem_pos = startpos; |
401 | mem_cnt = 0; | 406 | mem_cnt = 0; |
402 | mem_maxlen = max_offset; | 407 | mem_maxlen = max_offset; |
@@ -620,8 +625,9 @@ static void long2bytes(unsigned char *buf, long val) | |||
620 | buf[3] = val & 0xff; | 625 | buf[3] = val & 0xff; |
621 | } | 626 | } |
622 | 627 | ||
623 | int count_mp3_frames(int fd, int startpos, int filesize, | 628 | int count_mp3_frames(int fd, int startpos, int filesize, |
624 | void (*progressfunc)(int)) | 629 | void (*progressfunc)(int), |
630 | unsigned char* buf, size_t buflen) | ||
625 | { | 631 | { |
626 | unsigned long header = 0; | 632 | unsigned long header = 0; |
627 | struct mp3info info; | 633 | struct mp3info info; |
@@ -637,7 +643,7 @@ int count_mp3_frames(int fd, int startpos, int filesize, | |||
637 | if(lseek(fd, startpos, SEEK_SET) < 0) | 643 | if(lseek(fd, startpos, SEEK_SET) < 0) |
638 | return -1; | 644 | return -1; |
639 | 645 | ||
640 | buf_init(); | 646 | buf_init(buf, buflen); |
641 | 647 | ||
642 | /* Find out the total number of frames */ | 648 | /* Find out the total number of frames */ |
643 | num_frames = 0; | 649 | num_frames = 0; |
@@ -687,7 +693,8 @@ static const char cooltext[] = "Rockbox - rocks your box"; | |||
687 | int create_xing_header(int fd, long startpos, long filesize, | 693 | int create_xing_header(int fd, long startpos, long filesize, |
688 | unsigned char *buf, unsigned long num_frames, | 694 | unsigned char *buf, unsigned long num_frames, |
689 | unsigned long rec_time, unsigned long header_template, | 695 | unsigned long rec_time, unsigned long header_template, |
690 | void (*progressfunc)(int), bool generate_toc) | 696 | void (*progressfunc)(int), bool generate_toc, |
697 | unsigned char *tempbuf, size_t tempbuflen ) | ||
691 | { | 698 | { |
692 | struct mp3info info; | 699 | struct mp3info info; |
693 | unsigned char toc[100]; | 700 | unsigned char toc[100]; |
@@ -705,7 +712,7 @@ int create_xing_header(int fd, long startpos, long filesize, | |||
705 | if(generate_toc) | 712 | if(generate_toc) |
706 | { | 713 | { |
707 | lseek(fd, startpos, SEEK_SET); | 714 | lseek(fd, startpos, SEEK_SET); |
708 | buf_init(); | 715 | buf_init(tempbuf, tempbuflen); |
709 | 716 | ||
710 | /* Generate filepos table */ | 717 | /* Generate filepos table */ |
711 | last_pos = 0; | 718 | last_pos = 0; |