Changeset 1776
- Timestamp:
- Feb 3, 2008 4:59:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/jbuf2/pjsip-apps/src/samples/jbtest.c
r1772 r1776 34 34 pjmedia_port *read_port; 35 35 pjmedia_port *write_port; 36 pjmedia_resample *resampler; 36 37 pj_lock_t *mutex; 37 38 pj_int16_t seq; … … 45 46 " \n" 46 47 " PURPOSE: \n" 47 " Test jbuf2 with real sound device.\n"48 " Test drift compensation of jbuf2 with real sound device.\n" 48 49 " \n" 49 50 " USAGE: \n" 50 51 " sndtest --help \n" 51 " sndtest [options] 52 " sndtest [options] wavfile \n" 52 53 " \n" 53 54 " options: \n" 54 55 " --id=ID -i Use device ID (default is -1) \n" 55 56 " --rate=HZ -r Set test clock rate (default=8000)\n" 56 " --file=FILENAME -l Set input filename \n"57 57 " --drift=N -d Set clock drift (-2000 < N < 2000)\n" 58 58 " --verbose -v Show verbose result \n" … … 100 100 pjmedia_frame f_; 101 101 pj_status_t status; 102 char buf[ 1024];102 char buf[5*1024]; 103 103 104 104 PJ_UNUSED_ARG(ts); … … 107 107 108 108 f_.buf = buf; 109 f_.size = test_data-> samples_per_frame*2;109 f_.size = test_data->read_port->info.bytes_per_frame; 110 110 status = pjmedia_port_get_frame(test_data->read_port, &f_); 111 111 if (status != PJ_SUCCESS) { … … 115 115 116 116 test_data->seq++; 117 test_data->ts += test_data-> samples_per_frame;117 test_data->ts += test_data->read_port->info.samples_per_frame; 118 118 119 119 f.buffer = f_.buf; … … 137 137 pjmedia_frame f_; 138 138 pj_status_t status; 139 char buf[5*1024]; 139 140 140 141 PJ_UNUSED_ARG(timestamp); 141 142 PJ_ASSERT_RETURN(test_data, PJ_EINVAL); 142 143 143 f.buffer = output; 144 f.size = size; 144 f.buffer = test_data->resampler? buf : output; 145 f.size = sizeof(buf); 146 145 147 pj_lock_acquire(test_data->mutex); 146 148 pjmedia_jb2_get_frame(test_data->jb, &f); 147 149 pj_lock_release(test_data->mutex); 148 150 149 f_.buf = f.buffer; 150 f_.size = f.size; 151 if (test_data->resampler) 152 pjmedia_resample_run(test_data->resampler, f.buffer, output); 153 154 f_.buf = output; 155 f_.size = size; 151 156 f_.type = PJMEDIA_FRAME_TYPE_AUDIO; 152 157 f_.timestamp.u64 = f.ts; … … 187 192 test_data.clock_rate = clock_rate; 188 193 test_data.samples_per_frame = samples_per_frame; 189 190 jb_setting.max_frames = 0;191 jb_setting.samples_per_frame = samples_per_frame;192 jb_setting.frame_size = samples_per_frame * 2;193 194 pj_bzero(&jb_cb, sizeof(jb_cb));195 194 196 195 pj_lock_create_recursive_mutex(pool, "sndtest", &test_data.mutex); … … 210 209 } 211 210 212 PJ_TODO(wav_nchannel_validation); 213 PJ_TODO(resample); 211 if (test_data.read_port->info.channel_count != 1) { 212 app_perror("WAV file not mono.", status); 213 return PJ_EINVAL; 214 } 215 216 /* Init JB setting */ 217 pj_bzero(&jb_setting, sizeof(jb_setting)); 218 jb_setting.max_frames = 0; 219 jb_setting.samples_per_frame = test_data.read_port->info.samples_per_frame; 220 jb_setting.frame_size = test_data.read_port->info.bytes_per_frame; 221 222 /* Init JB callback */ 223 pj_bzero(&jb_cb, sizeof(jb_cb)); 224 225 /* Create jitter buffer */ 226 status = pjmedia_jb2_create(pool, NULL, &jb_setting, &jb_cb, &test_data.jb); 227 if (status != PJ_SUCCESS) { 228 app_perror("Unable to create jitter buffer", status); 229 return status; 230 } 231 232 /* Create the resample port when needed. */ 233 if (test_data.read_port->info.clock_rate != clock_rate) { 234 status = pjmedia_resample_create( pool, PJ_TRUE, PJ_FALSE, 1, 235 test_data.read_port->info.clock_rate, 236 clock_rate, 237 jb_setting.samples_per_frame, 238 &test_data.resampler); 239 if (status != PJ_SUCCESS) { 240 app_perror("Unable to create resample port", status); 241 return 1; 242 } 243 } else { 244 test_data.resampler = NULL; 245 } 214 246 215 247 /* Create WAV writer port */ … … 224 256 } 225 257 226 /* Create jitter buffer */227 status = pjmedia_jb2_create(pool, NULL, &jb_setting, &jb_cb, &test_data.jb);228 if (status != PJ_SUCCESS) {229 app_perror("Unable to create jitter buffer", status);230 return status;231 }232 233 258 /* Create media clock */ 234 259 status = pjmedia_clock_create(pool, clock_rate + drift, samples_per_frame, … … 254 279 pjmedia_snd_stream_get_info(strm, &si); 255 280 if (si.play_id >= 0) { 256 PJ_LOG(3,(THIS_FILE, "Testing playback device %s ",281 PJ_LOG(3,(THIS_FILE, "Testing playback device %s:", 257 282 pjmedia_snd_get_dev_info(si.play_id)->name)); 283 PJ_LOG(4,(THIS_FILE, "Channel: %d clock: %dhz samples/frame: %d", 284 si.channel_count, si.clock_rate, si.samples_per_frame)); 258 285 } 259 286 … … 312 339 pjmedia_clock_destroy(clock); 313 340 341 /* Destroy resample */ 342 if (test_data.resampler) 343 pjmedia_resample_destroy(test_data.resampler); 344 314 345 /* Destroy file port */ 315 346 pjmedia_port_destroy(test_data.read_port); … … 335 366 { "id", 1, 0, 'i' }, 336 367 { "rate", 1, 0, 'r' }, 337 { "file", 1, 0, 'l' },338 368 { "drift", 1, 0, 'd' }, 339 369 { "verbose", 0, 0, 'v' }, … … 381 411 drift = atoi(pj_optarg); 382 412 break; 383 case 'l':384 inputfile = pj_optarg;385 break;386 413 case 'v': 387 414 verbose = 1; … … 398 425 } 399 426 400 if ( pj_optind != argc) {427 if ((argc - pj_optind) != 1) { 401 428 printf("Error: invalid options\n"); 402 429 puts(desc); 403 430 return 1; 404 431 } 432 433 inputfile = argv[argc - 1]; 405 434 406 435 if (!verbose) … … 409 438 pj_log_set_level(4); 410 439 411 412 440 status = perform_test(pool, inputfile, id, clock_rate, drift); 413 441
Note: See TracChangeset
for help on using the changeset viewer.