[vlc-devel] [PATCH 3/8] avcodec: video: move call to lavc_GetVideoFormat() outside of lavc_UpdateVideoFormat()

Steve Lhomme robux4 at videolabs.io
Fri May 5 18:42:19 CEST 2017


---
 modules/codec/avcodec/video.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index e5640d4cd7..886eadebf3 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -288,23 +288,14 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_format_t *restrict fmt,
     return 0;
 }
 
-static int lavc_UpdateVideoFormat(decoder_t *dec, AVCodecContext *ctx,
-                                  enum AVPixelFormat fmt,
-                                  enum AVPixelFormat swfmt)
+static int lavc_UpdateVideoFormat(decoder_t *dec, video_format_t *fmt_out)
 {
-    video_format_t fmt_out;
-    int val;
-
-    val = lavc_GetVideoFormat(dec, &fmt_out, ctx, fmt, swfmt);
-    if (val)
-        return val;
-
-    fmt_out.p_palette = dec->fmt_out.video.p_palette;
+    fmt_out->p_palette = dec->fmt_out.video.p_palette;
     dec->fmt_out.video.p_palette = NULL;
 
     es_format_Clean(&dec->fmt_out);
-    es_format_Init(&dec->fmt_out, VIDEO_ES, fmt_out.i_chroma);
-    dec->fmt_out.video = fmt_out;
+    es_format_Init(&dec->fmt_out, VIDEO_ES, fmt_out->i_chroma);
+    dec->fmt_out.video = *fmt_out;
     dec->fmt_out.video.orientation = dec->fmt_in.video.orientation;
     dec->fmt_out.video.projection_mode = dec->fmt_in.video.projection_mode;
     dec->fmt_out.video.pose = dec->fmt_in.video.pose;
@@ -415,7 +406,10 @@ static int SetupHardwareFormat(decoder_t *p_dec, AVCodecContext *p_context,
         msg_Err(p_dec, "unspecified video dimensions");
         return VLC_EGENERIC;
     }
-    if (lavc_UpdateVideoFormat(p_dec, p_context, hwfmt, swfmt))
+
+    video_format_t fmt_out;
+    if ( lavc_GetVideoFormat(p_dec, &fmt_out, p_context, hwfmt, swfmt) ||
+         lavc_UpdateVideoFormat(p_dec, &fmt_out) )
         return VLC_EGENERIC;
 
     post_mt(p_dec->p_sys);
@@ -1032,10 +1026,14 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block, bool *error
         {   /* 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_sys->p_va == NULL)
+            {
+                video_format_t fmt_out;
+                if ( !lavc_GetVideoFormat(p_dec, &fmt_out, p_context,
+                                          p_context->pix_fmt, p_context->pix_fmt) &&
+                     lavc_UpdateVideoFormat(p_dec, &fmt_out) == 0 )
+                    p_pic = decoder_NewPicture(p_dec);
+            }
 
             if( !p_pic )
             {
@@ -1416,7 +1414,9 @@ static int lavc_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, int flags)
         /* Most unaccelerated decoders do not call get_format(), so we need to
          * update the output video format here. The MT semaphore must be held
          * to protect p_dec->fmt_out. */
-        if (lavc_UpdateVideoFormat(dec, ctx, ctx->pix_fmt, ctx->pix_fmt))
+        video_format_t fmt_out;
+        if ( lavc_GetVideoFormat(dec, &fmt_out, ctx, ctx->pix_fmt, ctx->pix_fmt) ||
+             lavc_UpdateVideoFormat(dec, &fmt_out) )
         {
             post_mt(sys);
             return -1;
-- 
2.12.1



More information about the vlc-devel mailing list