diff mbox series

[FFmpeg-devel] libavcodec/qsvdec: reinit decoder according to decode() return value

Message ID 20210322062713.2268376-1-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel] libavcodec/qsvdec: reinit decoder according to decode() return value
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Chen, Wenbin March 22, 2021, 6:27 a.m. UTC
From: "Chen,Wenbin" <wenbin.chen@intel.com>

FFmpeg-qsv decoder reinit codec when width and height change, but there
are not only resolution change need to reinit codec. I change it to use
return value from DecodeFrameAsync() to decide whether decoder need to
be reinitialized.

Signed-off-by Wenbin Chen <wenbin.chen@intel.com>
---
 libavcodec/qsvdec.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Xiang, Haihao March 23, 2021, 3:48 a.m. UTC | #1
On Mon, 2021-03-22 at 14:27 +0800, wenbin.chen@intel.com wrote:
> From: "Chen,Wenbin" <wenbin.chen@intel.com>
> 
> FFmpeg-qsv decoder reinit codec when width and height change, but there
> are not only resolution change need to reinit codec. I change it to use
> return value from DecodeFrameAsync() to decide whether decoder need to
> be reinitialized.
> 
> Signed-off-by Wenbin Chen <wenbin.chen@intel.com>
> ---
>  libavcodec/qsvdec.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index bca6e217fa..124f3e0a7a 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -438,6 +438,12 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> *q,
>  
>      } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
>  
> +    if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {
> +        q->reinit_flag = 1;
> +        av_log(avctx, AV_LOG_VERBOSE, "Video parameter change\n");

How about using AV_LOG_DEBUG instead? I think it is useful only for developers.
In addition, sync should be freed before returning 0.

> +        return 0;
> +    }
> +
>      if (ret != MFX_ERR_NONE &&
>          ret != MFX_ERR_MORE_DATA &&
>          ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
> @@ -591,9 +597,9 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext
> *q,
>  
>      ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
>  
> -    if (ret >= 0 && (q->orig_pix_fmt !=
> ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
> +    if (q->reinit_flag || (ret >= 0 && (q->orig_pix_fmt !=
> ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
>          avctx->coded_width  != param.mfx.FrameInfo.Width ||
> -        avctx->coded_height != param.mfx.FrameInfo.Height)) {
> +        avctx->coded_height != param.mfx.FrameInfo.Height))) {
>          AVPacket zero_pkt = {0};
>  
>          if (q->buffered_count) {
Chen, Wenbin March 23, 2021, 6:30 a.m. UTC | #2
> -----Original Message-----
> From: Xiang, Haihao <haihao.xiang@intel.com>
> Sent: Tuesday, March 23, 2021 11:49 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Chen, Wenbin <wenbin.chen@intel.com>
> Subject: Re: [FFmpeg-devel] [PATCH] libavcodec/qsvdec: reinit decoder
> according to decode() return value
> 
> On Mon, 2021-03-22 at 14:27 +0800, wenbin.chen@intel.com wrote:
> > From: "Chen,Wenbin" <wenbin.chen@intel.com>
> >
> > FFmpeg-qsv decoder reinit codec when width and height change, but there
> > are not only resolution change need to reinit codec. I change it to use
> > return value from DecodeFrameAsync() to decide whether decoder need to
> > be reinitialized.
> >
> > Signed-off-by Wenbin Chen <wenbin.chen@intel.com>
> > ---
> >  libavcodec/qsvdec.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > index bca6e217fa..124f3e0a7a 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -438,6 +438,12 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext
> > *q,
> >
> >      } while (ret == MFX_WRN_DEVICE_BUSY || ret ==
> MFX_ERR_MORE_SURFACE);
> >
> > +    if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {
> > +        q->reinit_flag = 1;
> > +        av_log(avctx, AV_LOG_VERBOSE, "Video parameter change\n");
> 
> How about using AV_LOG_DEBUG instead? I think it is useful only for
> developers.
> In addition, sync should be freed before returning 0.
>

Ok, I will submit another version. Thanks for your advice.

> 
> > +        return 0;
> > +    }
> > +
> >      if (ret != MFX_ERR_NONE &&
> >          ret != MFX_ERR_MORE_DATA &&
> >          ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
> > @@ -591,9 +597,9 @@ int ff_qsv_process_data(AVCodecContext *avctx,
> QSVContext
> > *q,
> >
> >      ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
> >
> > -    if (ret >= 0 && (q->orig_pix_fmt !=
> > ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
> > +    if (q->reinit_flag || (ret >= 0 && (q->orig_pix_fmt !=
> > ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
> >          avctx->coded_width  != param.mfx.FrameInfo.Width ||
> > -        avctx->coded_height != param.mfx.FrameInfo.Height)) {
> > +        avctx->coded_height != param.mfx.FrameInfo.Height))) {
> >          AVPacket zero_pkt = {0};
> >
> >          if (q->buffered_count) {
diff mbox series

Patch

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index bca6e217fa..124f3e0a7a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -438,6 +438,12 @@  static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 
     } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
 
+    if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {
+        q->reinit_flag = 1;
+        av_log(avctx, AV_LOG_VERBOSE, "Video parameter change\n");
+        return 0;
+    }
+
     if (ret != MFX_ERR_NONE &&
         ret != MFX_ERR_MORE_DATA &&
         ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
@@ -591,9 +597,9 @@  int ff_qsv_process_data(AVCodecContext *avctx, QSVContext *q,
 
     ret = qsv_decode_header(avctx, q, pkt, pix_fmt, &param);
 
-    if (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
+    if (q->reinit_flag || (ret >= 0 && (q->orig_pix_fmt != ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC) ||
         avctx->coded_width  != param.mfx.FrameInfo.Width ||
-        avctx->coded_height != param.mfx.FrameInfo.Height)) {
+        avctx->coded_height != param.mfx.FrameInfo.Height))) {
         AVPacket zero_pkt = {0};
 
         if (q->buffered_count) {