Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4197)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4218)
@@ -166,7 +166,9 @@
 
     /* Perform NAT detection */
-    status = pjsua_detect_nat_type();
-    if (status != PJ_SUCCESS) {
-	PJ_PERROR(1,(THIS_FILE, status, "NAT type detection failed"));
+    if (pjsua_var.ua_cfg.stun_srv_cnt) {
+	status = pjsua_detect_nat_type();
+	if (status != PJ_SUCCESS) {
+	    PJ_PERROR(1,(THIS_FILE, status, "NAT type detection failed"));
+	}
     }
 
@@ -227,5 +229,6 @@
  * address via STUN.
  */
-static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg,
+static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med,
+					const pjsua_transport_config *cfg,
 					pjmedia_sock_info *skinfo)
 {
@@ -241,8 +244,10 @@
 
     /* Make sure STUN server resolution has completed */
-    status = resolve_stun_server(PJ_TRUE);
-    if (status != PJ_SUCCESS) {
-	pjsua_perror(THIS_FILE, "Error resolving STUN server", status);
-	return status;
+    if (pjsua_sip_acc_is_using_stun(call_med->call->acc_id)) {
+	status = resolve_stun_server(PJ_TRUE);
+	if (status != PJ_SUCCESS) {
+	    pjsua_perror(THIS_FILE, "Error resolving STUN server", status);
+	    return status;
+	}
     }
 
@@ -319,5 +324,7 @@
 	 * and make sure that the mapped RTCP port is adjacent with the RTP.
 	 */
-	if (pjsua_var.stun_srv.addr.sa_family != 0) {
+	if (pjsua_sip_acc_is_using_stun(call_med->call->acc_id) &&
+	    pjsua_var.stun_srv.addr.sa_family != 0)
+	{
 	    char ip_addr[32];
 	    pj_str_t stun_srv;
@@ -441,5 +448,5 @@
     pj_status_t status;
 
-    status = create_rtp_rtcp_sock(cfg, &skinfo);
+    status = create_rtp_rtcp_sock(call_med, cfg, &skinfo);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create RTP/RTCP socket",
@@ -661,4 +668,5 @@
 {
     char stunip[PJ_INET6_ADDRSTRLEN];
+    pjsua_acc_config *acc_cfg;
     pj_ice_strans_cfg ice_cfg;
     pjmedia_ice_cb ice_cb;
@@ -666,4 +674,6 @@
     unsigned comp_cnt;
     pj_status_t status;
+
+    acc_cfg = &pjsua_var.acc[call_med->call->acc_id].cfg;
 
     /* Make sure STUN server resolution has completed */
@@ -683,5 +693,5 @@
     ice_cfg.resolver = pjsua_var.resolver;
     
-    ice_cfg.opt = pjsua_var.media_cfg.ice_opt;
+    ice_cfg.opt = acc_cfg->ice_cfg.ice_opt;
 
     /* Configure STUN settings */
@@ -691,6 +701,6 @@
 	ice_cfg.stun.port = pj_sockaddr_get_port(&pjsua_var.stun_srv);
     }
-    if (pjsua_var.media_cfg.ice_max_host_cands >= 0)
-	ice_cfg.stun.max_host_cands = pjsua_var.media_cfg.ice_max_host_cands;
+    if (acc_cfg->ice_cfg.ice_max_host_cands >= 0)
+	ice_cfg.stun.max_host_cands = acc_cfg->ice_cfg.ice_max_host_cands;
 
     /* Copy QoS setting to STUN setting */
@@ -700,6 +710,6 @@
 
     /* Configure TURN settings */
-    if (pjsua_var.media_cfg.enable_turn) {
-	status = parse_host_port(&pjsua_var.media_cfg.turn_server,
+    if (acc_cfg->turn_cfg.enable_turn) {
+	status = parse_host_port(&acc_cfg->turn_cfg.turn_server,
 				 &ice_cfg.turn.server,
 				 &ice_cfg.turn.port);
@@ -710,7 +720,7 @@
 	if (ice_cfg.turn.port == 0)
 	    ice_cfg.turn.port = 3479;
-	ice_cfg.turn.conn_type = pjsua_var.media_cfg.turn_conn_type;
+	ice_cfg.turn.conn_type = acc_cfg->turn_cfg.turn_conn_type;
 	pj_memcpy(&ice_cfg.turn.auth_cred, 
-		  &pjsua_var.media_cfg.turn_auth_cred,
+		  &acc_cfg->turn_cfg.turn_auth_cred,
 		  sizeof(ice_cfg.turn.auth_cred));
 
@@ -731,5 +741,5 @@
 
     comp_cnt = 1;
-    if (PJMEDIA_ADVERTISE_RTCP && !pjsua_var.media_cfg.ice_no_rtcp)
+    if (PJMEDIA_ADVERTISE_RTCP && !acc_cfg->ice_cfg.ice_no_rtcp)
 	++comp_cnt;
 
@@ -859,5 +869,5 @@
 
     /* Create the transports */
-    if (pjsua_var.media_cfg.enable_ice) {
+    if (pjsua_var.ice_cfg.enable_ice) {
 	status = create_ice_media_transports(&cfg);
     } else {
@@ -1245,5 +1255,5 @@
         pjsua_set_media_tp_state(call_med, PJSUA_MED_TP_CREATING);
 
-	if (pjsua_var.media_cfg.enable_ice) {
+	if (pjsua_var.acc[call_med->call->acc_id].cfg.ice_cfg.enable_ice) {
 	    status = create_ice_media_transport(tcfg, call_med, async);
             if (async && status == PJ_EPENDING) {
