]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add events for bug start and stop
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 2 Mar 2010 01:11:15 +0000 (01:11 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 2 Mar 2010 01:11:15 +0000 (01:11 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16858 d0543943-73ff-0310-b7d9-9358b9ac24b2

12 files changed:
libs/esl/src/esl_event.c
libs/esl/src/include/esl_event.h
src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_fax/mod_fax.c
src/mod/applications/mod_snapshot/mod_snapshot.c
src/mod/formats/mod_shout/mod_shout.c
src/switch_channel.c
src/switch_core_media_bug.c
src/switch_event.c
src/switch_ivr_async.c

index 2686f332c4eab5e23ee7ffac782c80d6a9b6d7d8..b89711d2dd67dab5f2a45d57e4ce882b4ea1a443 100644 (file)
@@ -131,6 +131,8 @@ static const char *EVENT_NAMES[] = {
        "CALL_UPDATE",
        "FAILURE",
        "SOCKET_DATA",
+       "MEDIA_BUG_START",
+       "MEDIA_BUG_START",
        "ALL"
 };
 
index 2ed782dc236869d2930c9893dda0787ebc2e58ea..61673bff4ba8a6ec694b9e968449151d3c61612b 100644 (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;
 
index 74387bf1b6f700e3d7bbf68a3f77076196c45ac4..0a9614f2b4604cbf5b6058f06b6e69c3ef9e93fa 100644 (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;
 };
 
index c2688d0f413d74b2674fc8821b4096913d68b466..63f3e4699e9deaf0cc39e90321f96727340a735f 100644 (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);
index 8ae0db483968cedd865b2ce23c7717d30e63561c..c63cc593c93741669e8233589e703594d7261f6a 100644 (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;
 
index 70b5abdb8b55cca54429339c9e18fd0cd776c0fc..2c170ef96d24601a6bf943def5b24c1378ba96f3 100644 (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;
        }
 
index 8983e09708d14cb726eca5d5f7ca4c666adb0be6..2001ebdd386e805ee6c624b694ab934aa863c852 100644 (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;
        }
 
index 32ad767b68973fc332637f2a4ffc6725e35d2ee1..1eef2e42d3bb23a2819557972396020c70a4f673 100644 (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;
                }
index 561f323657a7d701e8b510b5ee632c9b2ed38cf6..cb430a57cb21c383406534d46ff1ea5176825b4a 100644 (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 */
index cbcf66ac87adec01aed865a16c50b137cf17c1e9..b85e4b6affc271c89dd790a1cc2e7c0eb3e39470 100644 (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);
+                               }
+
+                       }
                }
        }
 
index 64ef1b317574052bb3ede4131b527c80faa43d84..4039c404cee408d1c11ff84d2cb5945ef6548f4c 100644 (file)
@@ -187,6 +187,8 @@ static char *EVENT_NAMES[] = {
        "CALL_UPDATE",
        "FAILURE",
        "SOCKET_DATA",
+       "MEDIA_BUG_START",
+       "MEDIA_BUG_STOP",
        "ALL"
 };
 
index bf84e9a8fc78b44ed9ff1bedc4872f6fd571e6ce..1988ccd79f618af776802f270c5e85129dc01d69 100644 (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;
        }