diff --git a/src/include/switch_core.h b/src/include/switch_core.h index c76eeabb0f..2558e1bb19 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -995,7 +995,9 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(_In_ switch_core_session_t * \brief Launch a service thread on a session to drop inbound data \param session the session the launch thread on */ -SWITCH_DECLARE(void) switch_core_service_session(_In_ switch_core_session_t *session); +SWITCH_DECLARE(void) switch_core_service_session_av(_In_ switch_core_session_t *session, switch_bool_t audio, switch_bool_t video); +#define switch_core_service_session(_s) switch_core_service_session_av(_s, SWITCH_TRUE, SWITCH_FALSE) + /*! \brief Request an outgoing session spawned from an existing session using a desired endpoing module diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 7630af165d..004b67c727 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1206,6 +1206,8 @@ typedef enum { CF_INTERCEPT, CF_INTERCEPTED, CF_VIDEO_REFRESH_REQ, + CF_SERVICE_AUDIO, + CF_SERVICE_VIDEO, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ /* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */ CF_FLAG_MAX diff --git a/src/mod/applications/mod_fsv/mod_fsv.c b/src/mod/applications/mod_fsv/mod_fsv.c index a4c8969621..c75600ea14 100644 --- a/src/mod/applications/mod_fsv/mod_fsv.c +++ b/src/mod/applications/mod_fsv/mod_fsv.c @@ -370,6 +370,8 @@ SWITCH_STANDARD_APP(play_fsv_function) } switch_core_session_set_read_codec(session, &codec); + switch_core_service_session_av(session, SWITCH_FALSE, SWITCH_TRUE); + while (switch_channel_ready(channel)) { if (read(fd, &bytes, sizeof(bytes)) != sizeof(bytes)) { @@ -440,6 +442,8 @@ SWITCH_STANDARD_APP(play_fsv_function) } + switch_core_thread_session_end(session); + switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "OK"); end: diff --git a/src/switch_core.c b/src/switch_core.c index d8dfa9a428..78f9623036 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -397,19 +397,37 @@ static void *SWITCH_THREAD_FUNC switch_core_service_thread(switch_thread_t *thre switch_channel_set_flag(channel, CF_SERVICE); while (switch_channel_test_flag(channel, CF_SERVICE)) { - switch (switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) { - case SWITCH_STATUS_SUCCESS: - case SWITCH_STATUS_TIMEOUT: - case SWITCH_STATUS_BREAK: - break; - default: - switch_channel_clear_flag(channel, CF_SERVICE); - continue; + + if (switch_channel_test_flag(channel, CF_SERVICE_AUDIO)) { + switch (switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) { + case SWITCH_STATUS_SUCCESS: + case SWITCH_STATUS_TIMEOUT: + case SWITCH_STATUS_BREAK: + break; + default: + switch_channel_clear_flag(channel, CF_SERVICE); + break; + } + } + + if (switch_channel_test_flag(channel, CF_SERVICE_VIDEO) && switch_channel_test_flag(channel, CF_VIDEO)) { + switch (switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) { + case SWITCH_STATUS_SUCCESS: + case SWITCH_STATUS_TIMEOUT: + case SWITCH_STATUS_BREAK: + break; + default: + switch_channel_clear_flag(channel, CF_SERVICE); + break; + } } } switch_mutex_unlock(session->frame_read_mutex); + switch_channel_clear_flag(channel, CF_SERVICE_AUDIO); + switch_channel_clear_flag(channel, CF_SERVICE_VIDEO); + switch_core_session_rwunlock(session); return NULL; @@ -425,9 +443,14 @@ SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_session_t *sessi switch_assert(channel); switch_channel_clear_flag(channel, CF_SERVICE); + switch_channel_clear_flag(channel, CF_SERVICE_AUDIO); + switch_channel_clear_flag(channel, CF_SERVICE_VIDEO); + + switch_core_session_kill_channel(session, SWITCH_SIG_BREAK); + } -SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session) +SWITCH_DECLARE(void) switch_core_service_session_av(switch_core_session_t *session, switch_bool_t audio, switch_bool_t video) { switch_channel_t *channel; switch_assert(session); @@ -435,6 +458,9 @@ SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session) channel = switch_core_session_get_channel(session); switch_assert(channel); + if (audio) switch_channel_set_flag(channel, CF_SERVICE_AUDIO); + if (video) switch_channel_set_flag(channel, CF_SERVICE_VIDEO); + switch_core_session_launch_thread(session, (void *(*)(switch_thread_t *,void *))switch_core_service_thread, session); }