From a5465795aef807c0afbc86b600a2fcf2d8df4b37 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 31 Oct 2007 08:59:29 +0000 Subject: More ticket #399: added PJSUA API to retrieve the remote NAT type git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1533 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsua-lib/pjsua_call.c | 48 +++++++++++++++++++++++++++++++++++++++- pjsip/src/pjsua-lib/pjsua_core.c | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) (limited to 'pjsip/src/pjsua-lib') diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index 220e2b19..f1fe3208 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -98,6 +98,7 @@ static void reset_call(pjsua_call_id id) call->conn_time.msec = 0; call->res_time.sec = 0; call->res_time.msec = 0; + call->rem_nat_type = PJ_STUN_NAT_TYPE_UNKNOWN; } @@ -429,6 +430,24 @@ on_error: } +/* Get the NAT type information in remote's SDP */ +static void update_remote_nat_type(pjsua_call *call, + const pjmedia_sdp_session *sdp) +{ + const pjmedia_sdp_attr *xnat; + + xnat = pjmedia_sdp_attr_find2(sdp->attr_count, sdp->attr, "X-nat", NULL); + if (xnat) { + call->rem_nat_type = (pj_stun_nat_type) (xnat->value.ptr[0] - '0'); + } else { + call->rem_nat_type = PJ_STUN_NAT_TYPE_UNKNOWN; + } + + PJ_LOG(5,(THIS_FILE, "Call %d: remote NAT type is %d (%s)", call->index, + call->rem_nat_type, pj_stun_get_nat_name(call->rem_nat_type))); +} + + /** * Handle incoming INVITE request. * Called by pjsua_core.c @@ -658,6 +677,13 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata) return PJ_TRUE; } + /* Update NAT type of remote endpoint */ + if (pjsua_var.ua_cfg.nat_type_in_sdp) { + const pjmedia_sdp_session *remote_sdp; + + if (pjmedia_sdp_neg_get_neg_remote(inv->neg, &remote_sdp)==PJ_SUCCESS) + update_remote_nat_type(call, remote_sdp); + } /* Create and attach pjsua_var data to the dialog: */ call->inv = inv; @@ -1022,6 +1048,21 @@ PJ_DEF(void*) pjsua_call_get_user_data(pjsua_call_id call_id) } +/* + * Get remote's NAT type. + */ +PJ_DEF(pj_status_t) pjsua_call_get_rem_nat_type(pjsua_call_id call_id, + pj_stun_nat_type *p_type) +{ + PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, + PJ_EINVAL); + PJ_ASSERT_RETURN(p_type != NULL, PJ_EINVAL); + + *p_type = pjsua_var.calls[call_id].rem_nat_type; + return PJ_SUCCESS; +} + + /* * Send response to incoming INVITE request. */ @@ -2267,7 +2308,6 @@ static void pjsua_call_on_media_update(pjsip_inv_session *inv, return; } - status = pjmedia_sdp_neg_get_active_remote(call->inv->neg, &remote_sdp); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, @@ -2278,6 +2318,12 @@ static void pjsua_call_on_media_update(pjsip_inv_session *inv, return; } + /* Update remote's NAT type */ + if (pjsua_var.ua_cfg.nat_type_in_sdp) { + update_remote_nat_type(call, remote_sdp); + } + + /* Update media channel with the new SDP */ status = pjsua_media_channel_update(call->index, local_sdp, remote_sdp); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to create media session", diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index a60301ad..2cfca8d9 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -86,7 +86,7 @@ PJ_DEF(void) pjsua_config_default(pjsua_config *cfg) cfg->max_calls = 4; cfg->thread_cnt = 1; - cfg->nat_type_in_sdp = 2; + cfg->nat_type_in_sdp = 1; } PJ_DEF(void) pjsua_config_dup(pj_pool_t *pool, -- cgit v1.2.3