blob: 1e054fb86e33d156490a5df6009670d2d118cfb2 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <stdio.h>
20#include <ctype.h>
21#include <pjmedia/jbuf.h>
22#include <pj/pool.h>
23
24#define JB_MIN 1
25#define JB_MAX 8
26#define JB_BUF_SIZE 10
27
28#define REPORT
29//#define PRINT_COMMENT
30
31int jbuf_main(pj_pool_factory *pf)
32{
33 pj_jitter_buffer jb;
34 FILE *input = fopen("JBTEST.DAT", "rt");
35 unsigned lastseq;
36 void *data = "Hello world";
37 char line[1024], *p;
38 int lastget = 0, lastput = 0;
39 pj_pool_t *pool;
40
41 pj_init();
42 pool = pj_pool_create(pf, "JBPOOL", 256*16, 256*16, NULL);
43
44 pj_jb_init(&jb, pool, JB_MIN, JB_MAX, JB_BUF_SIZE);
45
46 lastseq = 1;
47
48 while ((p=fgets(line, sizeof(line), input)) != NULL) {
49
50 while (*p && isspace(*p))
51 ++p;
52
53 if (!*p)
54 continue;
55
56 if (*p == '#') {
57#ifdef PRINT_COMMENT
58 printf("\n%s", p);
59#endif
60 continue;
61 }
62
63 pj_jb_reset(&jb);
64#ifdef REPORT
65 printf( "Initial\t%c size=%d prefetch=%d level=%d\n",
66 ' ', jb.lst.count, jb.prefetch, jb.level);
67#endif
68
69 while (*p) {
70 int c;
71 unsigned seq = 0;
72 void *thedata;
73 int status = 1234;
74
75 c = *p++;
76 if (isspace(c))
77 continue;
78
79 if (c == '/') {
80 char *end;
81
82 printf("/*");
83
84 do {
85 putchar(*++p);
86 } while (*p != '/');
87
88 putchar('\n');
89
90 c = *++p;
91 end = p;
92
93 }
94
95 if (isspace(c))
96 continue;
97
98 if (isdigit(c)) {
99 seq = c - '0';
100 while (*p) {
101 c = *p++;
102
103 if (isspace(c))
104 continue;
105
106 if (!isdigit(c))
107 break;
108
109 seq = seq * 10 + c - '0';
110 }
111 }
112
113 if (!*p)
114 break;
115
116 switch (toupper(c)) {
117 case 'G':
118 seq = -1;
119 status = pj_jb_get(&jb, &seq, &thedata);
120 lastget = seq;
121 break;
122 case 'P':
123 if (seq == 0)
124 seq = lastseq++;
125 else
126 lastseq = seq;
127 status = pj_jb_put(&jb, seq, data);
128 if (status == 0)
129 lastput = seq;
130 break;
131 default:
132 printf("Unknown character '%c'\n", c);
133 break;
134 }
135
136#ifdef REPORT
137 printf("seq=%d\t%c rc=%d\tsize=%d\tpfch=%d\tlvl=%d\tmxl=%d\tdelay=%d\n",
138 seq, toupper(c), status, jb.lst.count, jb.prefetch, jb.level, jb.max_level,
139 (lastget>0 && lastput>0) ? lastput-lastget : -1);
140#endif
141 }
142 }
143
144#ifdef REPORT
145 printf("0\t%c size=%d prefetch=%d level=%d\n",
146 ' ', jb.lst.count, jb.prefetch, jb.level);
147#endif
148
149 if (input != stdin)
150 fclose(input);
151
152 pj_pool_release(pool);
153 return 0;
154}