From cc63a0595a70249d29155e4484e7e4d07d05755a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 10 Jul 2008 19:59:57 +0000 Subject: [PATCH] add timeout to wait_for_silence git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8993 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_ivr.h | 2 +- src/mod/applications/mod_dptools/mod_dptools.c | 14 ++++++++++---- src/switch_ivr_play_say.c | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index fffa949bc3..52e60dd7ad 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -315,7 +315,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_input_args_t *args); SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, uint32_t silence_hits, - uint32_t listen_hits, const char *file); + uint32_t listen_hits, uint32_t timeout_ms, const char *file); SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 328cc803b6..abeb12d24b 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -2102,11 +2102,11 @@ SWITCH_STANDARD_APP(unhold_function) switch_ivr_unhold_uuid(switch_core_session_get_uuid(session)); } -#define WAIT_FOR_SILENCE_SYNTAX " []" +#define WAIT_FOR_SILENCE_SYNTAX " []" SWITCH_STANDARD_APP(wait_for_silence_function) { - char *argv[4] = { 0 }; - uint32_t thresh, silence_hits, listen_hits; + char *argv[5] = { 0 }; + uint32_t thresh, silence_hits, listen_hits, timeout_ms = 0; int argc; char *lbuf = NULL; @@ -2116,8 +2116,14 @@ SWITCH_STANDARD_APP(wait_for_silence_function) silence_hits = atoi(argv[1]); listen_hits = atoi(argv[2]); + if (argv[3]) { + if ((timeout_ms = atoi(argv[3])) < 0) { + timeout_ms = 0; + } + } + if (thresh > 0 && silence_hits > 0 && listen_hits > 0) { - switch_ivr_wait_for_silence(session, thresh, silence_hits, listen_hits, argv[3]); + switch_ivr_wait_for_silence(session, thresh, silence_hits, listen_hits, timeout_ms, argv[4]); return; } diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index e7bc645c5c..f90243a4cc 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -1195,7 +1195,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess return status; } -SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, uint32_t silence_hits, uint32_t listen_hits, const char *file) +SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_t *session, uint32_t thresh, + uint32_t silence_hits, uint32_t listen_hits, uint32_t timeout_ms, const char *file) { uint32_t score, count = 0, j = 0; double energy = 0; @@ -1213,9 +1214,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_ int16_t *abuf = NULL; switch_frame_t write_frame = {0}; switch_file_handle_t fh = {0}; + int32_t sample_count = 0; switch_assert(read_codec); + if (timeout_ms) { + sample_count = (read_codec->implementation->actual_samples_per_second / 1000) * timeout_ms; + } + if (file) { if (switch_core_file_open(&fh, file, @@ -1258,6 +1264,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_ break; } + if (sample_count) { + sample_count -= raw_codec.implementation->samples_per_frame; + if (sample_count <= 0) { + break; + } + } + if (abuf) { switch_size_t olen = raw_codec.implementation->samples_per_frame;