Fixed group audio issues when getting an old audio packet.

This commit is contained in:
irungentoo 2015-03-19 18:02:46 -04:00
parent 4d242231a8
commit 2b2c9f37a6
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -26,6 +26,7 @@
#include "../toxcore/logger.h"
#define GROUP_JBUF_SIZE 6
#define GROUP_JBUF_DEAD_SECONDS 4
typedef struct {
uint16_t sequnum;
@ -39,6 +40,7 @@ typedef struct {
uint32_t capacity;
uint16_t bottom;
uint16_t top;
uint64_t last_queued_time;
} Group_JitterBuffer;
static Group_JitterBuffer *create_queue(unsigned int capacity)
@ -90,11 +92,19 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk)
unsigned int num = sequnum % q->size;
if (!is_timeout(q->last_queued_time, GROUP_JBUF_DEAD_SECONDS)) {
if ((uint32_t)(sequnum - q->bottom) > (1 << 15)) {
/* Drop old packet. */
return -1;
}
}
if ((uint32_t)(sequnum - q->bottom) > q->size) {
clear_queue(q);
q->bottom = sequnum - q->capacity;
q->queue[num] = pk;
q->top = sequnum + 1;
q->last_queued_time = unix_time();
return 0;
}
@ -106,6 +116,7 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk)
if ((sequnum - q->bottom) >= (q->top - q->bottom))
q->top = sequnum + 1;
q->last_queued_time = unix_time();
return 0;
}