Ignore:
Timestamp:
Aug 7, 2012 2:18:15 AM (12 years ago)
Author:
bennylp
Message:

Fixed #1412: Account specific NAT settings: STUN, ICE, and TURN

File:
1 edited

Legend:

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

    r4197 r4218  
    166166 
    167167    /* Perform NAT detection */ 
    168     status = pjsua_detect_nat_type(); 
    169     if (status != PJ_SUCCESS) { 
    170         PJ_PERROR(1,(THIS_FILE, status, "NAT type detection failed")); 
     168    if (pjsua_var.ua_cfg.stun_srv_cnt) { 
     169        status = pjsua_detect_nat_type(); 
     170        if (status != PJ_SUCCESS) { 
     171            PJ_PERROR(1,(THIS_FILE, status, "NAT type detection failed")); 
     172        } 
    171173    } 
    172174 
     
    227229 * address via STUN. 
    228230 */ 
    229 static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg, 
     231static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, 
     232                                        const pjsua_transport_config *cfg, 
    230233                                        pjmedia_sock_info *skinfo) 
    231234{ 
     
    241244 
    242245    /* Make sure STUN server resolution has completed */ 
    243     status = resolve_stun_server(PJ_TRUE); 
    244     if (status != PJ_SUCCESS) { 
    245         pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 
    246         return status; 
     246    if (pjsua_sip_acc_is_using_stun(call_med->call->acc_id)) { 
     247        status = resolve_stun_server(PJ_TRUE); 
     248        if (status != PJ_SUCCESS) { 
     249            pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 
     250            return status; 
     251        } 
    247252    } 
    248253 
     
    319324         * and make sure that the mapped RTCP port is adjacent with the RTP. 
    320325         */ 
    321         if (pjsua_var.stun_srv.addr.sa_family != 0) { 
     326        if (pjsua_sip_acc_is_using_stun(call_med->call->acc_id) && 
     327            pjsua_var.stun_srv.addr.sa_family != 0) 
     328        { 
    322329            char ip_addr[32]; 
    323330            pj_str_t stun_srv; 
     
    441448    pj_status_t status; 
    442449 
    443     status = create_rtp_rtcp_sock(cfg, &skinfo); 
     450    status = create_rtp_rtcp_sock(call_med, cfg, &skinfo); 
    444451    if (status != PJ_SUCCESS) { 
    445452        pjsua_perror(THIS_FILE, "Unable to create RTP/RTCP socket", 
     
    661668{ 
    662669    char stunip[PJ_INET6_ADDRSTRLEN]; 
     670    pjsua_acc_config *acc_cfg; 
    663671    pj_ice_strans_cfg ice_cfg; 
    664672    pjmedia_ice_cb ice_cb; 
     
    666674    unsigned comp_cnt; 
    667675    pj_status_t status; 
     676 
     677    acc_cfg = &pjsua_var.acc[call_med->call->acc_id].cfg; 
    668678 
    669679    /* Make sure STUN server resolution has completed */ 
     
    683693    ice_cfg.resolver = pjsua_var.resolver; 
    684694     
    685     ice_cfg.opt = pjsua_var.media_cfg.ice_opt; 
     695    ice_cfg.opt = acc_cfg->ice_cfg.ice_opt; 
    686696 
    687697    /* Configure STUN settings */ 
     
    691701        ice_cfg.stun.port = pj_sockaddr_get_port(&pjsua_var.stun_srv); 
    692702    } 
    693     if (pjsua_var.media_cfg.ice_max_host_cands >= 0) 
    694         ice_cfg.stun.max_host_cands = pjsua_var.media_cfg.ice_max_host_cands; 
     703    if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) 
     704        ice_cfg.stun.max_host_cands = acc_cfg->ice_cfg.ice_max_host_cands; 
    695705 
    696706    /* Copy QoS setting to STUN setting */ 
     
    700710 
    701711    /* Configure TURN settings */ 
    702     if (pjsua_var.media_cfg.enable_turn) { 
    703         status = parse_host_port(&pjsua_var.media_cfg.turn_server, 
     712    if (acc_cfg->turn_cfg.enable_turn) { 
     713        status = parse_host_port(&acc_cfg->turn_cfg.turn_server, 
    704714                                 &ice_cfg.turn.server, 
    705715                                 &ice_cfg.turn.port); 
     
    710720        if (ice_cfg.turn.port == 0) 
    711721            ice_cfg.turn.port = 3479; 
    712         ice_cfg.turn.conn_type = pjsua_var.media_cfg.turn_conn_type; 
     722        ice_cfg.turn.conn_type = acc_cfg->turn_cfg.turn_conn_type; 
    713723        pj_memcpy(&ice_cfg.turn.auth_cred,  
    714                   &pjsua_var.media_cfg.turn_auth_cred, 
     724                  &acc_cfg->turn_cfg.turn_auth_cred, 
    715725                  sizeof(ice_cfg.turn.auth_cred)); 
    716726 
     
    731741 
    732742    comp_cnt = 1; 
    733     if (PJMEDIA_ADVERTISE_RTCP && !pjsua_var.media_cfg.ice_no_rtcp) 
     743    if (PJMEDIA_ADVERTISE_RTCP && !acc_cfg->ice_cfg.ice_no_rtcp) 
    734744        ++comp_cnt; 
    735745 
     
    859869 
    860870    /* Create the transports */ 
    861     if (pjsua_var.media_cfg.enable_ice) { 
     871    if (pjsua_var.ice_cfg.enable_ice) { 
    862872        status = create_ice_media_transports(&cfg); 
    863873    } else { 
     
    12451255        pjsua_set_media_tp_state(call_med, PJSUA_MED_TP_CREATING); 
    12461256 
    1247         if (pjsua_var.media_cfg.enable_ice) { 
     1257        if (pjsua_var.acc[call_med->call->acc_id].cfg.ice_cfg.enable_ice) { 
    12481258            status = create_ice_media_transport(tcfg, call_med, async); 
    12491259            if (async && status == PJ_EPENDING) { 
Note: See TracChangeset for help on using the changeset viewer.