]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] Fix ICE and media delay.
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 22 Feb 2019 23:40:28 +0000 (02:40 +0300)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 19:00:52 +0000 (22:00 +0300)
src/switch_rtp.c

index 36bd904e77318494da2c5eea2ad952f59163fa49..12360c522ceb25dc45269a0f7fb6138d855524c3 100644 (file)
@@ -266,6 +266,7 @@ typedef struct {
        uint8_t sending;
        uint8_t ready;
        uint8_t rready;
+       uint8_t init;
        int missed_count;
        char last_sent_id[13];
        switch_time_t last_ok;
@@ -965,7 +966,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
                rtp_session->first_stun = rtp_session->last_stun;
        }
 
-       if (ice->last_ok) {
+       if (ice->last_ok && (!rtp_session->dtls || rtp_session->dtls->state == DS_READY)) {
                ref_point = ice->last_ok;
        } else {
                ref_point = rtp_session->first_stun;
@@ -1256,19 +1257,29 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
                        port2 = switch_sockaddr_get_port(ice->addr);
                        cmp = switch_cmp_addr(from_addr, ice->addr, SWITCH_FALSE);
 
-                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG4,
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG2,
                                                          "STUN from %s:%d %s\n", host, port, cmp ? "EXPECTED" : "IGNORED");
 
+                       if (ice->init && !cmp && switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) {
+                               do_adj++;
+                               rtp_session->ice_adj++;
+                               rtp_session->wrong_addrs = 0;
+                               ice->init = 0;
+                       }
+                       
                        if (cmp) {
                                ice->last_ok = now;
                                rtp_session->wrong_addrs = 0;
                        } else {
-                               if (((rtp_session->dtls && rtp_session->dtls->state != DS_READY) || !ice->ready || !ice->rready) &&
-                                       (rtp_session->wrong_addrs > 2 || switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) && rtp_session->ice_adj == 0) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_DEBUG10, "ICE %d dt:%d i:%d i2:%d w:%d cmp:%d adj:%d\n", elapsed, (rtp_session->dtls && rtp_session->dtls->state != DS_READY), !ice->ready, !ice->rready, rtp_session->wrong_addrs, switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE), rtp_session->ice_adj);
+
+                               if ((rtp_session->dtls && rtp_session->dtls->state != DS_READY) ||
+                                       ((!ice->ready || !ice->rready) && (rtp_session->wrong_addrs > 2 || switch_cmp_addr(from_addr, ice->addr, SWITCH_TRUE)) &&
+                                        rtp_session->ice_adj < 10)) {
                                        do_adj++;
-                                       rtp_session->ice_adj = 1;
+                                       rtp_session->ice_adj++;
                                        rtp_session->wrong_addrs = 0;
-                               } else if (rtp_session->wrong_addrs > 10 || elapsed >= 10000) {
+                               } else if (rtp_session->wrong_addrs > 10 || elapsed >= 5000) {
                                        do_adj++;
                                }
 
@@ -5040,6 +5051,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio
        ice->pass = "";
        ice->rpass = "";
        ice->next_run = switch_micro_time_now();
+       ice->init = 1;
 
        if (password) {
                ice->pass = switch_core_strdup(rtp_session->pool, password);