1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* $Header: /pjproject/pjmedia/src/test/jbuf_test.c 9 6/24/05 11:18p Bennylp $ */
#include <stdio.h>
#include <ctype.h>
#include <pjmedia/jbuf.h>
#include <pj/pool.h>
#define JB_MIN 1
#define JB_MAX 8
#define JB_BUF_SIZE 10
#define REPORT
//#define PRINT_COMMENT
int jbuf_main(pj_pool_factory *pf)
{
pj_jitter_buffer jb;
FILE *input = fopen("JBTEST.DAT", "rt");
unsigned lastseq;
void *data = "Hello world";
char line[1024], *p;
int lastget = 0, lastput = 0;
pj_pool_t *pool;
pj_init();
pool = pj_pool_create(pf, "JBPOOL", 256*16, 256*16, NULL);
pj_jb_init(&jb, pool, JB_MIN, JB_MAX, JB_BUF_SIZE);
lastseq = 1;
while ((p=fgets(line, sizeof(line), input)) != NULL) {
while (*p && isspace(*p))
++p;
if (!*p)
continue;
if (*p == '#') {
#ifdef PRINT_COMMENT
printf("\n%s", p);
#endif
continue;
}
pj_jb_reset(&jb);
#ifdef REPORT
printf( "Initial\t%c size=%d prefetch=%d level=%d\n",
' ', jb.lst.count, jb.prefetch, jb.level);
#endif
while (*p) {
int c;
unsigned seq = 0;
void *thedata;
int status = 1234;
c = *p++;
if (isspace(c))
continue;
if (c == '/') {
char *end;
printf("/*");
do {
putchar(*++p);
} while (*p != '/');
putchar('\n');
c = *++p;
end = p;
}
if (isspace(c))
continue;
if (isdigit(c)) {
seq = c - '0';
while (*p) {
c = *p++;
if (isspace(c))
continue;
if (!isdigit(c))
break;
seq = seq * 10 + c - '0';
}
}
if (!*p)
break;
switch (toupper(c)) {
case 'G':
seq = -1;
status = pj_jb_get(&jb, &seq, &thedata);
lastget = seq;
break;
case 'P':
if (seq == 0)
seq = lastseq++;
else
lastseq = seq;
status = pj_jb_put(&jb, seq, data);
if (status == 0)
lastput = seq;
break;
default:
printf("Unknown character '%c'\n", c);
break;
}
#ifdef REPORT
printf("seq=%d\t%c rc=%d\tsize=%d\tpfch=%d\tlvl=%d\tmxl=%d\tdelay=%d\n",
seq, toupper(c), status, jb.lst.count, jb.prefetch, jb.level, jb.max_level,
(lastget>0 && lastput>0) ? lastput-lastget : -1);
#endif
}
}
#ifdef REPORT
printf("0\t%c size=%d prefetch=%d level=%d\n",
' ', jb.lst.count, jb.prefetch, jb.level);
#endif
if (input != stdin)
fclose(input);
pj_pool_release(pool);
return 0;
}
|