add hits to tone detect

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10435 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-11-18 02:05:11 +00:00
parent f617384fca
commit bd03bfb066
4 changed files with 45 additions and 13 deletions

View 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, SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
const char *key, const char *tone_spec, 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);

View File

@ -1148,14 +1148,15 @@ SWITCH_STANDARD_API(transfer_function)
return SWITCH_STATUS_SUCCESS; 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) SWITCH_STANDARD_API(tone_detect_session_function)
{ {
char *argv[7] = { 0 }; char *argv[8] = { 0 };
int argc; int argc;
char *mydata = NULL; char *mydata = NULL;
time_t to = 0; time_t to = 0;
switch_core_session_t *rsession; switch_core_session_t *rsession;
int hits = 1;
if (!cmd) { if (!cmd) {
stream->write_function(stream, "-USAGE: %s\n", TONE_DETECT_SYNTAX); 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]); stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]);
done: done:

View File

@ -1189,7 +1189,7 @@ SWITCH_STANDARD_APP(stop_dtmf_session_generate_function)
SWITCH_STANDARD_APP(fax_detect_session_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) SWITCH_STANDARD_APP(system_session_function)
@ -1202,10 +1202,11 @@ SWITCH_STANDARD_APP(system_session_function)
SWITCH_STANDARD_APP(tone_detect_session_function) SWITCH_STANDARD_APP(tone_detect_session_function)
{ {
char *argv[6] = { 0 }; char *argv[7] = { 0 };
int argc; int argc;
char *mydata = NULL; char *mydata = NULL;
time_t to = 0; time_t to = 0;
int hits = 1;
if (switch_strlen_zero(data) || !(mydata = switch_core_session_strdup(session, data))) { if (switch_strlen_zero(data) || !(mydata = switch_core_session_strdup(session, data))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID ARGS!\n"); 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_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) SWITCH_STANDARD_APP(stop_fax_detect_session_function)

View 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); 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; pvt->session = session;
@ -1193,6 +1192,8 @@ typedef struct {
char *key; char *key;
teletone_tone_map_t map; teletone_tone_map_t map;
int up; int up;
int hits;
int sleep;
} switch_tone_detect_t; } switch_tone_detect_t;
typedef struct { 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); frame = switch_core_media_bug_get_read_replace_frame(bug);
case SWITCH_ABC_TYPE_WRITE_REPLACE: case SWITCH_ABC_TYPE_WRITE_REPLACE:
{ {
if (!frame) { if (!frame) {
frame = switch_core_media_bug_get_write_replace_frame(bug); frame = switch_core_media_bug_get_write_replace_frame(bug);
} }
for (i = 0; i < cont->index; i++) { 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)) { if (cont->list[i].up && teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
switch_event_t *event; switch_event_t *event;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key); 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 (cont->list[i].app) {
if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) { if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute"); 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, SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
const char *key, const char *tone_spec, 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_channel_t *channel = switch_core_session_get_channel(session);
switch_codec_t *read_codec = switch_core_session_get_read_codec(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); } while (next);
cont->list[cont->index].map.freqs[i++] = 0; cont->list[cont->index].map.freqs[i++] = 0;
if (!ok) { if (!ok) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid tone spec!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid tone spec!\n");
return SWITCH_STATUS_FALSE; 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); 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].up = 1;
cont->list[cont->index].mt.sample_rate = read_codec->implementation->actual_samples_per_second; 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); teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);