#define MAX_BUG_BUFFER 1024 * 512
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session,
+ const char *function,
+ const char *target,
switch_media_bug_callback_t callback,
- void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
+ void *user_data, time_t stop_time,
+ switch_media_bug_flag_t flags,
+ switch_media_bug_t **new_bug)
{
switch_media_bug_t *bug; //, *bp;
switch_size_t bytes;
switch_codec_implementation_t read_impl = { 0 };
switch_codec_implementation_t write_impl = { 0 };
+ switch_event_t *event;
+
const char *p;
if (!switch_channel_media_ready(session->channel)) {
bug->user_data = user_data;
bug->session = session;
bug->flags = flags;
+ bug->function = "N/A";
+ bug->target = "N/A";
+
+ if (function) {
+ bug->function = switch_core_session_strdup(session, function);
+ }
+ if (target) {
+ bug->target = switch_core_session_strdup(session, target);
+ }
+
bug->stop_time = stop_time;
bytes = read_impl.decoded_bytes_per_packet;
switch_thread_rwlock_unlock(session->bug_rwlock);
*new_bug = bug;
+ if (switch_event_create(&event, SWITCH_EVENT_MEDIA_BUG_START) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(session->channel, event);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Function", "%s", bug->function);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Target", "%s", bug->target);
+ switch_event_fire(&event);
+ }
+
+
return SWITCH_STATUS_SUCCESS;
}
}
switch_thread_rwlock_unlock(session->bug_rwlock);
if (bp) {
- status = switch_core_media_bug_close(&bp);
+ switch_event_t *event;
+
+ if ((status = switch_core_media_bug_close(&bp)) == SWITCH_STATUS_SUCCESS) {
+ if (switch_event_create(&event, SWITCH_EVENT_MEDIA_BUG_STOP) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(session->channel, event);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Function", "%s", bp->function);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Media-Bug-Target", "%s", bp->target);
+ switch_event_fire(&event);
+ }
+
+ }
}
}
}
if (flags && strchr(flags, 'r')) {
- status = switch_core_media_bug_add(session, read_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
+ status = switch_core_media_bug_add(session, "displace", file,
+ read_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
} else {
- status = switch_core_media_bug_add(session, write_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
+ status = switch_core_media_bug_add(session, "displace", file,
+ write_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
}
if (status != SWITCH_STATUS_SUCCESS) {
switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex);
- if (switch_core_media_bug_add(tsession, eavesdrop_callback, ep, 0,
+ if (switch_core_media_bug_add(tsession, "eavesdrop", uuid,
+ eavesdrop_callback, ep, 0,
SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_REPLACE | SMBF_WRITE_REPLACE | SMBF_READ_PING | SMBF_THREAD_LOCK,
&bug) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot attach bug\n");
}
- if ((status = switch_core_media_bug_add(session, record_callback, rh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, "session_record", file,
+ record_callback, rh, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error adding media bug for file %s\n", file);
switch_core_file_close(fh);
return status;
}
- if ((status = switch_core_media_bug_add(session, preprocess_callback, cb, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, "preprocess", NULL,
+ preprocess_callback, cb, to, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error adding media bug.\n");
if (cb->read_st) {
speex_preprocess_state_destroy(cb->read_st);
if (existing) {
switch_core_media_bug_set_flag(bug, flags);
-
} else {
- if ((status = switch_core_media_bug_add(session, session_audio_callback, pvt, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, "audio", cmd,
+ session_audio_callback, pvt, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
return status;
}
return SWITCH_STATUS_FALSE;
}
- if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, "inband_dtmf", NULL,
+ inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
return status;
}
pvt->session = session;
pvt->read = !!read_stream;
- if ((status = switch_core_media_bug_add(session, inband_dtmf_generate_callback, pvt, 0,
+ if ((status = switch_core_media_bug_add(session, "inband_dtmf_generate", NULL,
+ inband_dtmf_generate_callback, pvt, 0,
pvt->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
return status;
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), 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) {
+ if ((status = switch_core_media_bug_add(session, "tone_detect", key,
+ tone_detect_callback, cont, timeout, bflags, &cont->bug)) != SWITCH_STATUS_SUCCESS) {
cont->bug_running = 0;
return status;
}
struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY);
switch_codec_implementation_t read_impl = { 0 };
const char *p;
+ char key[512] = "";
+
switch_core_session_get_read_impl(session, &read_impl);
+ switch_snprintf(key, sizeof(key), "%s/%s/%s/%s", mod_name, grammar, name, dest);
+
if (!ah) {
if (!(ah = switch_core_session_alloc(session, sizeof(*ah)))) {
return SWITCH_STATUS_MEMERR;
switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
}
- if ((status = switch_core_media_bug_add(session, speech_callback, sth, 0, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_media_bug_add(session, "detect_speech", key,
+ speech_callback, sth, 0, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) {
switch_core_asr_close(ah, &flags);
return status;
}