mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed group audio issues when getting an old audio packet.
This commit is contained in:
parent
4d242231a8
commit
2b2c9f37a6
|
@ -26,6 +26,7 @@
|
||||||
#include "../toxcore/logger.h"
|
#include "../toxcore/logger.h"
|
||||||
|
|
||||||
#define GROUP_JBUF_SIZE 6
|
#define GROUP_JBUF_SIZE 6
|
||||||
|
#define GROUP_JBUF_DEAD_SECONDS 4
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t sequnum;
|
uint16_t sequnum;
|
||||||
|
@ -39,6 +40,7 @@ typedef struct {
|
||||||
uint32_t capacity;
|
uint32_t capacity;
|
||||||
uint16_t bottom;
|
uint16_t bottom;
|
||||||
uint16_t top;
|
uint16_t top;
|
||||||
|
uint64_t last_queued_time;
|
||||||
} Group_JitterBuffer;
|
} Group_JitterBuffer;
|
||||||
|
|
||||||
static Group_JitterBuffer *create_queue(unsigned int capacity)
|
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;
|
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) {
|
if ((uint32_t)(sequnum - q->bottom) > q->size) {
|
||||||
clear_queue(q);
|
clear_queue(q);
|
||||||
q->bottom = sequnum - q->capacity;
|
q->bottom = sequnum - q->capacity;
|
||||||
q->queue[num] = pk;
|
q->queue[num] = pk;
|
||||||
q->top = sequnum + 1;
|
q->top = sequnum + 1;
|
||||||
|
q->last_queued_time = unix_time();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +116,7 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk)
|
||||||
if ((sequnum - q->bottom) >= (q->top - q->bottom))
|
if ((sequnum - q->bottom) >= (q->top - q->bottom))
|
||||||
q->top = sequnum + 1;
|
q->top = sequnum + 1;
|
||||||
|
|
||||||
|
q->last_queued_time = unix_time();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user