提交 2572621b authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-2368

上级 8825b6ea
...@@ -1831,10 +1831,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flag ...@@ -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", 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)); app, switch_channel_get_name(session->channel));
} else if (!switch_test_flag(application_interface, SAF_SUPPORT_NOMEDIA) && !switch_channel_media_ready(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", if (switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND) {
app, switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Application %s Requires media! pre_answering channel %s\n",
if (switch_channel_pre_answer(session->channel) != SWITCH_STATUS_SUCCESS) { app, switch_channel_get_name(session->channel));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Well, that didn't work very well did it? ...\n"); 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); switch_goto_status(SWITCH_STATUS_FALSE, done);
} }
} }
......
...@@ -155,7 +155,6 @@ struct switch_ivr_bridge_data { ...@@ -155,7 +155,6 @@ struct switch_ivr_bridge_data {
switch_input_callback_function_t input_callback; switch_input_callback_function_t input_callback;
void *session_data; void *session_data;
int clean_exit; int clean_exit;
uint32_t skip_frames;
}; };
typedef struct switch_ivr_bridge_data switch_ivr_bridge_data_t; 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) ...@@ -169,7 +168,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
switch_channel_t *chan_a, *chan_b; switch_channel_t *chan_a, *chan_b;
switch_frame_t *read_frame; switch_frame_t *read_frame;
switch_core_session_t *session_a, *session_b; 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 *app_name = NULL, *app_arg = NULL;
const char *hook_var = NULL; const char *hook_var = NULL;
int inner_bridge = 0; int inner_bridge = 0;
...@@ -181,6 +180,8 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) ...@@ -181,6 +180,8 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
const char *bridge_answer_timeout = NULL; const char *bridge_answer_timeout = NULL;
int answer_timeout, sent_update = 0; int answer_timeout, sent_update = 0;
time_t answer_limit = 0; time_t answer_limit = 0;
const char *exec_app = NULL;
const char *exec_data = NULL;
#ifdef SWITCH_VIDEO_IN_THREADS #ifdef SWITCH_VIDEO_IN_THREADS
switch_thread_t *vid_thread = NULL; switch_thread_t *vid_thread = NULL;
...@@ -201,6 +202,10 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) ...@@ -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_a = switch_core_session_get_channel(session_a);
chan_b = switch_core_session_get_channel(session_b); 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); 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); 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) ...@@ -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); 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 (!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) { if ((answer_timeout = atoi(bridge_answer_timeout)) < 0) {
answer_timeout = 0; answer_timeout = 0;
...@@ -285,7 +290,6 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) ...@@ -285,7 +290,6 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
switch_channel_state_t b_state; switch_channel_state_t b_state;
switch_status_t status; switch_status_t status;
switch_event_t *event; switch_event_t *event;
loop_count++;
if (switch_channel_test_flag(chan_a, CF_TRANSFER)) { if (switch_channel_test_flag(chan_a, CF_TRANSFER)) {
data->clean_exit = 1; data->clean_exit = 1;
...@@ -309,7 +313,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) ...@@ -309,7 +313,7 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
goto end_of_bridge_loop; 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); switch_channel_set_flag(chan_b, CF_SUSPEND);
msg.string_arg = data->b_uuid; msg.string_arg = data->b_uuid;
msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
...@@ -341,13 +345,34 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) ...@@ -341,13 +345,34 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj)
} }
#endif #endif
if (loop_count > DEFAULT_LEAD_FRAMES && switch_channel_media_ack(chan_a) && if (read_frame_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)) { if (exec_app) {
switch_ivr_nomedia(switch_core_session_get_uuid(session_a), SMF_REBRIDGE); switch_event_t *execute_event;
bypass_media_after_bridge = 0; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session_a), SWITCH_LOG_CRIT, "%s Bridge execute app %s(%s)\n",
switch_channel_clear_flag(chan_a, CF_BYPASS_MEDIA_AFTER_BRIDGE); switch_channel_get_name(chan_a), exec_app, exec_data);
goto end_of_bridge_loop;
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 */ /* 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) ...@@ -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); status = switch_core_session_read_frame(session_a, &read_frame, SWITCH_IO_FLAG_NONE, stream_id);
if (SWITCH_READ_ACCEPTABLE(status)) { if (SWITCH_READ_ACCEPTABLE(status)) {
read_frame_count++;
if (switch_test_flag(read_frame, SFF_CNG)) { if (switch_test_flag(read_frame, SFF_CNG)) {
if (silence_val) { if (silence_val) {
switch_generate_sln_silence((int16_t *) silence_frame.data, silence_frame.samples, 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) ...@@ -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)) { if (switch_channel_test_flag(chan_a, CF_BRIDGE_NOWRITE)) {
continue; continue;
} }
...@@ -1193,35 +1214,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses ...@@ -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)); 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"))) { if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_app"))) {
switch_event_t *execute_event; switch_channel_set_variable(caller_channel, "bridge_pre_execute_app", app);
data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_aleg_data"); if ((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_channel_set_variable(caller_channel, "bridge_pre_execute_data", data);
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;
} }
} }
if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_app"))) { if ((app = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_app"))) {
switch_event_t *execute_event; switch_channel_set_variable(peer_channel, "bridge_pre_execute_app", app);
data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data");
if (switch_event_create(&execute_event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) { if ((data = switch_channel_get_variable(caller_channel, "bridge_pre_execute_bleg_data"))) {
switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "call-command", "execute"); switch_channel_set_variable(peer_channel, "bridge_pre_execute_data", data);
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_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_private(peer_channel, "_bridge_", b_leg);
switch_channel_set_state(peer_channel, CS_EXCHANGE_MEDIA); switch_channel_set_state(peer_channel, CS_EXCHANGE_MEDIA);
audio_bridge_thread(NULL, (void *) a_leg); audio_bridge_thread(NULL, (void *) a_leg);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论