Index: pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 3664)
+++ pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 3841)
@@ -73,4 +73,5 @@
     pj_sockaddr		 rtcp_src_addr;	/**< Actual source RTCP address.    */
     unsigned		 rtp_src_cnt;	/**< How many pkt from this addr.   */
+    unsigned		 rtcp_src_cnt;  /**< How many pkt from this addr.   */
 
     unsigned		 tx_drop_pct;	/**< Percent of tx pkts to drop.    */
@@ -1517,4 +1518,6 @@
     if (tp_ice->use_ice || tp_ice->rtp_src_cnt) {
 	info->src_rtp_name  = tp_ice->rtp_src_addr;
+    }
+    if (tp_ice->use_ice || tp_ice->rtcp_src_cnt) {
 	info->src_rtcp_name = tp_ice->rtcp_src_addr;
     }
@@ -1582,4 +1585,5 @@
     tp_ice->rtcp_src_addr = tp_ice->remote_rtcp;
     tp_ice->rtp_src_cnt = 0;
+    tp_ice->rtcp_src_cnt = 0;
 
     return PJ_SUCCESS;
@@ -1657,4 +1661,5 @@
 {
     struct transport_ice *tp_ice;
+    pj_bool_t discard = PJ_FALSE;
 
     tp_ice = (struct transport_ice*) pj_ice_strans_get_user_data(ice_st);
@@ -1672,6 +1677,4 @@
 	}
 
-	(*tp_ice->rtp_cb)(tp_ice->stream, pkt, size);
-
 	/* See if source address of RTP packet is different than the 
 	 * configured address, and switch RTP remote address to 
@@ -1680,10 +1683,15 @@
 	 */
 	if (!tp_ice->use_ice) {
-
-	    /* Increment counter and avoid zero */
-	    if (++tp_ice->rtp_src_cnt == 0) 
-		tp_ice->rtp_src_cnt = 1;
-
-	    if (pj_sockaddr_cmp(&tp_ice->remote_rtp, src_addr) != 0) {
+	    pj_bool_t enable_switch =
+		    ((tp_ice->options & PJMEDIA_ICE_NO_SRC_ADDR_CHECKING)==0);
+
+	    if (!enable_switch ||
+		pj_sockaddr_cmp(&tp_ice->remote_rtp, src_addr) == 0)
+	    {
+		/* Don't switch while we're receiving from remote_rtp */
+		tp_ice->rtp_src_cnt = 0;
+	    } else {
+
+		++tp_ice->rtp_src_cnt;
 
 		/* Check if the source address is recognized. */
@@ -1693,9 +1701,10 @@
 		    /* Reset counter */
 		    tp_ice->rtp_src_cnt = 0;
+		    discard = PJ_TRUE;
 		}
 
-		if ((tp_ice->options & PJMEDIA_ICE_NO_SRC_ADDR_CHECKING)==0 &&
-		    tp_ice->rtp_src_cnt >= PJMEDIA_RTP_NAT_PROBATION_CNT) 
-		{
+		if (tp_ice->rtp_src_cnt < PJMEDIA_RTP_NAT_PROBATION_CNT) {
+		    discard = PJ_TRUE;
+		} else {
 		    char addr_text[80];
 
@@ -1726,5 +1735,6 @@
 
 			PJ_LOG(4,(tp_ice->base.name,
-				  "Remote RTCP address switched to %s",
+				  "Remote RTCP address switched to predicted "
+				  "address %s",
 				  pj_sockaddr_print(&tp_ice->remote_rtcp, 
 						    addr_text,
@@ -1734,6 +1744,9 @@
 	    }
 	}
+
+	if (!discard)
+	    (*tp_ice->rtp_cb)(tp_ice->stream, pkt, size);
+
     } else if (comp_id==2 && tp_ice->rtcp_cb) {
-	(*tp_ice->rtcp_cb)(tp_ice->stream, pkt, size);
 
 	/* Check if RTCP source address is the same as the configured
@@ -1742,21 +1755,32 @@
 	 */
 	if (!tp_ice->use_ice &&
-	    pj_sockaddr_cmp(&tp_ice->remote_rtcp, src_addr) != 0)
+	    (tp_ice->options & PJMEDIA_ICE_NO_SRC_ADDR_CHECKING)==0)
 	{
-	    pj_sockaddr_cp(&tp_ice->rtcp_src_addr, src_addr);
-
-	    if ((tp_ice->options & PJMEDIA_ICE_NO_SRC_ADDR_CHECKING)==0) {
+	    if (pj_sockaddr_cmp(&tp_ice->remote_rtcp, src_addr) == 0) {
+		tp_ice->rtcp_src_cnt = 0;
+	    } else {
 		char addr_text[80];
 
-		pj_sockaddr_cp(&tp_ice->remote_rtcp, src_addr);
-
-		pj_assert(tp_ice->addr_len == pj_sockaddr_get_len(src_addr));
-
-		PJ_LOG(4,(tp_ice->base.name,
-			  "Remote RTCP address switched to %s",
-			  pj_sockaddr_print(&tp_ice->remote_rtcp, addr_text,
-					    sizeof(addr_text), 3)));
+		++tp_ice->rtcp_src_cnt;
+		if (tp_ice->rtcp_src_cnt < PJMEDIA_RTCP_NAT_PROBATION_CNT) {
+		    discard = PJ_TRUE;
+		} else {
+		    tp_ice->rtcp_src_cnt = 0;
+		    pj_sockaddr_cp(&tp_ice->rtcp_src_addr, src_addr);
+		    pj_sockaddr_cp(&tp_ice->remote_rtcp, src_addr);
+
+		    pj_assert(tp_ice->addr_len==pj_sockaddr_get_len(src_addr));
+
+		    PJ_LOG(4,(tp_ice->base.name,
+			      "Remote RTCP address switched to %s",
+			      pj_sockaddr_print(&tp_ice->remote_rtcp,
+			                        addr_text, sizeof(addr_text),
+			                        3)));
+		}
 	    }
 	}
+
+	if (!discard)
+	    (*tp_ice->rtcp_cb)(tp_ice->stream, pkt, size);
     }
 
