[Freeswitch-svn] [commit] r10435 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/applications/mod_dptools
FreeSWITCH SVN
anthm at freeswitch.org
Mon Nov 17 18:05:12 PST 2008
Author: anthm
Date: Mon Nov 17 21:05:11 2008
New Revision: 10435
Log:
add hits to tone detect
Modified:
freeswitch/trunk/src/include/switch_ivr.h
freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
freeswitch/trunk/src/switch_ivr_async.c
Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h (original)
+++ freeswitch/trunk/src/include/switch_ivr.h Mon Nov 17 21:05:11 2008
@@ -298,7 +298,8 @@
*/
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);
+
Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c Mon Nov 17 21:05:11 2008
@@ -1148,14 +1148,15 @@
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_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:
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 Mon Nov 17 21:05:11 2008
@@ -1189,7 +1189,7 @@
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(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 @@
}
}
+ 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)
Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c (original)
+++ freeswitch/trunk/src/switch_ivr_async.c Mon Nov 17 21:05:11 2008
@@ -976,7 +976,6 @@
}
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 @@
char *key;
teletone_tone_map_t map;
int up;
+ int hits;
+ int sleep;
} switch_tone_detect_t;
typedef struct {
@@ -1217,18 +1218,28 @@
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_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 @@
}
} 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 @@
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);
More information about the Freeswitch-svn
mailing list