]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-2368
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 29 Nov 2010 19:00:19 +0000 (13:00 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 29 Nov 2010 19:00:19 +0000 (13:00 -0600)
src/switch_core_session.c
src/switch_ivr_bridge.c

index b3bb638c76b18f07e323693517c3a3315b0f6354..eca2f8daf2ae5f6e26b16e3cf93b573df014f749 100644 (file)
@@ -1831,10 +1831,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flag
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Application %s Requires media on channel %s!\n",
                                                  app, switch_channel_get_name(session->channel));
        } else if (!switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA) && !switch_channel_media_ready(session->channel)) {
-               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Application %s Requires media! pre_answering channel %s\n",
-                                                 app, switch_channel_get_name(session->channel));
-               if (switch_channel_pre_answer(session->channel) != SWITCH_STATUS_SUCCESS) {
-                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Well, that didn't work very well did it? ...\n");
+               if (switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Application %s Requires media! pre_answering channel %s\n",
+                                                         app, switch_channel_get_name(session->channel));
+                       if (switch_channel_pre_answer(session->channel) != SWITCH_STATUS_SUCCESS) {
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Well, that didn't work very well did it? ...\n");
+                               switch_goto_status(SWITCH_STATUS_FALSE, done);
+                       }
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, 
+                                                         "Cannot execute app '%s' media required on an outbound channel that does not have media established\n", app);
                        switch_goto_status(SWITCH_STATUS_FALSE, done);
                }
        }
index b6363ffa539ae71fc57e7f3663b601c6b6f377f1..64a5f8d7c964837a0606ec9c24f8e73459c188c7 100644 (file)
@@ -155,7 +155,6 @@ struct switch_ivr_bridge_data {
        switch_input_callback_function_t input_callback;
        void *session_data;
        int clean_exit;
-       uint32_t skip_frames;
 };
 typedef struct switch_ivr_bridge_data switch_ivr_bridge_data_t;
 
@@ -169,7 +168,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
        switch_channel_t *chan_a, *chan_b;
        switch_frame_t *read_frame;
        switch_core_session_t *session_a, *session_b;
-       uint32_t loop_count = 0;
+       uint32_t read_frame_count = 0;
        const char *app_name = NULL, *app_arg = NULL;
        const char *hook_var = NULL;
        int inner_bridge = 0;
@@ -181,6 +180,8 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
        const char *bridge_answer_timeout = NULL;
        int answer_timeout, sent_update = 0;
        time_t answer_limit = 0;
+       const char *exec_app = NULL;
+       const char *exec_data = NULL;
 
 #ifdef SWITCH_VIDEO_IN_THREADS
        switch_thread_t *vid_thread = NULL;
@@ -201,6 +202,10 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
        chan_a = switch_core_session_get_channel(session_a);
        chan_b = switch_core_session_get_channel(session_b);
 
+       if ((exec_app = switch_channel_get_variable(chan_a, "bridge_pre_execute_app"))) {
+               exec_data = switch_channel_get_variable(chan_a, "bridge_pre_execute_data");
+       }
+
        bypass_media_after_bridge = switch_channel_test_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE);
        switch_channel_clear_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE);
 
@@ -212,7 +217,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
        }
 
        inner_bridge = switch_channel_test_flag(chan_a, CF_INNER_BRIDGE);
-
+       
        if (!switch_channel_test_flag(chan_a, CF_ANSWERED) && (bridge_answer_timeout = switch_channel_get_variable(chan_a, "bridge_answer_timeout"))) {
                if ((answer_timeout = atoi(bridge_answer_timeout)) < 0) {
                        answer_timeout = 0;
@@ -285,7 +290,6 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                switch_channel_state_t b_state;
                switch_status_t status;
                switch_event_t *event;
-               loop_count++;
 
                if (switch_channel_test_flag(chan_a, CF_TRANSFER)) {
                        data->clean_exit = 1;
@@ -309,7 +313,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                        goto end_of_bridge_loop;
                }
                
-               if (loop_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a) && switch_core_session_private_event_count(session_a)) {
+               if (read_frame_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a) && switch_core_session_private_event_count(session_a)) {
                        switch_channel_set_flag(chan_b, CF_SUSPEND);
                        msg.string_arg = data->b_uuid;
                        msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
@@ -341,13 +345,34 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                }
 #endif
 
-               if (loop_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a) &&
-                       (bypass_media_after_bridge || switch_channel_test_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE)) && switch_channel_test_flag(chan_a, CF_ANSWERED)
-                       && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
-                       switch_ivr_nomedia(switch_core_session_get_uuid(session_a), SMF_REBRIDGE);
-                       bypass_media_after_bridge = 0;
-                       switch_channel_clear_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE);
-                       goto end_of_bridge_loop;
+               if (read_frame_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a)) {
+                       
+                       if (exec_app) {
+                               switch_event_t *execute_event;
+                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a), SWITCH_LOG_CRIT, "%s Bridge execute app %s(%s)\n", 
+                                                                 switch_channel_get_name(chan_a), exec_app, exec_data);
+
+                               if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
+                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", exec_app);
+                                       if (exec_data) {
+                                               switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", exec_data);
+                                       }
+                                       //switch_event_add_header(execute_event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
+                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
+                                       switch_core_session_queue_private_event(session_a, &execute_event, SWITCH_FALSE);
+                               }
+                               exec_app = exec_data = NULL;
+                       }
+
+
+                       if ((bypass_media_after_bridge || switch_channel_test_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE)) && switch_channel_test_flag(chan_a, CF_ANSWERED)
+                               && switch_channel_test_flag(chan_b, CF_ANSWERED)) {
+                               switch_ivr_nomedia(switch_core_session_get_uuid(session_a), SMF_REBRIDGE);
+                               bypass_media_after_bridge = 0;
+                               switch_channel_clear_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE);
+                               goto end_of_bridge_loop;
+                       }
                }
 
                /* if 1 channel has DTMF pass it to the other */
@@ -454,6 +479,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                status = switch_core_session_read_frame(session_a, &read_frame, SWITCH_IO_FLAG_NONE, stream_id);
 
                if (SWITCH_READ_ACCEPTABLE(status)) {
+                       read_frame_count++;
                        if (switch_test_flag(read_frame, SFF_CNG)) {
                                if (silence_val) {
                                        switch_generate_sln_silence((int16_t *) silence_frame.data, silence_frame.samples, silence_val);
@@ -463,11 +489,6 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
                                }
                        }
 
-                       if (data->skip_frames) {
-                               data->skip_frames--;
-                               continue;
-                       }
-
                        if (switch_channel_test_flag(chan_a, CF_BRIDGE_NOWRITE)) {
                                continue;
                        }
@@ -1193,35 +1214,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
                        switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session));
 
                        if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_app"))) {
-                               switch_event_t *execute_event;
-
-                               data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_data");
-                               if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", data);
-                                       switch_event_add_header(execute_event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
-                                       switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE);
-                                       a_leg->skip_frames = DEFAULT_LEAD_FRAMES;
+                               switch_channel_set_variable(caller_channel, "bridge_pre_execute_app", app);
+                               
+                               if ((data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_data"))) {
+                                       switch_channel_set_variable(caller_channel, "bridge_pre_execute_data", data);
                                }
-
                        }
 
                        if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_app"))) {
-                               switch_event_t *execute_event;
-                               data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data");
-                               if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute");
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", data);
-                                       switch_event_add_header(execute_event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-                                       switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
-                                       switch_core_session_queue_private_event(peer_session, &execute_event, SWITCH_FALSE);
-                                       b_leg->skip_frames = DEFAULT_LEAD_FRAMES;
+                               switch_channel_set_variable(peer_channel, "bridge_pre_execute_app", app);
+
+                               if ((data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data"))) {
+                                       switch_channel_set_variable(peer_channel, "bridge_pre_execute_data", data);
                                }
+                               
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "APP [%s][%s]\n", app, switch_str_nil(data));
+                               
                        }
-
+                       
                        switch_channel_set_private(peer_channel, "_bridge_", b_leg);
                        switch_channel_set_state(peer_channel, CS_EXCHANGE_MEDIA);
                        audio_bridge_thread(NULL, (void *) a_leg);