[Core] Fix hard coded dtmf durations based on 8k

This commit is contained in:
Anthony Minessale 2019-11-27 21:10:50 +00:00 committed by Andrey Volk
parent b93eea73ef
commit 7ce50c8bd0

View File

@ -1127,6 +1127,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
int i, argc;
char *argv[256];
int dur_total = 0;
int rate_mult = 8;
switch_codec_implementation_t write_impl = { 0 };
switch_assert(session != NULL);
@ -1156,13 +1159,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
switch_channel_pre_answer(session->channel);
}
switch_core_session_get_write_impl(session, &write_impl);
rate_mult = (write_impl.actual_samples_per_second / 1000);
for (i = 0; i < argc; i++) {
dtmf.duration = switch_core_default_dtmf_duration(0);
dur = switch_core_default_dtmf_duration(0) / 8;
dur = switch_core_default_dtmf_duration(0) / rate_mult;
if ((p = strchr(argv[i], '@'))) {
*p++ = '\0';
if ((dur = atoi(p)) > (int)switch_core_min_dtmf_duration(0) / 8) {
dtmf.duration = dur * 8;
if ((dur = atoi(p)) > (int)switch_core_min_dtmf_duration(0) / rate_mult) {
dtmf.duration = dur * rate_mult;
}
}
@ -1192,14 +1198,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s send dtmf\ndigit=%c ms=%u samples=%u\n",
switch_channel_get_name(session->channel), dtmf.digit, dur, dtmf.duration);
sent++;
dur_total += dtmf.duration + 2000; /* account for 250ms pause */
dur_total += dtmf.duration + (250 * rate_mult); /* account for 250ms pause */
}
}
}
if (dur_total) {
char tmp[32] = "";
switch_snprintf(tmp, sizeof(tmp), "%d", dur_total / 8);
switch_snprintf(tmp, sizeof(tmp), "%d", dur_total / rate_mult);
switch_channel_set_variable(session->channel, "last_dtmf_duration", tmp);
}