summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
808 } 808 }
809 } else { 809 } else {
810 /* only move the handle struct */ 810 /* only move the handle struct */
811 size_t rd = ringbuf_sub(h->ridx, h->data); 811 delta = ringbuf_sub(h->ridx, h->data);
812 size_t wr = ringbuf_sub(h->widx, h->data);
813
814 /* ridx could be ahead of widx on a mini rebuffer */
815 delta = MIN(rd, wr);
816 if (!move_handle(&h, &delta, 0, true)) 812 if (!move_handle(&h, &delta, 0, true))
817 return; 813 return;
818 814
@@ -1154,11 +1150,19 @@ static void rebuffer_handle(int handle_id, size_t newpos)
1154 h->ridx = ringbuf_add(h->data, amount); 1150 h->ridx = ringbuf_add(h->data, amount);
1155 1151
1156 if (buffer_handle(handle_id, amount + 1)) { 1152 if (buffer_handle(handle_id, amount + 1)) {
1157 queue_reply(&buffering_queue, 0); 1153 size_t rd = ringbuf_sub(h->ridx, h->data);
1158 buffer_handle(handle_id, 0); /* Ok, try the rest */ 1154 size_t wr = ringbuf_sub(h->widx, h->data);
1159 return; 1155 if (wr >= rd) {
1156 /* It really did succeed */
1157 queue_reply(&buffering_queue, 0);
1158 buffer_handle(handle_id, 0); /* Ok, try the rest */
1159 return;
1160 }
1160 } 1161 }
1161 /* Data collision - must reset */ 1162 /* Data collision or other file error - must reset */
1163
1164 if (newpos > h->filesize)
1165 newpos = h->filesize; /* file truncation happened above */
1162 } 1166 }
1163 1167
1164 /* Reset the handle to its new position */ 1168 /* Reset the handle to its new position */