common: videosink: add dropping frame mechanism in amvideo [1/1]
authorRico Yang <wei.yang@amlogic.com>
Thu, 30 May 2019 07:22:45 +0000 (15:22 +0800)
committerRico Yang <wei.yang@amlogic.com>
Mon, 17 Jun 2019 07:09:50 +0000 (15:09 +0800)
PD#OTT-4124

Problem:
video frames cannot be dropped when displayed in video layer

Solution:
add dropping frame mechanism in amvideo

Verify:
verified on franlin

Change-Id: I751883543adc5c840921bd5062484e56cde2c0fa
Signed-off-by: Rico Yang <wei.yang@amlogic.com>
drivers/amlogic/media/video_sink/video.c
drivers/amlogic/media/video_sink/video_priv.h

index 217696e..ceed8ac 100644 (file)
@@ -185,6 +185,10 @@ bool platform_type = 1;
 int bit_depth_flag = 8;
 
 bool omx_secret_mode;
+static int omx_continuous_drop_count;
+static bool omx_continuous_drop_flag;
+static u32 cur_disp_omx_index;
+#define OMX_CONTINUOUS_DROP_LEVEL 5
 #define DEBUG_FLAG_FFPLAY      (1<<0)
 #define DEBUG_FLAG_CALC_PTS_INC        (1<<1)
 
@@ -4183,6 +4187,10 @@ static void vsync_toggle_frame(struct vframe_s *vf, int line)
                }
        }
        cur_dispbuf = vf;
+
+       if (cur_dispbuf && omx_secret_mode)
+               cur_disp_omx_index = cur_dispbuf->omx_index;
+
        if (cur_dispbuf && (cur_dispbuf->type & VIDTYPE_MVC))
                last_mvc_status = true;
        else
@@ -6716,6 +6724,10 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                        /*add  greatest common divisor of duration*/
                        /*1500(60fps) 3000(30fps) 3750(24fps) for some video*/
                        /*that pts is not evenly*/
+                       if (debug_flag & DEBUG_FLAG_OMX_DEBUG_DROP_FRAME) {
+                               pr_info("pcrscr_set sys_time=%d, omx_pts=%d, diff=%d",
+                                               system_time, omx_pts, diff);
+                       }
                        timestamp_pcrscr_set(omx_pts + DURATION_GCD);
                } else if (((diff - omx_pts_interval_upper / 2) > 0
                        || (diff - omx_pts_interval_lower / 2) < 0)
@@ -6875,6 +6887,25 @@ static irqreturn_t vsync_isr_in(int irq, void *dev_id)
                judge_3d_fa_out_mode();
        }
        while (vf) {
+               if (debug_flag & DEBUG_FLAG_OMX_DEBUG_DROP_FRAME) {
+                       pr_info("next pts= %d,index %d,pcr = %d,vpts = %d\n",
+                               vf->pts, vf->omx_index,
+                               timestamp_pcrscr_get(), timestamp_vpts_get());
+               }
+               if (omx_continuous_drop_flag
+                       && !(debug_flag
+                               & DEBUG_FLAG_OMX_DISABLE_DROP_FRAME)) {
+                       if (debug_flag & DEBUG_FLAG_OMX_DEBUG_DROP_FRAME) {
+                               pr_info("drop omx_index %d, pts %d\n",
+                                       vf->omx_index, vf->pts);
+                       }
+                       vf = vf_get(RECEIVER_NAME);
+                       if (vf)
+                               vf_put(vf, RECEIVER_NAME);
+                       vf = video_vf_peek();
+                       continue;
+               }
+
                if (vpts_expire(cur_dispbuf, vf, toggle_cnt) || show_nosync) {
                        ATRACE_COUNTER(MODULE_NAME,  __LINE__);
                        if (debug_flag & DEBUG_FLAG_PTS_TRACE)
@@ -8681,7 +8712,11 @@ static int video_receiver_event_fun(int type, void *data, void *private_data)
                receive_frame_count = 0;
                display_frame_count = 0;
                //init_hdr_info();
-
+               mutex_lock(&omx_mutex);
+               omx_continuous_drop_count = 0;
+               omx_continuous_drop_flag = false;
+               cur_disp_omx_index = 0;
+               mutex_unlock(&omx_mutex);
        } else if (type == VFRAME_EVENT_PROVIDER_RESET) {
                video_vf_light_unreg_provider(1);
        } else if (type == VFRAME_EVENT_PROVIDER_LIGHT_UNREG)
@@ -8691,6 +8726,7 @@ static int video_receiver_event_fun(int type, void *data, void *private_data)
                drop_frame_count = 0;
                receive_frame_count = 0;
                display_frame_count = 0;
+               mutex_lock(&omx_mutex);
                omx_run = false;
                omx_pts_set_from_hwc_count = 0;
                omx_pts_set_from_hwc_count_begin = 0;
@@ -8698,6 +8734,10 @@ static int video_receiver_event_fun(int type, void *data, void *private_data)
                omx_need_drop_frame_num = 0;
                omx_drop_done = false;
                omx_pts_set_index = 0;
+               omx_continuous_drop_count = 0;
+               omx_continuous_drop_flag = false;
+               cur_disp_omx_index = 0;
+               mutex_unlock(&omx_mutex);
                //init_hdr_info();
 
 #ifdef CONFIG_AM_VIDEO2
@@ -9086,7 +9126,28 @@ static void set_omx_pts(u32 *p)
        if (debug_flag & DEBUG_FLAG_PTS_TRACE)
                pr_info("[set_omx_pts]tmp_pts:%d, set_from_hwc:%d,frame_num=%d, not_reset=%d\n",
                        tmp_pts, set_from_hwc, frame_num, not_reset);
-
+       if (set_from_hwc == 1) {
+               if (frame_num >= cur_disp_omx_index) {
+                       omx_continuous_drop_flag = false;
+                       omx_continuous_drop_count = 0;
+               } else {
+                       if (omx_continuous_drop_flag
+                               && (debug_flag
+                                       & DEBUG_FLAG_OMX_DEBUG_DROP_FRAME))
+                               pr_info("ignore previous rendered frame %d\n",
+                                       frame_num);
+               }
+       } else {
+               omx_continuous_drop_count++;
+               if (omx_continuous_drop_count >= OMX_CONTINUOUS_DROP_LEVEL
+                               && !(debug_flag
+                                       & DEBUG_FLAG_OMX_DISABLE_DROP_FRAME)) {
+                       omx_continuous_drop_flag = true;
+                       if (debug_flag & DEBUG_FLAG_OMX_DEBUG_DROP_FRAME)
+                               pr_info("countinous drop %d\n",
+                                       omx_continuous_drop_count);
+               }
+       }
        if (not_reset == 0) {
                time_setomxpts = sched_clock();
                omx_pts = tmp_pts;
index 656a5ed..159be89 100644 (file)
@@ -32,6 +32,8 @@
 #define DEBUG_FLAG_LATENCY             0x200000
 #define DEBUG_FLAG_PTS_TRACE            0x400000
 #define DEBUG_FLAG_FRAME_DETECT            0x800000
+#define DEBUG_FLAG_OMX_DEBUG_DROP_FRAME        0x1000000
+#define DEBUG_FLAG_OMX_DISABLE_DROP_FRAME        0x2000000
 
 /*for video.c's static int debug_flag;*/