- Timestamp:
- Dec 30, 2010 4:31:16 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/aviplay.c
r3401 r3402 91 91 { 92 92 pjmedia_vid_port *vid_port; 93 pjmedia_ aud_stream *aud_stream;93 pjmedia_snd_port *snd_port; 94 94 pj_bool_t is_running; 95 95 pj_bool_t is_quitting; … … 105 105 pjmedia_converter *conv; 106 106 } codec_port_data_t; 107 108 static pj_status_t avi_play_cb(void *user_data, pjmedia_frame *frame)109 {110 return pjmedia_port_get_frame((pjmedia_port*)user_data, frame);111 }112 107 113 108 static pj_status_t avi_event_cb(pjmedia_vid_stream *stream, … … 126 121 if (ap->is_running) { 127 122 pjmedia_vid_port_stop(ap->vid_port); 128 if (ap->aud_stream) 129 pjmedia_aud_stream_stop(ap->aud_stream); 123 if (ap->snd_port) 124 pjmedia_aud_stream_stop( 125 pjmedia_snd_port_get_snd_stream(ap->snd_port)); 130 126 } else { 131 127 pjmedia_vid_port_start(ap->vid_port); 132 if (ap->aud_stream) 133 pjmedia_aud_stream_start(ap->aud_stream); 128 if (ap->snd_port) 129 pjmedia_aud_stream_start( 130 pjmedia_snd_port_get_snd_stream(ap->snd_port)); 134 131 } 135 132 ap->is_running = !ap->is_running; … … 187 184 pjmedia_vid_port *renderer=NULL; 188 185 pjmedia_vid_port_param param; 189 pjmedia_aud_param aparam;190 186 const pjmedia_video_format_info *vfi; 191 187 pjmedia_video_format_detail *vfd; 192 pjmedia_audio_format_detail *afd; 193 pjmedia_aud_stream *strm = NULL; 188 pjmedia_snd_port *snd_port = NULL; 194 189 pj_status_t status; 195 190 int rc = 0; … … 376 371 377 372 if (aud_port) { 378 status = pjmedia_aud_dev_default_param( 379 PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV, 380 &aparam); 373 /* Create sound player port. */ 374 status = pjmedia_snd_port_create_player( 375 pool, /* pool */ 376 -1, /* use default dev. */ 377 PJMEDIA_PIA_SRATE(&aud_port->info),/* clock rate. */ 378 PJMEDIA_PIA_CCNT(&aud_port->info), /* # of channels. */ 379 PJMEDIA_PIA_SPF(&aud_port->info), /* samples per frame. */ 380 PJMEDIA_PIA_BITS(&aud_port->info), /* bits per sample. */ 381 0, /* options */ 382 &snd_port /* returned port */ 383 ); 381 384 if (status != PJ_SUCCESS) { 382 385 rc = 310; goto on_return; 383 386 } 384 387 385 aparam.dir = PJMEDIA_DIR_PLAYBACK; 386 afd = pjmedia_format_get_audio_format_detail(&aud_port->info.fmt, 387 PJ_TRUE); 388 aparam.clock_rate = afd->clock_rate; 389 aparam.channel_count = afd->channel_count; 390 aparam.bits_per_sample = afd->bits_per_sample; 391 aparam.samples_per_frame = afd->frame_time_usec * aparam.clock_rate * 392 aparam.channel_count / 1000000; 393 394 status = pjmedia_aud_stream_create(&aparam, NULL, &avi_play_cb, 395 aud_port, 396 &strm); 397 if (status != PJ_SUCCESS) { 398 rc = 320; goto on_return; 399 } 400 401 /* Start audio streaming.. */ 402 status = pjmedia_aud_stream_start(strm); 388 /* Connect file port to the sound player. 389 * Stream playing will commence immediately. 390 */ 391 status = pjmedia_snd_port_connect(snd_port, aud_port); 403 392 if (status != PJ_SUCCESS) { 404 393 rc = 330; goto on_return; … … 411 400 pj_bzero(&cb, sizeof(cb)); 412 401 cb.on_event_cb = avi_event_cb; 413 avi_port. aud_stream = strm;402 avi_port.snd_port = snd_port; 414 403 avi_port.vid_port = renderer; 415 404 avi_port.is_running = PJ_TRUE; 416 405 pjmedia_vid_port_set_cb(renderer, &cb, &avi_port); 406 407 if (snd_port) { 408 /* Synchronize video rendering and audio playback */ 409 pjmedia_vid_port_set_clock_src( 410 renderer, PJMEDIA_DIR_RENDER, 411 pjmedia_snd_port_get_clock_src( 412 snd_port, PJMEDIA_DIR_PLAYBACK)); 413 } 414 417 415 418 416 /* Start video streaming.. */ … … 428 426 429 427 on_return: 430 if (strm) { 431 pjmedia_aud_stream_stop(strm); 432 pjmedia_aud_stream_destroy(strm); 428 if (snd_port) { 429 pjmedia_snd_port_disconnect(snd_port); 430 /* Without this sleep, Windows/DirectSound will repeteadly 431 * play the last frame during destroy. 432 */ 433 pj_thread_sleep(100); 434 pjmedia_snd_port_destroy(snd_port); 433 435 } 434 436 if (renderer) 435 437 pjmedia_vid_port_destroy(renderer); 438 if (aud_port) 439 pjmedia_port_destroy(aud_port); 436 440 if (vid_port) 437 441 pjmedia_port_destroy(vid_port);
Note: See TracChangeset
for help on using the changeset viewer.