Changeset 2459


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

Added WMME device in audiodev

Location:
pjproject/branches/projects/aps-direct/pjmedia
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/pjmedia/build/pjmedia_audiodev.dsp

    r2458 r2459  
    9696SOURCE="..\src\pjmedia-audiodev\pa_dev.c" 
    9797# End Source File 
     98# Begin Source File 
     99 
     100SOURCE="..\src\pjmedia-audiodev\wmme_dev.c" 
     101# End Source File 
    98102# End Group 
    99103# Begin Group "Header Files" 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia-audiodev/audiodev.h

    r2458 r2459  
    2525 * @brief Audio device API. 
    2626 */ 
    27 #include <pjmedia/types.h> 
     27#include <pjmedia/port.h> 
    2828#include <pj/pool.h> 
    2929 
     
    100100 
    101101    /**  
    102      * Support for setting the audio device volume level. The value of this 
    103      * capability is an unsigned integer representing the audio volume in  
    104      * percent. 
    105      */ 
    106     PJMEDIA_AUD_DEV_CAP_SET_VOLUME = 8, 
    107  
    108     /**  
    109      * Support for audio volume level query. The value of this capability  
    110      * is unsigned integer representing the audio volume in percent. 
    111      */ 
    112     PJMEDIA_AUD_DEV_CAP_GET_VOLUME = 16, 
    113  
    114     /**  
    115      * Support for audio routing (e.g. loudspeaker vs earpiece). The value 
    116      * of this capability is an integer containing #pjmedia_aud_dev_route 
     102     * Support for setting/retrieving the audio input device volume level. 
     103     * The value of this capability is an unsigned integer representing  
     104     * the input audio volume setting in percent. 
     105     */ 
     106    PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING = 8, 
     107 
     108    /**  
     109     * Support for setting/retrieving the audio output device volume level. 
     110     * The value of this capability is an unsigned integer representing  
     111     * the output audio volume setting in percent. 
     112     */ 
     113    PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING = 16, 
     114 
     115    /**  
     116     * Support for monitoring the current audio input signal volume.  
     117     * The value of this capability is an unsigned integer representing  
     118     * the audio volume in percent. 
     119     */ 
     120    PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_VOLUME = 32, 
     121 
     122    /**  
     123     * Support for monitoring the current audio output signal volume.  
     124     * The value of this capability is an unsigned integer representing  
     125     * the audio volume in percent. 
     126     */ 
     127    PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_VOLUME = 64, 
     128 
     129    /**  
     130     * Support for audio input routing. The value of this capability is an  
     131     * integer containing #pjmedia_aud_dev_route enumeration. 
     132     */ 
     133    PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128, 
     134 
     135    /**  
     136     * Support for audio output routing (e.g. loudspeaker vs earpiece). The 
     137     * value of this capability is an integer containing #pjmedia_aud_dev_route 
    117138     * enumeration. 
    118139     */ 
    119     PJMEDIA_AUD_DEV_CAP_ROUTE = 32, 
     140    PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE = 256, 
    120141 
    121142    /**  
     
    123144     * capability is an integer containing boolean PJ_TRUE or PJ_FALSE. 
    124145     */ 
    125     PJMEDIA_AUD_DEV_CAP_EC = 64, 
     146    PJMEDIA_AUD_DEV_CAP_EC = 512, 
    126147 
    127148    /**  
     
    130151     * echo tail in milliseconds. 
    131152     */ 
    132     PJMEDIA_AUD_DEV_CAP_EC_TAIL = 128, 
     153    PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1024, 
    133154 
    134155    /**  
     
    137158     * PJ_FALSE. 
    138159     */ 
    139     PJMEDIA_AUD_DEV_CAP_VAD = 256, 
     160    PJMEDIA_AUD_DEV_CAP_VAD = 2048, 
    140161 
    141162    /**  
     
    144165     * PJ_FALSE. 
    145166     */ 
    146     PJMEDIA_AUD_DEV_CAP_CNG = 512, 
     167    PJMEDIA_AUD_DEV_CAP_CNG = 4096, 
    147168 
    148169    /**  
     
    151172     * PJ_FALSE. 
    152173     */ 
    153     PJMEDIA_AUD_DEV_CAP_PLC = 1024 
     174    PJMEDIA_AUD_DEV_CAP_PLC = 8192 
    154175     
    155176} pjmedia_aud_dev_cap; 
     
    239260 * buffer with audio samples. 
    240261 * 
    241  * @param user_data     User data associated with the stream. 
    242  * @param ts            Timestamp, in samples. 
    243  * @param output        Buffer to be filled out by application. 
    244  * @param size          The size requested in bytes, which will be equal to 
    245  *                      the size of one whole packet. 
    246  * 
    247  * @return              Non-zero to stop the stream. 
    248  */ 
    249 typedef pj_status_t (*pjmedia_aud_play_cb)(/* in */   void *user_data, 
    250                                            /* in */   const pj_timestamp *ts, 
    251                                            /* out */  void *output, 
    252                                            /* out */  unsigned size); 
     262 * The frame argument contains the following values: 
     263 *  - timestamp     Playback timestamp, in samples. 
     264 *  - buf           Buffer to be filled out by application. 
     265 *  - size          The size requested in bytes, which will be equal to 
     266 *                  the size of one whole packet. 
     267 * 
     268 * @param user_data User data associated with the stream. 
     269 * @param frame     Audio frame, which buffer is to be filled in by 
     270 *                  the application. 
     271 * 
     272 * @return          Returning non-PJ_SUCCESS will cause the audio stream 
     273 *                  to stop 
     274 */ 
     275typedef pj_status_t (*pjmedia_aud_play_cb)(void *user_data, 
     276                                           pjmedia_frame *frame); 
    253277 
    254278/** 
     
    256280 * packet worth of audio samples. 
    257281 * 
    258  * @param user_data     User data associated with the stream. 
    259  * @param ts            Timestamp, in samples. 
    260  * @param output        Buffer containing the captured audio samples. 
    261  * @param size          The size of the data in the buffer, in bytes. 
    262  * 
    263  * @return              Non-zero to stop the stream. 
    264  */ 
    265 typedef pj_status_t (*pjmedia_aud_rec_cb)(/* in */   void *user_data, 
    266                                           /* in */   const pj_timestamp *ts, 
    267                                           /* in */   void *input, 
    268                                           /* in*/    unsigned size); 
     282 * @param user_data User data associated with the stream. 
     283 * @param frame     Captured frame. 
     284 * 
     285 * @return          Returning non-PJ_SUCCESS will cause the audio stream 
     286 *                  to stop 
     287 */ 
     288typedef pj_status_t (*pjmedia_aud_rec_cb)(void *user_data, 
     289                                          pjmedia_frame *frame); 
    269290 
    270291/** 
     
    335356 
    336357    /**  
    337      * Set the audio route. This setting is optional, and will only be used 
    338      * if PJMEDIA_AUD_DEV_CAP_ROUTE is set in the flags. 
    339      */ 
    340     pjmedia_aud_dev_route route; 
     358     * Set the audio output route. This setting is optional, and will only be 
     359     * used if PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE is set in the flags. 
     360     */ 
     361    pjmedia_aud_dev_route out_route; 
    341362 
    342363    /** 
     
    546567#define PJMEDIA_EAUD_INVDEV     -1 
    547568 
     569/* Found no devices */ 
     570#define PJMEDIA_EAUD_NODEV      -1 
     571 
     572/* Unknown system error */ 
     573#define PJMEDIA_EAUD_SYSERR     -1 
     574 
     575 
    548576/** 
    549577 * @) 
  • pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia-audiodev/audiodev_imp.h

    r2458 r2459  
    6161     * 
    6262     * @param f         The audio device factory. 
    63      * @param id        The audio device ID. 
     63     * @param index     Device index. 
    6464     * @param info      The audio device information structure which will be 
    6565     *                  initialized by this function once it returns  
     
    6767     */ 
    6868    pj_status_t (*get_dev_info)(pjmedia_aud_dev_factory *f,  
    69                                 pjmedia_aud_dev_id id, 
     69                                unsigned index, 
    7070                                pjmedia_aud_dev_info *info); 
    7171 
     
    7575     * 
    7676     * @param f         The audio device factory. 
    77      * @param id        Device ID. 
     77     * @param index     Device index. 
    7878     * @param param     The audio device parameter. 
    7979     */ 
    8080    pj_status_t (*default_param)(pjmedia_aud_dev_factory *f, 
    81                                  pjmedia_aud_dev_id id, 
     81                                 unsigned index, 
    8282                                 pjmedia_aud_dev_param *param); 
    8383 
     
    167167 
    168168 
     169 
     170 
    169171/** 
    170172 * @} 
  • pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/audiodev.c

    r2458 r2459  
    2121#include <pj/errno.h> 
    2222 
    23  
     23/* 
     24 * The Device ID seen by application and driver is different.  
     25 * 
     26 * At application level, device ID is a 32bit value. The high 16bit contains 
     27 * the factory ID, and the low 16bit contains the device index in the  
     28 * specified factory. The device ID may also be -1 to denote default device. 
     29 * 
     30 * At driver level, device ID is a 16bit unsigned integer index. 
     31 */ 
    2432#define MAKE_DEV_ID(f_id, index)   (((f_id & 0xFFFF) << 16) & (index & 0xFFFF)) 
    2533#define GET_INDEX(dev_id)          ((dev_id) & 0xFFFF) 
    2634#define GET_FID(dev_id)            ((dev_id) >> 16) 
    27  
    28  
    29 /* extern */ 
     35#define DEFAULT_DEV_ID              0 
     36 
     37 
     38/* extern functions to create factories */ 
    3039pjmedia_aud_dev_factory* pjmedia_pa_factory(pj_pool_factory *pf); 
     40pjmedia_aud_dev_factory* pjmedia_wmme_factory(pj_pool_factory *pf); 
     41 
    3142 
    3243/* Array of factories */ 
     
    3849} factories[] =  
    3950{ 
     51    /* WMME */ 
     52    { 
     53        &pjmedia_wmme_factory 
     54    }, 
     55    /* PortAudio: */ 
    4056    { 
    4157        &pjmedia_pa_factory 
    42     } 
     58    }, 
    4359}; 
    4460static unsigned factory_cnt; 
     
    130146    int f_id, index; 
    131147 
     148    if (id == PJMEDIA_AUD_DEV_DEFAULT_ID) 
     149        id = DEFAULT_DEV_ID; 
     150 
    132151    f_id = GET_FID(id); 
    133152    index = GET_INDEX(id); 
     
    151170    int f_id, index; 
    152171    pj_status_t status; 
     172 
     173    if (id == PJMEDIA_AUD_DEV_DEFAULT_ID) 
     174        id = DEFAULT_DEV_ID; 
    153175 
    154176    f_id = GET_FID(id); 
     
    190212 
    191213    /* Set default device */ 
    192     if (param.rec_id == PJMEDIA_AUD_DEV_DEFAULT_ID) param.rec_id = 0; 
    193     if (param.play_id == PJMEDIA_AUD_DEV_DEFAULT_ID) param.play_id = 0; 
     214    if (param.rec_id == PJMEDIA_AUD_DEV_DEFAULT_ID)  
     215        param.rec_id = DEFAULT_DEV_ID; 
     216    if (param.play_id == PJMEDIA_AUD_DEV_DEFAULT_ID)  
     217        param.play_id = DEFAULT_DEV_ID; 
    194218     
    195219    if (param.dir & PJMEDIA_DIR_CAPTURE) 
  • 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.