summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 4516959cab..8d41324190 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -25,8 +25,6 @@
25#include <stdlib.h> 25#include <stdlib.h>
26#include <ctype.h> 26#include <ctype.h>
27#include <inttypes.h> 27#include <inttypes.h>
28#define assert(a)
29
30#include "buffering.h" 28#include "buffering.h"
31 29
32#include "storage.h" 30#include "storage.h"
@@ -613,16 +611,6 @@ static inline bool buffer_is_low(void)
613 return data_counters.useful < (conf_watermark / 2); 611 return data_counters.useful < (conf_watermark / 2);
614} 612}
615 613
616static uintptr_t beyond_handle(struct memory_handle *h)
617{
618 /*
619 * the last handle on the chain must leave at least one byte
620 * between itself and the first handle, to avoid overflowing the
621 * ring by advancing buf_widx up to buf_ridx
622 */
623 return h->next != 0 ? ringbuf_offset(h->next) : ringbuf_sub(buf_ridx, 1);
624}
625
626/* Buffer data for the given handle. 614/* Buffer data for the given handle.
627 Return whether or not the buffering should continue explicitly. */ 615 Return whether or not the buffering should continue explicitly. */
628static bool buffer_handle(int handle_id) 616static bool buffer_handle(int handle_id)
@@ -681,10 +669,10 @@ static bool buffer_handle(int handle_id)
681 buffer_len - h->widx); 669 buffer_len - h->widx);
682 670
683 ssize_t overlap; 671 ssize_t overlap;
684 uintptr_t next_handle = beyond_handle(h); 672 uintptr_t next_handle = ringbuf_offset(h->next);
685 673
686 /* stop copying if it would overwrite the reading position */ 674 /* stop copying if it would overwrite the reading position */
687 if (h->widx == next_handle || ringbuf_add_cross(h->widx, copy_n, buf_ridx) >= 0) 675 if (ringbuf_add_cross(h->widx, copy_n, buf_ridx) >= 0)
688 return false; 676 return false;
689 677
690 /* FIXME: This would overwrite the next handle 678 /* FIXME: This would overwrite the next handle
@@ -801,7 +789,8 @@ static void rebuffer_handle(int handle_id, size_t newpos)
801 LOGFQUEUE("buffering >| Q_RESET_HANDLE %d", handle_id); 789 LOGFQUEUE("buffering >| Q_RESET_HANDLE %d", handle_id);
802 queue_send(&buffering_queue, Q_RESET_HANDLE, handle_id); 790 queue_send(&buffering_queue, Q_RESET_HANDLE, handle_id);
803 791
804 if (ringbuf_sub(beyond_handle(h), h->data) < h->filesize - newpos) 792 uintptr_t next = ringbuf_offset(h->next);
793 if (ringbuf_sub(next, h->data) < h->filesize - newpos)
805 { 794 {
806 /* There isn't enough space to rebuffer all of the track from its new 795 /* There isn't enough space to rebuffer all of the track from its new
807 offset, so we ask the user to free some */ 796 offset, so we ask the user to free some */