[vlc-devel] [PATCH] DxVA2: use the same surface count as libav/FFMpeg

Steve Lhomme robUx4 at videolabs.io
Fri Apr 3 08:34:26 CEST 2015


---
 modules/codec/avcodec/dxva2.c | 51 ++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 66da9cd..3f3707e 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -329,7 +329,7 @@ static void DxDestroyVideoService(vlc_va_sys_t *);
 static int DxFindVideoServiceConversion(vlc_va_t *, GUID *input, D3DFORMAT *output);
 
 static int DxCreateVideoDecoder(vlc_va_t *,
-                                int codec_id, const video_format_t *);
+                                int codec_id, const video_format_t *, int);
 static void DxDestroyVideoDecoder(vlc_va_sys_t *);
 static int DxResetVideoDecoder(vlc_va_t *);
 
@@ -360,7 +360,7 @@ static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chroma)
     fmt.i_width = avctx->coded_width;
     fmt.i_height = avctx->coded_height;
 
-    if (DxCreateVideoDecoder(va, sys->codec_id, &fmt))
+    if (DxCreateVideoDecoder(va, sys->codec_id, &fmt, avctx->active_thread_type & FF_THREAD_FRAME))
         return VLC_EGENERIC;
     /* */
     sys->hw.decoder = sys->decoder;
@@ -874,10 +874,12 @@ static int DxFindVideoServiceConversion(vlc_va_t *va, GUID *input, D3DFORMAT *ou
 /**
  * It creates a DXVA2 decoder using the given video format
  */
-static int DxCreateVideoDecoder(vlc_va_t *va,
-                                int codec_id, const video_format_t *fmt)
+static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
+                                const video_format_t *fmt, int i_threading)
 {
     vlc_va_sys_t *sys = va->sys;
+    int surface_alignment;
+    int surface_count;
 
     /* */
     msg_Dbg(va, "DxCreateVideoDecoder id %d %dx%d",
@@ -886,23 +888,32 @@ static int DxCreateVideoDecoder(vlc_va_t *va,
     sys->width  = fmt->i_width;
     sys->height = fmt->i_height;
 
+    /* decoding MPEG-2 requires additional alignment on some Intel GPUs,
+       but it causes issues for H.264 on certain AMD GPUs..... */
+    if ( codec_id == AV_CODEC_ID_MPEG2VIDEO )
+        surface_alignment = 32;
+    /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
+       all coding features have enough room to work with */
+    else if ( codec_id == AV_CODEC_ID_HEVC )
+        surface_alignment = 128;
+    else
+        surface_alignment = 16;
+
     /* Allocates all surfaces needed for the decoder */
-    sys->surface_width  = (fmt->i_width  + 15) & ~15;
-    sys->surface_height = (fmt->i_height + 15) & ~15;
-    int surface_count;
-    switch (codec_id) {
-    case AV_CODEC_ID_HEVC:
-    case AV_CODEC_ID_H264:
-        surface_count = 16 + sys->thread_count + 2;
-        break;
-    case AV_CODEC_ID_MPEG1VIDEO:
-    case AV_CODEC_ID_MPEG2VIDEO:
-        surface_count = 2 + 2;
-        break;
-    default:
-        surface_count = 2 + 1;
-        break;
-    }
+    --surface_alignment;
+    sys->surface_width  = (fmt->i_width  + surface_alignment) & ~surface_alignment;
+    sys->surface_height = (fmt->i_height + surface_alignment) & ~surface_alignment;
+
+    surface_count = 4;
+    /* add surfaces based on number of possible refs */
+    if ( codec_id == AV_CODEC_ID_H264 || codec_id == AV_CODEC_ID_HEVC )
+        surface_count += 16;
+    else
+        surface_count += 2;
+
+    if ( i_threading )
+        surface_count += sys->thread_count;
+
     if (surface_count > VA_DXVA2_MAX_SURFACE_COUNT)
         return VLC_EGENERIC;
     sys->surface_count = surface_count;
-- 
2.3.2




More information about the vlc-devel mailing list