diff --git a/libs/esl/src/esl_event.c b/libs/esl/src/esl_event.c index 2686f332c4..b89711d2dd 100644 --- a/libs/esl/src/esl_event.c +++ b/libs/esl/src/esl_event.c @@ -131,6 +131,8 @@ static const char *EVENT_NAMES[] = { "CALL_UPDATE", "FAILURE", "SOCKET_DATA", + "MEDIA_BUG_START", + "MEDIA_BUG_START", "ALL" }; diff --git a/libs/esl/src/include/esl_event.h b/libs/esl/src/include/esl_event.h index 2ed782dc23..61673bff4b 100644 --- a/libs/esl/src/include/esl_event.h +++ b/libs/esl/src/include/esl_event.h @@ -119,6 +119,8 @@ typedef enum { ESL_EVENT_CALL_UPDATE, ESL_EVENT_FAILURE, ESL_EVENT_SOCKET_DATA, + ESL_EVENT_MEDIA_BUG_START, + ESL_EVENT_MEDIA_BUG_STOP, ESL_EVENT_ALL } esl_event_types_t; diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 74387bf1b6..0a9614f2b4 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -177,6 +177,8 @@ struct switch_media_bug { int16_t tmp[SWITCH_RECOMMENDED_BUFFER_SIZE]; time_t stop_time; switch_thread_id_t thread_id; + char *function; + char *target; struct switch_media_bug *next; }; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index c2688d0f41..63f3e4699e 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -147,6 +147,8 @@ SWITCH_DECLARE(void) switch_core_session_disable_heartbeat(switch_core_session_t \return SWITCH_STATUS_SUCCESS if the operation was a success */ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(_In_ switch_core_session_t *session, + _In_ const char *function, + _In_ const char *target, _In_ switch_media_bug_callback_t callback, _In_opt_ void *user_data, _In_ time_t stop_time, _In_ switch_media_bug_flag_t flags, _Out_ switch_media_bug_t **new_bug); diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 8ae0db4839..c63cc593c9 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1350,6 +1350,8 @@ typedef enum { SWITCH_EVENT_CALL_UPDATE, SWITCH_EVENT_FAILURE, SWITCH_EVENT_SOCKET_DATA, + SWITCH_EVENT_MEDIA_BUG_START, + SWITCH_EVENT_MEDIA_BUG_STOP, SWITCH_EVENT_ALL } switch_event_types_t; diff --git a/src/mod/applications/mod_fax/mod_fax.c b/src/mod/applications/mod_fax/mod_fax.c index 70b5abdb8b..2c170ef96d 100644 --- a/src/mod/applications/mod_fax/mod_fax.c +++ b/src/mod/applications/mod_fax/mod_fax.c @@ -843,7 +843,8 @@ switch_status_t spandsp_inband_dtmf_session(switch_core_session_t *session) 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, "spandsp_dtmf_detect", NULL, + inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) { return status; } diff --git a/src/mod/applications/mod_snapshot/mod_snapshot.c b/src/mod/applications/mod_snapshot/mod_snapshot.c index 8983e09708..2001ebdd38 100644 --- a/src/mod/applications/mod_snapshot/mod_snapshot.c +++ b/src/mod/applications/mod_snapshot/mod_snapshot.c @@ -125,7 +125,7 @@ static switch_status_t start_capture(switch_core_session_t *session, unsigned in switch_buffer_create_dynamic(&cb->buffer, bytes, bytes, bytes); switch_mutex_init(&cb->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); - if ((status = switch_core_media_bug_add(session, capture_callback, cb, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) { + if ((status = switch_core_media_bug_add(session, "snapshot", NULL, capture_callback, cb, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) { return status; } diff --git a/src/mod/formats/mod_shout/mod_shout.c b/src/mod/formats/mod_shout/mod_shout.c index 32ad767b68..1eef2e42d3 100644 --- a/src/mod/formats/mod_shout/mod_shout.c +++ b/src/mod/formats/mod_shout/mod_shout.c @@ -1187,7 +1187,8 @@ void do_telecast(switch_stream_handle_t *stream) switch_buffer_create_dynamic(&buffer, 1024, 2048, 0); switch_buffer_add_mutex(buffer, mutex); - if (switch_core_media_bug_add(tsession, telecast_callback, buffer, 0, + if (switch_core_media_bug_add(tsession, "telecast", NULL, + telecast_callback, buffer, 0, SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_PING, &bug) != SWITCH_STATUS_SUCCESS) { goto end; } diff --git a/src/switch_channel.c b/src/switch_channel.c index 561f323657..cb430a57cb 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1652,7 +1652,11 @@ SWITCH_DECLARE(void) switch_channel_event_set_extended_data(switch_channel_t *ch event->event_id == SWITCH_EVENT_SESSION_HEARTBEAT || event->event_id == SWITCH_EVENT_API || event->event_id == SWITCH_EVENT_RECORD_START || - event->event_id == SWITCH_EVENT_RECORD_STOP || event->event_id == SWITCH_EVENT_CALL_UPDATE || event->event_id == SWITCH_EVENT_CUSTOM) { + event->event_id == SWITCH_EVENT_RECORD_STOP || + event->event_id == SWITCH_EVENT_CALL_UPDATE || + event->event_id == SWITCH_EVENT_MEDIA_BUG_START || + event->event_id == SWITCH_EVENT_MEDIA_BUG_STOP || + event->event_id == SWITCH_EVENT_CUSTOM) { x = 0; /* Index Variables */ diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index cbcf66ac87..b85e4b6aff 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -240,13 +240,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b #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)) { @@ -298,7 +304,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t 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; @@ -340,6 +356,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t 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; } @@ -437,7 +461,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session } 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); + } + + } } } diff --git a/src/switch_event.c b/src/switch_event.c index 64ef1b3175..4039c404ce 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -187,6 +187,8 @@ static char *EVENT_NAMES[] = { "CALL_UPDATE", "FAILURE", "SOCKET_DATA", + "MEDIA_BUG_START", + "MEDIA_BUG_STOP", "ALL" }; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index bf84e9a8fc..1988ccd79f 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -403,9 +403,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_ } 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) { @@ -728,7 +730,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session 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"); @@ -1052,7 +1055,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t } - 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; @@ -1332,7 +1336,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_preprocess_session(switch_core_sessio } - 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); @@ -1488,9 +1493,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_audio(switch_core_session_t * 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; } @@ -1582,7 +1587,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_sessi 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; } @@ -1781,7 +1787,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_generate_session(switch_c 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; } @@ -2091,7 +2098,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_sessi 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; } @@ -2622,8 +2630,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * 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; @@ -2668,7 +2680,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * 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; }