summaryrefslogtreecommitdiffstats
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-03-02 06:24:50 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-03-02 06:24:50 +0000
commit05e180a1308a095d51d51d0e047fcd44425ea88f (patch)
tree10725fab9ce3240e8dd5d511f249dba3aaa459b4 /apps/buffering.c
parent64647f34036684d2d69c525460ee6a6409f2a31f (diff)
downloadrockbox-05e180a1308a095d51d51d0e047fcd44425ea88f.tar.gz
rockbox-05e180a1308a095d51d51d0e047fcd44425ea88f.tar.bz2
rockbox-05e180a1308a095d51d51d0e047fcd44425ea88f.zip
Do the ridx > widx check where it should be done. A small rebuffering request must completely succeed before buffer can later shrink a handle or else it must reset the handle.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29491 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 2f6623a936..2949a81a87 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -808,11 +808,7 @@ static void shrink_handle(struct memory_handle *h)
}
} else {
/* only move the handle struct */
- size_t rd = ringbuf_sub(h->ridx, h->data);
- size_t wr = ringbuf_sub(h->widx, h->data);
-
- /* ridx could be ahead of widx on a mini rebuffer */
- delta = MIN(rd, wr);
+ delta = ringbuf_sub(h->ridx, h->data);
if (!move_handle(&h, &delta, 0, true))
return;
@@ -1154,11 +1150,19 @@ static void rebuffer_handle(int handle_id, size_t newpos)
h->ridx = ringbuf_add(h->data, amount);
if (buffer_handle(handle_id, amount + 1)) {
- queue_reply(&buffering_queue, 0);
- buffer_handle(handle_id, 0); /* Ok, try the rest */
- return;
+ size_t rd = ringbuf_sub(h->ridx, h->data);
+ size_t wr = ringbuf_sub(h->widx, h->data);
+ if (wr >= rd) {
+ /* It really did succeed */
+ queue_reply(&buffering_queue, 0);
+ buffer_handle(handle_id, 0); /* Ok, try the rest */
+ return;
+ }
}
- /* Data collision - must reset */
+ /* Data collision or other file error - must reset */
+
+ if (newpos > h->filesize)
+ newpos = h->filesize; /* file truncation happened above */
}
/* Reset the handle to its new position */