Revision
16858
Author
anthm
Date
2010-03-01 19:11:15 -0600 (Mon, 01 Mar 2010)

Log Message

add events for bug start and stop

Modified Paths

Diff

Modified: freeswitch/trunk/libs/esl/src/esl_event.c (16857 => 16858)


--- freeswitch/trunk/libs/esl/src/esl_event.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/libs/esl/src/esl_event.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -131,6 +131,8 @@
 	"CALL_UPDATE",
 	"FAILURE",
 	"SOCKET_DATA",
+	"MEDIA_BUG_START",
+	"MEDIA_BUG_START",
 	"ALL"
 };
 

Modified: freeswitch/trunk/libs/esl/src/include/esl_event.h (16857 => 16858)


--- freeswitch/trunk/libs/esl/src/include/esl_event.h	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/libs/esl/src/include/esl_event.h	2010-03-02 01:11:15 UTC (rev 16858)
@@ -119,6 +119,8 @@
 	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;
 

Modified: freeswitch/trunk/src/include/private/switch_core_pvt.h (16857 => 16858)


--- freeswitch/trunk/src/include/private/switch_core_pvt.h	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/include/private/switch_core_pvt.h	2010-03-02 01:11:15 UTC (rev 16858)
@@ -177,6 +177,8 @@
 	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;
 };
 

Modified: freeswitch/trunk/src/include/switch_core.h (16857 => 16858)


--- freeswitch/trunk/src/include/switch_core.h	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/include/switch_core.h	2010-03-02 01:11:15 UTC (rev 16858)
@@ -147,6 +147,8 @@
   \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);

Modified: freeswitch/trunk/src/include/switch_types.h (16857 => 16858)


--- freeswitch/trunk/src/include/switch_types.h	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/include/switch_types.h	2010-03-02 01:11:15 UTC (rev 16858)
@@ -1350,6 +1350,8 @@
 	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;
 

Modified: freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c (16857 => 16858)


--- freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -843,7 +843,8 @@
 		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;
 	}
 

Modified: freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c (16857 => 16858)


--- freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/mod/applications/mod_snapshot/mod_snapshot.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -125,7 +125,7 @@
 	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;
 	}
 

Modified: freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c (16857 => 16858)


--- freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -1187,7 +1187,8 @@
 		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;
 		}

Modified: freeswitch/trunk/src/switch_channel.c (16857 => 16858)


--- freeswitch/trunk/src/switch_channel.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/switch_channel.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -1652,7 +1652,11 @@
 		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 */

Modified: freeswitch/trunk/src/switch_core_media_bug.c (16857 => 16858)


--- freeswitch/trunk/src/switch_core_media_bug.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/switch_core_media_bug.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -240,13 +240,19 @@
 
 #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 @@
 	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_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_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);
+				}
+
+			}
 		}
 	}
 

Modified: freeswitch/trunk/src/switch_event.c (16857 => 16858)


--- freeswitch/trunk/src/switch_event.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/switch_event.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -187,6 +187,8 @@
 	"CALL_UPDATE",
 	"FAILURE",
 	"SOCKET_DATA",
+	"MEDIA_BUG_START",
+	"MEDIA_BUG_STOP",
 	"ALL"
 };
 

Modified: freeswitch/trunk/src/switch_ivr_async.c (16857 => 16858)


--- freeswitch/trunk/src/switch_ivr_async.c	2010-03-02 01:08:31 UTC (rev 16857)
+++ freeswitch/trunk/src/switch_ivr_async.c	2010-03-02 01:11:15 UTC (rev 16858)
@@ -403,9 +403,11 @@
 	}
 
 	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_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 @@
 	}
 
 
-	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 @@
 	}
 
 
-	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 @@
 
 	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 @@
 		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 @@
 	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_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 @@
 	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_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;
 	}