diff mbox

[FFmpeg-devel,v3] libavcodec/vp8dec: fix the multi-thread HWAccel decode error

Message ID 1560235949-29164-1-git-send-email-shaofei.wang@intel.com
State New
Headers show

Commit Message

Shaofei Wang June 11, 2019, 6:52 a.m. UTC
Fix the issue: https://github.com/intel/media-driver/issues/317

the root cause is update_dimensions will be called multple times
when decoder thread number is not only 1, but update_dimensions
call get_pixel_format in each decode thread will trigger the
hwaccel_uninit/hwaccel_init more than once. But only one hwaccel
should be shared with all decode threads.
in current context,
there are 3 situations in the update_dimensions():
1. First time calling. No matter single thread or multithread,
   get_pixel_format() should be called after dimensions were
   set;
2. Dimention changed at the runtime. Dimention need to be
   updated when macroblocks_base is already allocated,
   get_pixel_format() should be called to recreate new frames
   according to updated dimension;
3. Multithread first time calling. After decoder init, the
   other threads will call update_dimensions() at first time
   to allocate macroblocks_base and set dimensions.
   But get_pixel_format() is shouldn't be called due to low
   level frames and context are already created.

In this fix, we only call update_dimensions as need.

Signed-off-by: Wang, Shaofei <shaofei.wang@intel.com>
Reviewed-by: Jun, Zhao <jun.zhao@intel.com>
Reviewed-by: Haihao Xiang <haihao.xiang@intel.com>
---
Updated typo in the commit message

 libavcodec/vp8.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Shaofei Wang July 1, 2019, 6:38 a.m. UTC | #1
Hello here,
A simple ping about this patch
Please feel free to ask if you have any question
mypopy@gmail.com July 1, 2019, 7:28 a.m. UTC | #2
On Mon, Jul 1, 2019 at 2:38 PM Wang, Shaofei <shaofei.wang@intel.com> wrote:
>
> Hello here,
> A simple ping about this patch
> Please feel free to ask if you have any question
Is it this patch https://patchwork.ffmpeg.org/patch/13723/ fix the same issue?
Shaofei Wang July 1, 2019, 8:22 a.m. UTC | #3
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of

> mypopy@gmail.com

> Sent: Monday, July 1, 2019 3:28 PM

> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>

> Cc: Xiang, Haihao <haihao.xiang@intel.com>

> Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the

> multi-thread HWAccel decode error

> 

> On Mon, Jul 1, 2019 at 2:38 PM Wang, Shaofei <shaofei.wang@intel.com>

> wrote:

> Is it this patch https://patchwork.ffmpeg.org/patch/13723/ fix the same

> issue?

It won't fix this issue in vp8.
Eoff, Ullysses A Sept. 21, 2020, 6:33 p.m. UTC | #4
*bump*

This patch fixes vp8d output corruption in multi-thread mode.  This bug has existed for way too long.

> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Wang, Shaofei
> Sent: Monday, July 01, 2019 1:22 AM
> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> Cc: Xiang, Haihao <haihao.xiang@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the multi-thread HWAccel decode error
> 
> > -----Original Message-----
> > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> > mypopy@gmail.com
> > Sent: Monday, July 1, 2019 3:28 PM
> > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> > Cc: Xiang, Haihao <haihao.xiang@intel.com>
> > Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the
> > multi-thread HWAccel decode error
> >
> > On Mon, Jul 1, 2019 at 2:38 PM Wang, Shaofei <shaofei.wang@intel.com>
> > wrote:
> > Is it this patch https://patchwork.ffmpeg.org/patch/13723/ fix the same
> > issue?
> It won't fix this issue in vp8.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Xiang, Haihao Sept. 22, 2020, 3:09 a.m. UTC | #5
> *bump*
> 
> This patch fixes vp8d output corruption in multi-thread mode.  This bug has
> existed for way too long.

This patch works fine for me too, could someone in MAINTAINERS take a look at
this patch and merge it if no problem?

Thanks
Haihao

> 
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Wang,
> > Shaofei
> > Sent: Monday, July 01, 2019 1:22 AM
> > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> > Cc: Xiang, Haihao <haihao.xiang@intel.com>
> > Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the multi-
> > thread HWAccel decode error
> > 
> > > -----Original Message-----
> > > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> > > mypopy@gmail.com
> > > Sent: Monday, July 1, 2019 3:28 PM
> > > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> > > Cc: Xiang, Haihao <haihao.xiang@intel.com>
> > > Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the
> > > multi-thread HWAccel decode error
> > > 
> > > On Mon, Jul 1, 2019 at 2:38 PM Wang, Shaofei <shaofei.wang@intel.com>
> > > wrote:
> > > Is it this patch https://patchwork.ffmpeg.org/patch/13723/ fix the same
> > > issue?
> > 
> > It won't fix this issue in vp8.
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > 
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Eoff, Ullysses A Sept. 23, 2020, 5:33 p.m. UTC | #6
I tested:

PASS: make THREADS=2 THREAD_TYPE=frame fate-vp8
PASS: make THREADS=1 THREAD_TYPE=frame fate-vp8
PASS: make THREADS=8 THREAD_TYPE=frame fate-vp8
PASS: make THREADS=6 THREAD_TYPE=frame fate-vp8

FAIL: make THREADS=2 THREAD_TYPE=tile fate-vp8
FAIL: make THREADS=1 THREAD_TYPE=tile fate-vp8
FAIL: make THREADS=8 THREAD_TYPE=tile fate-vp8
FAIL: make THREADS=6 THREAD_TYPE=tile fate-vp8

The vp8-2451 case fails, above, for tile thread type *without* this patch, too.

This patch also fixes the issues reported at:

https://github.com/intel/media-driver/issues/1028 and
https://github.com/intel/media-driver/issues/1028#issuecomment-695033952

Regards,
U. Artie

> -----Original Message-----
> From: Xiang, Haihao <haihao.xiang@intel.com>
> Sent: Monday, September 21, 2020 8:09 PM
> To: ffmpeg-devel@ffmpeg.org; Eoff, Ullysses A <ullysses.a.eoff@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the multi-thread HWAccel decode error
> 
> 
> > *bump*
> >
> > This patch fixes vp8d output corruption in multi-thread mode.  This bug has
> > existed for way too long.
> 
> This patch works fine for me too, could someone in MAINTAINERS take a look at
> this patch and merge it if no problem?
> 
> Thanks
> Haihao
> 
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Wang,
> > > Shaofei
> > > Sent: Monday, July 01, 2019 1:22 AM
> > > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> > > Cc: Xiang, Haihao <haihao.xiang@intel.com>
> > > Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the multi-
> > > thread HWAccel decode error
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of
> > > > mypopy@gmail.com
> > > > Sent: Monday, July 1, 2019 3:28 PM
> > > > To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
> > > > Cc: Xiang, Haihao <haihao.xiang@intel.com>
> > > > Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the
> > > > multi-thread HWAccel decode error
> > > >
> > > > On Mon, Jul 1, 2019 at 2:38 PM Wang, Shaofei <shaofei.wang@intel.com>
> > > > wrote:
> > > > Is it this patch https://patchwork.ffmpeg.org/patch/13723/ fix the same
> > > > issue?
> > >
> > > It won't fix this issue in vp8.
> > > _______________________________________________
> > > ffmpeg-devel mailing list
> > > ffmpeg-devel@ffmpeg.org
> > > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> > >
> > > To unsubscribe, visit link above, or email
> > > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Eoff, Ullysses A Sept. 23, 2020, 5:48 p.m. UTC | #7
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Eoff, Ullysses A
> Sent: Wednesday, September 23, 2020 10:33 AM
> To: Xiang, Haihao <haihao.xiang@intel.com>; ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the multi-thread HWAccel decode error
> 
> I tested:
> 
> PASS: make THREADS=2 THREAD_TYPE=frame fate-vp8
> PASS: make THREADS=1 THREAD_TYPE=frame fate-vp8
> PASS: make THREADS=8 THREAD_TYPE=frame fate-vp8
> PASS: make THREADS=6 THREAD_TYPE=frame fate-vp8
> 
> FAIL: make THREADS=2 THREAD_TYPE=tile fate-vp8
> FAIL: make THREADS=1 THREAD_TYPE=tile fate-vp8
> FAIL: make THREADS=8 THREAD_TYPE=tile fate-vp8
> FAIL: make THREADS=6 THREAD_TYPE=tile fate-vp8
> 
> The vp8-2451 case fails, above, for tile thread type *without* this patch, too.
> 
> This patch also fixes the issues reported at:
> 
> https://github.com/intel/media-driver/issues/1028 and
> https://github.com/intel/media-driver/issues/1028#issuecomment-695033952
> 
> Regards,
> U. Artie
> 

Oops, it is "slice" not "tile" (thanks BBB for your help), so:

PASS: make THREADS=2 THREAD_TYPE=slice fate-vp8
PASS: make THREADS=1 THREAD_TYPE=slice fate-vp8
PASS: make THREADS=8 THREAD_TYPE=slice fate-vp8
PASS: make THREADS=6 THREAD_TYPE=slice fate-vp8

Cheers,
U. Artie
Ronald S. Bultje Sept. 23, 2020, 6:13 p.m. UTC | #8
Hi,

On Wed, Sep 23, 2020 at 1:48 PM Eoff, Ullysses A <ullysses.a.eoff@intel.com>
wrote:

> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Eoff,
> Ullysses A
> > Sent: Wednesday, September 23, 2020 10:33 AM
> > To: Xiang, Haihao <haihao.xiang@intel.com>; ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH v3] libavcodec/vp8dec: fix the
> multi-thread HWAccel decode error
> >
> > I tested:
> >
> > PASS: make THREADS=2 THREAD_TYPE=frame fate-vp8
> > PASS: make THREADS=1 THREAD_TYPE=frame fate-vp8
> > PASS: make THREADS=8 THREAD_TYPE=frame fate-vp8
> > PASS: make THREADS=6 THREAD_TYPE=frame fate-vp8
> >
> > FAIL: make THREADS=2 THREAD_TYPE=tile fate-vp8
> > FAIL: make THREADS=1 THREAD_TYPE=tile fate-vp8
> > FAIL: make THREADS=8 THREAD_TYPE=tile fate-vp8
> > FAIL: make THREADS=6 THREAD_TYPE=tile fate-vp8
> >
> > The vp8-2451 case fails, above, for tile thread type *without* this
> patch, too.
> >
> > This patch also fixes the issues reported at:
> >
> > https://github.com/intel/media-driver/issues/1028 and
> > https://github.com/intel/media-driver/issues/1028#issuecomment-695033952
> >
> > Regards,
> > U. Artie
> >
>
> Oops, it is "slice" not "tile" (thanks BBB for your help), so:
>
> PASS: make THREADS=2 THREAD_TYPE=slice fate-vp8
> PASS: make THREADS=1 THREAD_TYPE=slice fate-vp8
> PASS: make THREADS=8 THREAD_TYPE=slice fate-vp8
> PASS: make THREADS=6 THREAD_TYPE=slice fate-vp8


Merged.

Ronald
diff mbox

Patch

diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index ba79e5f..0a7f38b 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -187,7 +187,7 @@  static av_always_inline
 int update_dimensions(VP8Context *s, int width, int height, int is_vp7)
 {
     AVCodecContext *avctx = s->avctx;
-    int i, ret;
+    int i, ret, dim_reset = 0;
 
     if (width  != s->avctx->width || ((width+15)/16 != s->mb_width || (height+15)/16 != s->mb_height) && s->macroblocks_base ||
         height != s->avctx->height) {
@@ -196,9 +196,12 @@  int update_dimensions(VP8Context *s, int width, int height, int is_vp7)
         ret = ff_set_dimensions(s->avctx, width, height);
         if (ret < 0)
             return ret;
+
+        dim_reset = (s->macroblocks_base != NULL);
     }
 
-    if (!s->actually_webp && !is_vp7) {
+    if ((s->pix_fmt == AV_PIX_FMT_NONE || dim_reset) &&
+         !s->actually_webp && !is_vp7) {
         s->pix_fmt = get_pixel_format(s);
         if (s->pix_fmt < 0)
             return AVERROR(EINVAL);