Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4336)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4342)
@@ -586,73 +586,4 @@
 }
 
-static void med_tp_nego_timer_cb(void *user_data)
-{
-    pjsua_call *call;
-    unsigned med_idx = (unsigned)(((long)user_data) & 0xFFFF);
-    pjsua_call_media *call_med;
-    pjmedia_transport *tp;
-    pjmedia_transport_info tpinfo;
-    pjmedia_ice_transport_info *ii = NULL;
-    unsigned i;
-    pjsip_dialog *dlg = NULL;
-
-    if ((acquire_call("med_tp_nego_timer_cb", ((long)user_data) >> 16,
-	             &call, &dlg) != PJ_SUCCESS) ||
-        (med_idx >= call->med_cnt))
-    {
-        /* Call have been terminated or media has been removed */
-	return;
-    }
-
-    call_med = &call->media[med_idx];
-    tp = call_med->tp;
-
-    if (!tp)
-        return;
-
-    /* Send UPDATE if default transport address is different than
-     * what was advertised (ticket #881)
-     */
-
-    pjmedia_transport_info_init(&tpinfo);
-    pjmedia_transport_get_info(tp, &tpinfo);
-    for (i=0; i<tpinfo.specific_info_cnt; ++i) {
-        if (tpinfo.spc_info[i].type==PJMEDIA_TRANSPORT_TYPE_ICE) {
-	    ii = (pjmedia_ice_transport_info*)
-	    tpinfo.spc_info[i].buffer;
-	    break;
-	}
-    }
-
-    if (ii && ii->role==PJ_ICE_SESS_ROLE_CONTROLLING &&
-	pj_sockaddr_cmp(&tpinfo.sock_info.rtp_addr_name,
-		        &call_med->rtp_addr))
-    {
-        pj_bool_t use_update;
-	const pj_str_t STR_UPDATE = { "UPDATE", 6 };
-	pjsip_dialog_cap_status support_update;
-	pjsip_dialog *dlg;
-
-	dlg = call_med->call->inv->dlg;
-	support_update = pjsip_dlg_remote_has_cap(dlg, PJSIP_H_ALLOW,
-					          NULL, &STR_UPDATE);
-        use_update = (support_update == PJSIP_DIALOG_CAP_SUPPORTED);
-
-	PJ_LOG(4,(THIS_FILE, 
-                  "ICE default transport address has changed for "
-		  "call %d, sending %s",
-		  call_med->call->index,
-		  (use_update ? "UPDATE" : "re-INVITE")));
-
-        if (use_update)
-	    pjsua_call_update(call_med->call->index, 0, NULL);
-	else
-	    pjsua_call_reinvite(call_med->call->index, 0, NULL);
-    }
-
-    if (dlg)
-        pjsip_dlg_dec_lock(dlg);
-}
-
 
 /* This callback is called when ICE negotiation completes */
@@ -662,8 +593,11 @@
 {
     pjsua_call_media *call_med = (pjsua_call_media*)tp->user_data;
+    pjsua_call *call;
 
     if (!call_med)
 	return;
 
+    call = call_med->call;
+    
     switch (op) {
     case PJ_ICE_STRANS_OP_INIT:
@@ -672,16 +606,20 @@
 	break;
     case PJ_ICE_STRANS_OP_NEGOTIATION:
-	if (result != PJ_SUCCESS) {
+	if (result == PJ_SUCCESS) {
+            /* Update RTP address */
+            pjmedia_transport_info tpinfo;
+            pjmedia_transport_info_init(&tpinfo);
+            pjmedia_transport_get_info(call_med->tp, &tpinfo);
+            pj_sockaddr_cp(&call_med->rtp_addr, &tpinfo.sock_info.rtp_addr_name);
+        } else {
 	    call_med->state = PJSUA_CALL_MEDIA_ERROR;
 	    call_med->dir = PJMEDIA_DIR_NONE;
-
-	    if (call_med->call && pjsua_var.ua_cfg.cb.on_call_media_state) {
-		pjsua_var.ua_cfg.cb.on_call_media_state(call_med->call->index);
-	    }
-	} else if (call_med->call) {
-            void *data = (void*)(long)( (call_med->call->index<<16) |
-                                        (call_med->idx & 0xFFFF) );
-            pjsua_schedule_timer2(&med_tp_nego_timer_cb, data, 1);
+	    if (call && pjsua_var.ua_cfg.cb.on_call_media_state) {
+		pjsua_var.ua_cfg.cb.on_call_media_state(call->index);
+	    }
         }
+	/* Check if default ICE transport address is changed */
+        call->reinv_ice_sent = PJ_FALSE;
+	pjsua_call_schedule_reinvite_check(call, 0);
 	break;
     case PJ_ICE_STRANS_OP_KEEP_ALIVE:
@@ -689,5 +627,5 @@
 	    PJ_PERROR(4,(THIS_FILE, result,
 		         "ICE keep alive failure for transport %d:%d",
-		         call_med->call->index, call_med->idx));
+		         call->index, call_med->idx));
 	}
         if (pjsua_var.ua_cfg.cb.on_call_media_transport_state) {
@@ -700,8 +638,8 @@
             info.ext_info = &op;
 	    (*pjsua_var.ua_cfg.cb.on_call_media_transport_state)(
-                call_med->call->index, &info);
+                call->index, &info);
         }
 	if (pjsua_var.ua_cfg.cb.on_ice_transport_error) {
-	    pjsua_call_id id = call_med->call->index;
+	    pjsua_call_id id = call->index;
 	    (*pjsua_var.ua_cfg.cb.on_ice_transport_error)(id, op, result,
 							  NULL);
@@ -856,5 +794,5 @@
     pjmedia_transport_simulate_lost(call_med->tp, PJMEDIA_DIR_DECODING,
 				    pjsua_var.media_cfg.rx_drop_pct);
-
+    
     return PJ_SUCCESS;
 
@@ -1340,5 +1278,5 @@
                 call_med->med_create_cb = &call_media_init_cb;
                 call_med->med_init_cb = cb;
-
+                
 	        return PJ_EPENDING;
 	    }
