Ignore:
Timestamp:
Dec 28, 2016 3:40:07 AM (7 years ago)
Author:
nanang
Message:

Re #1900: More merged from trunk (r5512 mistakenly contains merged changes in third-party dir only).

Location:
pjproject/branches/projects/uwp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/uwp

  • pjproject/branches/projects/uwp/pjsip/src/pjsip-ua/sip_inv.c

    r5109 r5513  
    196196 
    197197/* 
     198 * Add reference to INVITE session. 
     199 */ 
     200PJ_DEF(pj_status_t) pjsip_inv_add_ref( pjsip_inv_session *inv ) 
     201{ 
     202    PJ_ASSERT_RETURN(inv && inv->ref_cnt, PJ_EINVAL); 
     203 
     204    pj_atomic_inc(inv->ref_cnt); 
     205 
     206    return PJ_SUCCESS; 
     207} 
     208 
     209static void inv_session_destroy(pjsip_inv_session *inv) 
     210{ 
     211    if (inv->last_ack) { 
     212        pjsip_tx_data_dec_ref(inv->last_ack); 
     213        inv->last_ack = NULL; 
     214    } 
     215    if (inv->invite_req) { 
     216        pjsip_tx_data_dec_ref(inv->invite_req); 
     217        inv->invite_req = NULL; 
     218    } 
     219    if (inv->pending_bye) { 
     220        pjsip_tx_data_dec_ref(inv->pending_bye); 
     221        inv->pending_bye = NULL; 
     222    } 
     223    pjsip_100rel_end_session(inv); 
     224    pjsip_timer_end_session(inv); 
     225    pjsip_dlg_dec_session(inv->dlg, &mod_inv.mod); 
     226 
     227    /* Release the flip-flop pools */ 
     228    pj_pool_release(inv->pool_prov); 
     229    inv->pool_prov = NULL; 
     230    pj_pool_release(inv->pool_active); 
     231    inv->pool_active = NULL; 
     232 
     233    pj_atomic_destroy(inv->ref_cnt); 
     234    inv->ref_cnt = NULL; 
     235} 
     236 
     237/* 
     238 * Decrease INVITE session reference, destroy it when the reference count 
     239 * reaches zero. 
     240 */ 
     241PJ_DEF(pj_status_t) pjsip_inv_dec_ref( pjsip_inv_session *inv ) 
     242{ 
     243    pj_atomic_value_t ref_cnt; 
     244 
     245    PJ_ASSERT_RETURN(inv && inv->ref_cnt, PJ_EINVAL); 
     246 
     247    ref_cnt = pj_atomic_dec_and_get(inv->ref_cnt); 
     248    pj_assert( ref_cnt >= 0); 
     249    if (ref_cnt == 0) { 
     250        inv_session_destroy(inv); 
     251        return PJ_EGONE; 
     252    }  
     253    return PJ_SUCCESS;     
     254} 
     255 
     256/* 
    198257 * Set session state. 
    199258 */ 
     
    226285        } 
    227286 
    228         if (pjmedia_sdp_neg_get_state(inv->neg)!=PJMEDIA_SDP_NEG_STATE_DONE && 
    229             (tsx_inv_data && !tsx_inv_data->sdp_done) ) 
     287        if ((tsx_inv_data && !tsx_inv_data->sdp_done) && 
     288            (!inv->neg || pjmedia_sdp_neg_get_state(inv->neg)!= 
     289                                                PJMEDIA_SDP_NEG_STATE_DONE)) 
    230290        { 
    231291            pjsip_tx_data *bye; 
     
    261321        prev_state != PJSIP_INV_STATE_DISCONNECTED)  
    262322    { 
    263         if (inv->last_ack) { 
    264             pjsip_tx_data_dec_ref(inv->last_ack); 
    265             inv->last_ack = NULL; 
    266         } 
    267         if (inv->invite_req) { 
    268             pjsip_tx_data_dec_ref(inv->invite_req); 
    269             inv->invite_req = NULL; 
    270         } 
    271         if (inv->pending_bye) { 
    272             pjsip_tx_data_dec_ref(inv->pending_bye); 
    273             inv->pending_bye = NULL; 
    274         } 
    275         pjsip_100rel_end_session(inv); 
    276         pjsip_timer_end_session(inv); 
    277         pjsip_dlg_dec_session(inv->dlg, &mod_inv.mod); 
    278  
    279         /* Release the flip-flop pools */ 
    280         pj_pool_release(inv->pool_prov); 
    281         inv->pool_prov = NULL; 
    282         pj_pool_release(inv->pool_active); 
    283         inv->pool_active = NULL; 
     323        pjsip_inv_dec_ref(inv); 
    284324    } 
    285325} 
     
    838878    pj_assert(inv != NULL); 
    839879 
     880    status = pj_atomic_create(dlg->pool, 0, &inv->ref_cnt); 
     881    if (status != PJ_SUCCESS) { 
     882        pjsip_dlg_dec_lock(dlg); 
     883        return status; 
     884    } 
     885 
    840886    inv->pool = dlg->pool; 
    841887    inv->role = PJSIP_ROLE_UAC; 
     
    881927 
    882928    /* Done */ 
     929    pjsip_inv_add_ref(inv); 
    883930    *p_inv = inv; 
    884931 
     
    14711518    pj_assert(inv != NULL); 
    14721519 
     1520    status = pj_atomic_create(dlg->pool, 0, &inv->ref_cnt); 
     1521    if (status != PJ_SUCCESS) { 
     1522        pjsip_dlg_dec_lock(dlg); 
     1523        return status; 
     1524    } 
     1525 
    14731526    inv->pool = dlg->pool; 
    14741527    inv->role = PJSIP_ROLE_UAS; 
     
    15401593 
    15411594    /* Done */ 
     1595    pjsip_inv_add_ref(inv); 
    15421596    pjsip_dlg_dec_lock(dlg); 
    15431597    *p_inv = inv; 
Note: See TracChangeset for help on using the changeset viewer.