]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add hits to tone detect
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 18 Nov 2008 02:05:11 +0000 (02:05 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 18 Nov 2008 02:05:11 +0000 (02:05 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10435 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_ivr_async.c

index 15ef7bef71de98ebca9b87fcccc1152283e35cff..d170593b5d9b2c3c85788dfba8b3edcecc588d1b 100644 (file)
@@ -298,7 +298,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
                                                                                                                           const char *key, const char *tone_spec,
-                                                                                                                          const char *flags, time_t timeout, const char *app, const char *data);
+                                                                                                                          const char *flags, time_t timeout, int hits, const char *app, const char *data);
+
 
 
 
index 5ea53c3ff76193823c783ab6c066aa6faeab5343..23893e126ee5ad966101f25c3b7d59c55cc859ab 100644 (file)
@@ -1148,14 +1148,15 @@ SWITCH_STANDARD_API(transfer_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define TONE_DETECT_SYNTAX "<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args>]"
+#define TONE_DETECT_SYNTAX "<uuid> <key> <tone_spec> [<flags> <timeout> <app> <args> <hits>]"
 SWITCH_STANDARD_API(tone_detect_session_function)
 {
-       char *argv[7] = { 0 };
+       char *argv[8] = { 0 };
        int argc;
        char *mydata = NULL;
        time_t to = 0;
        switch_core_session_t *rsession;
+       int hits = 1;
 
        if (!cmd) {
                stream->write_function(stream, "-USAGE: %s\n", TONE_DETECT_SYNTAX);
@@ -1193,7 +1194,14 @@ SWITCH_STANDARD_API(tone_detect_session_function)
                }
        }
 
-       switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, argv[5], argv[6]);
+       if (argv[7]) {
+               hits = atoi(argv[7]);
+               if (hits < 0) {
+                       hits = 1;
+               }
+       }
+
+       switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, hits, argv[5], argv[6]);
        stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]);
 
   done:
index 2d0c8a8e4ffda96f502be3c4f20e15edeb45f768..47c4fd4047da3b6b056e8ebb4a3cb6bda49faeaa 100644 (file)
@@ -1189,7 +1189,7 @@ SWITCH_STANDARD_APP(stop_dtmf_session_generate_function)
 
 SWITCH_STANDARD_APP(fax_detect_session_function)
 {
-       switch_ivr_tone_detect_session(session, "fax", "1100.0", "r", 0, NULL, NULL);
+       switch_ivr_tone_detect_session(session, "fax", "1100.0", "r", 0, 1, NULL, NULL);
 }
 
 SWITCH_STANDARD_APP(system_session_function)
@@ -1202,10 +1202,11 @@ SWITCH_STANDARD_APP(system_session_function)
 
 SWITCH_STANDARD_APP(tone_detect_session_function)
 {
-       char *argv[6] = { 0 };
+       char *argv[7] = { 0 };
        int argc;
        char *mydata = NULL;
        time_t to = 0;
+       int hits = 1;
 
        if (switch_strlen_zero(data) || !(mydata = switch_core_session_strdup(session, data))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID ARGS!\n");
@@ -1235,9 +1236,16 @@ SWITCH_STANDARD_APP(tone_detect_session_function)
                }
        }
 
+       if (argv[7]) {
+               hits = atoi(argv[7]);
+               if (hits < 0) {
+                       hits = 1;
+               }
+       }
+
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabling tone detection '%s' '%s'\n", argv[0], argv[1]);
 
-       switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, argv[4], argv[5]);
+       switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, hits, argv[4], argv[5]);
 }
 
 SWITCH_STANDARD_APP(stop_fax_detect_session_function)
index 12f31e9cbc21c60d0f151e39360aaf5215a7bb26..df18d43d0ee0aee6b740bcfff9d042ff80964310 100644 (file)
@@ -976,7 +976,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_sessi
        }
 
        teletone_dtmf_detect_init(&pvt->dtmf_detect, read_codec->implementation->actual_samples_per_second);
-       printf ("WTF %d\n", read_codec->implementation->actual_samples_per_second);
 
        pvt->session = session;
 
@@ -1193,6 +1192,8 @@ typedef struct {
        char *key;
        teletone_tone_map_t map;
        int up;
+       int hits;
+       int sleep;
 } switch_tone_detect_t;
 
 typedef struct {
@@ -1217,18 +1218,28 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
                frame = switch_core_media_bug_get_read_replace_frame(bug);
        case SWITCH_ABC_TYPE_WRITE_REPLACE:
                {
-
+                       
                        if (!frame) {
                                frame = switch_core_media_bug_get_write_replace_frame(bug);
                        }
 
                        for (i = 0; i < cont->index; i++) {
+                               if (cont->list[i].sleep) {
+                                       cont->list[i].sleep--;
+                                       return SWITCH_TRUE;
+                               }
                                if (cont->list[i].up && teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
                                        switch_event_t *event;
 
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
-                                       cont->list[i].up = 0;
-
+                                       if (cont->list[i].hits) {
+                                               cont->list[i].up = cont->list[i].hits--;
+                                               cont->list[i].sleep = 25;
+                                               teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
+                                       } else {
+                                               cont->list[i].up = 0;
+                                       }
+                                       
                                        if (cont->list[i].app) {
                                                if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
                                                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
@@ -1279,7 +1290,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
                                                                                                                           const char *key, const char *tone_spec,
-                                                                                                                          const char *flags, time_t timeout, const char *app, const char *data)
+                                                                                                                          const char *flags, time_t timeout, int hits, const char *app, const char *data)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
        switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@@ -1340,7 +1351,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
                }
        } while (next);
        cont->list[cont->index].map.freqs[i++] = 0;
-
+       
        if (!ok) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid tone spec!\n");
                return SWITCH_STATUS_FALSE;
@@ -1356,6 +1367,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
                cont->list[cont->index].data = switch_core_session_strdup(session, data);
        }
 
+       if (!hits) hits = 1;
+
+       cont->list[cont->index].hits = hits;
+
        cont->list[cont->index].up = 1;
        cont->list[cont->index].mt.sample_rate = read_codec->implementation->actual_samples_per_second;
        teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);