Ignore:
Timestamp:
Oct 31, 2007 8:59:29 AM (17 years ago)
Author:
bennylp
Message:

More ticket #399: added PJSUA API to retrieve the remote NAT type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r1477 r1533  
    9999    call->res_time.sec = 0; 
    100100    call->res_time.msec = 0; 
     101    call->rem_nat_type = PJ_STUN_NAT_TYPE_UNKNOWN; 
    101102} 
    102103 
     
    427428    PJSUA_UNLOCK(); 
    428429    return status; 
     430} 
     431 
     432 
     433/* Get the NAT type information in remote's SDP */ 
     434static void update_remote_nat_type(pjsua_call *call,  
     435                                   const pjmedia_sdp_session *sdp) 
     436{ 
     437    const pjmedia_sdp_attr *xnat; 
     438 
     439    xnat = pjmedia_sdp_attr_find2(sdp->attr_count, sdp->attr, "X-nat", NULL); 
     440    if (xnat) { 
     441        call->rem_nat_type = (pj_stun_nat_type) (xnat->value.ptr[0] - '0'); 
     442    } else { 
     443        call->rem_nat_type = PJ_STUN_NAT_TYPE_UNKNOWN; 
     444    } 
     445 
     446    PJ_LOG(5,(THIS_FILE, "Call %d: remote NAT type is %d (%s)", call->index, 
     447              call->rem_nat_type, pj_stun_get_nat_name(call->rem_nat_type))); 
    429448} 
    430449 
     
    659678    } 
    660679 
     680    /* Update NAT type of remote endpoint */ 
     681    if (pjsua_var.ua_cfg.nat_type_in_sdp) { 
     682        const pjmedia_sdp_session *remote_sdp; 
     683 
     684        if (pjmedia_sdp_neg_get_neg_remote(inv->neg, &remote_sdp)==PJ_SUCCESS) 
     685            update_remote_nat_type(call, remote_sdp); 
     686    } 
    661687 
    662688    /* Create and attach pjsua_var data to the dialog: */ 
     
    10201046                     NULL); 
    10211047    return pjsua_var.calls[call_id].user_data; 
     1048} 
     1049 
     1050 
     1051/* 
     1052 * Get remote's NAT type. 
     1053 */ 
     1054PJ_DEF(pj_status_t) pjsua_call_get_rem_nat_type(pjsua_call_id call_id, 
     1055                                                pj_stun_nat_type *p_type) 
     1056{ 
     1057    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 
     1058                     PJ_EINVAL); 
     1059    PJ_ASSERT_RETURN(p_type != NULL, PJ_EINVAL); 
     1060 
     1061    *p_type = pjsua_var.calls[call_id].rem_nat_type; 
     1062    return PJ_SUCCESS; 
    10221063} 
    10231064 
     
    22682309    } 
    22692310 
    2270  
    22712311    status = pjmedia_sdp_neg_get_active_remote(call->inv->neg, &remote_sdp); 
    22722312    if (status != PJ_SUCCESS) { 
     
    22792319    } 
    22802320 
     2321    /* Update remote's NAT type */ 
     2322    if (pjsua_var.ua_cfg.nat_type_in_sdp) { 
     2323        update_remote_nat_type(call, remote_sdp); 
     2324    } 
     2325 
     2326    /* Update media channel with the new SDP */ 
    22812327    status = pjsua_media_channel_update(call->index, local_sdp, remote_sdp); 
    22822328    if (status != PJ_SUCCESS) { 
Note: See TracChangeset for help on using the changeset viewer.