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