diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-08-14 15:13:00 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-08-14 15:13:00 +0000 |
commit | d1322b71595336740eb5e18e5deed056ddb71c7a (patch) | |
tree | 812db6a9c2e9d78405ec0ed38465fd88dc5be748 /apps/mp3data.c | |
parent | 9b9bd73dfb212d4192fccc5fc5e269fc6499139c (diff) | |
download | rockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.tar.gz rockbox-d1322b71595336740eb5e18e5deed056ddb71c7a.zip |
GSoC/Buflib: Replace all direct accesses to audiobuf with buffer API functions.
Namely, introduce buffer_get_buffer() and buffer_release_buffer().
buffer_get_buffer() aquires all available and grabs a lock, attempting to
call buffer_alloc() or buffer_get_buffer() while this lock is locked will cause
a panicf() (doesn't actually happen, but is for debugging purpose).
buffer_release_buffer() unlocks that lock and can additionally increment the
audiobuf buffer to make an allocation. Pass 0 to only unlock if buffer was
used temporarily only.
buffer_available() is a replacement function to query audiobuflen, i.e. what's
left in the buffer.
Buffer init is moved up in the init chain and handles ipodvideo64mb internally.
Further changes happened to mp3data.c and talk.c as to not call the above API
functions, but get the buffer from callers. The caller is the audio system
which has the buffer lock while mp3data.c and talk mess with the buffer.
mpeg.c now implements some buffer related functions of playback.h, especially
audio_get_buffer(), allowing to reduce #ifdef hell a tiny bit.
audiobuf and audiobufend are local to buffer.c now.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30308 a1c6a512-1295-4272-9138-f99709370657
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; |