Fixed some issues with queue.

disconnecting then reconnecting right away should no longer kill
audio transmission.
This commit is contained in:
irungentoo 2014-07-24 20:56:07 -04:00
parent 450c503eba
commit da03feaace
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 19 additions and 10 deletions

View File

@ -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;
}
static void clear_queue(JitterBuffer *q)
{
for (; q->bottom != q->top; ++q->bottom) {
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;
for (; q->bottom != q->top; ++q->bottom) {
if (!q->queue[q->bottom % q->size])
rtp_free_msg(NULL, q->queue[q->bottom % q->size]);
}
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;

View File

@ -95,7 +95,7 @@ const ToxAvCodecSettings av_DefaultSettings = {
1,
600,
2
3
};