double f;
/* freq_table_t ft; */
avmd_state_t state;
+ switch_time_t start_time;
} avmd_session_t;
static void avmd_process(avmd_session_t *session, switch_frame_t *frame);
case SWITCH_ABC_TYPE_INIT:
read_codec = switch_core_session_get_read_codec(avmd_session->session);
avmd_session->rate = read_codec->implementation->samples_per_second;
+ avmd_session->start_time = switch_micro_time_now();
/* avmd_session->vmd_codec.channels = read_codec->implementation->number_of_channels; */
break;
/*! If variance is less than threshold then we have detection */
if(v < VARIANCE_THRESHOLD){
- switch_channel_execute_on(switch_core_session_get_channel(session->session), "execute_on_avmd_beep");
+ switch_channel_set_variable_printf(channel, "avmd_total_time", "%d", (int)(switch_micro_time_now() - session->start_time) / 1000);
+ switch_channel_execute_on(channel, "execute_on_avmd_beep");
/*! Throw an event to FreeSWITCH */
status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, AVMD_EVENT_BEEP);
int default_sleep;
int default_expires;
int once;
+ switch_time_t start_time;
switch_tone_detect_callback_t callback;
} switch_tone_detect_t;
int detect_fax;
} switch_tone_container_t;
+
+static void tone_detect_set_total_time(switch_tone_container_t *cont, int index)
+{
+ char *total_time = switch_mprintf("%d", (int)(switch_micro_time_now() - cont->list[index].start_time) / 1000);
+
+ switch_channel_set_variable_name_printf(switch_core_session_get_channel(cont->session), total_time, "tone_detect_%s_total_time",
+ cont->list[index].key);
+ switch_safe_free(total_time);
+}
+
static switch_status_t tone_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
i = cont->detect_fax;
+ tone_detect_set_total_time(cont, i);
if (cont->list[i].callback) {
cont->list[i].callback(cont->session, cont->list[i].app, cont->list[i].data);
} else {
}
-
static switch_bool_t tone_detect_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
switch_tone_container_t *cont = (switch_tone_container_t *) user_data;
if (cont->list[i].hits >= cont->list[i].total_hits) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "TONE %s DETECTED\n",
cont->list[i].key);
+ tone_detect_set_total_time(cont, i);
cont->list[i].up = 0;
if (cont->list[i].callback) {
cont->list[cont->index].hits = 0;
cont->list[cont->index].total_hits = hits;
+ cont->list[cont->index].start_time = switch_micro_time_now();
cont->list[cont->index].up = 1;
memset(&cont->list[cont->index].mt, 0, sizeof(cont->list[cont->index].mt));