]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-2971
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 25 Feb 2011 16:55:33 +0000 (10:55 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 25 Feb 2011 16:55:47 +0000 (10:55 -0600)
libs/esl/src/esl_event.c
libs/esl/src/include/esl_event.h
src/include/switch_types.h
src/switch_channel.c
src/switch_event.c
src/switch_ivr_play_say.c

index db7c581ee92bf9acf933af41ec0a4522adfc9f86..9bd78a838d95f84ded3eb8fd63a68af5e85b4c78 100644 (file)
@@ -131,6 +131,8 @@ static const char *EVENT_NAMES[] = {
        "NAT",
        "RECORD_START",
        "RECORD_STOP",
+       "PLAYBACK_START",
+       "PLAYBACK_STOP",
        "CALL_UPDATE",
        "FAILURE",
        "SOCKET_DATA",
index 0e6d3e37dbb3c8e785e2bcc31dde1bd5188eb941..7e619f47642902ad4151d12ebb50dd14b6951211 100644 (file)
@@ -119,6 +119,8 @@ typedef enum {
        ESL_EVENT_NAT,
        ESL_EVENT_RECORD_START,
        ESL_EVENT_RECORD_STOP,
+       ESL_EVENT_PLAYBACK_START,
+       ESL_EVENT_PLAYBACK_STOP,
        ESL_EVENT_CALL_UPDATE,
        ESL_EVENT_FAILURE,
        ESL_EVENT_SOCKET_DATA,
index 3972404290e70e079a949af2910e45471b05174f..4253d0e5426b3e8737ca4c54339f10779a549fc9 100644 (file)
@@ -1504,6 +1504,8 @@ typedef enum {
        SWITCH_EVENT_NAT,
        SWITCH_EVENT_RECORD_START,
        SWITCH_EVENT_RECORD_STOP,
+       SWITCH_EVENT_PLAYBACK_START,
+       SWITCH_EVENT_PLAYBACK_STOP,
        SWITCH_EVENT_CALL_UPDATE,
        SWITCH_EVENT_FAILURE,
        SWITCH_EVENT_SOCKET_DATA,
index 9e3064b625bf63b12f740200e4ede35308fe90df..179f63da7933cfe5ba874a8dbb73578b30cc4e9f 100644 (file)
@@ -2042,10 +2042,13 @@ SWITCH_DECLARE(void) switch_channel_event_set_extended_data(switch_channel_t *ch
                event->event_id == SWITCH_EVENT_REQUEST_PARAMS ||
                event->event_id == SWITCH_EVENT_CHANNEL_DATA ||
                event->event_id == SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE ||
+               event->event_id == SWITCH_EVENT_CHANNEL_DESTROY ||
                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_PLAYBACK_START ||
+               event->event_id == SWITCH_EVENT_PLAYBACK_STOP ||
                event->event_id == SWITCH_EVENT_CALL_UPDATE || 
                event->event_id == SWITCH_EVENT_MEDIA_BUG_START || 
                event->event_id == SWITCH_EVENT_MEDIA_BUG_STOP || 
index b626d5b846c91b799c02fce81c4d16bff6463d2b..56ee9e9a9cde60e1b4a9d3241bd9be27bd8d2ed2 100644 (file)
@@ -189,6 +189,8 @@ static char *EVENT_NAMES[] = {
        "NAT",
        "RECORD_START",
        "RECORD_STOP",
+       "PLAYBACK_START",
+       "PLAYBACK_STOP",
        "CALL_UPDATE",
        "FAILURE",
        "SOCKET_DATA",
index dc263e9be590e4a85c34bacef688db26bd4c0c74..98dfd0f71e0e0625ac688eb6e390066e075c2c1a 100644 (file)
@@ -746,12 +746,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
 
        }
 
-       if (switch_event_create(&event, SWITCH_EVENT_RECORD_STOP) == SWITCH_STATUS_SUCCESS) {
-               switch_channel_event_set_data(channel, event);
-               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Record-File-Path", file);
-               switch_event_fire(&event);
-       }
-
        if (fill_cng || waste_resources) {
                switch_core_codec_destroy(&write_codec);
        }
@@ -766,6 +760,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
 
        switch_channel_set_variable_printf(channel, "record_samples", "%d", fh->samples_out);
 
+       if (switch_event_create(&event, SWITCH_EVENT_RECORD_STOP) == SWITCH_STATUS_SUCCESS) {
+               switch_channel_event_set_data(channel, event);
+               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Record-File-Path", file);
+               switch_event_fire(&event);
+       }
+
        switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
        return status;
 }
@@ -951,6 +951,38 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_release_file_handle(switch_core_sessi
 #define FILE_BLOCKSIZE 1024 * 8
 #define FILE_BUFSIZE 1024 * 64
 
+static void add_playback_vars_to_event(switch_core_session_t *session, switch_event_t *event, char *vars)
+{
+       char *tmp;
+
+       if (!session || !event || !vars)
+               return;
+
+       if ((tmp = switch_core_session_strdup(session, vars))) {
+               char *argv[128] = { 0 };
+               int argc, i;
+
+               if (!(argc = switch_separate_string(tmp, ',', argv, (sizeof(argv) / sizeof(argv[0])))))
+                       return;
+
+               for (i = 0; i < argc; i++) {
+                       char *var, *val;
+
+                       if ((var = strchr(argv[i], '='))) {
+                               *var = '\0';
+                               val = var+1;
+                               var = argv[i];
+
+                               if (var && *var && val && *val) {
+                                       if ((var = switch_core_session_sprintf(session, "playback_variable_%s", var))) {
+                                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, var, val);
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, const char *file, switch_input_args_t *args)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -990,6 +1022,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
        int timeout_samples = 0;
        const char *var;
        int more_data = 0;
+       char *playback_vars, *tmp;
+       switch_event_t *event;
 
        if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
                return SWITCH_STATUS_FALSE;
@@ -1138,6 +1172,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
                        }
                }
 
+               /* Try to parse extra parameters for this playback (parameters within {} at the end of the filename */
+               playback_vars = NULL;
+               if ((tmp = strchr(file, '{'))) {
+                       char *tfile, *e;
+                       
+                       if ((tfile = switch_core_session_strdup(session, tmp))) {
+                               if ((e = switch_find_end_paren(tfile, '{', '}')) && *(e + 1) == '\0') {
+                                       *tmp = '\0';
+                                       *e = '\0';
+                                       playback_vars = tfile+1;
+                               }
+                       }
+               }
 
                if (!fh) {
                        fh = &lfh;
@@ -1293,6 +1340,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
 
                ilen = samples;
 
+               if (switch_event_create(&event, SWITCH_EVENT_PLAYBACK_START) == SWITCH_STATUS_SUCCESS) {
+                       switch_channel_event_set_data(channel, event);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Path", file);
+                       add_playback_vars_to_event(session, event, playback_vars); 
+                       switch_event_fire(&event);
+               }
+
                for (;;) {
                        int do_speed = 1;
                        int last_speed = -1;
@@ -1586,6 +1640,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
                }
                switch_channel_set_variable_printf(channel, "playback_samples", "%d", fh->samples_in);
 
+               if (switch_event_create(&event, SWITCH_EVENT_PLAYBACK_STOP) == SWITCH_STATUS_SUCCESS) {
+                       switch_channel_event_set_data(channel, event);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Path", file);
+                       if (status == SWITCH_STATUS_BREAK) {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-Status", "break");
+                       } else {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-Status", "done");
+                       }
+                       add_playback_vars_to_event(session, event, playback_vars); 
+                       switch_event_fire(&event);
+               }
+
                switch_core_session_io_write_lock(session);
                switch_channel_set_private(channel, "__fh", NULL);
                switch_core_session_io_rwunlock(session);