Changeset 762 for pjproject


Ignore:
Timestamp:
Oct 11, 2006 2:57:18 PM (18 years ago)
Author:
bennylp
Message:

Changed pasound.c to open multiple streams when input/output are on different devices

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/pasound.c

    r760 r762  
    5151    int                  channel_count; 
    5252 
    53     PaStream            *stream; 
     53    PaStream            *rec_strm; 
     54    PaStream            *play_strm; 
     55 
    5456    void                *user_data; 
    5557    pjmedia_snd_rec_cb   rec_cb; 
     
    387389    paFrames = samples_per_frame / channel_count; 
    388390 
    389     err = Pa_OpenStream( &stream->stream, &inputParam, NULL, 
     391    err = Pa_OpenStream( &stream->rec_strm, &inputParam, NULL, 
    390392                         clock_rate, paFrames,  
    391393                         paClipOff, &PaRecorderCallback, stream ); 
     
    395397    } 
    396398 
    397     paSI = Pa_GetStreamInfo(stream->stream); 
     399    paSI = Pa_GetStreamInfo(stream->rec_strm); 
    398400    paRate = (unsigned)paSI->sampleRate; 
    399401    paLatency = (unsigned)(paSI->inputLatency * 1000); 
     
    483485    paFrames = samples_per_frame / channel_count; 
    484486 
    485     err = Pa_OpenStream( &stream->stream, NULL, &outputParam, 
     487    err = Pa_OpenStream( &stream->play_strm, NULL, &outputParam, 
    486488                         clock_rate,  paFrames,  
    487489                         paClipOff, &PaPlayerCallback, stream ); 
     
    491493    } 
    492494 
    493     paSI = Pa_GetStreamInfo(stream->stream); 
     495    paSI = Pa_GetStreamInfo(stream->play_strm); 
    494496    paRate = (unsigned)(paSI->sampleRate); 
    495497    paLatency = (unsigned)(paSI->outputLatency * 1000); 
     
    524526    pj_pool_t *pool; 
    525527    pjmedia_snd_stream *stream; 
     528    PaStream *paStream = NULL; 
    526529    PaStreamParameters inputParam; 
    527530    PaStreamParameters outputParam; 
     
    612615    paFrames = samples_per_frame / channel_count; 
    613616 
    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 
    617651    if (err != paNoError) { 
    618652        pj_pool_release(pool); 
     
    620654    } 
    621655 
    622     paSI = Pa_GetStreamInfo(stream->stream); 
     656    paSI = Pa_GetStreamInfo(stream->rec_strm); 
    623657    paRate = (unsigned)(paSI->sampleRate); 
    624658    paInputLatency = (unsigned)(paSI->inputLatency * 1000); 
     659    paSI = Pa_GetStreamInfo(stream->play_strm); 
    625660    paOutputLatency = (unsigned)(paSI->outputLatency * 1000); 
    626661 
     
    648683                                                pjmedia_snd_stream_info *pi) 
    649684{ 
    650     const PaStreamInfo *paSI; 
     685    const PaStreamInfo *paPlaySI = NULL, *paRecSI = NULL; 
    651686 
    652687    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    } 
    656696 
    657697    pj_bzero(pi, sizeof(*pi)); 
     
    659699    pi->play_id = strm->play_id; 
    660700    pi->rec_id = strm->rec_id; 
    661     pi->clock_rate = (unsigned)(paSI->sampleRate); 
     701    pi->clock_rate = (unsigned)(paPlaySI ? paPlaySI->sampleRate :  
     702                                paRecSI->sampleRate); 
    662703    pi->channel_count = strm->channel_count; 
    663704    pi->samples_per_frame = strm->samples_per_frame; 
    664705    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); 
    667710 
    668711    return PJ_SUCCESS; 
     
    675718PJ_DEF(pj_status_t) pjmedia_snd_stream_start(pjmedia_snd_stream *stream) 
    676719{ 
    677     pj_status_t err; 
     720    int err = 0; 
    678721 
    679722    PJ_LOG(5,(THIS_FILE, "Starting %s stream..", stream->name.ptr)); 
    680723 
    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    } 
    682732 
    683733    PJ_LOG(5,(THIS_FILE, "Done, status=%d", err)); 
     
    691741PJ_DEF(pj_status_t) pjmedia_snd_stream_stop(pjmedia_snd_stream *stream) 
    692742{ 
    693     int i, err; 
     743    int i, err = 0; 
    694744 
    695745    stream->quit_flag = 1; 
     
    701751    PJ_LOG(5,(THIS_FILE, "Stopping stream..")); 
    702752 
    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); 
    704758 
    705759    PJ_LOG(5,(THIS_FILE, "Done, status=%d", err)); 
     
    713767PJ_DEF(pj_status_t) pjmedia_snd_stream_close(pjmedia_snd_stream *stream) 
    714768{ 
    715     int i, err; 
     769    int i, err = 0; 
    716770 
    717771    stream->quit_flag = 1; 
     
    725779                         stream->underflow, stream->overflow)); 
    726780 
    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 
    728787    pj_pool_release(stream->pool); 
    729788 
Note: See TracChangeset for help on using the changeset viewer.