Ignore:
Timestamp:
Dec 19, 2011 5:47:55 AM (12 years ago)
Author:
bennylp
Message:

Fixed #1426: Race condition in auto-closing and/or auto-opening of the sound device

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_media.c

    r3829 r3913  
    19851985        pjsua_var.snd_idle_timer.id = PJ_FALSE; 
    19861986    } 
    1987     PJSUA_UNLOCK(); 
    19881987 
    19891988 
     
    20392038                if (status != PJ_SUCCESS) { 
    20402039                    pjsua_perror(THIS_FILE, "Error opening sound device", status); 
     2040                    PJSUA_UNLOCK(); 
    20412041                    return status; 
    20422042                } 
     
    20522052                if (status != PJ_SUCCESS) { 
    20532053                    pjsua_perror(THIS_FILE, "Error opening sound device", status); 
     2054                    PJSUA_UNLOCK(); 
    20542055                    return status; 
    20552056                } 
     
    20592060                if (status != PJ_SUCCESS) { 
    20602061                    pjsua_perror(THIS_FILE, "Error opening sound device", status); 
     2062                    PJSUA_UNLOCK(); 
    20612063                    return status; 
    20622064                } 
     
    20762078            if (status != PJ_SUCCESS) { 
    20772079                pjsua_perror(THIS_FILE, "Error opening sound device", status); 
     2080                PJSUA_UNLOCK(); 
    20782081                return status; 
    20792082            } 
     
    20822085    } 
    20832086 
     2087    PJSUA_UNLOCK(); 
    20842088    return pjmedia_conf_connect_port(pjsua_var.mconf, source, sink, 0); 
    20852089} 
     
    29172921    pj_status_t status = -1; 
    29182922 
     2923    PJSUA_LOCK(); 
     2924 
    29192925    /* Null-sound */ 
    29202926    if (capture_dev==NULL_SND_DEV_ID && playback_dev==NULL_SND_DEV_ID) { 
     2927        PJSUA_UNLOCK(); 
    29212928        return pjsua_set_null_snd_dev(); 
    29222929    } 
     
    29492956                                  alt_cr[i], pjsua_var.media_cfg.channel_count, 
    29502957                                  samples_per_frame, 16); 
    2951         if (status != PJ_SUCCESS) 
     2958        if (status != PJ_SUCCESS) { 
     2959            PJSUA_UNLOCK(); 
    29522960            return status; 
     2961        } 
    29532962 
    29542963        /* Open! */ 
     
    29612970    if (status != PJ_SUCCESS) { 
    29622971        pjsua_perror(THIS_FILE, "Unable to open sound device", status); 
     2972        PJSUA_UNLOCK(); 
    29632973        return status; 
    29642974    } 
     
    29662976    pjsua_var.no_snd = PJ_FALSE; 
    29672977 
     2978    PJSUA_UNLOCK(); 
    29682979    return PJ_SUCCESS; 
    29692980} 
     
    29782989                                      int *playback_dev) 
    29792990{ 
     2991    PJSUA_LOCK(); 
     2992 
    29802993    if (capture_dev) { 
    29812994        *capture_dev = pjsua_var.cap_dev; 
     
    29852998    } 
    29862999 
     3000    PJSUA_UNLOCK(); 
     3001 
    29873002    return PJ_SUCCESS; 
    29883003} 
     
    29973012    pj_status_t status; 
    29983013 
     3014    PJSUA_LOCK(); 
     3015 
    29993016    /* Close existing sound device */ 
    30003017    close_snd_dev(); 
     
    30023019    /* Create memory pool for sound device. */ 
    30033020    pjsua_var.snd_pool = pjsua_pool_create("pjsua_snd", 4000, 4000); 
    3004     PJ_ASSERT_RETURN(pjsua_var.snd_pool, PJ_ENOMEM); 
     3021    PJ_ASSERT_ON_FAIL(pjsua_var.snd_pool, {PJSUA_UNLOCK(); return PJ_ENOMEM;}); 
    30053022 
    30063023    PJ_LOG(4,(THIS_FILE, "Opening null sound device..")); 
     
    30183035        pjsua_perror(THIS_FILE, "Unable to create null sound device", 
    30193036                     status); 
     3037        PJSUA_UNLOCK(); 
    30203038        return status; 
    30213039    } 
     
    30233041    /* Start the master port */ 
    30243042    status = pjmedia_master_port_start(pjsua_var.null_snd); 
    3025     PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 
     3043    PJ_ASSERT_ON_FAIL(status == PJ_SUCCESS, {PJSUA_UNLOCK(); return status;}); 
    30263044 
    30273045    pjsua_var.cap_dev = NULL_SND_DEV_ID; 
     
    30303048    pjsua_var.no_snd = PJ_FALSE; 
    30313049 
     3050    PJSUA_UNLOCK(); 
    30323051    return PJ_SUCCESS; 
    30333052} 
     
    30403059PJ_DEF(pjmedia_port*) pjsua_set_no_snd_dev(void) 
    30413060{ 
     3061    PJSUA_LOCK(); 
     3062 
    30423063    /* Close existing sound device */ 
    30433064    close_snd_dev(); 
    3044  
    30453065    pjsua_var.no_snd = PJ_TRUE; 
     3066 
     3067    PJSUA_UNLOCK(); 
     3068 
    30463069    return pjmedia_conf_get_master_port(pjsua_var.mconf); 
    30473070} 
     
    30533076PJ_DEF(pj_status_t) pjsua_set_ec(unsigned tail_ms, unsigned options) 
    30543077{ 
     3078    pj_status_t status = PJ_SUCCESS; 
     3079 
     3080    PJSUA_LOCK(); 
     3081 
    30553082    pjsua_var.media_cfg.ec_tail_len = tail_ms; 
    30563083 
    30573084    if (pjsua_var.snd_port) 
    3058         return pjmedia_snd_port_set_ec( pjsua_var.snd_port, pjsua_var.pool, 
    3059                                         tail_ms, options); 
     3085        status = pjmedia_snd_port_set_ec(pjsua_var.snd_port, pjsua_var.pool, 
     3086                                         tail_ms, options); 
    30603087     
    3061     return PJ_SUCCESS; 
     3088    PJSUA_UNLOCK(); 
     3089    return status; 
    30623090} 
    30633091 
     
    30953123        return PJMEDIA_EAUD_INVCAP; 
    30963124    } 
     3125 
     3126    PJSUA_LOCK(); 
    30973127 
    30983128    /* If sound is active, set it immediately */ 
     
    31063136    } 
    31073137 
    3108     if (status != PJ_SUCCESS) 
     3138    if (status != PJ_SUCCESS) { 
     3139        PJSUA_UNLOCK(); 
    31093140        return status; 
     3141    } 
    31103142 
    31113143    /* Save in internal param for later device open */ 
     
    31153147    } 
    31163148 
     3149    PJSUA_UNLOCK(); 
     3150 
    31173151    return status; 
    31183152} 
     
    31243158                                           void *pval) 
    31253159{ 
     3160    pj_status_t status; 
     3161 
     3162    PJSUA_LOCK(); 
     3163 
    31263164    /* If sound device has never been opened before, open it to  
    31273165     * retrieve the initial setting from the device (e.g. audio 
     
    31393177         
    31403178        strm = pjmedia_snd_port_get_snd_stream(pjsua_var.snd_port); 
    3141         return pjmedia_aud_stream_get_cap(strm, cap, pval); 
     3179        status = pjmedia_aud_stream_get_cap(strm, cap, pval); 
    31423180    } else { 
    31433181        /* Otherwise retrieve from internal param */ 
    3144         return pjmedia_aud_param_get_cap(&pjsua_var.aud_param, 
    3145                                          cap, pval); 
    3146     } 
     3182        status = pjmedia_aud_param_get_cap(&pjsua_var.aud_param, 
     3183                                           cap, pval); 
     3184    } 
     3185 
     3186    PJSUA_UNLOCK(); 
     3187    return status; 
    31473188} 
    31483189 
Note: See TracChangeset for help on using the changeset viewer.