]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10050: [core] chromakey add flag to detect keyframe
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 1 Mar 2017 17:38:57 +0000 (11:38 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 1 Mar 2017 17:38:57 +0000 (11:38 -0600)
src/include/switch_types.h
src/mod/applications/mod_video_filter/mod_video_filter.c
src/switch_core_media.c
src/switch_vpx.c

index a48d3a2aa9fd3cff0bdca22f1ea0e77a43123fd3..949877d0bb06b4f76d0ab4bf7c9115e0d75e18a6 100644 (file)
@@ -1607,7 +1607,8 @@ typedef enum {
        SFF_SAME_IMAGE = (1 << 15),
        SFF_USE_VIDEO_TIMESTAMP = (1 << 16),
        SFF_ENCODED = (1 << 17),
-       SFF_TEXT_LINE_BREAK = (1 << 18)
+       SFF_TEXT_LINE_BREAK = (1 << 18),
+       SFF_IS_KEYFRAME = (1 << 19)
 } switch_frame_flag_enum_t;
 typedef uint32_t switch_frame_flag_t;
 
index fdfc1088e00c861ecc84820723cfce84e6174dfe..52044bec1bbd2f516420e5d71cb76b9886bc3083 100644 (file)
@@ -56,6 +56,8 @@ typedef struct chromakey_context_s {
        int mask_len;
        switch_core_session_t *session;
        switch_mutex_t *command_mutex;
+       int patch;
+       int mod;
 } chromakey_context_t;
 
 static void init_context(chromakey_context_t *context)
@@ -85,11 +87,10 @@ static void parse_params(chromakey_context_t *context, int start, int argc, char
        int n = argc - start;
        int i = start;
 
-       switch_core_session_request_video_refresh(context->session);
-       switch_core_media_gen_key_frame(context->session);
-
        switch_mutex_lock(context->command_mutex);
 
+       context->patch = 0;
+
        if (n > 0 && argv[i]) { // color
                int j = 0;
                char *list[MAX_MASK];
@@ -194,17 +195,18 @@ static void parse_params(chromakey_context_t *context, int start, int argc, char
                if (!strcasecmp(argv[i], "patch")) {
                        *function = "patch:video";
                        *flags = SMBF_VIDEO_PATCH;
+                       context->patch++;
                }
 
                i++;
        }
 
-
+       switch_core_session_request_video_refresh(context->session);
+       context->mod++;
 
        switch_mutex_unlock(context->command_mutex);
 
-       switch_core_session_request_video_refresh(context->session);
-       switch_core_media_gen_key_frame(context->session);
+
 
 }
 
@@ -223,6 +225,13 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
                return SWITCH_STATUS_SUCCESS;
        }
 
+       if (!context->patch && context->mod && !switch_test_flag(frame, SFF_IS_KEYFRAME)) {
+               switch_core_session_request_video_refresh(context->session);
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       context->mod = 0;
+
        if (switch_mutex_trylock(context->command_mutex) != SWITCH_STATUS_SUCCESS) {
                switch_img_patch(frame->img, context->last_img, 0, 0);
                return SWITCH_STATUS_SUCCESS;
index 5a19e90462f25e0dd6f8a6f36b8e240f391a2ce2..9fa25851264a773f418d392aa35262f956d8c42d 100644 (file)
@@ -2092,6 +2092,8 @@ static void check_jb(switch_core_session_t *session, const char *input, int32_t
 
                                if (frames > 0) {
                                        switch_rtp_set_video_buffer_size(v_engine->rtp_session, frames, max_frames);
+                               } else {
+                                       switch_rtp_deactivate_jitter_buffer(v_engine->rtp_session);
                                }
                                return;
                        } else if (!strncasecmp(input, "vdebug:", 7)) {
@@ -14036,6 +14038,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
        uint32_t loops = 0;
        switch_media_handle_t *smh;
        int patchers = 0;
+       int is_keyframe = 0;
 
        switch_assert(session != NULL);
 
@@ -14109,7 +14112,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
                (*frame)->img = NULL;
 
                decode_status = switch_core_codec_decode_video((*frame)->codec, *frame);
-
+               if (switch_test_flag(*frame, SFF_IS_KEYFRAME)) {
+                       is_keyframe++;
+               }
                if ((*frame)->img && switch_channel_test_flag(session->channel, CF_VIDEO_DEBUG_READ)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "IMAGE %dx%d %dx%d\n",
                                                          (*frame)->img->w, (*frame)->img->h, (*frame)->img->d_w, (*frame)->img->d_h);
@@ -14152,6 +14157,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
 
   done:
 
+       if (*frame && is_keyframe) {
+               switch_set_flag(*frame, SFF_IS_KEYFRAME);
+       }
+
        if (session->bugs) {
                switch_media_bug_t *bp;
                int prune = 0;
index ab2de6d501e33503109950c4642fe46ca69b79a6..78bf2245bee166e8950bfdb5428918fd5ecd7b3d 100644 (file)
@@ -1178,6 +1178,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t *
        }
 
        if (is_keyframe) {
+               switch_set_flag(frame, SFF_IS_KEYFRAME);
                if (context->got_key_frame <= 0) {
                        context->got_key_frame = 1;
                        context->no_key_frame = 0;