From 112e57f9fea4cb48f5f1c6940a8f6cd31a27f8d7 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 13 Jul 2020 10:57:49 -0400 Subject: [PATCH] TT#86102 remove aggressive endpoint learning heuristics The previous approach causes problems during re-invites with updated port (or address) information. The UA might delay actually using the new endpoint until after the answer is seen, in which case rtpengine would erroneously immediately latch on to the old endpoint. We need to reinstate the endpoint learning delay in all cases, and make sure previously learned endpoints are forgotten whenever a new signal is seen. Change-Id: If42ed13c43710616c02cdf018b36a4543d7f6bfe --- daemon/media_socket.c | 11 +++++++---- include/call.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 91ae98863..12272986d 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1646,6 +1646,12 @@ static int media_packet_address_check(struct packet_handler_ctx *phc) && phc->mp.stream->advertised_endpoint.address.family && phc->mp.stream->advertised_endpoint.port) { + // check if we need to reset our learned endpoints + if (memcmp(&rtpe_now, &phc->mp.stream->ep_detect_signal, sizeof(rtpe_now))) { + memset(&phc->mp.stream->detected_endpoints, 0, sizeof(phc->mp.stream->detected_endpoints)); + phc->mp.stream->ep_detect_signal = rtpe_now; + } + // possible endpoints that can be detected in order of preference: // 0: endpoint that matches the address advertised in the SDP // 1: endpoint with the same address but different port @@ -1664,11 +1670,8 @@ static int media_packet_address_check(struct packet_handler_ctx *phc) // now grab the best matched endpoint for (idx = 0; idx < 4; idx++) { use_endpoint_confirm = &phc->mp.stream->detected_endpoints[idx]; - if (use_endpoint_confirm->address.family) { - if (idx == 0) // doesn't get any better than this - goto confirm_now; + if (use_endpoint_confirm->address.family) break; - } } } diff --git a/include/call.h b/include/call.h index fde0cccf5..23ec07dd8 100644 --- a/include/call.h +++ b/include/call.h @@ -266,6 +266,7 @@ struct packet_stream { const struct streamhandler *handler; /* LOCK: in_lock */ struct endpoint endpoint; /* LOCK: out_lock */ struct endpoint detected_endpoints[4]; /* LOCK: out_lock */ + struct timeval ep_detect_signal; /* LOCK: out_lock */ struct endpoint advertised_endpoint; /* RO */ struct crypto_context crypto; /* OUT direction, LOCK: out_lock */ struct ssrc_ctx *ssrc_in, /* LOCK: in_lock */ // XXX eliminate these