diff mbox series

[FFmpeg-devel,1/2] avcodec/d3d12va_decode: check existance before assigning a new index

Message ID 20240111063121.1467-1-tong1.wu@intel.com
State Accepted
Commit 8b41e9cfbe64c95c04d131632f099910296db48b
Headers show
Series [FFmpeg-devel,1/2] avcodec/d3d12va_decode: check existance before assigning a new index | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wu, Tong1 Jan. 11, 2024, 6:31 a.m. UTC
From: Tong Wu <tong1.wu@intel.com>

Fixes #10759.

It can happen in H.264, MPEG2, VC1 that the current frame resource
memory is already in ref_resource. For example, for a interlaced frame,
the same curr memory is passed twice. For the second time it could possibly
reference itself. When this happens the curr is already given an index and
in ref_resources. When the reference frame index is required, we should check
the existance in the ref_resources first before assigning a new index for it.

Signed-off-by: Tong Wu <tong1.wu@intel.com>
---
 libavcodec/d3d12va_decode.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Xiang, Haihao Jan. 17, 2024, 6:23 a.m. UTC | #1
On Do, 2024-01-11 at 14:31 +0800, tong1.wu-at-intel.com@ffmpeg.org wrote:
> From: Tong Wu <tong1.wu@intel.com>
> 
> Fixes #10759.
> 
> It can happen in H.264, MPEG2, VC1 that the current frame resource
> memory is already in ref_resource. For example, for a interlaced frame,
> the same curr memory is passed twice. For the second time it could possibly
> reference itself. When this happens the curr is already given an index and
> in ref_resources. When the reference frame index is required, we should check
> the existance in the ref_resources first before assigning a new index for it.
> 
> Signed-off-by: Tong Wu <tong1.wu@intel.com>
> ---
>  libavcodec/d3d12va_decode.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
> index c5c599675e..a6f40236d1 100644
> --- a/libavcodec/d3d12va_decode.c
> +++ b/libavcodec/d3d12va_decode.c
> @@ -62,14 +62,14 @@ unsigned ff_d3d12va_get_surface_index(const AVCodecContext
> *avctx,
>      if (!res)
>          goto fail;
>  
> -    if (!curr) {
> -        for (i = 0; i < ctx->max_num_ref; i++) {
> -            if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
> -                ctx->used_mask |= 1 << i;
> -                return i;
> -            }
> +    for (i = 0; i < ctx->max_num_ref; i++) {
> +        if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
> +            ctx->used_mask |= 1 << i;
> +            return i;
>          }
> -    } else {
> +    }
> +
> +    if (curr) {
>          for (i = 0; i < ctx->max_num_ref; i++) {
>              if (!((ctx->used_mask >> i) & 0x1)) {
>                  ctx->ref_resources[i] = res;

Patchset LGTM, 

BRs
Haihao
Xiang, Haihao Jan. 24, 2024, 7:14 a.m. UTC | #2
On Wo, 2024-01-17 at 06:23 +0000, Xiang, Haihao wrote:
> On Do, 2024-01-11 at 14:31 +0800, tong1.wu-at-intel.com@ffmpeg.org wrote:
> > From: Tong Wu <tong1.wu@intel.com>
> > 
> > Fixes #10759.
> > 
> > It can happen in H.264, MPEG2, VC1 that the current frame resource
> > memory is already in ref_resource. For example, for a interlaced frame,
> > the same curr memory is passed twice. For the second time it could possibly
> > reference itself. When this happens the curr is already given an index and
> > in ref_resources. When the reference frame index is required, we should
> > check
> > the existance in the ref_resources first before assigning a new index for
> > it.
> > 
> > Signed-off-by: Tong Wu <tong1.wu@intel.com>
> > ---
> >  libavcodec/d3d12va_decode.c | 14 +++++++-------
> >  1 file changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
> > index c5c599675e..a6f40236d1 100644
> > --- a/libavcodec/d3d12va_decode.c
> > +++ b/libavcodec/d3d12va_decode.c
> > @@ -62,14 +62,14 @@ unsigned ff_d3d12va_get_surface_index(const
> > AVCodecContext
> > *avctx,
> >      if (!res)
> >          goto fail;
> >  
> > -    if (!curr) {
> > -        for (i = 0; i < ctx->max_num_ref; i++) {
> > -            if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
> > -                ctx->used_mask |= 1 << i;
> > -                return i;
> > -            }
> > +    for (i = 0; i < ctx->max_num_ref; i++) {
> > +        if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
> > +            ctx->used_mask |= 1 << i;
> > +            return i;
> >          }
> > -    } else {
> > +    }
> > +
> > +    if (curr) {
> >          for (i = 0; i < ctx->max_num_ref; i++) {
> >              if (!((ctx->used_mask >> i) & 0x1)) {
> >                  ctx->ref_resources[i] = res;
> 
> Patchset LGTM, 
> 
Will apply,

- Haihao
diff mbox series

Patch

diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c
index c5c599675e..a6f40236d1 100644
--- a/libavcodec/d3d12va_decode.c
+++ b/libavcodec/d3d12va_decode.c
@@ -62,14 +62,14 @@  unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx,
     if (!res)
         goto fail;
 
-    if (!curr) {
-        for (i = 0; i < ctx->max_num_ref; i++) {
-            if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
-                ctx->used_mask |= 1 << i;
-                return i;
-            }
+    for (i = 0; i < ctx->max_num_ref; i++) {
+        if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
+            ctx->used_mask |= 1 << i;
+            return i;
         }
-    } else {
+    }
+
+    if (curr) {
         for (i = 0; i < ctx->max_num_ref; i++) {
             if (!((ctx->used_mask >> i) & 0x1)) {
                 ctx->ref_resources[i] = res;