summaryrefslogtreecommitdiff
path: root/toxav/group.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2015-04-17 19:19:58 +0200
committermannol <eniz_vukovic@hotmail.com>2015-04-17 19:19:58 +0200
commitd1fd3e36a6b58d4cd6b3e2a7ccbed7e1e5d2e2a3 (patch)
tree6ae0aacc5fba56fc356be615b6f459c95647d597 /toxav/group.c
parent969367b72aebaa2ecfc168cf2e86b20501298c20 (diff)
parentf8087887feaf77577a345ae1be68776459613c03 (diff)
Updated with upstream
Diffstat (limited to 'toxav/group.c')
-rw-r--r--toxav/group.c12
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
30typedef struct { 32typedef 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
44static Group_JitterBuffer *create_queue(unsigned int capacity) 47static 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