[vlc-devel] [PATCH 1/8] avcodec: video: move the hardware acceleration setup in a separate function

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


---
 modules/codec/avcodec/video.c | 70 ++++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 632b317b2f..e487c22d1d 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -404,6 +404,44 @@ static int OpenVideoCodec( decoder_t *p_dec )
     return 0;
 }
 
+static int SetupHardwareFormat(decoder_t *p_dec, AVCodecContext *p_context,
+                               enum AVPixelFormat hwfmt, enum AVPixelFormat swfmt)
+{
+    p_dec->fmt_out.video.i_chroma = vlc_va_GetChroma(hwfmt, swfmt);
+    if (p_dec->fmt_out.video.i_chroma == 0)
+        return VLC_EGENERIC; /* Unknown brand of hardware acceleration */
+    if (p_context->width == 0 || p_context->height == 0)
+    {   /* should never happen */
+        msg_Err(p_dec, "unspecified video dimensions");
+        return VLC_EGENERIC;
+    }
+    if (lavc_UpdateVideoFormat(p_dec, p_context, hwfmt, swfmt))
+        return VLC_EGENERIC;
+
+    post_mt(p_dec->p_sys);
+
+    picture_t *test_pic = decoder_NewPicture(p_dec);
+    assert(!test_pic || test_pic->format.i_chroma == p_dec->fmt_out.video.i_chroma);
+    vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt,
+                              &p_dec->fmt_in,
+                              test_pic ? test_pic->p_sys : NULL);
+    if ( test_pic )
+        picture_Release( test_pic );
+    if (va == NULL)
+    {
+        wait_mt(p_dec->p_sys);
+        return VLC_EGENERIC; /* Unsupported codec profile or such */
+    }
+
+    if (va->description != NULL)
+        msg_Info(p_dec, "Using %s for hardware decoding", va->description);
+
+    p_dec->p_sys->p_va = va;
+    p_dec->p_sys->pix_fmt = hwfmt;
+    p_context->draw_horiz_band = NULL;
+    return VLC_SUCCESS;
+}
+
 /*****************************************************************************
  * InitVideo: initialize the video decoder
  *****************************************************************************
@@ -1476,39 +1514,9 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
 
     for( size_t i = 0; pi_fmt[i] != AV_PIX_FMT_NONE; i++ )
     {
-        enum PixelFormat hwfmt = pi_fmt[i];
-
-        p_dec->fmt_out.video.i_chroma = vlc_va_GetChroma(hwfmt, swfmt);
-        if (p_dec->fmt_out.video.i_chroma == 0)
-            continue; /* Unknown brand of hardware acceleration */
-        if (p_context->width == 0 || p_context->height == 0)
-        {   /* should never happen */
-            msg_Err(p_dec, "unspecified video dimensions");
+        if (SetupHardwareFormat(p_dec, p_context, pi_fmt[i], swfmt))
             continue;
-        }
-        if (lavc_UpdateVideoFormat(p_dec, p_context, hwfmt, swfmt))
-            continue; /* Unsupported brand of hardware acceleration */
-        post_mt(p_sys);
-
-        picture_t *test_pic = decoder_NewPicture(p_dec);
-        assert(!test_pic || test_pic->format.i_chroma == p_dec->fmt_out.video.i_chroma);
-        vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt,
-                                  &p_dec->fmt_in,
-                                  test_pic ? test_pic->p_sys : NULL);
-        if (test_pic)
-            picture_Release(test_pic);
-        if (va == NULL)
-        {
-            wait_mt(p_sys);
-            continue; /* Unsupported codec profile or such */
-        }
-
-        if (va->description != NULL)
-            msg_Info(p_dec, "Using %s for hardware decoding", va->description);
 
-        p_sys->p_va = va;
-        p_sys->pix_fmt = hwfmt;
-        p_context->draw_horiz_band = NULL;
         return pi_fmt[i];
     }
 
-- 
2.12.1



More information about the vlc-devel mailing list