Ignore:
Timestamp:
Feb 18, 2009 1:55:03 PM (15 years ago)
Author:
bennylp
Message:

Added WMME device in audiodev

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/pa_dev.c

    r2458 r2459  
    2727 
    2828#define THIS_FILE       "pa_dev.c" 
    29 #define DRIVER_NAME     "portaudio" 
     29#define DRIVER_NAME     "PA" 
    3030 
    3131struct pa_aud_factory 
     
    102102static unsigned     pa_get_dev_count(pjmedia_aud_dev_factory *f); 
    103103static pj_status_t  pa_get_dev_info(pjmedia_aud_dev_factory *f,  
    104                                     pjmedia_aud_dev_id id, 
     104                                    unsigned index, 
    105105                                    pjmedia_aud_dev_info *info); 
    106106static pj_status_t  pa_default_param(pjmedia_aud_dev_factory *f, 
    107                                      pjmedia_aud_dev_id id, 
     107                                     unsigned index, 
    108108                                     pjmedia_aud_dev_param *param); 
    109109static pj_status_t  pa_create_stream(pjmedia_aud_dev_factory *f, 
     
    190190        ++stream->overflow; 
    191191 
    192     stream->rec_timestamp.u64 += frameCount; 
    193  
    194192    /* Calculate number of samples we've got */ 
    195193    nsamples = frameCount * stream->channel_count + stream->rec_buf_count; 
     
    202200        if (stream->rec_buf_count) { 
    203201            unsigned chunk_count = 0; 
     202            pjmedia_frame frame; 
    204203         
    205204            chunk_count = stream->samples_per_frame - stream->rec_buf_count; 
    206205            pjmedia_copy_samples(stream->rec_buf + stream->rec_buf_count, 
    207206                                 (pj_int16_t*)input, chunk_count); 
    208             status = (*stream->rec_cb)(stream->user_data,  
    209                                        &stream->rec_timestamp, 
    210                                        (void*) stream->rec_buf,  
    211                                        stream->samples_per_frame *  
    212                                        stream->bytes_per_sample); 
     207 
     208            frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     209            frame.buf = (void*) stream->rec_buf; 
     210            frame.size = stream->samples_per_frame * stream->bytes_per_sample; 
     211            frame.timestamp.u64 = stream->rec_timestamp.u64; 
     212            frame.bit_info = 0; 
     213 
     214            status = (*stream->rec_cb)(stream->user_data, &frame); 
    213215 
    214216            input = (pj_int16_t*) input + chunk_count; 
    215217            nsamples -= stream->samples_per_frame; 
    216218            stream->rec_buf_count = 0; 
     219            stream->rec_timestamp.u64 += stream->samples_per_frame / 
     220                                         stream->channel_count; 
    217221        } 
    218222 
    219223        /* Give all frames we have */ 
    220224        while (nsamples >= stream->samples_per_frame && status == 0) { 
    221             status = (*stream->rec_cb)(stream->user_data,  
    222                                        &stream->rec_timestamp, 
    223                                        (void*) input,  
    224                                        stream->samples_per_frame *  
    225                                        stream->bytes_per_sample); 
     225            pjmedia_frame frame; 
     226 
     227            frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     228            frame.buf = (void*) input; 
     229            frame.size = stream->samples_per_frame * stream->bytes_per_sample; 
     230            frame.timestamp.u64 = stream->rec_timestamp.u64; 
     231            frame.bit_info = 0; 
     232 
     233            status = (*stream->rec_cb)(stream->user_data, &frame); 
     234 
    226235            input = (pj_int16_t*) input + stream->samples_per_frame; 
    227236            nsamples -= stream->samples_per_frame; 
     237            stream->rec_timestamp.u64 += stream->samples_per_frame / 
     238                                         stream->channel_count; 
    228239        } 
    229240 
     
    291302        ++stream->overflow; 
    292303 
    293     stream->play_timestamp.u64 += frameCount; 
    294304 
    295305    /* Check if any buffered samples */ 
     
    319329    while (nsamples_req && status == 0) { 
    320330        if (nsamples_req >= stream->samples_per_frame) { 
    321             status = (*stream->play_cb)(stream->user_data,  
    322                                         &stream->play_timestamp,  
    323                                         output,  
    324                                         stream->samples_per_frame *  
    325                                         stream->bytes_per_sample); 
     331            pjmedia_frame frame; 
     332 
     333            frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     334            frame.buf = output; 
     335            frame.size = stream->samples_per_frame *  stream->bytes_per_sample; 
     336            frame.timestamp.u64 = stream->play_timestamp.u64; 
     337            frame.bit_info = 0; 
     338 
     339            status = (*stream->play_cb)(stream->user_data, &frame); 
     340            if (status != PJ_SUCCESS) 
     341                goto on_break; 
     342 
     343            if (frame.type != PJMEDIA_FRAME_TYPE_AUDIO) 
     344                pj_bzero(frame.buf, frame.size); 
     345 
    326346            nsamples_req -= stream->samples_per_frame; 
    327347            output = (pj_int16_t*)output + stream->samples_per_frame; 
    328348        } else { 
    329             status = (*stream->play_cb)(stream->user_data,  
    330                                         &stream->play_timestamp,  
    331                                         stream->play_buf, 
    332                                         stream->samples_per_frame *  
    333                                         stream->bytes_per_sample); 
     349            pjmedia_frame frame; 
     350 
     351            frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 
     352            frame.buf = stream->play_buf; 
     353            frame.size = stream->samples_per_frame *  stream->bytes_per_sample; 
     354            frame.timestamp.u64 = stream->play_timestamp.u64; 
     355            frame.bit_info = 0; 
     356 
     357            status = (*stream->play_cb)(stream->user_data, &frame); 
     358            if (status != PJ_SUCCESS) 
     359                goto on_break; 
     360 
     361            if (frame.type != PJMEDIA_FRAME_TYPE_AUDIO) 
     362                pj_bzero(frame.buf, frame.size); 
     363 
    334364            pjmedia_copy_samples((pj_int16_t*)output, stream->play_buf,  
    335365                                 nsamples_req); 
     
    340370            nsamples_req = 0; 
    341371        } 
     372 
     373        stream->play_timestamp.u64 += stream->samples_per_frame / 
     374                                      stream->channel_count; 
    342375    } 
    343376     
     
    453486/* API: Get device info. */ 
    454487static pj_status_t  pa_get_dev_info(pjmedia_aud_dev_factory *f,  
    455                                     pjmedia_aud_dev_id id, 
     488                                    unsigned index, 
    456489                                    pjmedia_aud_dev_info *info) 
    457490{ 
     
    460493    PJ_UNUSED_ARG(f); 
    461494 
    462     pa_info = Pa_GetDeviceInfo(id); 
     495    pa_info = Pa_GetDeviceInfo(index); 
    463496    if (!pa_info) 
    464497        return PJMEDIA_EAUD_INVDEV; 
     
    481514/* API: fill in with default parameter. */ 
    482515static pj_status_t  pa_default_param(pjmedia_aud_dev_factory *f, 
    483                                      pjmedia_aud_dev_id id, 
     516                                     unsigned index, 
    484517                                     pjmedia_aud_dev_param *param) 
    485518{ 
     
    489522    PJ_UNUSED_ARG(f); 
    490523 
    491     status = pjmedia_aud_dev_get_info(id, &adi); 
     524    status = pa_get_dev_info(f, index, &adi); 
    492525    if (status != PJ_SUCCESS) 
    493526        return status; 
     
    496529    if (adi.input_count && adi.output_count) { 
    497530        param->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 
    498         param->rec_id = id; 
    499         param->play_id = id; 
     531        param->rec_id = index; 
     532        param->play_id = index; 
    500533    } else if (adi.input_count) { 
    501534        param->dir = PJMEDIA_DIR_CAPTURE; 
    502         param->rec_id = id; 
     535        param->rec_id = index; 
    503536        param->play_id = PJMEDIA_AUD_DEV_DEFAULT_ID; 
    504537    } else if (adi.output_count) { 
    505538        param->dir = PJMEDIA_DIR_PLAYBACK; 
    506         param->play_id = id; 
     539        param->play_id = index; 
    507540        param->rec_id = PJMEDIA_AUD_DEV_DEFAULT_ID; 
    508541    } else { 
     
    10801113        pi->flags |= PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY; 
    10811114        pi->input_latency_ms = (unsigned)(paRecSI ? paRecSI->inputLatency *  
    1082                                                     paRecSI->sampleRate : 0); 
     1115                                                    1000 : 0); 
    10831116    } 
    10841117    if (paPlaySI) { 
    10851118        pi->flags |= PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY; 
    10861119        pi->output_latency_ms = (unsigned)(paPlaySI? paPlaySI->outputLatency *  
    1087                                                      paPlaySI->sampleRate : 0); 
     1120                                                     1000 : 0); 
    10881121    } 
    10891122 
     
    11061139            return PJ_EINVALIDOP; 
    11071140 
    1108         *(unsigned*)pval = (unsigned)(si->inputLatency * si->sampleRate); 
     1141        *(unsigned*)pval = (unsigned)(si->inputLatency * 1000); 
    11091142        return PJ_SUCCESS; 
    11101143    } else if (cap==PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY && strm->play_strm) { 
     
    11131146            return PJ_EINVALIDOP; 
    11141147 
    1115         *(unsigned*)pval = (unsigned)(si->outputLatency * si->sampleRate); 
     1148        *(unsigned*)pval = (unsigned)(si->outputLatency * 1000); 
    11161149        return PJ_SUCCESS; 
    11171150    } else { 
Note: See TracChangeset for help on using the changeset viewer.