mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-25 11:16:04 +00:00
clean up tone_detect
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11738 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7dd39a1309
commit
ba77f23278
@ -34,6 +34,7 @@ if [ -z $arg ] ; then
|
|||||||
$MAKE install_core 2>&1 > /dev/null
|
$MAKE install_core 2>&1 > /dev/null
|
||||||
mods=`find src/mod -name \*.so | grep .libs`
|
mods=`find src/mod -name \*.so | grep .libs`
|
||||||
/bin/cp -fp $mods $prefix/mod
|
/bin/cp -fp $mods $prefix/mod
|
||||||
|
mods=`find $prefix/mod -name \*.so`
|
||||||
echo installed core and $mods
|
echo installed core and $mods
|
||||||
exit;
|
exit;
|
||||||
fi
|
fi
|
||||||
|
@ -174,10 +174,16 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma
|
|||||||
float theta = 0;
|
float theta = 0;
|
||||||
int x = 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 = 102;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mt->min_samples *= (mt->sample_rate / 8000);
|
||||||
|
|
||||||
if (!mt->positive_factor) {
|
if (!mt->positive_factor) {
|
||||||
mt->positive_factor = 2;
|
mt->positive_factor = 2;
|
||||||
}
|
}
|
||||||
@ -190,10 +196,6 @@ void teletone_multi_tone_init(teletone_multi_tone_t *mt, teletone_tone_map_t *ma
|
|||||||
mt->hit_factor = 2;
|
mt->hit_factor = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mt->sample_rate) {
|
|
||||||
mt->sample_rate = 8000;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(x = 0; x < TELETONE_MAX_TONES; x++) {
|
for(x = 0; x < TELETONE_MAX_TONES; x++) {
|
||||||
if ((int) map->freqs[x] == 0) {
|
if ((int) map->freqs[x] == 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -1228,6 +1228,7 @@ typedef struct {
|
|||||||
int index;
|
int index;
|
||||||
switch_media_bug_t *bug;
|
switch_media_bug_t *bug;
|
||||||
switch_core_session_t *session;
|
switch_core_session_t *session;
|
||||||
|
int bug_running;
|
||||||
} switch_tone_container_t;
|
} switch_tone_container_t;
|
||||||
|
|
||||||
static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
|
static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
|
||||||
@ -1239,6 +1240,9 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SWITCH_ABC_TYPE_INIT:
|
case SWITCH_ABC_TYPE_INIT:
|
||||||
|
if (cont) {
|
||||||
|
cont->bug_running = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SWITCH_ABC_TYPE_CLOSE:
|
case SWITCH_ABC_TYPE_CLOSE:
|
||||||
break;
|
break;
|
||||||
@ -1253,8 +1257,6 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
|
|||||||
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) {
|
if (cont->list[i].sleep) {
|
||||||
@ -1289,12 +1291,15 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
|
|||||||
if (cont->list[i].hits >= cont->list[i].total_hits) {
|
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);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
|
||||||
cont->list[i].up = 0;
|
cont->list[i].up = 0;
|
||||||
if (cont->list[i].once) {
|
|
||||||
rval = SWITCH_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cont->list[i].callback) {
|
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) {
|
} else 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");
|
||||||
@ -1305,6 +1310,10 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cont->list[i].once) {
|
||||||
|
rval = SWITCH_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_event_t *dup;
|
switch_event_t *dup;
|
||||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
|
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
|
||||||
@ -1328,6 +1337,11 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rval == SWITCH_FALSE) {
|
||||||
|
cont->bug_running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1335,9 +1349,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_
|
|||||||
{
|
{
|
||||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_");
|
switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_");
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
if (cont) {
|
if (cont) {
|
||||||
switch_channel_set_private(channel, "_tone_detect_", NULL);
|
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);
|
switch_core_media_bug_remove(session, &cont->bug);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -1347,7 +1365,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 *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_tone_detect_callback_t callback)
|
||||||
{
|
{
|
||||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
@ -1373,9 +1392,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < cont->index; i++) {
|
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);
|
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].hits = 0;
|
||||||
cont->list[i].sleep = 0;
|
cont->list[i].sleep = 0;
|
||||||
cont->list[i].expires = 0;
|
cont->list[i].expires = 0;
|
||||||
@ -1436,6 +1455,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
|
|||||||
cont->list[cont->index].total_hits = hits;
|
cont->list[cont->index].total_hits = hits;
|
||||||
|
|
||||||
cont->list[cont->index].up = 1;
|
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;
|
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);
|
teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
|
||||||
cont->session = session;
|
cont->session = session;
|
||||||
@ -1476,11 +1496,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
|
if (cont->bug_running) {
|
||||||
return status;
|
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++;
|
cont->index++;
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
@ -101,6 +101,8 @@ typedef struct {
|
|||||||
uint8_t progress;
|
uint8_t progress;
|
||||||
uint8_t return_ring_ready;
|
uint8_t return_ring_ready;
|
||||||
uint8_t monitor_early_media_ring;
|
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 monitor_early_media_fail;
|
||||||
uint8_t gen_ringback;
|
uint8_t gen_ringback;
|
||||||
uint8_t ignore_early_media;
|
uint8_t ignore_early_media;
|
||||||
@ -266,6 +268,11 @@ static switch_bool_t monitor_callback(switch_core_session_t *session, const char
|
|||||||
switch_channel_set_variable(channel, "originate_disposition", bd);
|
switch_channel_set_variable(channel, "originate_disposition", bd);
|
||||||
|
|
||||||
if (oglobals) {
|
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);
|
switch_channel_set_private(channel, "_oglobals_", NULL);
|
||||||
|
|
||||||
@ -296,6 +303,7 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
|
|||||||
int pindex = -1;
|
int pindex = -1;
|
||||||
oglobals->hups = 0;
|
oglobals->hups = 0;
|
||||||
oglobals->idx = IDX_NADA;
|
oglobals->idx = IDX_NADA;
|
||||||
|
char bug_key[256] = "";
|
||||||
|
|
||||||
if (oglobals->session) {
|
if (oglobals->session) {
|
||||||
caller_channel = switch_core_session_get_channel(oglobals->session);
|
caller_channel = switch_core_session_get_channel(oglobals->session);
|
||||||
@ -304,7 +312,7 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
|
|||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
switch_channel_state_t state;
|
switch_channel_state_t state;
|
||||||
if (!originate_status[i].peer_channel) {
|
if (!(originate_status[i].peer_channel && originate_status[i].peer_session)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +340,7 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
|
|||||||
int fail_count = 0;
|
int fail_count = 0;
|
||||||
char *fail_data = strdup(var);
|
char *fail_data = strdup(var);
|
||||||
int fx;
|
int fx;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
switch_assert(fail_data);
|
switch_assert(fail_data);
|
||||||
fail_count = switch_separate_string(fail_data, '!', fail_array, (sizeof(fail_array) / sizeof(fail_array[0])));
|
fail_count = switch_separate_string(fail_data, '!', fail_array, (sizeof(fail_array) / sizeof(fail_array[0])));
|
||||||
@ -375,10 +384,13 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
|
|||||||
*q = ',';
|
*q = ',';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch_snprintf(bug_key, sizeof(bug_key), "monitor_early_media_fail_%d", ++y);
|
||||||
switch_ivr_tone_detect_session(originate_status[i].peer_session,
|
switch_ivr_tone_detect_session(originate_status[i].peer_session,
|
||||||
"monitor_early_media_fail",
|
bug_key,
|
||||||
p, "r", 0, hits, "fail", cause, monitor_callback);
|
p, "r", 0,
|
||||||
|
hits,
|
||||||
|
"fail",
|
||||||
|
cause, monitor_callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,11 +401,13 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
|
|||||||
|
|
||||||
if (oglobals->monitor_early_media_ring) {
|
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 = 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)) {
|
if (!switch_strlen_zero(var)) {
|
||||||
char *ring_array[128] = {0};
|
char *ring_array[128] = {0};
|
||||||
int ring_count = 0;
|
int ring_count = 0;
|
||||||
char *ring_data = strdup(var);
|
char *ring_data = strdup(var);
|
||||||
int fx;
|
int fx;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
switch_assert(ring_data);
|
switch_assert(ring_data);
|
||||||
ring_count = switch_separate_string(ring_data, '!', ring_array, (sizeof(ring_array) / sizeof(ring_array[0])));
|
ring_count = switch_separate_string(ring_data, '!', ring_array, (sizeof(ring_array) / sizeof(ring_array[0])));
|
||||||
@ -429,12 +443,22 @@ static uint8_t check_channel_status(originate_global_t *oglobals, originate_stat
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_set_private(originate_status[i].peer_channel, "_oglobals_", oglobals);
|
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,
|
switch_ivr_tone_detect_session(originate_status[i].peer_session,
|
||||||
"monitor_early_media_ring",
|
bug_key,
|
||||||
p, "r", 0, hits, "ring", NULL, monitor_callback);
|
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);
|
switch_safe_free(ring_data);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -992,6 +1016,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
|
|||||||
ok = 1;
|
ok = 1;
|
||||||
} else if (!strcasecmp((char *) hi->name, "monitor_early_media_ring")) {
|
} else if (!strcasecmp((char *) hi->name, "monitor_early_media_ring")) {
|
||||||
ok = 1;
|
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")) {
|
} else if (!strcasecmp((char *) hi->name, "monitor_early_media_fail")) {
|
||||||
ok = 1;
|
ok = 1;
|
||||||
} else if (!strcasecmp((char *) hi->name, "return_ring_ready")) {
|
} else if (!strcasecmp((char *) hi->name, "return_ring_ready")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user