[vlc-devel] [PATCH 3/4] avcodec: reverse the if() logic between p_sys->p_va and p_pic NULL testing

Steve Lhomme robux4 at videolabs.io
Tue Nov 29 14:19:37 CET 2016


That will allow a different meaning for frame->opaque when va is used.
---
 modules/codec/avcodec/video.c | 44 ++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 0c70800..e9110cc 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -951,28 +951,38 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         }
 
         picture_t *p_pic = frame->opaque;
-        if( p_pic == NULL )
-        {   /* When direct rendering is not used, get_format() and get_buffer()
-             * might not be called. The output video format must be set here
-             * then picture buffer can be allocated. */
-            if (p_sys->p_va == NULL
-             && lavc_UpdateVideoFormat(p_dec, p_context, p_context->pix_fmt,
-                                       p_context->pix_fmt) == 0)
-                p_pic = decoder_NewPicture(p_dec);
-
-            if( !p_pic )
+        if (p_sys->p_va == NULL)
+        {
+            if (p_pic != NULL)
+                picture_Hold( p_pic );
+            else
             {
-                av_frame_free(&frame);
-                break;
-            }
+                /* When direct rendering is not used, get_format() and get_buffer()
+                 * might not be called. The output video format must be set here
+                 * then picture buffer can be allocated. */
+                if (lavc_UpdateVideoFormat(p_dec, p_context, p_context->pix_fmt,
+                                           p_context->pix_fmt) == 0)
+                    p_pic = decoder_NewPicture(p_dec);
+
+                if( !p_pic )
+                {
+                    av_frame_free(&frame);
+                    break;
+                }
 
-            /* Fill picture_t from AVFrame */
-            lavc_CopyPicture(p_dec, p_pic, frame);
+                /* Fill picture_t from AVFrame */
+                lavc_CopyPicture(p_dec, p_pic, frame);
+            }
         }
         else
         {
-            if( p_sys->p_va != NULL )
-                vlc_va_Extract( p_sys->p_va, p_pic, frame->data[3] );
+            if( unlikely(p_pic==NULL) )
+            {
+                av_frame_free(&frame);
+                break;
+            }
+
+            vlc_va_Extract( p_sys->p_va, p_pic, frame->data[3] );
             picture_Hold( p_pic );
         }
 
-- 
2.10.1



More information about the vlc-devel mailing list