Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore RTP packets when adjusting UDPTL media port #2607

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/switch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ typedef enum {
SWITCH_RTP_FLAG_VAD,
SWITCH_RTP_FLAG_BREAK,
SWITCH_RTP_FLAG_UDPTL,
SWITCH_RTP_FLAG_UDPTL_INIT,
SWITCH_RTP_FLAG_DATAWAIT,
SWITCH_RTP_FLAG_BYTESWAP,
SWITCH_RTP_FLAG_PASS_RFC2833,
Expand Down
16 changes: 15 additions & 1 deletion src/switch_rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ struct switch_rtp {
uint32_t rtcp_autoadj_threshold;
uint32_t rtcp_autoadj_tally;

uint32_t udptl_autoadj_threshold;

srtp_ctx_t *send_ctx[2];
srtp_ctx_t *recv_ctx[2];

Expand Down Expand Up @@ -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_PROXY_MEDIA);
switch_socket_opt_set(rtp_session->sock_input, SWITCH_SO_NONBLOCK, FALSE);
Expand Down Expand Up @@ -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_threshold = 10;
rtp_session->autoadj_tally = 0;
rtp_session->udptl_autoadj_threshold = 1;

switch_mutex_lock(rtp_session->flag_mutex);
rtp_session->flags[SWITCH_RTP_FLAG_RTCP_AUTOADJ] = 1;
Expand Down Expand Up @@ -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 (!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;
uint32_t old = rtp_session->remote_port;
const char *tx_host;
Expand Down Expand Up @@ -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 (--rtp_session->autoadj_window == 0) {
switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
switch_rtp_clear_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL_INIT);
}
}

Expand Down