[Freeswitch-svn] [commit] r7125 - in freeswitch/trunk/src: . include mod/applications/mod_conference mod/applications/mod_rss mod/applications/mod_voicemail mod/languages/mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Mon Jan 7 11:49:46 EST 2008


Author: anthm
Date: Mon Jan  7 11:49:46 2008
New Revision: 7125

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/switch_cpp.cpp
   freeswitch/trunk/src/switch_ivr.c
   freeswitch/trunk/src/switch_ivr_menu.c
   freeswitch/trunk/src/switch_ivr_originate.c
   freeswitch/trunk/src/switch_ivr_play_say.c

Log:
fix dtmf code

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Mon Jan  7 11:49:46 2008
@@ -134,13 +134,19 @@
   \param maxdigits max number of digits to read
   \param terminators digits to end the collection
   \param terminator actual digit that caused the collection to end (if any)
-  \param timeout timeout in ms
+  \param first_timeout timeout in ms
+  \param digit_timeout digit timeout in ms
+  \param abs_timeout abs timeout in ms
   \return SWITCH_STATUS_SUCCESS to keep the collection moving.
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
 																char *buf,
 																switch_size_t buflen,
-																switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t timeout);
+																switch_size_t maxdigits, 
+																const char *terminators, char *terminator, 
+																uint32_t first_timeout,
+																uint32_t digit_timeout,
+																uint32_t abs_timeout);
 
 /*!
   \brief Engage background Speech detection on a session

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Mon Jan  7 11:49:46 2008
@@ -4125,7 +4125,7 @@
 					status = switch_ivr_collect_digits_count(session,
 															 buf,
 															 sizeof(pin_buf) - strlen(pin_buf),
-															 strlen(conference->pin) - strlen(pin_buf), "#", &term, 10000);
+															 strlen(conference->pin) - strlen(pin_buf), "#", &term, 10000, 0, 0);
 				}
 
 				pin_valid = (status == SWITCH_STATUS_SUCCESS && strcmp(pin_buf, conference->pin) == 0);

Modified: freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	Mon Jan  7 11:49:46 2008
@@ -367,7 +367,7 @@
 				switch_size_t blen = sizeof(cmd) - strlen(cmd);
 
 				cp = cmd + blen;
-				switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000);
+				switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000, 0, 0);
 			}
 
 			x = atoi(cmd) - 1;

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Mon Jan  7 11:49:46 2008
@@ -826,7 +826,7 @@
 		maxlen = buflen -1;
 	}
 	if (bslen < maxlen) {
-		status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout);
+		status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout, 0, 0);
 	}
 
 	return status;

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Mon Jan  7 11:49:46 2008
@@ -1928,7 +1928,7 @@
 	struct js_session *jss = JS_GetPrivate(cx, obj);
 	char *terminators = NULL;
 	char buf[513] = { 0 };
-	int32 digits = 0, timeout = 5000;
+	int32 digits = 0, timeout = 5000, digit_timeout = 0, abs_timeout = 0;
 	switch_channel_t *channel;
 
 	METHOD_SANITY_CHECK();
@@ -1950,12 +1950,21 @@
 		if (argc > 1) {
 			terminators = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 		}
+
 		if (argc > 2) {
 			JS_ValueToInt32(cx, argv[2], &timeout);
 		}
 
+		if (argc > 3) {
+			JS_ValueToInt32(cx, argv[3], &digit_timeout);
+		}
+
+		if (argc > 4) {
+			JS_ValueToInt32(cx, argv[4], &abs_timeout);
+		}
+
 
-		switch_ivr_collect_digits_count(jss->session, buf, sizeof(buf), digits, terminators, &term, timeout);
+		switch_ivr_collect_digits_count(jss->session, buf, sizeof(buf), digits, terminators, &term, timeout, digit_timeout, abs_timeout);
 		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
 		return JS_TRUE;
 	}

Modified: freeswitch/trunk/src/switch_cpp.cpp
==============================================================================
--- freeswitch/trunk/src/switch_cpp.cpp	(original)
+++ freeswitch/trunk/src/switch_cpp.cpp	Mon Jan  7 11:49:46 2008
@@ -216,7 +216,7 @@
 											 maxdigits, 
 											 terminators, 
 											 terminator, 
-											 (uint32_t) timeout);
+											 (uint32_t) timeout, 0, 0);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "getDigits dtmf_buf: %s\n", dtmf_buf);
 	end_allow_threads();

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Mon Jan  7 11:49:46 2008
@@ -599,13 +599,18 @@
 SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
 																char *buf,
 																switch_size_t buflen,
-																switch_size_t maxdigits, const char *terminators, char *terminator, uint32_t timeout)
+																switch_size_t maxdigits, 
+																const char *terminators, char *terminator, 
+																uint32_t first_timeout,
+																uint32_t digit_timeout,
+																uint32_t abs_timeout)
 {
 	switch_size_t i = 0, x = strlen(buf);
 	switch_channel_t *channel;
 	switch_status_t status = SWITCH_STATUS_FALSE;
-	switch_time_t started = 0;
-	uint32_t elapsed;
+	switch_time_t started = 0, digit_started = 0;
+	uint32_t abs_elapsed = 0, digit_elapsed = 0;
+	uint32_t eff_timeout = 0;
 
 	channel = switch_core_session_get_channel(session);
 	switch_assert(channel != NULL);
@@ -622,16 +627,31 @@
 		}
 	}
 
-	if (timeout) {
-		started = switch_time_now();
+	if (abs_timeout) {
+		started = switch_timestamp_now();
 	}
 
+	if (digit_timeout && first_timeout) {
+		eff_timeout = first_timeout;
+	} else if (digit_timeout && !first_timeout) {
+		first_timeout = eff_timeout = digit_timeout;
+	} else if (first_timeout) {
+		digit_timeout = eff_timeout = first_timeout;
+	}
+	
+
+	if (eff_timeout) {
+		digit_started = switch_timestamp_now();
+	}
+
+
+
 	while (switch_channel_ready(channel)) {
 		switch_frame_t *read_frame;
 		
-		if (timeout) {
-			elapsed = (uint32_t) ((switch_time_now() - started) / 1000);
-			if (elapsed >= timeout) {
+		if (abs_timeout) {
+			abs_elapsed = (uint32_t) ((switch_timestamp_now() - started) / 1000);
+			if (abs_elapsed >= abs_timeout) {
 				break;
 			}
 		}
@@ -640,10 +660,23 @@
             switch_ivr_parse_all_events(session);
         }
 
+
+		if (eff_timeout) {
+			digit_elapsed = (uint32_t) ((switch_timestamp_now() - digit_started) / 1000);
+			if (digit_elapsed >= eff_timeout) {
+				break;
+			}
+		}
+
 		if (switch_channel_has_dtmf(channel)) {
 			switch_dtmf_t dtmf = {0};
 			switch_size_t y;
 			
+			if (eff_timeout) {
+				eff_timeout = digit_timeout;
+				digit_started = switch_timestamp_now();
+			}
+
 			for (y = 0; y < maxdigits; y++) {
 				if (switch_channel_dequeue_dtmf(channel, &dtmf) != SWITCH_STATUS_SUCCESS) {
 					break;

Modified: freeswitch/trunk/src/switch_ivr_menu.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_menu.c	(original)
+++ freeswitch/trunk/src/switch_ivr_menu.c	Mon Jan  7 11:49:46 2008
@@ -274,7 +274,7 @@
 			menu->ptr += strlen(menu->buf);
 			if (strlen(menu->buf) < need) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "waiting for %u digits\n", (uint32_t)need);
-				status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf), need, "#", &terminator, menu->timeout);
+				status = switch_ivr_collect_digits_count(session, menu->ptr, menu->inlen - strlen(menu->buf), need, "#", &terminator, menu->timeout, 0, 0);
 			}
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "digits '%s'\n", menu->buf);
 		}

Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c	(original)
+++ freeswitch/trunk/src/switch_ivr_originate.c	Mon Jan  7 11:49:46 2008
@@ -129,7 +129,7 @@
 			args.buflen = sizeof(buf);
 			switch_ivr_play_file(collect->session, NULL, collect->file, &args);
 		} else {
-			switch_ivr_collect_digits_count(collect->session, buf, sizeof(buf), 1, SWITCH_BLANK_STRING, &term, 0);
+			switch_ivr_collect_digits_count(collect->session, buf, sizeof(buf), 1, SWITCH_BLANK_STRING, &term, 0, 0, 0);
 		}
 
 		for (p = buf; *p; p++) {

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	Mon Jan  7 11:49:46 2008
@@ -1179,7 +1179,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Calling more digits try %d\n", max_tries);
 
 		//Try to grab some more digits for the timeout period
-		status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout);
+		status = switch_ivr_collect_digits_count(session, digit_buffer, digit_buffer_length, max_digits, valid_terminators, &terminator, timeout, 0, 0);
 
 		//Make sure we made it out alive
 		if (status != SWITCH_STATUS_SUCCESS) {



More information about the Freeswitch-svn mailing list