summaryrefslogtreecommitdiff
path: root/apps/playback.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-14 15:13:00 +0000
commitd1322b71595336740eb5e18e5deed056ddb71c7a (patch)
tree812db6a9c2e9d78405ec0ed38465fd88dc5be748 /apps/playback.c
parent9b9bd73dfb212d4192fccc5fc5e269fc6499139c (diff)
downloadrockbox-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/playback.c')
-rw-r--r--apps/playback.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/apps/playback.c b/apps/playback.c
index fe9bd579d4..3f6ee71ad7 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -744,16 +744,25 @@ static void audio_reset_buffer(void)
744 /* see audio_get_recording_buffer if this is modified */ 744 /* see audio_get_recording_buffer if this is modified */
745 logf("%s()", __func__); 745 logf("%s()", __func__);
746 746
747 /* release the buffer on behalf of any caller of audio_get_buffer() */
748 buffer_release_buffer(0);
749
747 /* If the setup of anything allocated before the file buffer is 750 /* If the setup of anything allocated before the file buffer is
748 changed, do check the adjustments after the buffer_alloc call 751 changed, do check the adjustments after the buffer_alloc call
749 as it will likely be affected and need sliding over */ 752 as it will likely be affected and need sliding over */
750 753
751 /* Initially set up file buffer as all space available */ 754 /* Initially set up file buffer as all space available */
752 unsigned char *filebuf = audiobuf + talk_get_bufsize(); 755 size_t filebuflen, allocsize;
753 size_t filebuflen = audiobufend - filebuf; 756 unsigned char *filebuf = buffer_get_buffer(&filebuflen);
754 size_t allocsize;
755 757
756 ALIGN_BUFFER(filebuf, filebuflen, sizeof (intptr_t)); 758 /* Subtract whatever voice needs */
759 allocsize = talkbuf_init(filebuf);
760 allocsize = ALIGN_UP(allocsize, sizeof (intptr_t));
761 if (allocsize > filebuflen)
762 goto bufpanic;
763
764 filebuf += allocsize;
765 filebuflen -= allocsize;
757 766
758 if (talk_voice_required()) 767 if (talk_voice_required())
759 { 768 {
@@ -3335,6 +3344,7 @@ void audio_hard_stop(void)
3335#ifdef PLAYBACK_VOICE 3344#ifdef PLAYBACK_VOICE
3336 voice_stop(); 3345 voice_stop();
3337#endif 3346#endif
3347 buffer_release_buffer(0);
3338} 3348}
3339 3349
3340/* Resume playback if paused */ 3350/* Resume playback if paused */
@@ -3441,7 +3451,7 @@ void audio_flush_and_reload_tracks(void)
3441 voicing */ 3451 voicing */
3442unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) 3452unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
3443{ 3453{
3444 unsigned char *buf, *end; 3454 unsigned char *buf;
3445 3455
3446 if (audio_is_initialized) 3456 if (audio_is_initialized)
3447 { 3457 {
@@ -3461,7 +3471,7 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
3461 || !talk_voice_required()) 3471 || !talk_voice_required())
3462 { 3472 {
3463 logf("get buffer: talk, audio"); 3473 logf("get buffer: talk, audio");
3464 /* Ok to use everything from audiobuf to audiobufend - voice is loaded, 3474 /* Ok to use everything from audiobuf - voice is loaded,
3465 the talk buffer is not needed because voice isn't being used, or 3475 the talk buffer is not needed because voice isn't being used, or
3466 could be AUDIOBUF_STATE_TRASHED already. If state is 3476 could be AUDIOBUF_STATE_TRASHED already. If state is
3467 AUDIOBUF_STATE_VOICED_ONLY, no problem as long as memory isn't 3477 AUDIOBUF_STATE_VOICED_ONLY, no problem as long as memory isn't
@@ -3474,9 +3484,7 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
3474 talk_buffer_steal(); 3484 talk_buffer_steal();
3475 buffer_state = AUDIOBUF_STATE_TRASHED; 3485 buffer_state = AUDIOBUF_STATE_TRASHED;
3476 } 3486 }
3477 3487 buf = buffer_get_buffer(buffer_size);
3478 buf = audiobuf;
3479 end = audiobufend;
3480 } 3488 }
3481 else 3489 else
3482 { 3490 {
@@ -3485,14 +3493,18 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
3485 /* Skip talk buffer and move pcm buffer to end to maximize available 3493 /* Skip talk buffer and move pcm buffer to end to maximize available
3486 contiguous memory - no audio running means voice will not need the 3494 contiguous memory - no audio running means voice will not need the
3487 swap space */ 3495 swap space */
3496 size_t siz, talkbuf_size;
3488 logf("get buffer: audio"); 3497 logf("get buffer: audio");
3489 buf = audiobuf + talk_get_bufsize(); 3498 /* call buffer_get_buffer() to make use of the locking mechanism */
3490 end = audiobufend - voicebuf_init(audiobufend); 3499 buf = buffer_get_buffer(&siz);
3500 buf += talkbuf_size = talkbuf_init(buf);
3501 siz -= talkbuf_size;
3502 siz -= voicebuf_init(buf + siz);
3503 *buffer_size = siz;
3504
3491 buffer_state = AUDIOBUF_STATE_VOICED_ONLY; 3505 buffer_state = AUDIOBUF_STATE_VOICED_ONLY;
3492 } 3506 }
3493 3507
3494 *buffer_size = end - buf;
3495
3496 return buf; 3508 return buf;
3497} 3509}
3498 3510
@@ -3500,14 +3512,11 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size)
3500/* Stop audio, voice and obtain all available buffer space */ 3512/* Stop audio, voice and obtain all available buffer space */
3501unsigned char * audio_get_recording_buffer(size_t *buffer_size) 3513unsigned char * audio_get_recording_buffer(size_t *buffer_size)
3502{ 3514{
3503 audio_hard_stop();
3504 talk_buffer_steal(); 3515 talk_buffer_steal();
3516 audio_hard_stop();
3505 3517
3506 unsigned char *end = audiobufend;
3507 buffer_state = AUDIOBUF_STATE_TRASHED; 3518 buffer_state = AUDIOBUF_STATE_TRASHED;
3508 *buffer_size = end - audiobuf; 3519 return buffer_get_buffer(buffer_size);
3509
3510 return (unsigned char *)audiobuf;
3511} 3520}
3512#endif /* HAVE_RECORDING */ 3521#endif /* HAVE_RECORDING */
3513 3522