diff --git a/src/switch_channel.c b/src/switch_channel.c index 13392da933..2a77ac9976 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -380,18 +380,23 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan char str[2] = ""; str[0] = new_dtmf.digit; + + if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') { + if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { + switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s EXCESSIVE DTMF DIGIT [%s] LEN [%d]\n", + switch_channel_get_name(channel), str, new_dtmf.duration); + new_dtmf.duration = switch_core_max_dtmf_duration(0); + } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) { + switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s SHORT DTMF DIGIT [%s] LEN [%d]\n", + switch_channel_get_name(channel), str, new_dtmf.duration); + new_dtmf.duration = switch_core_min_dtmf_duration(0); + } + } - if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { - switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s EXCESSIVE DTMF DIGIT [%s] LEN [%d]\n", - switch_channel_get_name(channel), str, new_dtmf.duration); - new_dtmf.duration = switch_core_max_dtmf_duration(0); - } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) { - switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s SHORT DTMF DIGIT [%s] LEN [%d]\n", - switch_channel_get_name(channel), str, new_dtmf.duration); - new_dtmf.duration = switch_core_min_dtmf_duration(0); - } else if (!new_dtmf.duration) { + if (!new_dtmf.duration) { new_dtmf.duration = switch_core_default_dtmf_duration(0); } + switch_zmalloc(dt, sizeof(*dt)); *dt = new_dtmf; diff --git a/src/switch_core_io.c b/src/switch_core_io.c index d8a519a294..7d19e95f71 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -1341,19 +1341,22 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio switch_assert(dtmf); new_dtmf = *dtmf; - - if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n", + + if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') { + if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n", + switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration); + new_dtmf.duration = switch_core_max_dtmf_duration(0); + } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n", switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration); - new_dtmf.duration = switch_core_max_dtmf_duration(0); - } else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n", - switch_channel_get_name(session->channel), new_dtmf.digit, new_dtmf.duration); - new_dtmf.duration = switch_core_min_dtmf_duration(0); - } else if (!new_dtmf.duration) { - new_dtmf.duration = switch_core_default_dtmf_duration(0); + new_dtmf.duration = switch_core_min_dtmf_duration(0); + } } + if (!new_dtmf.duration) { + new_dtmf.duration = switch_core_default_dtmf_duration(0); + } if (!switch_test_flag(dtmf, DTMF_FLAG_SKIP_PROCESS)) { for (ptr = session->event_hooks.send_dtmf; ptr; ptr = ptr->next) { @@ -1444,18 +1447,23 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core for (p = argv[i]; p && *p; p++) { if (is_dtmf(*p)) { dtmf.digit = *p; - - if (dtmf.duration > switch_core_max_dtmf_duration(0)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n", - switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration); - dtmf.duration = switch_core_max_dtmf_duration(0); - } else if (dtmf.duration < switch_core_min_dtmf_duration(0)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n", - switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration); - dtmf.duration = switch_core_min_dtmf_duration(0); - } else if (!dtmf.duration) { + + if (dtmf.digit != 'w' && dtmf.digit != 'W') { + if (dtmf.duration > switch_core_max_dtmf_duration(0)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n", + switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration); + dtmf.duration = switch_core_max_dtmf_duration(0); + } else if (dtmf.duration < switch_core_min_dtmf_duration(0)) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n", + switch_channel_get_name(session->channel), dtmf.digit, dtmf.duration); + dtmf.duration = switch_core_min_dtmf_duration(0); + } + } + + if (!dtmf.duration) { dtmf.duration = switch_core_default_dtmf_duration(0); } + if (switch_core_session_send_dtmf(session, &dtmf) == SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s send dtmf\ndigit=%c ms=%u samples=%u\n", diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 0ea3a978b0..38e4019d56 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -185,7 +185,7 @@ struct switch_rtp { uint32_t last_read_ts; uint32_t last_cng_ts; uint32_t last_write_samplecount; - uint32_t next_write_samplecount; + uint32_t delay_samples; uint32_t max_next_write_samplecount; uint32_t queue_delay; switch_time_t last_write_timestamp; @@ -2318,7 +2318,6 @@ static void do_2833(switch_rtp_t *rtp_session, switch_core_session_t *session) rtp_session->dtmf_data.out_digit_dur = 0; set_dtmf_delay(rtp_session, 40, 500); - return; } } @@ -2327,16 +2326,23 @@ static void do_2833(switch_rtp_t *rtp_session, switch_core_session_t *session) void *pop; if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { - if (rtp_session->last_write_ts < rtp_session->next_write_samplecount && rtp_session->timer.samplecount < rtp_session->max_next_write_samplecount) { + if (rtp_session->timer.samplecount < rtp_session->max_next_write_samplecount) { return; } + if (rtp_session->timer.samplecount >= rtp_session->max_next_write_samplecount) { rtp_session->queue_delay = 0; } - } else { - if (rtp_session->last_write_ts < rtp_session->next_write_samplecount) { - return; + } else if (rtp_session->queue_delay) { + if (rtp_session->delay_samples >= rtp_session->samples_per_interval) { + rtp_session->delay_samples -= rtp_session->samples_per_interval; + } else { + rtp_session->delay_samples = 0; + } + + if (!rtp_session->delay_samples) { + rtp_session->queue_delay = 0; } } @@ -3926,7 +3932,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, rtp_session->last_write_ts = this_ts; if (rtp_session->queue_delay) { - rtp_session->next_write_samplecount = rtp_session->last_write_ts + rtp_session->queue_delay; + rtp_session->delay_samples = rtp_session->queue_delay; rtp_session->queue_delay = 0; } @@ -4175,9 +4181,11 @@ SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_fra fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0; - if (!fwd && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) { + if (!fwd && !rtp_session->sending_dtmf && !rtp_session->queue_delay && + switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (rtp_session->rtp_bugs & RTP_BUG_GEN_ONE_GEN_ALL)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Generating RTP locally but timestamp passthru is configured, disabling....\n"); switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE); + rtp_session->last_write_ts = RTP_TS_RESET; } switch_assert(frame != NULL);