- Timestamp:
- Feb 19, 2009 12:08:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/aps-direct/pjsip-apps/src/samples/auddemo.c
r2463 r2464 26 26 #define THIS_FILE "auddemo.c" 27 27 #define MAX_DEVICES 64 28 #define WAV_FILE "auddemo.wav" 28 29 29 30 … … 167 168 char bitrate[32]; 168 169 169 switch (info.ext_fmt[i]. fmt_id) {170 switch (info.ext_fmt[i].id) { 170 171 case PJMEDIA_FORMAT_L16: 171 172 strcat(formats, "L16/"); … … 273 274 } 274 275 } 276 } 277 278 279 static pj_status_t wav_rec_cb(void *user_data, pjmedia_frame *frame) 280 { 281 return pjmedia_port_put_frame((pjmedia_port*)user_data, frame); 282 } 283 284 static void record(unsigned rec_index, const char *filename) 285 { 286 pj_pool_t *pool = NULL; 287 pjmedia_port *wav = NULL; 288 pjmedia_aud_dev_param param; 289 pjmedia_aud_stream *strm = NULL; 290 char line[10]; 291 pj_status_t status; 292 293 if (filename == NULL) 294 filename = WAV_FILE; 295 296 pool = pj_pool_create(pjmedia_aud_subsys_get_pool_factory(), "wav", 297 1000, 1000, NULL); 298 299 status = pjmedia_wav_writer_port_create(pool, filename, 16000, 300 1, 320, 16, 0, 0, &wav); 301 if (status != PJ_SUCCESS) { 302 app_perror("Error creating WAV file", status); 303 goto on_return; 304 } 305 306 status = pjmedia_aud_dev_default_param(dev_id[rec_index], ¶m); 307 if (status != PJ_SUCCESS) { 308 app_perror("pjmedia_aud_dev_default_param()", status); 309 goto on_return; 310 } 311 312 param.dir = PJMEDIA_DIR_CAPTURE; 313 param.clock_rate = wav->info.clock_rate; 314 param.samples_per_frame = wav->info.samples_per_frame; 315 param.channel_count = wav->info.channel_count; 316 param.bits_per_sample = wav->info.bits_per_sample; 317 318 status = pjmedia_aud_stream_create(¶m, &wav_rec_cb, NULL, wav, 319 &strm); 320 if (status != PJ_SUCCESS) { 321 app_perror("Error opening the sound device", status); 322 goto on_return; 323 } 324 325 status = pjmedia_aud_stream_start(strm); 326 if (status != PJ_SUCCESS) { 327 app_perror("Error starting the sound device", status); 328 goto on_return; 329 } 330 331 PJ_LOG(3,(THIS_FILE, "Recording started, press ENTER to stop")); 332 fgets(line, sizeof(line), stdin); 333 334 on_return: 335 if (strm) { 336 pjmedia_aud_stream_stop(strm); 337 pjmedia_aud_stream_destroy(strm); 338 } 339 if (wav) 340 pjmedia_port_destroy(wav); 341 if (pool) 342 pj_pool_release(pool); 343 } 344 345 346 static pj_status_t wav_play_cb(void *user_data, pjmedia_frame *frame) 347 { 348 return pjmedia_port_get_frame((pjmedia_port*)user_data, frame); 349 } 350 351 352 static void play_file(unsigned play_index, const char *filename) 353 { 354 pj_pool_t *pool = NULL; 355 pjmedia_port *wav = NULL; 356 pjmedia_aud_dev_param param; 357 pjmedia_aud_stream *strm = NULL; 358 char line[10]; 359 pj_status_t status; 360 361 if (filename == NULL) 362 filename = WAV_FILE; 363 364 pool = pj_pool_create(pjmedia_aud_subsys_get_pool_factory(), "wav", 365 1000, 1000, NULL); 366 367 status = pjmedia_wav_player_port_create(pool, filename, 20, 0, 0, &wav); 368 if (status != PJ_SUCCESS) { 369 app_perror("Error opening WAV file", status); 370 goto on_return; 371 } 372 373 status = pjmedia_aud_dev_default_param(dev_id[play_index], ¶m); 374 if (status != PJ_SUCCESS) { 375 app_perror("pjmedia_aud_dev_default_param()", status); 376 goto on_return; 377 } 378 379 param.dir = PJMEDIA_DIR_PLAYBACK; 380 param.clock_rate = wav->info.clock_rate; 381 param.samples_per_frame = wav->info.samples_per_frame; 382 param.channel_count = wav->info.channel_count; 383 param.bits_per_sample = wav->info.bits_per_sample; 384 385 status = pjmedia_aud_stream_create(¶m, NULL, &wav_play_cb, wav, 386 &strm); 387 if (status != PJ_SUCCESS) { 388 app_perror("Error opening the sound device", status); 389 goto on_return; 390 } 391 392 status = pjmedia_aud_stream_start(strm); 393 if (status != PJ_SUCCESS) { 394 app_perror("Error starting the sound device", status); 395 goto on_return; 396 } 397 398 PJ_LOG(3,(THIS_FILE, "Playback started, press ENTER to stop")); 399 fgets(line, sizeof(line), stdin); 400 401 on_return: 402 if (strm) { 403 pjmedia_aud_stream_stop(strm); 404 pjmedia_aud_stream_destroy(strm); 405 } 406 if (wav) 407 pjmedia_port_destroy(wav); 408 if (pool) 409 pj_pool_release(pool); 275 410 } 276 411 … … 289 424 puts(" PTIM: ptime in ms"); 290 425 puts(" CH: # of channels"); 426 puts(" r RID [FILE] Record capture device RID to WAV file"); 427 puts(" p PID [FILE] Playback WAV file to device ID PID"); 291 428 puts(" v Toggle log verbosity"); 292 429 puts(" q Quit"); … … 392 529 break; 393 530 531 case 'r': 532 /* record */ 533 { 534 int index; 535 char filename[80]; 536 int count; 537 538 count = sscanf(line+2, "%d %s", &index, filename); 539 if (count==1) 540 record(index, NULL); 541 else if (count==2) 542 record(index, filename); 543 else 544 puts("error: invalid command syntax"); 545 } 546 break; 547 548 case 'p': 549 /* playback */ 550 { 551 int index; 552 char filename[80]; 553 int count; 554 555 count = sscanf(line+2, "%d %s", &index, filename); 556 if (count==1) 557 play_file(index, NULL); 558 else if (count==2) 559 play_file(index, filename); 560 else 561 puts("error: invalid command syntax"); 562 } 563 break; 564 394 565 case 'v': 395 566 if (pj_log_get_level() <= 3) {
Note: See TracChangeset
for help on using the changeset viewer.