diff --git a/src/include/switch_core_media.h b/src/include/switch_core_media.h index 340f18f0b6..46167543af 100644 --- a/src/include/switch_core_media.h +++ b/src/include/switch_core_media.h @@ -326,6 +326,7 @@ SWITCH_DECLARE(void) switch_core_session_stop_media(switch_core_session_t *sessi SWITCH_DECLARE(switch_media_flow_t) switch_core_session_media_flow(switch_core_session_t *session, switch_media_type_t type); SWITCH_DECLARE(switch_status_t) switch_core_media_get_vid_params(switch_core_session_t *session, switch_vid_params_t *vid_params); SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_session_t *session, switch_file_handle_t *fh, switch_rw_t rw); +SWITCH_DECLARE(switch_bool_t) switch_core_session_in_video_thread(switch_core_session_t *session); SWITCH_END_EXTERN_C #endif diff --git a/src/mod/applications/mod_fsv/mod_fsv.c b/src/mod/applications/mod_fsv/mod_fsv.c index 6791f2a95e..77ac9caeb7 100644 --- a/src/mod/applications/mod_fsv/mod_fsv.c +++ b/src/mod/applications/mod_fsv/mod_fsv.c @@ -670,10 +670,6 @@ static void decode_video_thread(switch_core_session_t *session, void *obj) goto done; } - switch_channel_set_flag(channel, CF_VIDEO_DECODED_READ); - switch_channel_set_flag(channel, CF_VIDEO_DEBUG_READ); - switch_channel_set_flag(channel, CF_VIDEO_DEBUG_WRITE); - while (switch_channel_ready(channel)) { switch_status_t status = switch_core_session_read_video_frame(session, &frame, SWITCH_IO_FLAG_NONE, 0); @@ -687,6 +683,7 @@ static void decode_video_thread(switch_core_session_t *session, void *obj) } if (frame && frame->datalen > 0) { + printf("WTF %p\n", (void *)frame->img); switch_core_session_write_video_frame(session, frame, SWITCH_IO_FLAG_NONE, 0); } else { continue; @@ -733,6 +730,11 @@ SWITCH_STANDARD_APP(decode_video_function) switch_channel_answer(channel); switch_core_session_request_video_refresh(session); + + switch_channel_set_flag(channel, CF_VIDEO_DECODED_READ); + switch_channel_set_flag(channel, CF_VIDEO_DEBUG_READ); + switch_channel_set_flag(channel, CF_VIDEO_DEBUG_WRITE); + switch_core_media_start_video_function(session, decode_video_thread, &max_pictures); switch_ivr_play_file(session, NULL, moh, NULL); diff --git a/src/switch_channel.c b/src/switch_channel.c index fe7df086c2..10a2af61ec 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1831,7 +1831,9 @@ SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, sw } if (flag == CF_VIDEO_DECODED_READ) { - switch_channel_wait_for_flag(channel, CF_VIDEO_READY, SWITCH_TRUE, 10000, NULL); + if (!switch_core_session_in_video_thread(channel->session)) { + switch_channel_wait_for_flag(channel, CF_VIDEO_READY, SWITCH_TRUE, 10000, NULL); + } } } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 519c20828d..557ba8365a 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -159,6 +159,7 @@ typedef struct switch_rtp_engine_s { switch_codec_settings_t codec_settings; switch_media_flow_t rmode; switch_media_flow_t smode; + switch_thread_id_t thread_id; } switch_rtp_engine_t; struct switch_media_handle_s { @@ -4634,7 +4635,7 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi switch_status_t status; switch_frame_t *read_frame; switch_media_handle_t *smh; - uint32_t loops = 0, xloops = 0, vloops = 0; + uint32_t loops = 0, xloops = 0, vloops = 0, viloops = 0; switch_frame_t fr = { 0 }; unsigned char *buf = NULL; switch_image_t *blank_img = NULL; @@ -4645,13 +4646,12 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi blank_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 320, 240, 1); switch_img_fill(blank_img, 0, 0, blank_img->d_w, blank_img->d_h, &bgcolor); - - if (!(smh = session->media_handle)) { return NULL; } v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO]; + v_engine->thread_id = switch_thread_self(); switch_core_session_read_lock(session); @@ -4731,9 +4731,9 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi if (switch_test_flag(read_frame, SFF_CNG)) { continue; } - + if (read_frame->img) { - if (vloops > 10) { + if (++viloops > 10) { switch_channel_set_flag(channel, CF_VIDEO_READY); smh->vid_params.width = read_frame->img->d_w; smh->vid_params.height = read_frame->img->d_h; @@ -4884,6 +4884,23 @@ SWITCH_DECLARE(void) switch_core_media_end_video_function(switch_core_session_t } } +SWITCH_DECLARE(switch_bool_t) switch_core_session_in_video_thread(switch_core_session_t *session) +{ + switch_rtp_engine_t *v_engine; + switch_media_handle_t *smh; + + switch_assert(session); + + if (!(smh = session->media_handle)) { + return SWITCH_FALSE; + } + + v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO]; + + return switch_thread_equal(switch_thread_self(), v_engine->thread_id) ? SWITCH_TRUE : SWITCH_FALSE; +} + + //? #define RA_PTR_LEN 512 SWITCH_DECLARE(switch_status_t) switch_core_media_proxy_remote_addr(switch_core_session_t *session, const char *sdp_str)