mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 08:29:45 +00:00
add hits to tone_detect
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10454 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
a8a66e9157
commit
1a179a676e
@ -1195,7 +1195,7 @@ typedef struct {
|
|||||||
int total_hits;
|
int total_hits;
|
||||||
int hits;
|
int hits;
|
||||||
int sleep;
|
int sleep;
|
||||||
time_t expires;
|
int expires;
|
||||||
} switch_tone_detect_t;
|
} switch_tone_detect_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -1217,36 +1217,49 @@ static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_da
|
|||||||
case SWITCH_ABC_TYPE_CLOSE:
|
case SWITCH_ABC_TYPE_CLOSE:
|
||||||
break;
|
break;
|
||||||
case SWITCH_ABC_TYPE_READ_REPLACE:
|
case SWITCH_ABC_TYPE_READ_REPLACE:
|
||||||
frame = switch_core_media_bug_get_read_replace_frame(bug);
|
|
||||||
case SWITCH_ABC_TYPE_WRITE_REPLACE:
|
case SWITCH_ABC_TYPE_WRITE_REPLACE:
|
||||||
{
|
{
|
||||||
|
int skip = 0;
|
||||||
if (!frame) {
|
|
||||||
|
if (type == SWITCH_ABC_TYPE_READ_REPLACE) {
|
||||||
|
frame = switch_core_media_bug_get_read_replace_frame(bug);
|
||||||
|
} else {
|
||||||
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].expires && cont->list[i].expires < switch_timestamp(NULL)) {
|
|
||||||
cont->list[i].hits = 0;
|
|
||||||
cont->list[i].sleep = 0;
|
|
||||||
cont->list[i].expires = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cont->list[i].sleep) {
|
if (cont->list[i].sleep) {
|
||||||
cont->list[i].sleep--;
|
cont->list[i].sleep--;
|
||||||
return SWITCH_TRUE;
|
if (cont->list[i].sleep) {
|
||||||
|
skip = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (cont->list[i].up && teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
|
|
||||||
|
if (cont->list[i].expires) {
|
||||||
|
cont->list[i].expires--;
|
||||||
|
if (!cont->list[i].expires) {
|
||||||
|
cont->list[i].hits = 0;
|
||||||
|
cont->list[i].sleep = 0;
|
||||||
|
cont->list[i].expires = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cont->list[i].up) skip = 1;
|
||||||
|
|
||||||
|
if (skip) return SWITCH_TRUE;
|
||||||
|
|
||||||
|
if (teletone_multi_tone_detect(&cont->list[i].mt, frame->data, frame->samples)) {
|
||||||
switch_event_t *event;
|
switch_event_t *event;
|
||||||
|
cont->list[i].hits++;
|
||||||
cont->list[i].up = cont->list[i].hits++;
|
|
||||||
cont->list[i].sleep = 25;
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s HIT %d/%d\n",
|
||||||
cont->list[i].expires = switch_timestamp(NULL) + 5;
|
cont->list[i].key, cont->list[i].hits, cont->list[i].total_hits);
|
||||||
teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
|
cont->list[i].sleep = 50;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s HIT %d/%d\n",
|
cont->list[i].expires = 250;
|
||||||
cont->list[i].key, cont->list[i].up, cont->list[i].hits);
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@ -1332,7 +1345,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
|
|||||||
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;
|
||||||
teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1403,7 +1415,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi
|
|||||||
bflags |= SMBF_WRITE_REPLACE;
|
bflags |= SMBF_WRITE_REPLACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
|
if ((status = switch_core_media_bug_add(session, tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user