diff --git a/src/include/switch_core.h b/src/include/switch_core.h index dfa1d39d7c..880cf9b893 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1015,6 +1015,8 @@ SWITCH_DECLARE(switch_app_log_t *) switch_core_session_get_app_log(_In_ switch_c */ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(_In_ switch_core_session_t *session, _In_ const switch_application_interface_t *application_interface, _In_opt_z_ const char *arg); + +SWITCH_DECLARE(void) switch_core_session_video_reset(switch_core_session_t *session); /*! \brief Execute an application on a session \param session the current session diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 99b992befd..698b2079bd 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -7472,6 +7472,8 @@ SWITCH_STANDARD_APP(conference_function) switch_channel_set_app_flag_key("conf_silent", channel, CONF_SILENT_REQ); } + switch_core_session_video_reset(session); + switch_channel_set_flag(channel, CF_CONFERENCE); if (switch_channel_answer(channel) != SWITCH_STATUS_SUCCESS) { @@ -8028,6 +8030,7 @@ SWITCH_STANDARD_APP(conference_function) switch_channel_clear_flag(channel, CF_CONFERENCE); + switch_core_session_video_reset(session); } /* Create a thread for the conference and launch it */ diff --git a/src/switch_core_media.c b/src/switch_core_media.c index b7c57a5abe..b18ec859e8 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -1225,12 +1225,19 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_read_frame(switch_core_session switch_assert(engine->rtp_session != NULL); engine->read_frame.datalen = 0; + if (!switch_channel_up_nosig(session->channel) || !switch_rtp_ready(engine->rtp_session) || switch_channel_test_flag(session->channel, CF_NOT_READY)) { + return SWITCH_STATUS_FALSE; + } + if (switch_mutex_trylock(engine->read_mutex) != SWITCH_STATUS_SUCCESS) { - /* return CNG for now */ + /* return CNG, another thread is already reading */ *frame = &engine->read_frame; switch_set_flag((*frame), SFF_CNG); (*frame)->datalen = engine->read_impl.encoded_bytes_per_packet; memset((*frame)->data, 0, (*frame)->datalen); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being read for %s\n", + switch_channel_get_name(session->channel), type2str(type)); + switch_yield(10000); return SWITCH_STATUS_SUCCESS; } diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 0768feed15..a67359d677 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -2521,6 +2521,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_async(sw return SWITCH_STATUS_FALSE; } +SWITCH_DECLARE(void) switch_core_session_video_reset(switch_core_session_t *session) +{ + if (switch_channel_test_flag(session->channel, CF_VIDEO)) { + switch_channel_set_flag(session->channel, CF_VIDEO_ECHO); + switch_channel_clear_flag(session->channel, CF_VIDEO_PASSIVE); + switch_core_session_refresh_video(session); + } +} SWITCH_DECLARE(switch_status_t) switch_core_session_execute_application_get_flags(switch_core_session_t *session, const char *app, const char *arg, int32_t *flags) @@ -2736,19 +2744,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_exec(switch_core_session_t * msg.string_array_arg[1] = expanded; switch_core_session_receive_message(session, &msg); - if (switch_channel_test_flag(channel, CF_VIDEO)) { - switch_channel_set_flag(channel, CF_VIDEO_ECHO); - switch_channel_clear_flag(channel, CF_VIDEO_PASSIVE); - switch_core_session_refresh_video(session); - } - application_interface->application_function(session, expanded); - if (switch_channel_test_flag(channel, CF_VIDEO)) { - switch_channel_set_flag(channel, CF_VIDEO_ECHO); - switch_channel_clear_flag(channel, CF_VIDEO_PASSIVE); - switch_core_session_refresh_video(session); - } if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_EXECUTE_COMPLETE) == SWITCH_STATUS_SUCCESS) { const char *resp = switch_channel_get_variable(session->channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE); switch_channel_event_set_data(session->channel, event); diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 56811a1e75..5926e52586 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -216,6 +216,8 @@ static void switch_core_standard_on_execute(switch_core_session_t *session) top: switch_channel_clear_flag(session->channel, CF_RESET); + + switch_core_session_video_reset(session); if ((extension = switch_channel_get_caller_extension(session->channel)) == 0) { switch_channel_hangup(session->channel, SWITCH_CAUSE_NORMAL_CLEARING); diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index f9b22f8a4f..e0d005aec9 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -63,7 +63,7 @@ static void *SWITCH_THREAD_FUNC video_bridge_thread(switch_thread_t *thread, voi if (!switch_stristr("loopback", source) && !switch_stristr("loopback", b_source)) { switch_channel_set_flag(channel, CF_VIDEO_PASSIVE); - switch_channel_set_flag(b_channel, CF_VIDEO_PASSIVE); + //switch_channel_set_flag(b_channel, CF_VIDEO_PASSIVE); } switch_core_session_refresh_video(vh->session_a); @@ -94,7 +94,7 @@ static void *SWITCH_THREAD_FUNC video_bridge_thread(switch_thread_t *thread, voi } switch_channel_clear_flag(channel, CF_VIDEO_PASSIVE); - switch_channel_clear_flag(b_channel, CF_VIDEO_PASSIVE); + //switch_channel_clear_flag(b_channel, CF_VIDEO_PASSIVE); switch_core_session_kill_channel(vh->session_b, SWITCH_SIG_BREAK); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(vh->session_a), SWITCH_LOG_DEBUG, "%s video thread ended.\n", switch_channel_get_name(channel)); @@ -624,7 +624,8 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) if (vid_thread) { switch_status_t st; - if (vh.up) { + if (vh.up == 1) { + vh.up = -1; switch_core_session_kill_channel(session_a, SWITCH_SIG_BREAK); switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK); }