1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "speex/speex_jitter.h"
6 #include <stdio.h>
7
8 union jbpdata {
9 unsigned int idx;
10 unsigned char data[4];
11 };
12
synthIn(JitterBufferPacket * in,int idx,int span)13 void synthIn(JitterBufferPacket *in, int idx, int span) {
14 union jbpdata d;
15 d.idx = idx;
16
17 in->data = d.data;
18 in->len = sizeof(d);
19 in->timestamp = idx * 10;
20 in->span = span * 10;
21 in->sequence = idx;
22 in->user_data = 0;
23 }
24
jitterFill(JitterBuffer * jb)25 void jitterFill(JitterBuffer *jb) {
26 char buffer[65536];
27 JitterBufferPacket in, out;
28 int i;
29
30 out.data = buffer;
31
32 jitter_buffer_reset(jb);
33
34 for(i=0;i<100;++i) {
35 synthIn(&in, i, 1);
36 jitter_buffer_put(jb, &in);
37
38 out.len = 65536;
39 if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) {
40 printf("Fill test failed iteration %d\n", i);
41 }
42 if (out.timestamp != i * 10) {
43 printf("Fill test expected %d got %d\n", i*10, out.timestamp);
44 }
45 jitter_buffer_tick(jb);
46 }
47 }
48
main()49 int main()
50 {
51 char buffer[65536];
52 JitterBufferPacket in, out;
53 int i;
54
55 JitterBuffer *jb = jitter_buffer_init(10);
56
57 out.data = buffer;
58
59 /* Frozen sender case */
60 jitterFill(jb);
61 for(i=0;i<100;++i) {
62 out.len = 65536;
63 jitter_buffer_get(jb, &out, 10, NULL);
64 jitter_buffer_tick(jb);
65 }
66 synthIn(&in, 100, 1);
67 jitter_buffer_put(jb, &in);
68 out.len = 65536;
69 if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) {
70 printf("Failed frozen sender resynchronize\n");
71 } else {
72 printf("Frozen sender: Jitter %d\n", out.timestamp - 100*10);
73 }
74 return 0;
75 }
76