Changeset 1895 for pjproject/trunk/pjmedia/src/test/jbuf_test.c
- Timestamp:
- Mar 26, 2008 4:18:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/test/jbuf_test.c
r974 r1895 19 19 #include <stdio.h> 20 20 #include <ctype.h> 21 #include <pjmedia/jbuf.h>22 21 #include <pj/pool.h> 22 #include "test.h" 23 23 24 #define JB_MIN 1 25 #define JB_MAX 8 26 #define JB_BUF_SIZE 10 24 #define JB_INIT_PREFETCH 0 25 #define JB_MIN_PREFETCH 0 26 #define JB_MAX_PREFETCH 10 27 #define JB_PTIME 20 28 #define JB_BUF_SIZE 20 27 29 28 30 #define REPORT 29 31 //#define PRINT_COMMENT 30 32 31 int jbuf_main( pj_pool_factory *pf)33 int jbuf_main(void) 32 34 { 33 pj _jitter_bufferjb;35 pjmedia_jbuf *jb; 34 36 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; 37 unsigned seq; 38 char line[1024 * 10], *p; 39 39 pj_pool_t *pool; 40 pjmedia_jb_state state; 41 pj_str_t jb_name = {"JBTEST", 6}; 40 42 41 43 pj_init(); 42 pool = pj_pool_create( pf, "JBPOOL", 256*16, 256*16, NULL);44 pool = pj_pool_create(mem, "JBPOOL", 256*16, 256*16, NULL); 43 45 44 pj _jb_init(&jb, pool, JB_MIN, JB_MAX, JB_BUF_SIZE);45 46 lastseq = 1;46 pjmedia_jbuf_create(pool, &jb_name, 1, JB_PTIME, JB_BUF_SIZE, &jb); 47 pjmedia_jbuf_set_adaptive(jb, JB_INIT_PREFETCH, JB_MIN_PREFETCH, 48 JB_MAX_PREFETCH); 47 49 48 50 while ((p=fgets(line, sizeof(line), input)) != NULL) { … … 56 58 if (*p == '#') { 57 59 #ifdef PRINT_COMMENT 58 printf(" \n%s", p);60 printf("%s", p); 59 61 #endif 60 62 continue; 61 63 } 62 64 63 pj_jb_reset(&jb); 65 pjmedia_jbuf_reset(jb); 66 seq = 1; 67 64 68 #ifdef REPORT 65 printf( "Initial\t%c size=%d prefetch=%d level=%d\n", 66 ' ', jb.lst.count, jb.prefetch, jb.level); 69 pjmedia_jbuf_get_state(jb, &state); 70 printf("Initial\tsize=%d\tprefetch=%d\tmin.pftch=%d\tmax.pftch=%d\n", 71 state.size, state.prefetch, state.min_prefetch, state.max_prefetch); 67 72 #endif 68 73 69 74 while (*p) { 70 75 int c; 71 unsigned seq = 0; 72 void *thedata; 73 int status = 1234; 76 char frame[1]; 77 char f_type; 74 78 75 79 c = *p++; … … 78 82 79 83 if (c == '/') { 80 char *end;84 putchar('\n'); 81 85 82 printf("/*"); 83 84 do { 85 putchar(*++p); 86 } while (*p != '/'); 86 while (*++p && *p != '/') 87 putchar(*p); 87 88 88 89 putchar('\n'); 89 90 90 c = *++p;91 end = p;91 if (*++p == 0) 92 break; 92 93 94 continue; 93 95 } 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 96 116 97 switch (toupper(c)) { 117 98 case 'G': 118 seq = -1; 119 status = pj_jb_get(&jb, &seq, &thedata); 120 lastget = seq; 99 pjmedia_jbuf_get_frame(jb, frame, &f_type); 121 100 break; 122 101 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; 102 pjmedia_jbuf_put_frame(jb, (void*)frame, 1, seq); 103 seq++; 104 break; 105 case 'L': 106 seq++; 107 printf("Lost\n"); 130 108 break; 131 109 default: … … 135 113 136 114 #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); 115 if (toupper(c) != 'L') { 116 pjmedia_jbuf_get_state(jb, &state); 117 printf("seq=%d\t%c\tsize=%d\tprefetch=%d\n", 118 seq, toupper(c), state.size, state.prefetch); 119 } 140 120 #endif 141 121 } 142 122 } 143 123 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 124 pjmedia_jbuf_destroy(jb); 148 125 149 126 if (input != stdin)
Note: See TracChangeset
for help on using the changeset viewer.