From da03feaaced60e251006992e790abc8c00911826 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 24 Jul 2014 20:56:07 -0400 Subject: Fixed some issues with queue. disconnecting then reconnecting right away should no longer kill audio transmission. --- toxav/codec.c | 25 +++++++++++++++++-------- toxav/toxav.c | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/toxav/codec.c b/toxav/codec.c index 8b1855a0..448edd4c 100644 --- a/toxav/codec.c +++ b/toxav/codec.c @@ -40,7 +40,7 @@ JitterBuffer *create_queue(unsigned int capacity) { unsigned int size = 1; - while (size <= (capacity + 1) * 2) { + while (size <= (capacity + 4) * 2) { size *= 2; } @@ -58,15 +58,19 @@ JitterBuffer *create_queue(unsigned int capacity) return q; } -void terminate_queue(JitterBuffer *q) +static void clear_queue(JitterBuffer *q) { - if (!q) return; - for (; q->bottom != q->top; ++q->bottom) { - if (!q->queue[q->bottom % q->size]) + if (q->queue[q->bottom % q->size]) rtp_free_msg(NULL, q->queue[q->bottom % q->size]); } +} + +void terminate_queue(JitterBuffer *q) +{ + if (!q) return; + clear_queue(q); free(q->queue); free(q); } @@ -75,11 +79,16 @@ void queue(JitterBuffer *q, RTPMessage *pk) { uint16_t sequnum = pk->header->sequnum; - if (sequnum - q->bottom > q->size) - return; - unsigned int num = sequnum % q->size; + if (sequnum - q->bottom > q->size) { + clear_queue(q); + q->bottom = sequnum; + q->queue[num] = pk; + q->top = sequnum + 1; + return; + } + if (q->queue[num]) return; diff --git a/toxav/toxav.c b/toxav/toxav.c index 06127ef4..e15c409d 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -95,7 +95,7 @@ const ToxAvCodecSettings av_DefaultSettings = { 1, 600, - 2 + 3 }; -- cgit v1.2.3