[Freeswitch-svn] [commit] r8993 - in freeswitch/trunk/src: . include mod/applications/mod_dptools

Freeswitch SVN anthm at freeswitch.org
Thu Jul 10 15:59:57 EDT 2008


Author: anthm
Date: Thu Jul 10 15:59:57 2008
New Revision: 8993

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/switch_ivr_play_say.c

Log:
add timeout to wait_for_silence

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Thu Jul 10 15:59:57 2008
@@ -315,7 +315,7 @@
 													 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);
 

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Thu Jul 10 15:59:57 2008
@@ -2102,11 +2102,11 @@
 	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 @@
 		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;
 		}
 

Modified: freeswitch/trunk/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_play_say.c	(original)
+++ freeswitch/trunk/src/switch_ivr_play_say.c	Thu Jul 10 15:59:57 2008
@@ -1195,7 +1195,8 @@
 	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 @@
 	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 @@
 			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;
 			



More information about the Freeswitch-svn mailing list