]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix dtmf code
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 7 Jan 2008 16:49:46 +0000 (16:49 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 7 Jan 2008 16:49:46 +0000 (16:49 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7125 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 748dc50c10793c0d098187c1fe81a29d2cb199fc..7eb3a4c40d093fe1544df6422d6a23d6cdb0d296 100644 (file)
@@ -134,13 +134,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
   \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
index e9a7351cafa20ffcc51b3c8819a427caf1ddf5d7..b0f9469968fac57c6486889dd91570395a0503af 100644 (file)
@@ -4125,7 +4125,7 @@ SWITCH_STANDARD_APP(conference_function)
                                        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);
index 3d97f78e2c004377c3b1d7902e4c628cc48091e2..93b46d401dbd248a76eeb407f615cc994b948cb3 100644 (file)
@@ -367,7 +367,7 @@ SWITCH_STANDARD_APP(rss_function)
                                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;
index ec3ade8e4916e7f97063669737b6942fc0a12f09..d7d6c170fc2a656df7621e32c51e0fc52ede83e6 100644 (file)
@@ -826,7 +826,7 @@ static switch_status_t vm_macro_get(switch_core_session_t *session,
                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;
index f102c336a0a66cf4fb9500e1ec44f2954d2b1e0a..aa39da22e73dd470d39297751e264a877a4e8d84 100644 (file)
@@ -1928,7 +1928,7 @@ static JSBool session_get_digits(JSContext * cx, JSObject * obj, uintN argc, jsv
        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 @@ static JSBool session_get_digits(JSContext * cx, JSObject * obj, uintN argc, jsv
                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;
        }
index a4c2d29fbb37857ba45bcc1fab676d1d998daf18..13626237af1277b0cba9cc8cff7ceb70482bae39 100644 (file)
@@ -216,7 +216,7 @@ int CoreSession::getDigits(char *dtmf_buf,
                                                                                         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();
index 47b3c72fdde0a6535d37ebfca038b2e370ab5fcf..8a1ac74d757220a209840543a4790a3fedb15486 100644 (file)
@@ -599,13 +599,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
 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 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
                }
        }
 
-       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_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
             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;
index 60e33203c965752a85134df76a21f019a270880d..de9f8130c67dd4203814135afa141264d1a64a8e 100644 (file)
@@ -274,7 +274,7 @@ static switch_status_t play_or_say(switch_core_session_t *session, switch_ivr_me
                        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);
                }
index 2c1d8f8f773bd5089656a9e33cdf1cf010a1f35e..9b1bf72d7b55a0d9b65e88e5fa3fb389b4e76419 100644 (file)
@@ -129,7 +129,7 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t * thread, voi
                        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++) {
index aecd1bcc32fb89b3892385c5bec30d4174fdf87f..bea3036f87e5bfd6945ec50b58401b8eef8227dd 100644 (file)
@@ -1179,7 +1179,7 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
                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) {