[vlc-devel] [PATCH 1/3] codec: avcodec: simplify hurry-up cases

Francois Cartegnie fcvlcdev at free.fr
Fri Jan 15 16:27:48 CET 2016


---
 modules/codec/avcodec/video.c | 82 ++++++++++++++++++-------------------------
 1 file changed, 35 insertions(+), 47 deletions(-)

diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 6b23375..534bf85 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -571,13 +571,11 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         }
     }
 
-    if( p_dec->b_frame_drop_allowed && (p_sys->i_late_frames > 0) &&
-        (mdate() - p_sys->i_late_frames_start > INT64_C(5000000)) )
+    const mtime_t i_late = ( p_sys->i_late_frames > 0 ) ? mdate() - p_sys->i_late_frames_start : 0;
+
+    if( p_dec->b_frame_drop_allowed && i_late > CLOCK_FREQ * 5 )
     {
-        if( p_sys->i_pts > VLC_TS_INVALID )
-        {
-            p_sys->i_pts = VLC_TS_INVALID; /* To make sure we recover properly */
-        }
+        p_sys->i_pts = VLC_TS_INVALID; /* To make sure we recover properly */
         if( p_block )
             block_Release( p_block );
         p_sys->i_late_frames--;
@@ -586,52 +584,42 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    /* A good idea could be to decode all I pictures and see for the other */
-    if( p_dec->b_frame_drop_allowed &&
-        p_sys->b_hurry_up &&
-        (p_sys->i_late_frames > 4) )
+    b_drawpicture = ( !p_block || !(p_block->i_flags & BLOCK_FLAG_PREROLL) );
+
+    if( p_sys->b_hurry_up )
     {
-        b_drawpicture = 0;
-        if( p_sys->i_late_frames < 12 )
+        /* reset any changes from previous frame, if we stopped dropping */
+        p_context->skip_frame = p_sys->i_skip_frame;
+
+        /* A good idea could be to decode all I pictures and see for the other */
+        if( p_dec->b_frame_drop_allowed && p_sys->i_late_frames > 4 )
         {
-            p_context->skip_frame =
-                    (p_sys->i_skip_frame <= AVDISCARD_NONREF) ?
-                    AVDISCARD_NONREF : p_sys->i_skip_frame;
+            if( p_sys->i_late_frames < 12 )
+            {
+                b_drawpicture = 0;
+                if( p_context->width > 0 && p_context->height > 0 )
+                    p_context->skip_frame = __MAX( p_sys->i_skip_frame, AVDISCARD_NONREF );
+            }
+            else
+            {
+                /* picture too late, won't decode
+                 * but break picture until a new I, and for mpeg4 ...*/
+                p_sys->i_late_frames--; /* needed else it will never be decrease */
+                if( p_block )
+                    block_Release( p_block );
+                msg_Warn( p_dec, "More than 4 late frames, dropping frame" );
+                return NULL;
+            }
         }
-        else
+#if 0
+        if( !b_drawpicture )
         {
-            /* picture too late, won't decode
-             * but break picture until a new I, and for mpeg4 ...*/
-            p_sys->i_late_frames--; /* needed else it will never be decrease */
-            if( p_block )
-                block_Release( p_block );
-            msg_Warn( p_dec, "More than 4 late frames, dropping frame" );
-            return NULL;
-        }
-    }
-    else
-    {
-        if( p_sys->b_hurry_up )
-            p_context->skip_frame = p_sys->i_skip_frame;
-        if( !p_block || !(p_block->i_flags & BLOCK_FLAG_PREROLL) )
-            b_drawpicture = 1;
-        else
-            b_drawpicture = 0;
-    }
+           /* It creates broken picture
+            * FIXME either our parser or ffmpeg is broken */
 
-    if( p_context->width <= 0 || p_context->height <= 0 )
-    {
-        if( p_sys->b_hurry_up )
-            p_context->skip_frame = p_sys->i_skip_frame;
-    }
-    else if( !b_drawpicture )
-    {
-        /* It creates broken picture
-         * FIXME either our parser or ffmpeg is broken */
-#if 0
-        if( p_sys->b_hurry_up )
-            p_context->skip_frame = __MAX( p_context->skip_frame,
-                                                  AVDISCARD_NONREF );
+               p_context->skip_frame = __MAX( p_context->skip_frame,
+                                                     AVDISCARD_NONREF );
+        }
 #endif
     }
 
-- 
2.5.0



More information about the vlc-devel mailing list