diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 8b12efaffb..fd11a3da47 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -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); }