Changeset 762 for pjproject/trunk
- Timestamp:
- Oct 11, 2006 2:57:18 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/pasound.c
r760 r762 51 51 int channel_count; 52 52 53 PaStream *stream; 53 PaStream *rec_strm; 54 PaStream *play_strm; 55 54 56 void *user_data; 55 57 pjmedia_snd_rec_cb rec_cb; … … 387 389 paFrames = samples_per_frame / channel_count; 388 390 389 err = Pa_OpenStream( &stream-> stream, &inputParam, NULL,391 err = Pa_OpenStream( &stream->rec_strm, &inputParam, NULL, 390 392 clock_rate, paFrames, 391 393 paClipOff, &PaRecorderCallback, stream ); … … 395 397 } 396 398 397 paSI = Pa_GetStreamInfo(stream-> stream);399 paSI = Pa_GetStreamInfo(stream->rec_strm); 398 400 paRate = (unsigned)paSI->sampleRate; 399 401 paLatency = (unsigned)(paSI->inputLatency * 1000); … … 483 485 paFrames = samples_per_frame / channel_count; 484 486 485 err = Pa_OpenStream( &stream-> stream, NULL, &outputParam,487 err = Pa_OpenStream( &stream->play_strm, NULL, &outputParam, 486 488 clock_rate, paFrames, 487 489 paClipOff, &PaPlayerCallback, stream ); … … 491 493 } 492 494 493 paSI = Pa_GetStreamInfo(stream-> stream);495 paSI = Pa_GetStreamInfo(stream->play_strm); 494 496 paRate = (unsigned)(paSI->sampleRate); 495 497 paLatency = (unsigned)(paSI->outputLatency * 1000); … … 524 526 pj_pool_t *pool; 525 527 pjmedia_snd_stream *stream; 528 PaStream *paStream = NULL; 526 529 PaStreamParameters inputParam; 527 530 PaStreamParameters outputParam; … … 612 615 paFrames = samples_per_frame / channel_count; 613 616 614 err = Pa_OpenStream( &stream->stream, &inputParam, &outputParam, 615 clock_rate, paFrames, 616 paClipOff, &PaRecorderPlayerCallback, stream ); 617 /* If both input and output are on the same device, open a single stream 618 * for both input and output. 619 */ 620 if (rec_id == play_id) { 621 err = Pa_OpenStream( &paStream, &inputParam, &outputParam, 622 clock_rate, paFrames, 623 paClipOff, &PaRecorderPlayerCallback, stream ); 624 if (err == paNoError) { 625 /* Set play stream and record stream to the same stream */ 626 stream->play_strm = stream->rec_strm = paStream; 627 } 628 } else { 629 err = -1; 630 } 631 632 /* .. otherwise if input and output are on the same device, OR if we're 633 * unable to open a bidirectional stream, then open two separate 634 * input and output stream. 635 */ 636 if (paStream == NULL) { 637 /* Open input stream */ 638 err = Pa_OpenStream( &stream->rec_strm, &inputParam, NULL, 639 clock_rate, paFrames, 640 paClipOff, &PaRecorderCallback, stream ); 641 if (err == paNoError) { 642 /* Open output stream */ 643 err = Pa_OpenStream( &stream->play_strm, NULL, &outputParam, 644 clock_rate, paFrames, 645 paClipOff, &PaPlayerCallback, stream ); 646 if (err != paNoError) 647 Pa_CloseStream(stream->rec_strm); 648 } 649 } 650 617 651 if (err != paNoError) { 618 652 pj_pool_release(pool); … … 620 654 } 621 655 622 paSI = Pa_GetStreamInfo(stream-> stream);656 paSI = Pa_GetStreamInfo(stream->rec_strm); 623 657 paRate = (unsigned)(paSI->sampleRate); 624 658 paInputLatency = (unsigned)(paSI->inputLatency * 1000); 659 paSI = Pa_GetStreamInfo(stream->play_strm); 625 660 paOutputLatency = (unsigned)(paSI->outputLatency * 1000); 626 661 … … 648 683 pjmedia_snd_stream_info *pi) 649 684 { 650 const PaStreamInfo *pa SI;685 const PaStreamInfo *paPlaySI = NULL, *paRecSI = NULL; 651 686 652 687 PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL); 653 PJ_ASSERT_RETURN(strm->stream, PJ_EINVALIDOP); 654 655 paSI = Pa_GetStreamInfo(strm->stream); 688 PJ_ASSERT_RETURN(strm->play_strm || strm->rec_strm, PJ_EINVALIDOP); 689 690 if (strm->play_strm) { 691 paPlaySI = Pa_GetStreamInfo(strm->play_strm); 692 } 693 if (strm->rec_strm) { 694 paRecSI = Pa_GetStreamInfo(strm->rec_strm); 695 } 656 696 657 697 pj_bzero(pi, sizeof(*pi)); … … 659 699 pi->play_id = strm->play_id; 660 700 pi->rec_id = strm->rec_id; 661 pi->clock_rate = (unsigned)(paSI->sampleRate); 701 pi->clock_rate = (unsigned)(paPlaySI ? paPlaySI->sampleRate : 702 paRecSI->sampleRate); 662 703 pi->channel_count = strm->channel_count; 663 704 pi->samples_per_frame = strm->samples_per_frame; 664 705 pi->bits_per_sample = strm->bytes_per_sample * 8; 665 pi->rec_latency = (unsigned)(paSI->inputLatency * paSI->sampleRate); 666 pi->play_latency = (unsigned)(paSI->outputLatency * paSI->sampleRate); 706 pi->rec_latency = (unsigned)(paRecSI ? paRecSI->inputLatency * 707 paRecSI->sampleRate : 0); 708 pi->play_latency = (unsigned)(paPlaySI ? paPlaySI->outputLatency * 709 paPlaySI->sampleRate : 0); 667 710 668 711 return PJ_SUCCESS; … … 675 718 PJ_DEF(pj_status_t) pjmedia_snd_stream_start(pjmedia_snd_stream *stream) 676 719 { 677 pj_status_t err;720 int err = 0; 678 721 679 722 PJ_LOG(5,(THIS_FILE, "Starting %s stream..", stream->name.ptr)); 680 723 681 err = Pa_StartStream(stream->stream); 724 if (stream->play_strm) 725 err = Pa_StartStream(stream->play_strm); 726 727 if (err==0 && stream->rec_strm && stream->rec_strm != stream->play_strm) { 728 err = Pa_StartStream(stream->rec_strm); 729 if (err != 0) 730 Pa_StopStream(stream->play_strm); 731 } 682 732 683 733 PJ_LOG(5,(THIS_FILE, "Done, status=%d", err)); … … 691 741 PJ_DEF(pj_status_t) pjmedia_snd_stream_stop(pjmedia_snd_stream *stream) 692 742 { 693 int i, err ;743 int i, err = 0; 694 744 695 745 stream->quit_flag = 1; … … 701 751 PJ_LOG(5,(THIS_FILE, "Stopping stream..")); 702 752 703 err = Pa_StopStream(stream->stream); 753 if (stream->play_strm) 754 err = Pa_StopStream(stream->play_strm); 755 756 if (stream->rec_strm && stream->rec_strm != stream->play_strm) 757 err = Pa_StopStream(stream->rec_strm); 704 758 705 759 PJ_LOG(5,(THIS_FILE, "Done, status=%d", err)); … … 713 767 PJ_DEF(pj_status_t) pjmedia_snd_stream_close(pjmedia_snd_stream *stream) 714 768 { 715 int i, err ;769 int i, err = 0; 716 770 717 771 stream->quit_flag = 1; … … 725 779 stream->underflow, stream->overflow)); 726 780 727 err = Pa_CloseStream(stream->stream); 781 if (stream->play_strm) 782 err = Pa_CloseStream(stream->play_strm); 783 784 if (stream->rec_strm && stream->rec_strm != stream->play_strm) 785 err = Pa_CloseStream(stream->rec_strm); 786 728 787 pj_pool_release(stream->pool); 729 788
Note: See TracChangeset
for help on using the changeset viewer.