]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7500: don't wait for video ready from inside video thread that sets that flag
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 11 Mar 2015 16:56:28 +0000 (11:56 -0500)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:11 +0000 (12:47 -0500)
src/include/switch_core_media.h
src/mod/applications/mod_fsv/mod_fsv.c
src/switch_channel.c
src/switch_core_media.c

index 340f18f0b6798ec65772dbd038d8b25bcb4360f0..46167543af0c248a72a6ff3d70fb6f6ff378ee0f 100644 (file)
@@ -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
index 6791f2a95ec7465dfc37e1fe7815a979b9191eaa..77ac9caeb7f9fa01a8b501bfd2c68227077c6638 100644 (file)
@@ -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);
index fe7df086c27f52f7f91fb3f080f6453ca761b297..10a2af61ec7c9f2c93005ef0859554b77b6ae238 100644 (file)
@@ -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);
+               }
        }
 }
 
index 519c20828d4aaf747405bf9236b6fbe969baa5b3..557ba8365a989a55bb0232ea6ec8a5d43bed65c9 100644 (file)
@@ -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)