Ignore RTP packets when adjusting UDPTL media port

When auto-adjusting UDPTL media port at the start of a call, ignore any
RTP packets that is received which can arrive after FreeSWITCH has
switched and come from a different port on the remote side.
This commit is contained in:
Patrice Fournier 2018-03-06 13:54:34 -05:00
parent c402ce1dee
commit 16658f8463
2 changed files with 16 additions and 1 deletions

View File

@ -816,6 +816,7 @@ typedef enum {
SWITCH_RTP_FLAG_VAD, SWITCH_RTP_FLAG_VAD,
SWITCH_RTP_FLAG_BREAK, SWITCH_RTP_FLAG_BREAK,
SWITCH_RTP_FLAG_UDPTL, SWITCH_RTP_FLAG_UDPTL,
SWITCH_RTP_FLAG_UDPTL_INIT,
SWITCH_RTP_FLAG_DATAWAIT, SWITCH_RTP_FLAG_DATAWAIT,
SWITCH_RTP_FLAG_BYTESWAP, SWITCH_RTP_FLAG_BYTESWAP,
SWITCH_RTP_FLAG_PASS_RFC2833, SWITCH_RTP_FLAG_PASS_RFC2833,

View File

@ -354,6 +354,8 @@ struct switch_rtp {
uint32_t rtcp_autoadj_threshold; uint32_t rtcp_autoadj_threshold;
uint32_t rtcp_autoadj_tally; uint32_t rtcp_autoadj_tally;
uint32_t udptl_autoadj_threshold;
srtp_ctx_t *send_ctx[2]; srtp_ctx_t *send_ctx[2];
srtp_ctx_t *recv_ctx[2]; srtp_ctx_t *recv_ctx[2];
@ -3107,6 +3109,9 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_udptl_mode(switch_rtp_t *rtp_session)
} }
} }
if (!rtp_session->flags[SWITCH_RTP_FLAG_UDPTL]) {
switch_rtp_set_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL_INIT);
}
switch_rtp_set_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL); switch_rtp_set_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL);
switch_rtp_set_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA); switch_rtp_set_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE); switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE);
@ -5388,6 +5393,7 @@ SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_f
rtp_session->autoadj_window = 20; rtp_session->autoadj_window = 20;
rtp_session->autoadj_threshold = 10; rtp_session->autoadj_threshold = 10;
rtp_session->autoadj_tally = 0; rtp_session->autoadj_tally = 0;
rtp_session->udptl_autoadj_threshold = 1;
switch_mutex_lock(rtp_session->flag_mutex); switch_mutex_lock(rtp_session->flag_mutex);
rtp_session->flags[SWITCH_RTP_FLAG_RTCP_AUTOADJ] = 1; rtp_session->flags[SWITCH_RTP_FLAG_RTCP_AUTOADJ] = 1;
@ -7642,9 +7648,16 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
} }
} }
/* ignore RTP packets when looking for UDPTL media */
if (rtp_session->flags[SWITCH_RTP_FLAG_AUTOADJ] && rtp_session->flags[SWITCH_RTP_FLAG_UDPTL_INIT]) {
if (bytes && rtp_session->last_seq > 100) {
goto recvfrom;
}
}
if (bytes && rtp_session->flags[SWITCH_RTP_FLAG_AUTOADJ] && switch_sockaddr_get_port(rtp_session->rtp_from_addr)) { if (bytes && rtp_session->flags[SWITCH_RTP_FLAG_AUTOADJ] && switch_sockaddr_get_port(rtp_session->rtp_from_addr)) {
if (!switch_cmp_addr(rtp_session->rtp_from_addr, rtp_session->remote_addr, SWITCH_FALSE)) { if (!switch_cmp_addr(rtp_session->rtp_from_addr, rtp_session->remote_addr, SWITCH_FALSE)) {
if (++rtp_session->autoadj_tally >= rtp_session->autoadj_threshold) { if (++rtp_session->autoadj_tally >= (rtp_session->flags[SWITCH_RTP_FLAG_UDPTL] ? rtp_session->udptl_autoadj_threshold : rtp_session->autoadj_threshold)) {
const char *err; const char *err;
uint32_t old = rtp_session->remote_port; uint32_t old = rtp_session->remote_port;
const char *tx_host; const char *tx_host;
@ -7705,6 +7718,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
if (bytes && !(rtp_session->rtp_bugs & RTP_BUG_ALWAYS_AUTO_ADJUST) && rtp_session->autoadj_window) { if (bytes && !(rtp_session->rtp_bugs & RTP_BUG_ALWAYS_AUTO_ADJUST) && rtp_session->autoadj_window) {
if (--rtp_session->autoadj_window == 0) { if (--rtp_session->autoadj_window == 0) {
switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ); switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL_INIT);
} }
} }