[vlc-devel] [PATCH 6/6] contrib: ffmpeg/libav: fix the D3D11 slice index used by the decoder

Steve Lhomme robux4 at videolabs.io
Tue Oct 4 17:40:28 CEST 2016


This allows arbitrary slice index in the output buffer we provide the decoder.
---
 .../0001-d3d11va-use-the-proper-slice-index.patch  | 56 ++++++++++++++++++++++
 ...d3d11va-use-the-proper-slice-index.patch.ffmpeg | 56 ++++++++++++++++++++++
 contrib/src/ffmpeg/rules.mak                       |  2 +
 modules/codec/avcodec/d3d11va.c                    |  2 +
 4 files changed, 116 insertions(+)
 create mode 100644 contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch
 create mode 100644 contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch.ffmpeg

diff --git a/contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch b/contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch
new file mode 100644
index 0000000..67984bb
--- /dev/null
+++ b/contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch
@@ -0,0 +1,56 @@
+From 7da121ca19ceda87642c833fce278bd8e2cf4a7b Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at videolabs.io>
+Date: Tue, 4 Oct 2016 16:41:22 +0200
+Subject: [PATCH] d3d11va: use the proper slice index
+
+The slice index expected by D3D11VA is the one from the texture not from the
+array or texture/slices.
+
+In VLC the slices we provide the decoder don't start from 0 and thus pictures
+appear in bogus order. With possible crashes and corruptions when using an
+invalid index.
+
+--
+forgot to bump the micro version
+---
+ libavcodec/dxva2.c   | 9 +++++++++
+ libavcodec/version.h | 2 +-
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
+index 9157094..c8982dc 100644
+--- a/libavcodec/dxva2.c
++++ b/libavcodec/dxva2.c
+@@ -43,7 +43,16 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
+ 
+     for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++)
+         if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface)
++#if CONFIG_D3D11VA
++        {
++            ID3D11VideoDecoderOutputView *pOut = DXVA_CONTEXT_SURFACE(avctx, ctx, i);
++            D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
++            ID3D11VideoDecoderOutputView_GetDesc( pOut, &viewDesc );
++            return viewDesc.Texture2D.ArraySlice;
++        }
++#elif CONFIG_DXVA2
+             return i;
++#endif
+ 
+     assert(0);
+     return 0;
+diff --git a/libavcodec/version.h b/libavcodec/version.h
+index 71ec9ce..6f439c0 100644
+--- a/libavcodec/version.h
++++ b/libavcodec/version.h
+@@ -28,7 +28,7 @@
+ #include "libavutil/version.h"
+ 
+ #define LIBAVCODEC_VERSION_MAJOR 57
+-#define LIBAVCODEC_VERSION_MINOR 27
++#define LIBAVCODEC_VERSION_MINOR 28
+ #define LIBAVCODEC_VERSION_MICRO  1
+ 
+ #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
+-- 
+2.7.2.windows.1
+
diff --git a/contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch.ffmpeg b/contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch.ffmpeg
new file mode 100644
index 0000000..9fdb89e
--- /dev/null
+++ b/contrib/src/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch.ffmpeg
@@ -0,0 +1,56 @@
+From 7bba9791fc50e7c175841a3f9e8cc77c9378559b Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at videolabs.io>
+Date: Tue, 4 Oct 2016 16:40:54 +0200
+Subject: [PATCH] d3d11va: use the proper slice index
+
+The slice index expected by D3D11VA is the one from the texture not from the
+array or texture/slices.
+
+In VLC the slices we provide the decoder don't start from 0 and thus pictures
+appear in bogus order. With possible crashes and corruptions when using an
+invalid index.
+
+--
+forgot to bump the micro version
+---
+ libavcodec/dxva2.c   | 9 +++++++++
+ libavcodec/version.h | 2 +-
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
+index f68df86..f8801c9 100644
+--- a/libavcodec/dxva2.c
++++ b/libavcodec/dxva2.c
+@@ -43,7 +43,16 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
+ 
+     for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++)
+         if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface)
++#if CONFIG_D3D11VA
++        {
++            ID3D11VideoDecoderOutputView *pOut = DXVA_CONTEXT_SURFACE(avctx, ctx, i);
++            D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
++            ID3D11VideoDecoderOutputView_GetDesc( pOut, &viewDesc );
++            return viewDesc.Texture2D.ArraySlice;
++        }
++#elif CONFIG_DXVA2
+             return i;
++#endif
+ 
+     assert(0);
+     return 0;
+diff --git a/libavcodec/version.h b/libavcodec/version.h
+index de7280f..7e30a16 100644
+--- a/libavcodec/version.h
++++ b/libavcodec/version.h
+@@ -28,7 +28,7 @@
+ #include "libavutil/version.h"
+ 
+ #define LIBAVCODEC_VERSION_MAJOR  57
+-#define LIBAVCODEC_VERSION_MINOR  60
++#define LIBAVCODEC_VERSION_MINOR  61
+ #define LIBAVCODEC_VERSION_MICRO 101
+ 
+ #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
+-- 
+2.7.2.windows.1
+
diff --git a/contrib/src/ffmpeg/rules.mak b/contrib/src/ffmpeg/rules.mak
index e4178c6..e82b652 100644
--- a/contrib/src/ffmpeg/rules.mak
+++ b/contrib/src/ffmpeg/rules.mak
@@ -8,6 +8,7 @@ ifdef USE_FFMPEG
 FFMPEG_HASH=HEAD
 FFMPEG_SNAPURL := http://git.videolan.org/?p=ffmpeg.git;a=snapshot;h=$(FFMPEG_HASH);sf=tgz
 FFMPEG_GITURL := git://git.videolan.org/ffmpeg.git
+PATCH_SUFFIX =.ffmpeg
 else
 FFMPEG_HASH=HEAD
 FFMPEG_SNAPURL := http://git.libav.org/?p=libav.git;a=snapshot;h=$(FFMPEG_HASH);sf=tgz
@@ -216,6 +217,7 @@ ffmpeg: ffmpeg-$(FFMPEG_HASH).tar.xz .sum-ffmpeg
 	rm -Rf $@ $@-$(FFMPEG_HASH)
 	mkdir -p $@-$(FFMPEG_HASH)
 	$(XZCAT) "$<" | (cd $@-$(FFMPEG_HASH) && tar xv --strip-components=1)
+	$(APPLY) $(SRC)/ffmpeg/0001-d3d11va-use-the-proper-slice-index.patch$(PATCH_SUFFIX)
 	$(MOVE)
 
 .ffmpeg: ffmpeg
diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 89e9b4a..b34508f 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -991,6 +991,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
             assert(texDesc.Format == sys->render);
             assert(texDesc.BindFlags & D3D11_BIND_DECODER);
 
+#if !LIBAVCODEC_VERSION_CHECK( 57, 28 ,0, 61 ,100 )
             if (pic->p_sys->slice_index != surface_idx)
             {
                 msg_Warn(va, "d3d11va requires decoding slices to be the first in the texture (%d/%d)",
@@ -998,6 +999,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id, const video_forma
                 sys->b_extern_pool = false;
                 break;
             }
+#endif
 
             viewDesc.Texture2D.ArraySlice = pic->p_sys->slice_index;
             hr = ID3D11VideoDevice_CreateVideoDecoderOutputView( (ID3D11VideoDevice*) dx_sys->d3ddec,
-- 
2.8.2



More information about the vlc-devel mailing list