Changeset 2007


Ignore:
Timestamp:
Jun 12, 2008 12:48:59 PM (11 years ago)
Author:
nanang
Message:

Ticket #542: added new API and macro for sound device latency settings, also added new param for this in pjsua

Location:
pjproject/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/config.h

    r1971 r2007  
    8484 
    8585/** 
    86  * Specify PortAudio maximum buffering latency, in milliseconds. 
    87  */ 
    88 #ifndef PJMEDIA_PASOUND_MAX_LATENCY 
    89 #   define PJMEDIA_PASOUND_MAX_LATENCY      100 
     86 * Specify sound device latency default, in milisecond. 
     87 */ 
     88#ifndef PJMEDIA_SND_DEFAULT_REC_LATENCY 
     89#   define PJMEDIA_SND_DEFAULT_REC_LATENCY  10 
     90#endif 
     91 
     92#ifndef PJMEDIA_SND_DEFAULT_PLAY_LATENCY 
     93#   define PJMEDIA_SND_DEFAULT_PLAY_LATENCY 100 
    9094#endif 
    9195 
  • pjproject/trunk/pjmedia/include/pjmedia/sound.h

    r974 r2007  
    152152 */ 
    153153PJ_DECL(const pjmedia_snd_dev_info*) pjmedia_snd_get_dev_info(unsigned index); 
     154 
     155 
     156/** 
     157 * Set sound device latency, this function must be called before sound device 
     158 * opened, or otherwise default latency setting will be used, @see 
     159 * PJMEDIA_SND_DEFAULT_REC_LATENCY & PJMEDIA_SND_DEFAULT_PLAY_LATENCY. 
     160 * 
     161 * Choosing latency value is not straightforward, it should accomodate both  
     162 * minimum latency and stability. Lower latency tends to cause sound device  
     163 * less reliable (producing audio dropouts) on CPU load disturbance. Moreover, 
     164 * the best latency setting may vary based on many aspects, e.g: sound card,  
     165 * CPU, OS, kernel, etc. 
     166 * 
     167 * @param input_latency     The latency of input device, in ms, set to 0 
     168 *                          for default PJMEDIA_SND_DEFAULT_REC_LATENCY. 
     169 * @param output_latency    The latency of output device, in ms, set to 0 
     170 *                          for default PJMEDIA_SND_DEFAULT_PLAY_LATENCY. 
     171 * 
     172 * @return                  PJ_SUCCESS on success. 
     173 */ 
     174PJ_DECL(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,  
     175                                             unsigned output_latency); 
    154176 
    155177 
  • pjproject/trunk/pjmedia/src/pjmedia/dsound.c

    r1422 r2007  
    6060static int snd_init_count; 
    6161 
     62/* Latency settings */ 
     63static unsigned snd_input_latency  = PJMEDIA_SND_DEFAULT_REC_LATENCY; 
     64static unsigned snd_output_latency = PJMEDIA_SND_DEFAULT_PLAY_LATENCY; 
     65 
    6266 
    6367/* Individual DirectSound capture/playback stream descriptor */ 
     
    987991 
    988992 
     993/* 
     994 * Set sound latency. 
     995 */ 
     996PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,  
     997                                            unsigned output_latency) 
     998{ 
     999    PJ_TODO(APPLY_LATENCY_SETTINGS_ON_DSOUND); 
     1000 
     1001    snd_input_latency  = (input_latency == 0)?  
     1002                         PJMEDIA_SND_DEFAULT_REC_LATENCY : input_latency; 
     1003    snd_output_latency = (output_latency == 0)?  
     1004                         PJMEDIA_SND_DEFAULT_PLAY_LATENCY : output_latency; 
     1005 
     1006    return PJ_SUCCESS; 
     1007} 
     1008 
    9891009#endif  /* PJMEDIA_SOUND_IMPLEMENTATION */ 
    9901010 
  • pjproject/trunk/pjmedia/src/pjmedia/nullsound.c

    r1269 r2007  
    182182} 
    183183 
     184/* 
     185 * Set sound latency. 
     186 */ 
     187PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,  
     188                                            unsigned output_latency) 
     189{ 
     190    /* Nothing to do */ 
     191    PJ_UNUSED_ARG(input_latency); 
     192    PJ_UNUSED_ARG(output_latency); 
     193    return PJ_SUCCESS; 
     194} 
     195 
    184196#endif  /* PJMEDIA_SOUND_IMPLEMENTATION */ 
  • pjproject/trunk/pjmedia/src/pjmedia/pasound.c

    r1919 r2007  
    2929#define THIS_FILE       "pasound.c" 
    3030 
    31 #define MAX_LATENCY     (PJMEDIA_PASOUND_MAX_LATENCY / 1000.0) 
    32  
    3331static int snd_init_count; 
     32 
     33/* Latency settings */ 
     34static unsigned snd_input_latency  = PJMEDIA_SND_DEFAULT_REC_LATENCY; 
     35static unsigned snd_output_latency = PJMEDIA_SND_DEFAULT_PLAY_LATENCY; 
    3436 
    3537static struct snd_mgr 
     
    562564    inputParam.hostApiSpecificStreamInfo = NULL; 
    563565    inputParam.sampleFormat = sampleFormat; 
    564     inputParam.suggestedLatency = paDevInfo->defaultLowInputLatency; 
    565     if (inputParam.suggestedLatency > MAX_LATENCY) 
    566         inputParam.suggestedLatency = MAX_LATENCY; 
     566    inputParam.suggestedLatency = snd_input_latency / 1000.0; 
    567567 
    568568    paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi); 
     
    664664    outputParam.hostApiSpecificStreamInfo = NULL; 
    665665    outputParam.sampleFormat = sampleFormat; 
    666     outputParam.suggestedLatency = paDevInfo->defaultLowOutputLatency; 
    667     if (outputParam.suggestedLatency > MAX_LATENCY) 
    668         outputParam.suggestedLatency = MAX_LATENCY; 
     666    outputParam.suggestedLatency = snd_output_latency / 1000.0; 
    669667 
    670668    paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi); 
     
    795793    inputParam.hostApiSpecificStreamInfo = NULL; 
    796794    inputParam.sampleFormat = sampleFormat; 
    797     inputParam.suggestedLatency = paRecDevInfo->defaultLowInputLatency; 
    798     if (inputParam.suggestedLatency > MAX_LATENCY) 
    799         inputParam.suggestedLatency = MAX_LATENCY; 
     795    inputParam.suggestedLatency = snd_input_latency / 1000.0; 
    800796 
    801797    paRecHostApiInfo = Pa_GetHostApiInfo(paRecDevInfo->hostApi); 
     
    806802    outputParam.hostApiSpecificStreamInfo = NULL; 
    807803    outputParam.sampleFormat = sampleFormat; 
    808     outputParam.suggestedLatency = paPlayDevInfo->defaultLowOutputLatency; 
    809     if (outputParam.suggestedLatency > MAX_LATENCY) 
    810         outputParam.suggestedLatency = MAX_LATENCY; 
     804    outputParam.suggestedLatency = snd_output_latency / 1000.0; 
    811805 
    812806    paPlayHostApiInfo = Pa_GetHostApiInfo(paPlayDevInfo->hostApi); 
     
    10131007} 
    10141008 
     1009/* 
     1010 * Set sound latency. 
     1011 */ 
     1012PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,  
     1013                                            unsigned output_latency) 
     1014{ 
     1015    snd_input_latency  = (input_latency == 0)?  
     1016                         PJMEDIA_SND_DEFAULT_REC_LATENCY : input_latency; 
     1017    snd_output_latency = (output_latency == 0)?  
     1018                         PJMEDIA_SND_DEFAULT_PLAY_LATENCY : output_latency; 
     1019 
     1020    return PJ_SUCCESS; 
     1021} 
    10151022 
    10161023#endif  /* PJMEDIA_SOUND_IMPLEMENTATION */ 
  • pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c

    r1984 r2007  
    327327         * is taken to be totally around 30ms + sound device latency. 
    328328         */ 
    329         est_extra_delay = 30 +  
    330 #if PJMEDIA_SOUND_IMPLEMENTATION==PJMEDIA_SOUND_PORTAUDIO_SOUND 
    331                           PJMEDIA_PASOUND_MAX_LATENCY 
    332 #elif PJMEDIA_SOUND_IMPLEMENTATION==PJMEDIA_SOUND_NULL_SOUND 
    333                           0 
    334 #else 
    335                           (PJMEDIA_SOUND_BUFFER_COUNT * 15) 
     329        est_extra_delay = 30; 
     330 
     331#if PJMEDIA_SOUND_IMPLEMENTATION!=PJMEDIA_SOUND_NULL_SOUND 
     332        est_extra_delay += PJMEDIA_SND_DEFAULT_REC_LATENCY +  
     333                           PJMEDIA_SND_DEFAULT_PLAY_LATENCY; 
    336334#endif 
    337                           ; 
     335 
    338336        sess->stat.rx.voip_mtc.end_sys_delay = (pj_uint16_t) 
    339337                                 (sess->stat.rx.voip_mtc.rnd_trip_delay / 2 + 
  • pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp

    r1688 r2007  
    928928} 
    929929 
     930 
     931/* 
     932 * Set sound latency. 
     933 */ 
     934PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,  
     935                                            unsigned output_latency) 
     936{ 
     937    /* Nothing to do */ 
     938    PJ_UNUSED_ARG(input_latency); 
     939    PJ_UNUSED_ARG(output_latency); 
     940    return PJ_SUCCESS; 
     941} 
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r1990 r2007  
    8686 
    8787    int                     capture_dev, playback_dev; 
     88    unsigned                capture_lat, playback_lat; 
    8889} app_config; 
    8990 
     
    195196    puts  ("  --capture-dev=id    Audio capture device ID (default=-1)"); 
    196197    puts  ("  --playback-dev=id   Audio playback device ID (default=-1)"); 
     198    puts  ("  --capture-lat=N     Audio capture latency, in ms (default=10)"); 
     199    puts  ("  --playback-lat=N    Audio playback latency, in ms (default=100)"); 
    197200 
    198201    puts  (""); 
     
    253256    cfg->capture_dev = PJSUA_INVALID_ID; 
    254257    cfg->playback_dev = PJSUA_INVALID_ID; 
     258    cfg->capture_lat = PJMEDIA_SND_DEFAULT_REC_LATENCY; 
     259    cfg->playback_lat = PJMEDIA_SND_DEFAULT_PLAY_LATENCY; 
    255260 
    256261    for (i=0; i<PJ_ARRAY_SIZE(cfg->acc_cfg); ++i) 
     
    414419           OPT_TLS_NEG_TIMEOUT, 
    415420           OPT_CAPTURE_DEV, OPT_PLAYBACK_DEV, 
     421           OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT, 
    416422           OPT_AUTO_UPDATE_NAT,OPT_USE_COMPACT_FORM,OPT_DIS_CODEC 
    417423    }; 
     
    500506        { "capture-dev",    1, 0, OPT_CAPTURE_DEV}, 
    501507        { "playback-dev",   1, 0, OPT_PLAYBACK_DEV}, 
     508        { "capture-lat",    1, 0, OPT_CAPTURE_LAT}, 
     509        { "playback-lat",   1, 0, OPT_PLAYBACK_LAT}, 
    502510        { NULL, 0, 0, 0} 
    503511    }; 
     
    10761084        case OPT_PLAYBACK_DEV: 
    10771085            cfg->playback_dev = atoi(pj_optarg); 
     1086            break; 
     1087 
     1088        case OPT_CAPTURE_LAT: 
     1089            cfg->capture_lat = atoi(pj_optarg); 
     1090            break; 
     1091 
     1092        case OPT_PLAYBACK_LAT: 
     1093            cfg->playback_lat = atoi(pj_optarg); 
    10781094            break; 
    10791095 
     
    14721488    if (config->playback_dev != PJSUA_INVALID_ID) { 
    14731489        pj_ansi_sprintf(line, "--playback-dev %d\n", config->playback_dev); 
     1490        pj_strcat2(&cfg, line); 
     1491    } 
     1492 
     1493    /* Sound device latency */ 
     1494    if (config->capture_lat != PJMEDIA_SND_DEFAULT_REC_LATENCY) { 
     1495        pj_ansi_sprintf(line, "--capture-lat %d\n", config->capture_lat); 
     1496        pj_strcat2(&cfg, line); 
     1497    } 
     1498    if (config->playback_dev != PJMEDIA_SND_DEFAULT_PLAY_LATENCY) { 
     1499        pj_ansi_sprintf(line, "--playback-lat %d\n", config->playback_lat); 
    14741500        pj_strcat2(&cfg, line); 
    14751501    } 
     
    37143740        goto on_error; 
    37153741 
     3742    /* Set sound device latency */ 
     3743    pjmedia_snd_set_latency(app_config.capture_lat, app_config.playback_lat); 
     3744 
    37163745    /* Use null sound device? */ 
    37173746#ifndef STEREO_DEMO 
Note: See TracChangeset for help on using the changeset viewer.