[Freeswitch-svn] [commit] r11738 - in freeswitch/trunk: build libs/libteletone/src src
FreeSWITCH SVN
anthm at freeswitch.org
Tue Feb 10 16:16:36 PST 2009
Author: anthm
Date: Tue Feb 10 18:16:36 2009
New Revision: 11738
Log:
clean up tone_detect
Modified:
freeswitch/trunk/build/turbo_build.sh
freeswitch/trunk/libs/libteletone/src/libteletone_detect.c
freeswitch/trunk/src/switch_ivr_async.c
freeswitch/trunk/src/switch_ivr_originate.c
Modified: freeswitch/trunk/build/turbo_build.sh
==============================================================================
--- freeswitch/trunk/build/turbo_build.sh (original)
+++ freeswitch/trunk/build/turbo_build.sh Tue Feb 10 18:16:36 2009
@@ -34,6 +34,7 @@
$MAKE install_core 2>&1 > /dev/null
mods=`find src/mod -name \*.so | grep .libs`
/bin/cp -fp $mods $prefix/mod
+ mods=`find $prefix/mod -name \*.so`
echo installed core and $mods
exit;
fi
Modified: freeswitch/trunk/libs/libteletone/src/libteletone_detect.c
==============================================================================
--- freeswitch/trunk/libs/libteletone/src/libteletone_detect.c (original)
+++ freeswitch/trunk/libs/libteletone/src/libteletone_detect.c Tue Feb 10 18:16:36 2009
@@ -174,10 +174,16 @@
float theta = 0;
int x = 0;
- if(!mt->min_samples) {
+ if (!mt->sample_rate) {
+ mt->sample_rate = 8000;
+ }
+
+ if (!mt->min_samples) {
mt->min_samples = 102;
}
+ mt->min_samples *= (mt->sample_rate / 8000);
+
if (!mt->positive_factor) {
mt->positive_factor = 2;
}
@@ -190,10 +196,6 @@
mt->hit_factor = 2;
}
- if (!mt->sample_rate) {
- mt->sample_rate = 8000;
- }
-
for(x = 0; x < TELETONE_MAX_TONES; x++) {
if ((int) map->freqs[x] == 0) {
break;
Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c (original)
+++ freeswitch/trunk/src/switch_ivr_async.c Tue Feb 10 18:16:36 2009
@@ -1228,6 +1228,7 @@
int index;
switch_media_bug_t *bug;
switch_core_session_t *session;
+ int bug_running;
} switch_tone_container_t;
static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
@@ -1239,6 +1240,9 @@
switch (type) {
case SWITCH_ABC_TYPE_INIT:
+ if (cont) {
+ cont->bug_running = 1;
+ }
break;
case SWITCH_ABC_TYPE_CLOSE:
break;
@@ -1252,9 +1256,7 @@
} else {
frame = switch_core_media_bug_get_write_replace_frame(bug);
}
-
-
-
+
for (i = 0; i < cont->index; i++) {
if (cont->list[i].sleep) {
@@ -1274,9 +1276,9 @@
}
if (!cont->list[i].up) skip = 1;
-
- if (skip) return SWITCH_TRUE;
+ if (skip) return SWITCH_TRUE;
+
if (teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
switch_event_t *event;
cont->list[i].hits++;
@@ -1289,12 +1291,15 @@
if (cont->list[i].hits >= cont->list[i].total_hits) {
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].once) {
- rval = SWITCH_FALSE;
- }
-
+
if (cont->list[i].callback) {
- rval = cont->list[i].callback(cont->session, cont->list[i].app, cont->list[i].data);
+ if ((rval = cont->list[i].callback(cont->session, cont->list[i].app, cont->list[i].data)) == SWITCH_TRUE) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-enabling %s\n", cont->list[i].key);
+ cont->list[i].up = 1;
+ cont->list[i].hits = 0;
+ cont->list[i].sleep = 0;
+ cont->list[i].expires = 0;
+ }
} else 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");
@@ -1305,6 +1310,10 @@
}
}
+ if (cont->list[i].once) {
+ rval = SWITCH_FALSE;
+ }
+
if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
switch_event_t *dup;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
@@ -1328,6 +1337,11 @@
default:
break;
}
+
+ if (rval == SWITCH_FALSE) {
+ cont->bug_running = 0;
+ }
+
return rval;
}
@@ -1335,9 +1349,13 @@
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_");
+ int i = 0;
if (cont) {
switch_channel_set_private(channel, "_tone_detect_", NULL);
+ for (i = 0; i < cont->index; i++) {
+ cont->list[i].up = 0;
+ }
switch_core_media_bug_remove(session, &cont->bug);
return SWITCH_STATUS_SUCCESS;
}
@@ -1347,7 +1365,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,
- int hits, const char *app, const char *data,
+ int hits,
+ const char *app, const char *data,
switch_tone_detect_callback_t callback)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -1360,7 +1379,7 @@
switch_codec_implementation_t read_impl = {0};
switch_core_session_get_read_impl(session, &read_impl);
-
+
if (switch_strlen_zero(key)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Key Specified!\n");
return SWITCH_STATUS_FALSE;
@@ -1373,9 +1392,9 @@
}
for (i = 0; i < cont->index; i++) {
- if (!switch_strlen_zero(cont->list[cont->index].key) && !strcasecmp(key, cont->list[cont->index].key)) {
+ if (!switch_strlen_zero(cont->list[i].key) && !strcasecmp(key, cont->list[i].key)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-enabling %s\n", key);
- cont->list[cont->index].up = 1;
+ cont->list[i].up = 1;
cont->list[i].hits = 0;
cont->list[i].sleep = 0;
cont->list[i].expires = 0;
@@ -1436,6 +1455,7 @@
cont->list[cont->index].total_hits = hits;
cont->list[cont->index].up = 1;
+ memset(&cont->list[cont->index].mt, 0, sizeof(cont->list[cont->index].mt));
cont->list[cont->index].mt.sample_rate = read_impl.actual_samples_per_second;
teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
cont->session = session;
@@ -1468,7 +1488,7 @@
if (strchr(flags, 'o')) {
cont->list[cont->index].once = 1;
}
-
+
if (strchr(flags, 'r')) {
bflags |= SMBF_READ_REPLACE;
} else if (strchr(flags, 'w')) {
@@ -1476,11 +1496,18 @@
}
}
- if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
- return status;
+ if (cont->bug_running) {
+ status = SWITCH_STATUS_SUCCESS;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s bug already running\n", switch_channel_get_name(channel));
+ } else {
+ cont->bug_running = 1;
+ if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
+ cont->bug_running = 0;
+ return status;
+ }
+ switch_channel_set_private(channel, "_tone_detect_", cont);
}
- switch_channel_set_private(channel, "_tone_detect_", cont);
cont->index++;
return SWITCH_STATUS_SUCCESS;
Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c (original)
+++ freeswitch/trunk/src/switch_ivr_originate.c Tue Feb 10 18:16:36 2009
@@ -101,6 +101,8 @@
uint8_t progress;
uint8_t return_ring_ready;
uint8_t monitor_early_media_ring;
+ uint8_t monitor_early_media_ring_total;
+ uint8_t monitor_early_media_ring_count;
uint8_t monitor_early_media_fail;
uint8_t gen_ringback;
uint8_t ignore_early_media;
@@ -264,9 +266,14 @@
bd = "monitor_early_media_ring";
}
switch_channel_set_variable(channel, "originate_disposition", bd);
-
+
if (oglobals) {
-
+ if (oglobals->monitor_early_media_ring_total && ++oglobals->monitor_early_media_ring_count < oglobals->monitor_early_media_ring_total) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ring %d/%d\n",
+ oglobals->monitor_early_media_ring_count, oglobals->monitor_early_media_ring_total);
+ return SWITCH_TRUE;
+ }
+
switch_channel_set_private(channel, "_oglobals_", NULL);
if (!oglobals->progress) {
@@ -296,6 +303,7 @@
int pindex = -1;
oglobals->hups = 0;
oglobals->idx = IDX_NADA;
+ char bug_key[256] = "";
if (oglobals->session) {
caller_channel = switch_core_session_get_channel(oglobals->session);
@@ -304,7 +312,7 @@
for (i = 0; i < len; i++) {
switch_channel_state_t state;
- if (!originate_status[i].peer_channel) {
+ if (!(originate_status[i].peer_channel && originate_status[i].peer_session)) {
continue;
}
@@ -332,7 +340,8 @@
int fail_count = 0;
char *fail_data = strdup(var);
int fx;
-
+ int y = 0;
+
switch_assert(fail_data);
fail_count = switch_separate_string(fail_data, '!', fail_array, (sizeof(fail_array) / sizeof(fail_array[0])));
@@ -375,10 +384,13 @@
*q = ',';
}
}
-
+ switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_fail_%d", ++y);
switch_ivr_tone_detect_session(originate_status[i].peer_session,
- "monitor_early_media_fail",
- p, "r", 0, hits, "fail", cause, monitor_callback);
+ bug_key,
+ p, "r", 0,
+ hits,
+ "fail",
+ cause, monitor_callback);
}
@@ -389,12 +401,14 @@
if (oglobals->monitor_early_media_ring) {
const char *var = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_ring");
+ const char *var_total = switch_channel_get_variable(originate_status[i].peer_channel, "monitor_early_media_ring_total");
if (!switch_strlen_zero(var)) {
char *ring_array[128] = {0};
int ring_count = 0;
char *ring_data = strdup(var);
int fx;
-
+ int y = 0;
+
switch_assert(ring_data);
ring_count = switch_separate_string(ring_data, '!', ring_array, (sizeof(ring_array) / sizeof(ring_array[0])));
@@ -429,12 +443,22 @@
}
switch_channel_set_private(originate_status[i].peer_channel, "_oglobals_", oglobals);
+ switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_ring_%d", ++y);
switch_ivr_tone_detect_session(originate_status[i].peer_session,
- "monitor_early_media_ring",
+ bug_key,
p, "r", 0, hits, "ring", NULL, monitor_callback);
}
+ if (var_total) {
+ int tmp = atoi(var_total);
+ if (tmp > 0 && tmp < 100) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s setting ring total to %d\n",
+ switch_channel_get_name(originate_status[i].peer_channel), tmp);
+ oglobals->monitor_early_media_ring_total = tmp;
+ }
+ }
+
switch_safe_free(ring_data);
}
@@ -992,6 +1016,8 @@
ok = 1;
} else if (!strcasecmp((char *) hi->name, "monitor_early_media_ring")) {
ok = 1;
+ } else if (!strcasecmp((char *) hi->name, "monitor_early_media_ring_total")) {
+ ok = 1;
} else if (!strcasecmp((char *) hi->name, "monitor_early_media_fail")) {
ok = 1;
} else if (!strcasecmp((char *) hi->name, "return_ring_ready")) {
@@ -1269,7 +1295,7 @@
char *vdata;
end = NULL;
chan_type = peer_names[i];
-
+
while (chan_type && *chan_type && *chan_type == ' ') {
chan_type++;
}
More information about the Freeswitch-svn
mailing list