]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix some regressions and improve candidate selection
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 20 Feb 2013 02:18:12 +0000 (20:18 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Apr 2013 02:27:26 +0000 (21:27 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia_media.c
src/switch_core_media.c
src/switch_rtp.c

index f483a0c8c6cbccc639c346486bb7ab76fe61d9b8..c088e7a940e8e733f9bd477d18e1705adc071a9b 100644 (file)
@@ -689,7 +689,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
        }
 
        if (sofia_test_flag(tech_pvt, TFLAG_ANS) || switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
-               printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_SUCCESS;
+               return SWITCH_STATUS_SUCCESS;
        }
 
 
@@ -703,7 +703,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
                if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
                        switch_core_media_patch_sdp(tech_pvt->session);
                        if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                               printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_FALSE;
+                               return SWITCH_STATUS_FALSE;
                        }
                }
        } else {
@@ -722,7 +722,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
                                if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
                                        switch_core_media_patch_sdp(tech_pvt->session);
                                        if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                                               printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_FALSE;
+                                               return SWITCH_STATUS_FALSE;
                                        }
                                }
                        }
@@ -777,7 +777,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
                        }
 
                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n");
-                       printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_SUCCESS;
+                       return SWITCH_STATUS_SUCCESS;
                }
 
                if ((is_proxy && !b_sdp) || sofia_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) ||
@@ -800,14 +800,14 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session)
                                        //switch_mutex_lock(tech_pvt->sofia_mutex);
                                        //nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
                                        //switch_mutex_unlock(tech_pvt->sofia_mutex);
-                                       printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_FALSE;
+                                       return SWITCH_STATUS_FALSE;
                                }
                        }
                }
 
                if ((status = switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0)) != SWITCH_STATUS_SUCCESS) {
                        switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                       printf("BALLZ %d\n", __LINE__);return status;
+                       return status;
                }
 
                switch_core_media_gen_local_sdp(session, NULL, 0, NULL, 0);
index ff6f3ae1c746d5d90d1dab61d1bdb5ca5abe76db..2d8cc97e258827b1095e41e2ff6c97d40fb800e3 100644 (file)
@@ -77,20 +77,20 @@ switch_status_t sofia_media_tech_media(private_object_t *tech_pvt, const char *r
        switch_assert(r_sdp != NULL);
 
        if (zstr(r_sdp)) {
-               printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_FALSE;
+               return SWITCH_STATUS_FALSE;
        }
 
        if ((match = sofia_media_negotiate_sdp(tech_pvt->session, r_sdp))) {
                if (switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0) != SWITCH_STATUS_SUCCESS) {
-                       printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_FALSE;
+                       return SWITCH_STATUS_FALSE;
                }
                if (sofia_media_activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) {
-                       printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_FALSE;
+                       return SWITCH_STATUS_FALSE;
                }
                switch_channel_set_variable(tech_pvt->channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "EARLY MEDIA");
                sofia_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
                switch_channel_mark_pre_answered(tech_pvt->channel);
-               printf("BALLZ %d\n", __LINE__);return SWITCH_STATUS_SUCCESS;
+               return SWITCH_STATUS_SUCCESS;
        }
 
 
index 10f8d1aed8af97b2fe6e088d55197abb8f80043d..1586928240c739d32d5ce55b1e52e079c5786c0b 100644 (file)
@@ -1946,6 +1946,58 @@ static void check_ice(switch_media_handle_t *smh, switch_media_type_t type, sdp_
                }
                
        }
+       
+       /* still no candidates, so start searching for some based on sane deduction */
+
+       /* look for candidates on the same network */
+       if (!engine->ice_in.chosen[0] || !engine->ice_in.chosen[1]) {
+               for (i = 0; i <= engine->ice_in.cand_idx && (!engine->ice_in.chosen[0] || !engine->ice_in.chosen[1]); i++) {
+                       if (!engine->ice_in.chosen[0] && engine->ice_in.cands[i][0].component_id == 1 && 
+                               !engine->ice_in.cands[i][0].rport && switch_check_network_list_ip(engine->ice_in.cands[i][0].con_addr, "localnet.auto")) {
+                               engine->ice_in.chosen[0] = i;
+                               engine->ice_in.cands[engine->ice_in.chosen[0]][0].ready++;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_NOTICE, "No RTP candidate found; defaulting to the first local one.\n");
+                       }
+                       if (!engine->ice_in.chosen[1] && engine->ice_in.cands[i][1].component_id == 2 && 
+                               !engine->ice_in.cands[i][1].rport && switch_check_network_list_ip(engine->ice_in.cands[i][1].con_addr, "localnet.auto")) {
+                               engine->ice_in.chosen[1] = i;
+                               engine->ice_in.cands[engine->ice_in.chosen[1]][1].ready++;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session),SWITCH_LOG_NOTICE, "No RTCP candidate found; defaulting to the first local one.\n");
+                       }
+               }
+       }
+
+       /* look for candidates with srflx */
+       if (!engine->ice_in.chosen[0] || !engine->ice_in.chosen[1]) {
+               for (i = 0; i <= engine->ice_in.cand_idx && (!engine->ice_in.chosen[0] || !engine->ice_in.chosen[1]); i++) {
+                       if (!engine->ice_in.chosen[0] && engine->ice_in.cands[i][0].component_id == 1 && engine->ice_in.cands[i][0].rport) {
+                               engine->ice_in.chosen[0] = i;
+                               engine->ice_in.cands[engine->ice_in.chosen[0]][0].ready++;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_NOTICE, "No RTP candidate found; defaulting to the first srflx one.\n");
+                       }
+                       if (!engine->ice_in.chosen[1] && engine->ice_in.cands[i][1].component_id == 2 && engine->ice_in.cands[i][1].rport) {
+                               engine->ice_in.chosen[1] = i;
+                               engine->ice_in.cands[engine->ice_in.chosen[1]][1].ready++;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session),SWITCH_LOG_NOTICE, "No RTCP candidate found; defaulting to the first srflx one.\n");
+                       }
+               }
+       }
+
+       /* look for any candidates and hope for auto-adjust */
+       if (!engine->ice_in.chosen[0] || !engine->ice_in.chosen[1]) {
+               for (i = 0; i <= engine->ice_in.cand_idx && (!engine->ice_in.chosen[0] || !engine->ice_in.chosen[1]); i++) {
+                       if (!engine->ice_in.chosen[0] && engine->ice_in.cands[i][0].component_id == 1) {
+                               engine->ice_in.chosen[0] = i;
+                               engine->ice_in.cands[engine->ice_in.chosen[0]][0].ready++;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_NOTICE, "No RTP candidate found; defaulting to the first one.\n");
+                       }
+                       if (!engine->ice_in.chosen[1] && engine->ice_in.cands[i][1].component_id == 2) {
+                               engine->ice_in.chosen[1] = i;
+                               engine->ice_in.cands[engine->ice_in.chosen[1]][1].ready++;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(smh->session), SWITCH_LOG_NOTICE, "No RTCP candidate found; defaulting to the first one.\n");
+                       }
+               }
+       }
 
        for (i = 0; i < 2; i++) {
                if (engine->ice_in.cands[engine->ice_in.chosen[i]][i].ready) {
index 1026b2b7f54314cdb40529526376c0279dc4ce5e..8968a3a141ec23ea838154d17b9dbb025dbce9bc 100644 (file)
@@ -845,7 +845,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
        }
 
        if ((ice->type & ICE_VANILLA)) {
-               if (!ok && ice == &rtp_session->ice && pri && 
+               if (!ok && ice == &rtp_session->ice && rtp_session->rtcp_ice.ice_params && pri && 
                        *pri == rtp_session->rtcp_ice.ice_params->cands[rtp_session->rtcp_ice.ice_params->chosen[1]][1].priority) {
                        ice = &rtp_session->rtcp_ice;
                        ok = 1;
@@ -937,7 +937,7 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
 
        }
 
-       if (ok || ice->missed_count > 1) {
+       if (ok || (ice->missed_count > 3 && !ice->rready)) {
                if ((packet->header.type == SWITCH_STUN_BINDING_RESPONSE)) {
                        if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
                                rtp_session->ice.rready = 1;
@@ -996,13 +996,13 @@ static void handle_ice(switch_rtp_t *rtp_session, switch_rtp_ice_t *ice, void *d
 
                                switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
 
-                               if (!is_rtcp) {
+                               if (!is_rtcp || rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
                                        switch_rtp_set_remote_address(rtp_session, host, port, 0, SWITCH_FALSE, &err);
                                }
 
                                if (rtp_session->dtls) {
 
-                                       if (!is_rtcp) {
+                                       if (!is_rtcp || rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
                                                switch_sockaddr_info_get(&rtp_session->dtls->remote_addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
                                        }