diff options
author | Nanang Izzuddin <nanang@teluu.com> | 2016-07-14 06:14:46 +0000 |
---|---|---|
committer | Nanang Izzuddin <nanang@teluu.com> | 2016-07-14 06:14:46 +0000 |
commit | f977c5f0bef635b126cd2784226f122aa2e0d526 (patch) | |
tree | 0aeea39342cf9f18d8f22bcd7d6cb393a018ff2c | |
parent | e1c6fe15fdd58ddf2431f56c3ff9be08ebbd2ace (diff) |
Misc (re #1928): Cleaned up STUN transport config setup for ICE in pjsua.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5384 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_media.c | 102 |
1 files changed, 57 insertions, 45 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index f53884e8..9062b1f2 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -842,6 +842,8 @@ static pj_status_t create_ice_media_transport( /* Create ICE stream transport configuration */ pj_ice_strans_cfg_default(&ice_cfg); + pj_bzero(&ice_cfg.stun, sizeof(ice_cfg.stun)); + pj_bzero(&ice_cfg.turn, sizeof(ice_cfg.turn)); pj_stun_config_init(&ice_cfg.stun_cfg, &pjsua_var.cp.factory, 0, pjsip_endpt_get_ioqueue(pjsua_var.endpt), pjsip_endpt_get_timer_heap(pjsua_var.endpt)); @@ -850,7 +852,7 @@ static pj_status_t create_ice_media_transport( ice_cfg.opt = acc_cfg->ice_cfg.ice_opt; - /* Check if STUN transport is configured */ + /* If STUN transport is configured, initialize STUN transport settings */ if ((pj_sockaddr_has_addr(&pjsua_var.stun_srv) && pjsua_media_acc_is_using_stun(call_med->call->acc_id)) || acc_cfg->ice_cfg.ice_max_host_cands != 0) @@ -864,45 +866,60 @@ static pj_status_t create_ice_media_transport( } } - /* Configure STUN settings */ - if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) && - pjsua_media_acc_is_using_stun(call_med->call->acc_id)) - { - pj_sockaddr_print(&pjsua_var.stun_srv, stunip, sizeof(stunip), 0); - ice_cfg.stun_tp[0].server = pj_str(stunip); - ice_cfg.stun_tp[0].port = pj_sockaddr_get_port(&pjsua_var.stun_srv); - } - if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) { - ice_cfg.stun_tp[0].max_host_cands = - acc_cfg->ice_cfg.ice_max_host_cands; - if (use_ipv6) - ice_cfg.stun_tp[1].max_host_cands = - acc_cfg->ice_cfg.ice_max_host_cands; - } - - /* Copy binding port setting to STUN setting */ - pj_sockaddr_init(ice_cfg.stun_tp[0].af, &ice_cfg.stun_tp[0].cfg.bound_addr, - &cfg->bound_addr, (pj_uint16_t)cfg->port); - ice_cfg.stun_tp[0].cfg.port_range = (pj_uint16_t)cfg->port_range; - if (cfg->port != 0 && ice_cfg.stun_tp[0].cfg.port_range == 0) { - ice_cfg.stun_tp[0].cfg.port_range = - (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10); - } - if (use_ipv6) { - pj_str_t IN6_ADDR_ANY = {"0", 1}; - pj_sockaddr_init(pj_AF_INET6(), &ice_cfg.stun_tp[1].cfg.bound_addr, - &IN6_ADDR_ANY, (pj_uint16_t)cfg->port); - ice_cfg.stun_tp[1].cfg.port_range = ice_cfg.stun_tp[0].cfg.port_range; - } + /* Configure STUN transport settings */ + if (ice_cfg.stun_tp_cnt) { + unsigned i; + + /* Configure STUN server (currently only for IPv4) */ + if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) && + pjsua_media_acc_is_using_stun(call_med->call->acc_id)) + { + pj_sockaddr_print(&pjsua_var.stun_srv, stunip, sizeof(stunip), 0); + ice_cfg.stun_tp[0].server = pj_str(stunip); + ice_cfg.stun_tp[0].port = + pj_sockaddr_get_port(&pjsua_var.stun_srv); + } - /* Copy QoS setting to STUN setting */ - ice_cfg.stun_tp[0].cfg.qos_type = cfg->qos_type; - pj_memcpy(&ice_cfg.stun_tp[0].cfg.qos_params, &cfg->qos_params, - sizeof(cfg->qos_params)); - if (use_ipv6) { - ice_cfg.stun_tp[1].cfg.qos_type = cfg->qos_type; - pj_memcpy(&ice_cfg.stun_tp[1].cfg.qos_params, &cfg->qos_params, + /* Configure max host candidates */ + if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) { + for (i = 0; i < ice_cfg.stun_tp_cnt; ++i) + ice_cfg.stun_tp[i].max_host_cands = + acc_cfg->ice_cfg.ice_max_host_cands; + } + + /* Configure binding address */ + pj_sockaddr_init(ice_cfg.stun_tp[0].af, + &ice_cfg.stun_tp[0].cfg.bound_addr, + &cfg->bound_addr, (pj_uint16_t)cfg->port); + ice_cfg.stun_tp[0].cfg.port_range = (pj_uint16_t)cfg->port_range; + if (cfg->port != 0 && ice_cfg.stun_tp[0].cfg.port_range == 0) { + ice_cfg.stun_tp[0].cfg.port_range = + (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10); + } + if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) { + pj_str_t IN6_ADDR_ANY = {"0", 1}; + pj_sockaddr_init(pj_AF_INET6(), + &ice_cfg.stun_tp[1].cfg.bound_addr, + &IN6_ADDR_ANY, (pj_uint16_t)cfg->port); + ice_cfg.stun_tp[1].cfg.port_range = + ice_cfg.stun_tp[0].cfg.port_range; + } + + /* Configure QoS setting */ + ice_cfg.stun_tp[0].cfg.qos_type = cfg->qos_type; + pj_memcpy(&ice_cfg.stun_tp[0].cfg.qos_params, &cfg->qos_params, sizeof(cfg->qos_params)); + if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) { + ice_cfg.stun_tp[1].cfg.qos_type = cfg->qos_type; + pj_memcpy(&ice_cfg.stun_tp[1].cfg.qos_params, &cfg->qos_params, + sizeof(cfg->qos_params)); + } + + /* Configure max packet size */ + ice_cfg.stun_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; + if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) + ice_cfg.stun_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU; + } /* Configure TURN settings */ @@ -935,14 +952,9 @@ static pj_status_t create_ice_media_transport( if (cfg->port != 0 && ice_cfg.turn_tp[0].cfg.port_range == 0) ice_cfg.turn_tp[0].cfg.port_range = (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10); - } - - /* Configure packet size for STUN and TURN sockets */ - ice_cfg.stun_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; - ice_cfg.turn_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; - if (use_ipv6) { - ice_cfg.stun_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU; + /* Configure max packet size */ + ice_cfg.turn_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; } pj_bzero(&ice_cb, sizeof(pjmedia_ice_cb)); |