diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/buffering.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index d3a30088e6..664a178db0 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -176,6 +176,12 @@ static struct queue_sender_list buffering_queue_sender_list; | |||
176 | 176 | ||
177 | 177 | ||
178 | /* Ring buffer helper functions */ | 178 | /* Ring buffer helper functions */ |
179 | |||
180 | static inline uintptr_t ringbuf_offset(const void *ptr) | ||
181 | { | ||
182 | return (uintptr_t)(ptr - (void*)buffer); | ||
183 | } | ||
184 | |||
179 | /* Buffer pointer (p) plus value (v), wrapped if necessary */ | 185 | /* Buffer pointer (p) plus value (v), wrapped if necessary */ |
180 | static inline uintptr_t ringbuf_add(uintptr_t p, size_t v) | 186 | static inline uintptr_t ringbuf_add(uintptr_t p, size_t v) |
181 | { | 187 | { |
@@ -347,7 +353,7 @@ static bool rm_handle(const struct memory_handle *h) | |||
347 | buf_ridx = buf_widx = 0; | 353 | buf_ridx = buf_widx = 0; |
348 | } else { | 354 | } else { |
349 | /* update buf_ridx to point to the new first handle */ | 355 | /* update buf_ridx to point to the new first handle */ |
350 | buf_ridx = (void *)first_handle - (void *)buffer; | 356 | buf_ridx = (size_t)ringbuf_offset(first_handle); |
351 | } | 357 | } |
352 | } else { | 358 | } else { |
353 | struct memory_handle *m = first_handle; | 359 | struct memory_handle *m = first_handle; |
@@ -433,13 +439,9 @@ static bool move_handle(struct memory_handle **h, size_t *delta, | |||
433 | int32_t *there; | 439 | int32_t *there; |
434 | int32_t *end; | 440 | int32_t *end; |
435 | int32_t *begin; | 441 | int32_t *begin; |
436 | size_t oldpos; | 442 | size_t final_delta = *delta, size_to_move, n; |
437 | size_t newpos; | 443 | uintptr_t oldpos, newpos; |
438 | size_t size_to_move; | 444 | intptr_t overlap, overlap_old; |
439 | size_t final_delta = *delta; | ||
440 | size_t n; | ||
441 | int overlap; | ||
442 | int overlap_old; | ||
443 | 445 | ||
444 | if (h == NULL || (src = *h) == NULL) | 446 | if (h == NULL || (src = *h) == NULL) |
445 | return false; | 447 | return false; |
@@ -456,7 +458,7 @@ static bool move_handle(struct memory_handle **h, size_t *delta, | |||
456 | mutex_lock(&llist_mutex); | 458 | mutex_lock(&llist_mutex); |
457 | mutex_lock(&llist_mod_mutex); | 459 | mutex_lock(&llist_mod_mutex); |
458 | 460 | ||
459 | oldpos = (void *)src - (void *)buffer; | 461 | oldpos = ringbuf_offset(src); |
460 | newpos = ringbuf_add(oldpos, final_delta); | 462 | newpos = ringbuf_add(oldpos, final_delta); |
461 | overlap = ringbuf_add_cross(newpos, size_to_move, buffer_len - 1); | 463 | overlap = ringbuf_add_cross(newpos, size_to_move, buffer_len - 1); |
462 | overlap_old = ringbuf_add_cross(oldpos, size_to_move, buffer_len -1); | 464 | overlap_old = ringbuf_add_cross(oldpos, size_to_move, buffer_len -1); |
@@ -470,7 +472,7 @@ static bool move_handle(struct memory_handle **h, size_t *delta, | |||
470 | * backed out. This may become conditional if ever we move | 472 | * backed out. This may become conditional if ever we move |
471 | * data that is allowed to wrap (ie audio) */ | 473 | * data that is allowed to wrap (ie audio) */ |
472 | correction = overlap; | 474 | correction = overlap; |
473 | } else if ((unsigned)overlap > data_size) { | 475 | } else if ((uintptr_t)overlap > data_size) { |
474 | /* Correct the position and real delta to prevent the struct from | 476 | /* Correct the position and real delta to prevent the struct from |
475 | * wrapping, this guarantees an aligned delta, I think */ | 477 | * wrapping, this guarantees an aligned delta, I think */ |
476 | correction = overlap - data_size; | 478 | correction = overlap - data_size; |
@@ -669,7 +671,7 @@ static bool buffer_handle(int handle_id) | |||
669 | buffer_len - h->widx); | 671 | buffer_len - h->widx); |
670 | 672 | ||
671 | ssize_t overlap; | 673 | ssize_t overlap; |
672 | intptr_t next_handle = (intptr_t)h->next - (intptr_t)buffer; | 674 | uintptr_t next_handle = ringbuf_offset(h->next); |
673 | 675 | ||
674 | /* stop copying if it would overwrite the reading position */ | 676 | /* stop copying if it would overwrite the reading position */ |
675 | if (ringbuf_add_cross(h->widx, copy_n, buf_ridx) >= 0) | 677 | if (ringbuf_add_cross(h->widx, copy_n, buf_ridx) >= 0) |
@@ -790,7 +792,7 @@ static void rebuffer_handle(int handle_id, size_t newpos) | |||
790 | LOGFQUEUE("buffering >| Q_RESET_HANDLE %d", handle_id); | 792 | LOGFQUEUE("buffering >| Q_RESET_HANDLE %d", handle_id); |
791 | queue_send(&buffering_queue, Q_RESET_HANDLE, handle_id); | 793 | queue_send(&buffering_queue, Q_RESET_HANDLE, handle_id); |
792 | 794 | ||
793 | size_t next = (intptr_t)h->next - (intptr_t)buffer; | 795 | uintptr_t next = ringbuf_offset(h->next); |
794 | if (ringbuf_sub(next, h->data) < h->filesize - newpos) | 796 | if (ringbuf_sub(next, h->data) < h->filesize - newpos) |
795 | { | 797 | { |
796 | /* There isn't enough space to rebuffer all of the track from its new | 798 | /* There isn't enough space to rebuffer all of the track from its new |
@@ -836,8 +838,8 @@ static void shrink_handle(struct memory_handle *h) | |||
836 | h->type == TYPE_ATOMIC_AUDIO)) | 838 | h->type == TYPE_ATOMIC_AUDIO)) |
837 | { | 839 | { |
838 | /* metadata handle: we can move all of it */ | 840 | /* metadata handle: we can move all of it */ |
839 | size_t handle_distance = | 841 | uintptr_t handle_distance = |
840 | ringbuf_sub((unsigned)((void *)h->next - (void*)buffer), h->data); | 842 | ringbuf_sub(ringbuf_offset(h->next), h->data); |
841 | delta = handle_distance - h->available; | 843 | delta = handle_distance - h->available; |
842 | 844 | ||
843 | /* The value of delta might change for alignment reasons */ | 845 | /* The value of delta might change for alignment reasons */ |