d3d11va: use the proper slice index

Message ID 1475654108-12028-1-git-send-email-robux4@videolabs.io
State New
Headers show

Commit Message

Steve Lhomme Oct. 5, 2016, 7:55 a.m.
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
* get rid of DXVA_CONTEXT_SURFACE
---
 libavcodec/dxva2.c          | 12 +++++++++++-
 libavcodec/dxva2_internal.h |  3 ---
 libavcodec/version.h        |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

Comments

Diego Biurrun Oct. 5, 2016, 8:20 a.m. | #1
On Wed, Oct 05, 2016 at 09:55:08AM +0200, Steve Lhomme wrote:
> 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

You bumped minor, not micro, what was your intention?

> --- a/libavcodec/dxva2.c
> +++ b/libavcodec/dxva2.c
> @@ -42,8 +42,18 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
>      unsigned i;
>  
>      for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++)
> -        if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface)
> +#if CONFIG_D3D11VA
> +        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD && ctx->d3d11va.surface[i] == surface)
> +        {

if (..) {

> --- 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

If you bump minor, you should reset micro.

Diego
Steve Lhomme Oct. 5, 2016, 10:34 a.m. | #2
On Wed, Oct 5, 2016 at 10:20 AM, Diego Biurrun <diego@biurrun.de> wrote:
> On Wed, Oct 05, 2016 at 09:55:08AM +0200, Steve Lhomme wrote:
>> 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
>
> You bumped minor, not micro, what was your intention?

Be able to detect grammatically the old/new behavior.

>> --- a/libavcodec/dxva2.c
>> +++ b/libavcodec/dxva2.c
>> @@ -42,8 +42,18 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
>>      unsigned i;
>>
>>      for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++)
>> -        if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface)
>> +#if CONFIG_D3D11VA
>> +        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD && ctx->d3d11va.surface[i] == surface)
>> +        {
>
> if (..) {
>
>> --- 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
>
> If you bump minor, you should reset micro.

OK, I thought micro was either 0 or 100, if you see what I mean :)

I'll do a patch with MINOR incremented.

> Diego
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel

Patch

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 9157094..2fc5f47 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -42,8 +42,18 @@  unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
     unsigned i;
 
     for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++)
-        if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface)
+#if CONFIG_D3D11VA
+        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD && ctx->d3d11va.surface[i] == surface)
+        {
+            D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
+            ID3D11VideoDecoderOutputView_GetDesc(ctx->d3d11va.surface[i], &viewDesc);
+            return viewDesc.Texture2D.ArraySlice;
+        }
+#endif
+#if CONFIG_DXVA2
+        if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD && ctx->dxva2.surface[i] == surface)
             return i;
+#endif
 
     assert(0);
     return 0;
diff --git a/libavcodec/dxva2_internal.h b/libavcodec/dxva2_internal.h
index 30aec8b..f0fe3d6 100644
--- a/libavcodec/dxva2_internal.h
+++ b/libavcodec/dxva2_internal.h
@@ -69,7 +69,6 @@  typedef union {
 #if CONFIG_D3D11VA && CONFIG_DXVA2
 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.workaround : ctx->dxva2.workaround)
 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.surface_count : ctx->dxva2.surface_count)
-#define DXVA_CONTEXT_SURFACE(avctx, ctx, i)     (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.surface[i] : ctx->dxva2.surface[i])
 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.decoder : ctx->dxva2.decoder)
 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? &ctx->d3d11va.report_id : &ctx->dxva2.report_id))
 #define DXVA_CONTEXT_CFG(avctx, ctx)            (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ? ctx->d3d11va.cfg : ctx->dxva2.cfg)
@@ -79,7 +78,6 @@  typedef union {
 #elif CONFIG_DXVA2
 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ctx->dxva2.workaround)
 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ctx->dxva2.surface_count)
-#define DXVA_CONTEXT_SURFACE(avctx, ctx, i)     (ctx->dxva2.surface[i])
 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ctx->dxva2.decoder)
 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(&ctx->dxva2.report_id))
 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ctx->dxva2.cfg)
@@ -89,7 +87,6 @@  typedef union {
 #elif CONFIG_D3D11VA
 #define DXVA_CONTEXT_WORKAROUND(avctx, ctx)     (ctx->d3d11va.workaround)
 #define DXVA_CONTEXT_COUNT(avctx, ctx)          (ctx->d3d11va.surface_count)
-#define DXVA_CONTEXT_SURFACE(avctx, ctx, i)     (ctx->d3d11va.surface[i])
 #define DXVA_CONTEXT_DECODER(avctx, ctx)        (ctx->d3d11va.decoder)
 #define DXVA_CONTEXT_REPORT_ID(avctx, ctx)      (*(&ctx->d3d11va.report_id))
 #define DXVA_CONTEXT_CFG(avctx, ctx)            (ctx->d3d11va.cfg)
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, \