]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add timeout to wait_for_silence
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 10 Jul 2008 19:59:57 +0000 (19:59 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 10 Jul 2008 19:59:57 +0000 (19:59 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8993 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_ivr_play_say.c

index fffa949bc3287f43da5a22900b42cf138d89966c..52e60dd7ad102644369ba79b66c218b5bfcdd320 100644 (file)
@@ -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);
 
index 328cc803b69cf13ded3731b22bd24e0cfd2b138c..abeb12d24b471734cdfe411359cca9dd1a27672f 100644 (file)
@@ -2102,11 +2102,11 @@ SWITCH_STANDARD_APP(unhold_function)
        switch_ivr_unhold_uuid(switch_core_session_get_uuid(session));
 }
 
-#define WAIT_FOR_SILENCE_SYNTAX "<silence_thresh> <silence_hits> <listen_hits> [<file>]"
+#define WAIT_FOR_SILENCE_SYNTAX "<silence_thresh> <silence_hits> <listen_hits> <timeout_ms> [<file>]"
 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;
                }
 
index e7bc645c5c32a04283fcde8c4a73e607f537cf3d..f90243a4cc0b98d287e23e45be9d7f9ee5b8594a 100644 (file)
@@ -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;