diff options
Diffstat (limited to 'toxav/group.c')
-rw-r--r-- | toxav/group.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/toxav/group.c b/toxav/group.c index 3c09878a..817ee6e6 100644 --- a/toxav/group.c +++ b/toxav/group.c | |||
@@ -23,9 +23,11 @@ | |||
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #include "group.h" | 25 | #include "group.h" |
26 | #include "../toxcore/util.h" | ||
26 | #include "../toxcore/logger.h" | 27 | #include "../toxcore/logger.h" |
27 | 28 | ||
28 | #define GROUP_JBUF_SIZE 6 | 29 | #define GROUP_JBUF_SIZE 6 |
30 | #define GROUP_JBUF_DEAD_SECONDS 4 | ||
29 | 31 | ||
30 | typedef struct { | 32 | typedef struct { |
31 | uint16_t sequnum; | 33 | uint16_t sequnum; |
@@ -39,6 +41,7 @@ typedef struct { | |||
39 | uint32_t capacity; | 41 | uint32_t capacity; |
40 | uint16_t bottom; | 42 | uint16_t bottom; |
41 | uint16_t top; | 43 | uint16_t top; |
44 | uint64_t last_queued_time; | ||
42 | } Group_JitterBuffer; | 45 | } Group_JitterBuffer; |
43 | 46 | ||
44 | static Group_JitterBuffer *create_queue(unsigned int capacity) | 47 | static Group_JitterBuffer *create_queue(unsigned int capacity) |
@@ -90,11 +93,19 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk) | |||
90 | 93 | ||
91 | unsigned int num = sequnum % q->size; | 94 | unsigned int num = sequnum % q->size; |
92 | 95 | ||
96 | if (!is_timeout(q->last_queued_time, GROUP_JBUF_DEAD_SECONDS)) { | ||
97 | if ((uint32_t)(sequnum - q->bottom) > (1 << 15)) { | ||
98 | /* Drop old packet. */ | ||
99 | return -1; | ||
100 | } | ||
101 | } | ||
102 | |||
93 | if ((uint32_t)(sequnum - q->bottom) > q->size) { | 103 | if ((uint32_t)(sequnum - q->bottom) > q->size) { |
94 | clear_queue(q); | 104 | clear_queue(q); |
95 | q->bottom = sequnum - q->capacity; | 105 | q->bottom = sequnum - q->capacity; |
96 | q->queue[num] = pk; | 106 | q->queue[num] = pk; |
97 | q->top = sequnum + 1; | 107 | q->top = sequnum + 1; |
108 | q->last_queued_time = unix_time(); | ||
98 | return 0; | 109 | return 0; |
99 | } | 110 | } |
100 | 111 | ||
@@ -106,6 +117,7 @@ static int queue(Group_JitterBuffer *q, Group_Audio_Packet *pk) | |||
106 | if ((sequnum - q->bottom) >= (q->top - q->bottom)) | 117 | if ((sequnum - q->bottom) >= (q->top - q->bottom)) |
107 | q->top = sequnum + 1; | 118 | q->top = sequnum + 1; |
108 | 119 | ||
120 | q->last_queued_time = unix_time(); | ||
109 | return 0; | 121 | return 0; |
110 | } | 122 | } |
111 | 123 | ||