summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-30 14:11:03 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-10-30 14:11:03 +0000
commit4ff2f9f3729c4e432e475ec8cd8957cf7cdb06cc (patch)
tree7923afec5b23c89d07ea6e2e632151c033996e53 /apps
parentbe6e85dc590552eff8194fcd5f8a0b9bf2526f69 (diff)
downloadrockbox-4ff2f9f3729c4e432e475ec8cd8957cf7cdb06cc.zip
rockbox-4ff2f9f3729c4e432e475ec8cd8957cf7cdb06cc.tar.gz
rockbox-4ff2f9f3729c4e432e475ec8cd8957cf7cdb06cc.tar.bz2
rockbox-4ff2f9f3729c4e432e475ec8cd8957cf7cdb06cc.tar.xz
can_add_handle() can be removed, but its logic must remain: before adding a handle, we need to make sure the there'll be space left for the curent one to finish buffering. This should fix the audio dropout problems people were experiencing.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15374 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/buffering.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index b527264..97f85df 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -231,9 +231,20 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap,
mutex_lock(&llist_mutex);
- /* Allocate the remainder of the space for the current handle */
- if (cur_handle)
- new_widx = RINGBUF_ADD(cur_handle->widx, cur_handle->filerem);
+ if (cur_handle && cur_handle->filerem > 0) {
+ /* the current handle hasn't finished buffering. We can only add
+ a new one if there is already enough free space to finish
+ the buffering. */
+ size_t req = cur_handle->filerem + sizeof(struct memory_handle);
+ if (RINGBUF_ADD_CROSS(cur_handle->widx, req, buf_ridx) >= 0) {
+ /* Not enough space */
+ mutex_unlock(&llist_mutex);
+ return NULL;
+ } else {
+ /* Allocate the remainder of the space for the current handle */
+ new_widx = RINGBUF_ADD(cur_handle->widx, cur_handle->filerem);
+ }
+ }
/* align buf_widx to 4 bytes up */
new_widx = (RINGBUF_ADD(new_widx, 3)) & ~3;