diff mbox series

[FFmpeg-devel] avfilter/qsvvpp: Work around a bug in MSDK where VPP processing hangs under certain conditions

Message ID BYAPR04MB52220D9214B2CAB99826CB28BAB20@BYAPR04MB5222.namprd04.prod.outlook.com
State Superseded
Headers show
Series [FFmpeg-devel] avfilter/qsvvpp: Work around a bug in MSDK where VPP processing hangs under certain conditions | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Soft Works May 24, 2020, 12:13 p.m. UTC
These conditions are:
- Dimensions are aligned to 16/32 byte (e.g. 1920x800)
- No scaling is done
- Color format conversion (e.g. 10bit to 8bit)

Example command:
ffmpeg -c:v hevc_qsv -hwaccel qsv -i hevc_10bit_1920_800.mkv -filter_complex "scale_qsv=format=nv12" -c:v h264_qsv out.mkv

Fix:
- Increase the frame height to the next alignment value
---
 libavfilter/qsvvpp.c       | 7 ++++++-
 libavfilter/vf_scale_qsv.c | 9 ++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Comments

mypopy@gmail.com May 24, 2020, 12:29 p.m. UTC | #1
On Sun, May 24, 2020 at 8:13 PM Soft Works <softworkz@hotmail.com> wrote:
>
> These conditions are:
> - Dimensions are aligned to 16/32 byte (e.g. 1920x800)
> - No scaling is done
> - Color format conversion (e.g. 10bit to 8bit)
>
> Example command:
> ffmpeg -c:v hevc_qsv -hwaccel qsv -i hevc_10bit_1920_800.mkv -filter_complex "scale_qsv=format=nv12" -c:v h264_qsv out.mkv
>
> Fix:
> - Increase the frame height to the next alignment value
> ---
>  libavfilter/qsvvpp.c       | 7 ++++++-
>  libavfilter/vf_scale_qsv.c | 9 ++++++++-
>  2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 1bbb7a7e68..98d2353d1c 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -420,6 +420,7 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
>      mfxHandleType handle_type;
>      mfxVersion ver;
>      mfxIMPL impl;
> +    int height_align_adjust = 0;
>      int ret, i;
>
>      if (inlink->hw_frames_ctx) {
> @@ -463,9 +464,13 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
>          out_frames_ctx   = (AVHWFramesContext *)out_frames_ref->data;
>          out_frames_hwctx = out_frames_ctx->hwctx;
>
> +        /* work around a bug in MSDK where VPP processing hangs under certain conditions */
> +        if (inlink->h == outlink->h)
> +            height_align_adjust = 1;
> +
>          out_frames_ctx->format            = AV_PIX_FMT_QSV;
>          out_frames_ctx->width             = FFALIGN(outlink->w, 32);
> -        out_frames_ctx->height            = FFALIGN(outlink->h, 32);
> +        out_frames_ctx->height            = FFALIGN(outlink->h + height_align_adjust, 32);
>          out_frames_ctx->sw_format         = s->out_sw_format;
>          out_frames_ctx->initial_pool_size = 64;
>          if (avctx->extra_hw_frames > 0)
> diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> index 5259104a4f..303d2101a9 100644
> --- a/libavfilter/vf_scale_qsv.c
> +++ b/libavfilter/vf_scale_qsv.c
> @@ -181,8 +181,10 @@ static int init_out_pool(AVFilterContext *ctx,
>      AVQSVFramesContext *out_frames_hwctx;
>      enum AVPixelFormat in_format;
>      enum AVPixelFormat out_format;
> +    int height_align_adjust = 0;
>      int i, ret;
>
> +
>      /* check that we have a hw context */
>      if (!ctx->inputs[0]->hw_frames_ctx) {
>          av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
> @@ -191,6 +193,7 @@ static int init_out_pool(AVFilterContext *ctx,
>      in_frames_ctx   = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
>      in_frames_hwctx = in_frames_ctx->hwctx;
>
> +    in_format     = in_frames_ctx->sw_format;
>      in_format     = in_frames_ctx->sw_format;
>      out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
>
> @@ -200,9 +203,13 @@ static int init_out_pool(AVFilterContext *ctx,
>      out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
>      out_frames_hwctx = out_frames_ctx->hwctx;
>
> +    /* work around a bug in MSDK where VPP processing hangs under certain conditions */
> +    if (in_frames_ctx->height == out_height)
> +        height_align_adjust = 1;
> +
Add a warning message in this case more better, same as above "
height_align_adjust = 1;"

>      out_frames_ctx->format            = AV_PIX_FMT_QSV;
>      out_frames_ctx->width             = FFALIGN(out_width,  16);
> -    out_frames_ctx->height            = FFALIGN(out_height, 16);
> +    out_frames_ctx->height            = FFALIGN(out_height + height_align_adjust, 16);
>      out_frames_ctx->sw_format         = out_format;
>      out_frames_ctx->initial_pool_size = 4;
>
> --
Zhong Li May 24, 2020, 12:46 p.m. UTC | #2
Soft Works <softworkz@hotmail.com> 于2020年5月24日周日 下午8:13写道:
>
> These conditions are:
> - Dimensions are aligned to 16/32 byte (e.g. 1920x800)
> - No scaling is done
> - Color format conversion (e.g. 10bit to 8bit)
>
> Example command:
> ffmpeg -c:v hevc_qsv -hwaccel qsv -i hevc_10bit_1920_800.mkv -filter_complex "scale_qsv=format=nv12" -c:v h264_qsv out.mkv

Could you help to file a bug on https://trac.ffmpeg.org/ or prove a
link to download the tested video hevc_10bit_1920_800.mkv ?

> Fix:
> - Increase the frame height to the next alignment value
> ---
>  libavfilter/qsvvpp.c       | 7 ++++++-
>  libavfilter/vf_scale_qsv.c | 9 ++++++++-
>  2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 1bbb7a7e68..98d2353d1c 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -420,6 +420,7 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
>      mfxHandleType handle_type;
>      mfxVersion ver;
>      mfxIMPL impl;
> +    int height_align_adjust = 0;
>      int ret, i;
>
>      if (inlink->hw_frames_ctx) {
> @@ -463,9 +464,13 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
>          out_frames_ctx   = (AVHWFramesContext *)out_frames_ref->data;
>          out_frames_hwctx = out_frames_ctx->hwctx;
>
> +        /* work around a bug in MSDK where VPP processing hangs under certain conditions */
> +        if (inlink->h == outlink->h)
> +            height_align_adjust = 1;
> +
>          out_frames_ctx->format            = AV_PIX_FMT_QSV;
>          out_frames_ctx->width             = FFALIGN(outlink->w, 32);
> -        out_frames_ctx->height            = FFALIGN(outlink->h, 32);
> +        out_frames_ctx->height            = FFALIGN(outlink->h + height_align_adjust, 32);
>          out_frames_ctx->sw_format         = s->out_sw_format;
>          out_frames_ctx->initial_pool_size = 64;
>          if (avctx->extra_hw_frames > 0)
> diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> index 5259104a4f..303d2101a9 100644
> --- a/libavfilter/vf_scale_qsv.c
> +++ b/libavfilter/vf_scale_qsv.c
> @@ -181,8 +181,10 @@ static int init_out_pool(AVFilterContext *ctx,
>      AVQSVFramesContext *out_frames_hwctx;
>      enum AVPixelFormat in_format;
>      enum AVPixelFormat out_format;
> +    int height_align_adjust = 0;
>      int i, ret;
>
> +
>      /* check that we have a hw context */
>      if (!ctx->inputs[0]->hw_frames_ctx) {
>          av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
> @@ -191,6 +193,7 @@ static int init_out_pool(AVFilterContext *ctx,
>      in_frames_ctx   = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
>      in_frames_hwctx = in_frames_ctx->hwctx;
>
> +    in_format     = in_frames_ctx->sw_format;
>      in_format     = in_frames_ctx->sw_format;
>      out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
>
> @@ -200,9 +203,13 @@ static int init_out_pool(AVFilterContext *ctx,
>      out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
>      out_frames_hwctx = out_frames_ctx->hwctx;
>
> +    /* work around a bug in MSDK where VPP processing hangs under certain conditions */
> +    if (in_frames_ctx->height == out_height)
> +        height_align_adjust = 1;
> +
>      out_frames_ctx->format            = AV_PIX_FMT_QSV;
>      out_frames_ctx->width             = FFALIGN(out_width,  16);
> -    out_frames_ctx->height            = FFALIGN(out_height, 16);
> +    out_frames_ctx->height            = FFALIGN(out_height + height_align_adjust, 16);
>      out_frames_ctx->sw_format         = out_format;
>      out_frames_ctx->initial_pool_size = 4;

Probally make sense, but have you tested the width value with similar issue?
Soft Works May 24, 2020, 1:02 p.m. UTC | #3
I'm afraid, I spent enough time on identifying the problem. I won't file a bug after I have provided a fix.

But I'll send you a short clip that will allow you to reproduce.

Best regards
softworkz

> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Zhong Li
> Sent: Sunday, May 24, 2020 2:47 PM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/qsvvpp: Work around a bug in
> MSDK where VPP processing hangs under certain conditions
> 
> Soft Works <softworkz@hotmail.com> 于2020年5月24日周日 下午8:13写道
> :
> >
> > These conditions are:
> > - Dimensions are aligned to 16/32 byte (e.g. 1920x800)
> > - No scaling is done
> > - Color format conversion (e.g. 10bit to 8bit)
> >
> > Example command:
> > ffmpeg -c:v hevc_qsv -hwaccel qsv -i hevc_10bit_1920_800.mkv
> > -filter_complex "scale_qsv=format=nv12" -c:v h264_qsv out.mkv
> 
> Could you help to file a bug on https://trac.ffmpeg.org/ or prove a link to
> download the tested video hevc_10bit_1920_800.mkv ?
> 
> > Fix:
> > - Increase the frame height to the next alignment value
> > ---
> >  libavfilter/qsvvpp.c       | 7 ++++++-
> >  libavfilter/vf_scale_qsv.c | 9 ++++++++-
> >  2 files changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index
> > 1bbb7a7e68..98d2353d1c 100644
> > --- a/libavfilter/qsvvpp.c
> > +++ b/libavfilter/qsvvpp.c
> > @@ -420,6 +420,7 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
> >      mfxHandleType handle_type;
> >      mfxVersion ver;
> >      mfxIMPL impl;
> > +    int height_align_adjust = 0;
> >      int ret, i;
> >
> >      if (inlink->hw_frames_ctx) {
> > @@ -463,9 +464,13 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
> >          out_frames_ctx   = (AVHWFramesContext *)out_frames_ref->data;
> >          out_frames_hwctx = out_frames_ctx->hwctx;
> >
> > +        /* work around a bug in MSDK where VPP processing hangs under
> certain conditions */
> > +        if (inlink->h == outlink->h)
> > +            height_align_adjust = 1;
> > +
> >          out_frames_ctx->format            = AV_PIX_FMT_QSV;
> >          out_frames_ctx->width             = FFALIGN(outlink->w, 32);
> > -        out_frames_ctx->height            = FFALIGN(outlink->h, 32);
> > +        out_frames_ctx->height            = FFALIGN(outlink->h +
> height_align_adjust, 32);
> >          out_frames_ctx->sw_format         = s->out_sw_format;
> >          out_frames_ctx->initial_pool_size = 64;
> >          if (avctx->extra_hw_frames > 0) diff --git
> > a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index
> > 5259104a4f..303d2101a9 100644
> > --- a/libavfilter/vf_scale_qsv.c
> > +++ b/libavfilter/vf_scale_qsv.c
> > @@ -181,8 +181,10 @@ static int init_out_pool(AVFilterContext *ctx,
> >      AVQSVFramesContext *out_frames_hwctx;
> >      enum AVPixelFormat in_format;
> >      enum AVPixelFormat out_format;
> > +    int height_align_adjust = 0;
> >      int i, ret;
> >
> > +
> >      /* check that we have a hw context */
> >      if (!ctx->inputs[0]->hw_frames_ctx) {
> >          av_log(ctx, AV_LOG_ERROR, "No hw context provided on
> > input\n"); @@ -191,6 +193,7 @@ static int init_out_pool(AVFilterContext
> *ctx,
> >      in_frames_ctx   = (AVHWFramesContext*)ctx->inputs[0]-
> >hw_frames_ctx->data;
> >      in_frames_hwctx = in_frames_ctx->hwctx;
> >
> > +    in_format     = in_frames_ctx->sw_format;
> >      in_format     = in_frames_ctx->sw_format;
> >      out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format : s-
> >format;
> >
> > @@ -200,9 +203,13 @@ static int init_out_pool(AVFilterContext *ctx,
> >      out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx-
> >data;
> >      out_frames_hwctx = out_frames_ctx->hwctx;
> >
> > +    /* work around a bug in MSDK where VPP processing hangs under
> certain conditions */
> > +    if (in_frames_ctx->height == out_height)
> > +        height_align_adjust = 1;
> > +
> >      out_frames_ctx->format            = AV_PIX_FMT_QSV;
> >      out_frames_ctx->width             = FFALIGN(out_width,  16);
> > -    out_frames_ctx->height            = FFALIGN(out_height, 16);
> > +    out_frames_ctx->height            = FFALIGN(out_height +
> height_align_adjust, 16);
> >      out_frames_ctx->sw_format         = out_format;
> >      out_frames_ctx->initial_pool_size = 4;
> 
> Probally make sense, but have you tested the width value with similar issue?
> _______________________________________________
> 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".
Soft Works May 24, 2020, 1:09 p.m. UTC | #4
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> mypopy@gmail.com
> Sent: Sunday, May 24, 2020 2:29 PM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/qsvvpp: Work around a bug in
> MSDK where VPP processing hangs under certain conditions
> 
> On Sun, May 24, 2020 at 8:13 PM Soft Works <softworkz@hotmail.com>
> wrote:
> >
> > These conditions are:
> > - Dimensions are aligned to 16/32 byte (e.g. 1920x800)
> > - No scaling is done
> > - Color format conversion (e.g. 10bit to 8bit)
> >
> > Example command:
> > ffmpeg -c:v hevc_qsv -hwaccel qsv -i hevc_10bit_1920_800.mkv
> > -filter_complex "scale_qsv=format=nv12" -c:v h264_qsv out.mkv
> >
> > Fix:
> > - Increase the frame height to the next alignment value
> > ---
> >  libavfilter/qsvvpp.c       | 7 ++++++-
> >  libavfilter/vf_scale_qsv.c | 9 ++++++++-
> >  2 files changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c index
> > 1bbb7a7e68..98d2353d1c 100644
> > --- a/libavfilter/qsvvpp.c
> > +++ b/libavfilter/qsvvpp.c
> > @@ -420,6 +420,7 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
> >      mfxHandleType handle_type;
> >      mfxVersion ver;
> >      mfxIMPL impl;
> > +    int height_align_adjust = 0;
> >      int ret, i;
> >
> >      if (inlink->hw_frames_ctx) {
> > @@ -463,9 +464,13 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
> >          out_frames_ctx   = (AVHWFramesContext *)out_frames_ref->data;
> >          out_frames_hwctx = out_frames_ctx->hwctx;
> >
> > +        /* work around a bug in MSDK where VPP processing hangs under
> certain conditions */
> > +        if (inlink->h == outlink->h)
> > +            height_align_adjust = 1;
> > +
> >          out_frames_ctx->format            = AV_PIX_FMT_QSV;
> >          out_frames_ctx->width             = FFALIGN(outlink->w, 32);
> > -        out_frames_ctx->height            = FFALIGN(outlink->h, 32);
> > +        out_frames_ctx->height            = FFALIGN(outlink->h +
> height_align_adjust, 32);
> >          out_frames_ctx->sw_format         = s->out_sw_format;
> >          out_frames_ctx->initial_pool_size = 64;
> >          if (avctx->extra_hw_frames > 0) diff --git
> > a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c index
> > 5259104a4f..303d2101a9 100644
> > --- a/libavfilter/vf_scale_qsv.c
> > +++ b/libavfilter/vf_scale_qsv.c
> > @@ -181,8 +181,10 @@ static int init_out_pool(AVFilterContext *ctx,
> >      AVQSVFramesContext *out_frames_hwctx;
> >      enum AVPixelFormat in_format;
> >      enum AVPixelFormat out_format;
> > +    int height_align_adjust = 0;
> >      int i, ret;
> >
> > +
> >      /* check that we have a hw context */
> >      if (!ctx->inputs[0]->hw_frames_ctx) {
> >          av_log(ctx, AV_LOG_ERROR, "No hw context provided on
> > input\n"); @@ -191,6 +193,7 @@ static int init_out_pool(AVFilterContext
> *ctx,
> >      in_frames_ctx   = (AVHWFramesContext*)ctx->inputs[0]-
> >hw_frames_ctx->data;
> >      in_frames_hwctx = in_frames_ctx->hwctx;
> >
> > +    in_format     = in_frames_ctx->sw_format;
> >      in_format     = in_frames_ctx->sw_format;
> >      out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format : s-
> >format;
> >
> > @@ -200,9 +203,13 @@ static int init_out_pool(AVFilterContext *ctx,
> >      out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx-
> >data;
> >      out_frames_hwctx = out_frames_ctx->hwctx;
> >
> > +    /* work around a bug in MSDK where VPP processing hangs under
> certain conditions */
> > +    if (in_frames_ctx->height == out_height)
> > +        height_align_adjust = 1;
> > +
> Add a warning message in this case more better, same as above "
> height_align_adjust = 1;"

Why? What should somebody be warned about. There's nothing he 
could do (except being glad that it's not failing).

softworkz
Max Dmitrichenko May 24, 2020, 2:42 p.m. UTC | #5
On Sun, May 24, 2020 at 2:13 PM Soft Works <softworkz@hotmail.com> wrote:

> These conditions are:
> - Dimensions are aligned to 16/32 byte (e.g. 1920x800)
> - No scaling is done
> - Color format conversion (e.g. 10bit to 8bit)
>
> Example command:
> ffmpeg -c:v hevc_qsv -hwaccel qsv -i hevc_10bit_1920_800.mkv
> -filter_complex "scale_qsv=format=nv12" -c:v h264_qsv out.mkv
>
> Fix:
> - Increase the frame height to the next alignment value
>


there is a strong feeling that adjustments are enforced in more cases than
actually needed,
only height is checked for decision.


> ---
>  libavfilter/qsvvpp.c       | 7 ++++++-
>  libavfilter/vf_scale_qsv.c | 9 ++++++++-
>  2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 1bbb7a7e68..98d2353d1c 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -420,6 +420,7 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
>      mfxHandleType handle_type;
>      mfxVersion ver;
>      mfxIMPL impl;
> +    int height_align_adjust = 0;
>      int ret, i;
>
>      if (inlink->hw_frames_ctx) {
> @@ -463,9 +464,13 @@ static int init_vpp_session(AVFilterContext *avctx,
> QSVVPPContext *s)
>          out_frames_ctx   = (AVHWFramesContext *)out_frames_ref->data;
>          out_frames_hwctx = out_frames_ctx->hwctx;
>
> +        /* work around a bug in MSDK where VPP processing hangs under
> certain conditions */
>

is this confirmed to be a bug from
https://github.com/Intel-Media-SDK/MediaSDK/issues ?


> +        if (inlink->h == outlink->h)
> +            height_align_adjust = 1;
> +
>          out_frames_ctx->format            = AV_PIX_FMT_QSV;
>          out_frames_ctx->width             = FFALIGN(outlink->w, 32);
> -        out_frames_ctx->height            = FFALIGN(outlink->h, 32);
> +        out_frames_ctx->height            = FFALIGN(outlink->h +
> height_align_adjust, 32);
>          out_frames_ctx->sw_format         = s->out_sw_format;
>          out_frames_ctx->initial_pool_size = 64;
>          if (avctx->extra_hw_frames > 0)
> diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> index 5259104a4f..303d2101a9 100644
> --- a/libavfilter/vf_scale_qsv.c
> +++ b/libavfilter/vf_scale_qsv.c
> @@ -181,8 +181,10 @@ static int init_out_pool(AVFilterContext *ctx,
>      AVQSVFramesContext *out_frames_hwctx;
>      enum AVPixelFormat in_format;
>      enum AVPixelFormat out_format;
> +    int height_align_adjust = 0;
>      int i, ret;
>
> +
>      /* check that we have a hw context */
>      if (!ctx->inputs[0]->hw_frames_ctx) {
>          av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
> @@ -191,6 +193,7 @@ static int init_out_pool(AVFilterContext *ctx,
>      in_frames_ctx   =
> (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
>      in_frames_hwctx = in_frames_ctx->hwctx;
>
> +    in_format     = in_frames_ctx->sw_format;
>      in_format     = in_frames_ctx->sw_format;
>      out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format :
> s->format;
>
> @@ -200,9 +203,13 @@ static int init_out_pool(AVFilterContext *ctx,
>      out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
>      out_frames_hwctx = out_frames_ctx->hwctx;
>
> +    /* work around a bug in MSDK where VPP processing hangs under certain
> conditions */
> +    if (in_frames_ctx->height == out_height)
> +        height_align_adjust = 1;
> +
>      out_frames_ctx->format            = AV_PIX_FMT_QSV;
>      out_frames_ctx->width             = FFALIGN(out_width,  16);
> -    out_frames_ctx->height            = FFALIGN(out_height, 16);
> +    out_frames_ctx->height            = FFALIGN(out_height +
> height_align_adjust, 16);
>      out_frames_ctx->sw_format         = out_format;
>      out_frames_ctx->initial_pool_size = 4;
>
> --
> 2.26.2.windows.1
>
>
>
without sample input video - patch has no meaning.

regards
Max
Soft Works May 24, 2020, 9:01 p.m. UTC | #6
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Max Dmitrichenko
> Sent: Sunday, May 24, 2020 4:43 PM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/qsvvpp: Work around a bug in
> MSDK where VPP processing hangs under certain conditions
> 
> On Sun, May 24, 2020 at 2:13 PM Soft Works <softworkz@hotmail.com>
> wrote:

> > Fix:
> > - Increase the frame height to the next alignment value
> >
> 
> 
> there is a strong feeling that adjustments are enforced in more cases than
> actually needed, only height is checked for decision.

That may be right, but I haven't done enough testing to know exactly and
I wanted to be sure to catch all possible cases.

With regards to the amount of "wasted" memory, there's a much 
more severe issue in vpp_qsv, because the alignment requirements
for height and width are 16 pixels, not 32 pixels. This is done right
in scale_qsv but not in vpp_qsv.

I haven't changed that because I didn't want to mix two different 
issues in a single patch.

> is this confirmed to be a bug from
> https://github.com/Intel-Media-SDK/MediaSDK/issues ?

I didn't bother to file a bug there, because I needed an immediate
fix for all driver versions and can't wait for an update from that
side.

> without sample input video - patch has no meaning.

I have forwarded the clip to you and to Zhong. When anybody else
is interested, just drop me a note.

Regards
softworkz
Moritz Barsnick May 24, 2020, 10:03 p.m. UTC | #7
I don't understand functionally, but:

On Sun, May 24, 2020 at 12:13:07 +0000, Soft Works wrote:
> +    int height_align_adjust = 0;
>      int i, ret;
>
> +
>      /* check that we have a hw context */

Stray line.

>
> +    in_format     = in_frames_ctx->sw_format;
>      in_format     = in_frames_ctx->sw_format;

What happened here? A line got duplicated?

Moritz.
Soft Works May 24, 2020, 10:50 p.m. UTC | #8
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Moritz Barsnick
> Sent: Monday, May 25, 2020 12:04 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/qsvvpp: Work around a bug in
> MSDK where VPP processing hangs under certain conditions
> 
> I don't understand functionally, but:
> 
> On Sun, May 24, 2020 at 12:13:07 +0000, Soft Works wrote:
> > +    int height_align_adjust = 0;
> >      int i, ret;
> >
> > +
> >      /* check that we have a hw context */
> 
> Stray line.
> 
> >
> > +    in_format     = in_frames_ctx->sw_format;
> >      in_format     = in_frames_ctx->sw_format;
> 
> What happened here? A line got duplicated?

Hi Moritz,

thanks for the hint. I still haven't really accommodated to working with
those patch files ;-)

The nature of the bug can be roughly explained like this:

- MSDK seems to compare some width/height values between input
  and output to determine whether it should do something (e.g. scale)
- it seems to compare the wrong values for this check (probably for input
  the video dimensions and for output (incorrectly) the aligned size of the
  hw frame
- when there's no difference but a color conversion, it hangs
- the bug wasn't noted, because in most cases, the size-alignment caused
  a difference with regards to that incorrect check
- but when the original size is already aligned to 32 pixels, the bug
  becomes visible
- I fix it, by adding 32 to the hw frame height in order to make sure that
  there exists a difference, even in those cases where the video dimensions
  are already aligned

softworkz
diff mbox series

Patch

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 1bbb7a7e68..98d2353d1c 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -420,6 +420,7 @@  static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
     mfxHandleType handle_type;
     mfxVersion ver;
     mfxIMPL impl;
+    int height_align_adjust = 0;
     int ret, i;
 
     if (inlink->hw_frames_ctx) {
@@ -463,9 +464,13 @@  static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
         out_frames_ctx   = (AVHWFramesContext *)out_frames_ref->data;
         out_frames_hwctx = out_frames_ctx->hwctx;
 
+        /* work around a bug in MSDK where VPP processing hangs under certain conditions */
+        if (inlink->h == outlink->h)
+            height_align_adjust = 1;
+
         out_frames_ctx->format            = AV_PIX_FMT_QSV;
         out_frames_ctx->width             = FFALIGN(outlink->w, 32);
-        out_frames_ctx->height            = FFALIGN(outlink->h, 32);
+        out_frames_ctx->height            = FFALIGN(outlink->h + height_align_adjust, 32);
         out_frames_ctx->sw_format         = s->out_sw_format;
         out_frames_ctx->initial_pool_size = 64;
         if (avctx->extra_hw_frames > 0)
diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 5259104a4f..303d2101a9 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -181,8 +181,10 @@  static int init_out_pool(AVFilterContext *ctx,
     AVQSVFramesContext *out_frames_hwctx;
     enum AVPixelFormat in_format;
     enum AVPixelFormat out_format;
+    int height_align_adjust = 0;
     int i, ret;
 
+
     /* check that we have a hw context */
     if (!ctx->inputs[0]->hw_frames_ctx) {
         av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
@@ -191,6 +193,7 @@  static int init_out_pool(AVFilterContext *ctx,
     in_frames_ctx   = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
     in_frames_hwctx = in_frames_ctx->hwctx;
 
+    in_format     = in_frames_ctx->sw_format;
     in_format     = in_frames_ctx->sw_format;
     out_format    = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
 
@@ -200,9 +203,13 @@  static int init_out_pool(AVFilterContext *ctx,
     out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
     out_frames_hwctx = out_frames_ctx->hwctx;
 
+    /* work around a bug in MSDK where VPP processing hangs under certain conditions */
+    if (in_frames_ctx->height == out_height)
+        height_align_adjust = 1;
+
     out_frames_ctx->format            = AV_PIX_FMT_QSV;
     out_frames_ctx->width             = FFALIGN(out_width,  16);
-    out_frames_ctx->height            = FFALIGN(out_height, 16);
+    out_frames_ctx->height            = FFALIGN(out_height + height_align_adjust, 16);
     out_frames_ctx->sw_format         = out_format;
     out_frames_ctx->initial_pool_size = 4;