albertz/shairport — Issue #118: last-chance resend improvement
Author: stefdude
Created: 2011-10-09 18:30:28+00:00
State: open

While finding the bug that gave me the distorted audio (cf issue #117), I found that the last-chance resend was sometimes fired up to 6 times (probably while receiving multiple new packets while playing the same buffer-data).

The following patch corrects this: only one retry is sent out.
For this to happen, I change abuf->ready to -1 ("1 retry sent out") and by changing the other comparisons of abuf->ready to != 1.

Probably, this could be improved, by implementing a first check at t-30, t-20, t-10, ...

diff --git a/hairtunes.c b/hairtunes.c
index 28b4906..4b54915 100644
--- a/hairtunes.c
+++ b/hairtunes.c
@@ -393,8 +393,10 @@ void buffer_put_packet(seq_t seqno, char *data, int len) {
// check if the t+10th packet has arrived... last-chance resend
read = ab_read + 10;
abuf = audio_buffer + BUFIDX(read);
- if (!abuf->ready)
+ if (abuf->ready != 1) {
rtp_request_resend(read, read);
+ abuf->ready = -1;
+ }
}
}

@@ -671,7 +673,7 @@ short *buffer_get_frame(void) {
bf_est_update(buf_fill);

volatile abuf_t *curframe = audio_buffer + BUFIDX(read);
- if (!curframe->ready) {
+ if (curframe->ready != 1) {
fprintf(stderr, "\nmissing frame.\n");
memset(curframe->data, 0, FRAME_BYTES);
}