From d50d43f78832bf3e2ae772c0cc48d76d9539ea34 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Mon, 8 Apr 2013 11:00:22 -0500
Subject: [PATCH] make auto-adjust more logical

---
 src/switch_rtp.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/switch_rtp.c b/src/switch_rtp.c
index 2c99711ccc..87d6526f48 100644
--- a/src/switch_rtp.c
+++ b/src/switch_rtp.c
@@ -949,11 +949,14 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
 				}
 			}
 		}
-
-
 	}
 
-	if (ok || (ice->missed_count > 3 && !ice->rready)) {
+	if (ice->missed_count > 3) {
+		ice->rready = 0;
+	}
+
+
+	if (ok || !ice->rready) {
 		if ((packet->header.type == SWITCH_STUN_BINDING_RESPONSE)) {
 			if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
 				rtp_session->ice.rready = 1;
@@ -997,12 +1000,15 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
 
 			bytes = switch_stun_packet_length(rpacket);
 
-			if ((ice->type & ICE_VANILLA) && ice->ice_params && !switch_cmp_addr(from_addr, ice->addr)) {
+			if (!ice->rready && (ice->type & ICE_VANILLA) && ice->ice_params && !switch_cmp_addr(from_addr, ice->addr)) {
 				const char *host;
 				switch_port_t port;
 				char buf[80] = "";
 				const char *err = "";
 
+				ice->missed_count = 0;
+				ice->rready = 1;
+
 				host = switch_get_addr(buf, len, from_addr);
 				port = switch_sockaddr_get_port(from_addr);