diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h index 9d1de7a..ed23d0b 100644 --- a/src/include/switch_rtp.h +++ b/src/include/switch_rtp.h @@ -462,6 +462,7 @@ SWITCH_DECLARE(void) switch_rtp_intentional_bugs(switch_rtp_t *rtp_session, swit SWITCH_DECLARE(switch_rtp_stats_t *) switch_rtp_get_stats(switch_rtp_t *rtp_session, switch_memory_pool_t *pool); SWITCH_DECLARE(switch_byte_t) switch_rtp_check_auto_adj(switch_rtp_t *rtp_session); SWITCH_DECLARE(void) switch_rtp_set_interdigit_delay(switch_rtp_t *rtp_session, uint32_t delay); +SWITCH_DECLARE(void) switch_rtp_set_auto_adjust(switch_rtp_t *rtp_session, uint32_t autoadj); /*! \} diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 795f961..c029ba0 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -669,6 +669,7 @@ struct sofia_profile { int ireg_seconds; sofia_paid_type_t paid_type; uint32_t rtp_digit_delay; + uint32_t rtp_auto_adjust; }; struct private_object { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 9614b1c..8c0dc05 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3202,6 +3202,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) } else { sofia_clear_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION); } + } else if (!strcasecmp(var, "rtp-auto-adjust")) { + int autoadj = atoi(val); + if (autoadj < 1) { + autoadj = 1; + } + profile->rtp_auto_adjust = (uint32_t) autoadj; } else if (!strcasecmp(var, "disable-rtp-auto-adjust")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_DISABLE_RTP_AUTOADJ); @@ -3748,6 +3754,7 @@ switch_status_t config_sofia(int reload, char *profile_name) switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool); profile->dtmf_duration = 100; profile->rtp_digit_delay = 40; + profile->rtp_auto_adjust = 10; profile->sip_force_expires = 0; profile->sip_expires_max_deviation = 0; profile->tls_version = 0; @@ -4034,6 +4041,12 @@ switch_status_t config_sofia(int reload, char *profile_name) sofia_set_pflag(profile, PFLAG_RECIEVED_IN_NAT_REG_CONTACT); } else if (!strcasecmp(var, "aggressive-nat-detection") && switch_true(val)) { sofia_set_pflag(profile, PFLAG_AGGRESSIVE_NAT_DETECTION); + } else if (!strcasecmp(var, "rtp-auto-adjust")) { + int autoadj = atoi(val); + if (autoadj < 1) { + autoadj = 1; + } + profile->rtp_auto_adjust = (uint32_t) autoadj; } else if (!strcasecmp(var, "disable-rtp-auto-adjust") && switch_true(val)) { sofia_set_pflag(profile, PFLAG_DISABLE_RTP_AUTOADJ); } else if (!strcasecmp(var, "NDLB-support-asterisk-missing-srtp-auth") && switch_true(val)) { diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 0d7f0b5..c8fda60 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -3538,6 +3538,21 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f } + if (tech_pvt->profile->rtp_auto_adjust || ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_auto_adjust")))) { + uint32_t autoadj = tech_pvt->profile->rtp_auto_adjust; + + if (!autoadj) { + int autoadji = atoi(val); + if (autoadji < 1) autoadji = 1; + autoadj = (uint32_t) autoadji; + } + + switch_rtp_set_auto_adjust(tech_pvt->rtp_session, autoadj); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, + "%s Set rtp auto-adjust to %u\n", switch_channel_get_name(tech_pvt->channel), autoadj); + + } + if (tech_pvt->cng_pt && !sofia_test_pflag(tech_pvt->profile, PFLAG_SUPPRESS_CNG)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Set comfort noise payload to %u\n", tech_pvt->cng_pt); switch_rtp_set_cng_pt(tech_pvt->rtp_session, tech_pvt->cng_pt); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 72d7a8e..e16d5a8 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -170,6 +170,7 @@ struct switch_rtp { switch_sockaddr_t *remote_stun_addr; + uint32_t autoadj; uint32_t autoadj_window; uint32_t autoadj_tally; @@ -2258,11 +2259,18 @@ SWITCH_DECLARE(void) switch_rtp_set_invald_handler(switch_rtp_t *rtp_session, sw rtp_session->invalid_handler = on_invalid; } +SWITCH_DECLARE(void) switch_rtp_set_auto_adjust(switch_rtp_t *rtp_session, uint32_t autoadj) +{ + rtp_session->autoadj = autoadj; + if (rtp_session->autoadj_window < autoadj) rtp_session->autoadj_window = autoadj + 10; +} + SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags) { switch_set_flag_locked(rtp_session, flags); if (flags & SWITCH_RTP_FLAG_AUTOADJ) { - rtp_session->autoadj_window = 20; + if (!rtp_session->autoadj) rtp_session->autoadj = 10; + if (!rtp_session->autoadj_window) rtp_session->autoadj_window = 20; rtp_session->autoadj_tally = 0; rtp_flush_read_buffer(rtp_session, SWITCH_RTP_FLUSH_ONCE); } else if (flags & SWITCH_RTP_FLAG_NOBLOCK) { @@ -3221,7 +3229,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) { if (!switch_cmp_addr(rtp_session->from_addr, rtp_session->remote_addr)) { - if (++rtp_session->autoadj_tally >= 10) { + if (++rtp_session->autoadj_tally >= rtp_session->autoadj) { const char *err; uint32_t old = rtp_session->remote_port; const char *tx_host;