add events for bug start and stop

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16858 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2010-03-02 01:11:15 +00:00
parent 85587aa6b9
commit cc39f9e4bc
12 changed files with 82 additions and 17 deletions

View File

@ -131,6 +131,8 @@ static const char *EVENT_NAMES[] = {
"CALL_UPDATE",
"FAILURE",
"SOCKET_DATA",
"MEDIA_BUG_START",
"MEDIA_BUG_START",
"ALL"
};

View File

@ -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;

View File

@ -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;
};

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 */

View File

@ -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);
}
}
}
}

View File

@ -187,6 +187,8 @@ static char *EVENT_NAMES[] = {
"CALL_UPDATE",
"FAILURE",
"SOCKET_DATA",
"MEDIA_BUG_START",
"MEDIA_BUG_STOP",
"ALL"
};

View File

@ -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;
}