summaryrefslogtreecommitdiff
path: root/apps/mp3data.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/mp3data.c')
-rw-r--r--apps/mp3data.c41
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__
312static int fnf_read_index; 312static int fnf_read_index;
313static int fnf_buf_len; 313static int fnf_buf_len;
314static unsigned char *fnf_buf;
314 315
315static int buf_getbyte(int fd, unsigned char *c) 316static 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
364static void buf_init(void) 365static 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
375static int audiobuflen; 377static size_t mem_buflen;
376static int mem_pos; 378static unsigned char* mem_buf;
379static size_t mem_pos;
377static int mem_cnt; 380static int mem_cnt;
378static int mem_maxlen; 381static 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)
394unsigned long mem_find_next_frame(int startpos, 397unsigned 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
623int count_mp3_frames(int fd, int startpos, int filesize, 628int 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";
687int create_xing_header(int fd, long startpos, long filesize, 693int 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;