Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-18 Thread Gurulev, Dmitry
> -Original Message-
> From: Rogozhkin, Dmitry V
> Sent: Saturday, March 16, 2019 4:18 AM
> To: Li, Zhong ; ffmpeg-devel@ffmpeg.org; Gurulev, Dmitry
> 
> Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser
> with MFXVideoDECODE_DecodeHeader()
> 
> On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > > -Original Message-
> > > From: Rogozhkin, Dmitry V
> > > Sent: Saturday, March 9, 2019 8:48 AM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Li, Zhong 
> > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > current parser with MFXVideoDECODE_DecodeHeader()
> > >
> > > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > > (E.g:
> > > > sps declares a wrong level_idc, smaller than it should be).
> > > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > > VP9
> > > > since current parser can't provide enough information.
> > > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > > and
> > > > merged as commit 1acb19d, but was overwritten when merged libav
> > > > patches (commit: 1f26a23) without any explain.
> > > >
> > > > v2: split decode header from decode_init, and call it for
> > > > everyframe to detect format/resoultion change. It can fix some
> > > > regression issues such as hevc 10bits decoding.
> > > >
> > > > Signed-off-by: Zhong Li 
> > > > ---
> > > >  libavcodec/qsvdec.c   | 172 --
> > > > 
> > > > 
> > > >  libavcodec/qsvdec.h   |   2 +
> > > >  libavcodec/qsvdec_h2645.c |   1 +
> > > >  libavcodec/qsvdec_other.c |   1 +
> > > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > >
> > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > > 4a0be811fb..b78026e14d 100644
> > > > --- a/libavcodec/qsvdec.c
> > > > +++ b/libavcodec/qsvdec.c
> > > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > > qsv_fifo_size(const
> > > > AVFifoBuffer* fifo)
> > > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > > >  }
> > > >
> > > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > > *q,
> > > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > > >  {
> > > > -const AVPixFmtDescriptor *desc;
> > > >  mfxSession session = NULL;
> > > >  int iopattern = 0;
> > > > -mfxVideoParam param = { 0 };
> > > > -int frame_width  = avctx->coded_width;
> > > > -int frame_height = avctx->coded_height;
> > > >  int ret;
> > > >
> > > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > > -if (!desc)
> > > > -return AVERROR_BUG;
> > > > +ret = ff_get_format(avctx, pix_fmts);
> > > > +if (ret < 0) {
> > > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > > +return ret;
> > > > +}
> > > >
> > > >  if (!q->async_fifo) {
> > > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > >  return ret;
> > > >  }
> > > >
> > > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > > -if (ret < 0)
> > > > -return ret;
> > > > +param->IOPattern   = q->iopattern;
> > > > +param->AsyncDepth  = q->async_depth;
> > > > +param->ExtParam= q->ext_buffers;
> > > > +param->NumExtParam = q->nb_ext_buffers;
> > > >
> > > > -param.mfx.CodecId  = ret;
> > > > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx-
> > > > >codec_id,
> > > > avctx->profile);
> > > > -param.mfx.CodecLevel   = avctx->level ==
> > >
> > > FF

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-18 Thread Gurulev, Dmitry
> -Original Message-
> From: Rogozhkin, Dmitry V
> Sent: Saturday, March 16, 2019 4:17 AM
> To: Li, Zhong ; ffmpeg-devel@ffmpeg.org; Gurulev, Dmitry
> 
> Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser
> with MFXVideoDECODE_DecodeHeader()
> 
> On Thu, 2019-03-14 at 19:03 +0800, Li, Zhong wrote:
> > > From: Rogozhkin, Dmitry V
> > > Sent: Tuesday, March 12, 2019 7:37 AM
> > > To: Li, Zhong ; ffmpeg-devel@ffmpeg.org
> > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > current parser with MFXVideoDECODE_DecodeHeader()
> > >
> > > On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > > > > -Original Message-
> > > > > From: Rogozhkin, Dmitry V
> > > > > Sent: Saturday, March 9, 2019 8:48 AM
> > > > > To: ffmpeg-devel@ffmpeg.org
> > > > > Cc: Li, Zhong 
> > > > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > > > current parser with MFXVideoDECODE_DecodeHeader()
> > > > >
> > > > > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > > > > Using MSDK parser can improve qsv decoder pass rate in some
> > > > > > cases
> > > > > > (E.g:
> > > > > > sps declares a wrong level_idc, smaller than it should be).
> > > > > > And it is necessary for adding new qsv decoders such as MJPEG
> > > > > > and
> > > > > > VP9
> > > > > > since current parser can't provide enough information.
> > > > > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > > > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.ht
> > > > > > ml
> > > > > > and
> > > > > > merged as commit 1acb19d, but was overwritten when merged
> > > > > > libav patches (commit: 1f26a23) without any explain.
> > > > > >
> > > > > > v2: split decode header from decode_init, and call it for
> > > > > > everyframe to detect format/resoultion change. It can fix some
> > > > > > regression issues such as hevc 10bits decoding.
> > > > > >
> > > > > > Signed-off-by: Zhong Li 
> > > > > > ---
> > > > > >  libavcodec/qsvdec.c   | 172
> > >
> > > --
> > > > > > 
> > > > > > 
> > > > > >  libavcodec/qsvdec.h   |   2 +
> > > > > >  libavcodec/qsvdec_h2645.c |   1 +
> > > > > >  libavcodec/qsvdec_other.c |   1 +
> > > > > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > > > >
> > > > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > > > > 4a0be811fb..b78026e14d 100644
> > > > > > --- a/libavcodec/qsvdec.c
> > > > > > +++ b/libavcodec/qsvdec.c
> > > > > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > > > > qsv_fifo_size(const
> > > > > > AVFifoBuffer* fifo)
> > > > > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > > > > >  }
> > > > > >
> > > > > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext
> > > > > > *q)
> > > > > > +static int qsv_decode_preinit(AVCodecContext *avctx,
> > > > > > QSVContext
> > > > > > *q,
> > > > > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > > > > >  {
> > > > > > -const AVPixFmtDescriptor *desc;
> > > > > >  mfxSession session = NULL;
> > > > > >  int iopattern = 0;
> > > > > > -mfxVideoParam param = { 0 };
> > > > > > -int frame_width  = avctx->coded_width;
> > > > > > -int frame_height = avctx->coded_height;
> > > > > >  int ret;
> > > > > >
> > > > > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > > > > -if (!desc)
> > > > > > -return AVERROR_BUG;
> > > > > > +ret = ff_get_format(avctx, pix_fmts);
> > > > > > +if (ret < 0) {
> > > > > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> >

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-17 Thread Li, Zhong
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Mark Thompson
> Sent: Sunday, March 17, 2019 10:20 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current
> parser with MFXVideoDECODE_DecodeHeader()
> 
> On 08/03/2019 07:40, Zhong Li wrote:
> > Using MSDK parser can improve qsv decoder pass rate in some cases (E.g:
> > sps declares a wrong level_idc, smaller than it should be).
> > And it is necessary for adding new qsv decoders such as MJPEG and VP9
> > since current parser can't provide enough information.
> > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html and
> > merged as commit 1acb19d, but was overwritten when merged libav
> patches (commit: 1f26a23) without any explain.
> >
> > v2: split decode header from decode_init, and call it for everyframe
> > to detect format/resoultion change. It can fix some regression issues
> > such as hevc 10bits decoding.
> >
> > Signed-off-by: Zhong Li 
> > ---
> >  libavcodec/qsvdec.c   | 172
> --
> >  libavcodec/qsvdec.h   |   2 +
> >  libavcodec/qsvdec_h2645.c |   1 +
> >  libavcodec/qsvdec_other.c |   1 +
> >  4 files changed, 93 insertions(+), 83 deletions(-)
> >
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > 4a0be811fb..b78026e14d 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -120,19 +120,17 @@ static inline unsigned int qsv_fifo_size(const
> AVFifoBuffer* fifo)
> >  return av_fifo_size(fifo) / qsv_fifo_item_size();  }
> >
> > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q,
> > +enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> >  {
> > -const AVPixFmtDescriptor *desc;
> >  mfxSession session = NULL;
> >  int iopattern = 0;
> > -mfxVideoParam param = { 0 };
> > -int frame_width  = avctx->coded_width;
> > -int frame_height = avctx->coded_height;
> >  int ret;
> >
> > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > -if (!desc)
> > -return AVERROR_BUG;
> > +ret = ff_get_format(avctx, pix_fmts);
> > +if (ret < 0) {
> > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > +return ret;
> > +}
> >
> >  if (!q->async_fifo) {
> >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> >  return ret;
> >  }
> >
> > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > -if (ret < 0)
> > -return ret;
> > +param->IOPattern   = q->iopattern;
> > +param->AsyncDepth  = q->async_depth;
> > +param->ExtParam= q->ext_buffers;
> > +param->NumExtParam = q->nb_ext_buffers;
> >
> > -param.mfx.CodecId  = ret;
> > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id,
> avctx->profile);
> > -param.mfx.CodecLevel   = avctx->level == FF_LEVEL_UNKNOWN ?
> MFX_LEVEL_UNKNOWN : avctx->level;
> > -
> > -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> > -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> > -param.mfx.FrameInfo.Shift  = desc->comp[0].depth > 8;
> > -param.mfx.FrameInfo.FourCC = q->fourcc;
> > -param.mfx.FrameInfo.Width  = frame_width;
> > -param.mfx.FrameInfo.Height = frame_height;
> > -param.mfx.FrameInfo.ChromaFormat   =
> MFX_CHROMAFORMAT_YUV420;
> > -
> > -switch (avctx->field_order) {
> > -case AV_FIELD_PROGRESSIVE:
> > -param.mfx.FrameInfo.PicStruct =
> MFX_PICSTRUCT_PROGRESSIVE;
> > -break;
> > -case AV_FIELD_TT:
> > -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
> > -break;
> > -case AV_FIELD_BB:
> > -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
> > -break;
> > -default:
> > -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
> > -break;
> > -}
> > +return 0;
> > + }
> >
> > -param.IOPattern   = q->iopattern;
> > -param.AsyncDepth  = q->async_depth;
&

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-17 Thread Mark Thompson
On 08/03/2019 07:40, Zhong Li wrote:
> Using MSDK parser can improve qsv decoder pass rate in some cases (E.g:
> sps declares a wrong level_idc, smaller than it should be).
> And it is necessary for adding new qsv decoders such as MJPEG and VP9
> since current parser can't provide enough information.
> Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html and merged as 
> commit 1acb19d,
> but was overwritten when merged libav patches (commit: 1f26a23) without any 
> explain.
> 
> v2: split decode header from decode_init, and call it for everyframe to
> detect format/resoultion change. It can fix some regression issues such
> as hevc 10bits decoding.
> 
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvdec.c   | 172 --
>  libavcodec/qsvdec.h   |   2 +
>  libavcodec/qsvdec_h2645.c |   1 +
>  libavcodec/qsvdec_other.c |   1 +
>  4 files changed, 93 insertions(+), 83 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 4a0be811fb..b78026e14d 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -120,19 +120,17 @@ static inline unsigned int qsv_fifo_size(const 
> AVFifoBuffer* fifo)
>  return av_fifo_size(fifo) / qsv_fifo_item_size();
>  }
>  
> -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum 
> AVPixelFormat *pix_fmts, mfxVideoParam *param)
>  {
> -const AVPixFmtDescriptor *desc;
>  mfxSession session = NULL;
>  int iopattern = 0;
> -mfxVideoParam param = { 0 };
> -int frame_width  = avctx->coded_width;
> -int frame_height = avctx->coded_height;
>  int ret;
>  
> -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> -if (!desc)
> -return AVERROR_BUG;
> +ret = ff_get_format(avctx, pix_fmts);
> +if (ret < 0) {
> +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> +return ret;
> +}
>  
>  if (!q->async_fifo) {
>  q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
> @@ -170,48 +168,72 @@ static int qsv_decode_init(AVCodecContext *avctx, 
> QSVContext *q)
>  return ret;
>  }
>  
> -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> -if (ret < 0)
> -return ret;
> +param->IOPattern   = q->iopattern;
> +param->AsyncDepth  = q->async_depth;
> +param->ExtParam= q->ext_buffers;
> +param->NumExtParam = q->nb_ext_buffers;
>  
> -param.mfx.CodecId  = ret;
> -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id, 
> avctx->profile);
> -param.mfx.CodecLevel   = avctx->level == FF_LEVEL_UNKNOWN ? 
> MFX_LEVEL_UNKNOWN : avctx->level;
> -
> -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> -param.mfx.FrameInfo.Shift  = desc->comp[0].depth > 8;
> -param.mfx.FrameInfo.FourCC = q->fourcc;
> -param.mfx.FrameInfo.Width  = frame_width;
> -param.mfx.FrameInfo.Height = frame_height;
> -param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
> -
> -switch (avctx->field_order) {
> -case AV_FIELD_PROGRESSIVE:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
> -break;
> -case AV_FIELD_TT:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
> -break;
> -case AV_FIELD_BB:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
> -break;
> -default:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
> -break;
> -}
> +return 0;
> + }
>  
> -param.IOPattern   = q->iopattern;
> -param.AsyncDepth  = q->async_depth;
> -param.ExtParam= q->ext_buffers;
> -param.NumExtParam = q->nb_ext_buffers;
> +static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q, 
> mfxVideoParam *param)
> +{
> +int ret;
>  
> -ret = MFXVideoDECODE_Init(q->session, );
> +avctx->width= param->mfx.FrameInfo.CropW;
> +avctx->height   = param->mfx.FrameInfo.CropH;
> +avctx->coded_width  = param->mfx.FrameInfo.Width;
> +avctx->coded_height = param->mfx.FrameInfo.Height;
> +avctx->level= param->mfx.CodecLevel;
> +avctx->profile  = param->mfx.CodecProfile;

This feels insufficient for the UNKNOWN cases?  (VP8 in particular has no 
profiles.)

> +avctx->field_order  = 
> ff_qsv_map_picstruct(param->mfx.FrameInfo.PicStruct);
> +avctx->pix_fmt  = ff_qsv_map_fourcc(param->mfx.FrameInfo.FourCC);
> +
> +ret = MFXVideoDECODE_Init(q->session, param);
>  if (ret < 0)
>  return ff_qsv_print_error(avctx, ret,
>"Error initializing the MFX video 
> decoder");
>  
> -q->frame_info = param.mfx.FrameInfo;
> +q->frame_info = param->mfx.FrameInfo;
> +
> +return 

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-15 Thread Rogozhkin, Dmitry V
On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > -Original Message-
> > From: Rogozhkin, Dmitry V
> > Sent: Saturday, March 9, 2019 8:48 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Li, Zhong 
> > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > current
> > parser with MFXVideoDECODE_DecodeHeader()
> > 
> > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > (E.g:
> > > sps declares a wrong level_idc, smaller than it should be).
> > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > VP9
> > > since current parser can't provide enough information.
> > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > and
> > > merged as commit 1acb19d, but was overwritten when merged libav
> > > patches (commit: 1f26a23) without any explain.
> > > 
> > > v2: split decode header from decode_init, and call it for
> > > everyframe
> > > to detect format/resoultion change. It can fix some regression
> > > issues
> > > such as hevc 10bits decoding.
> > > 
> > > Signed-off-by: Zhong Li 
> > > ---
> > >  libavcodec/qsvdec.c   | 172 --
> > > 
> > > 
> > >  libavcodec/qsvdec.h   |   2 +
> > >  libavcodec/qsvdec_h2645.c |   1 +
> > >  libavcodec/qsvdec_other.c |   1 +
> > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > 
> > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > 4a0be811fb..b78026e14d 100644
> > > --- a/libavcodec/qsvdec.c
> > > +++ b/libavcodec/qsvdec.c
> > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > qsv_fifo_size(const
> > > AVFifoBuffer* fifo)
> > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > >  }
> > > 
> > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > *q,
> > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > >  {
> > > -const AVPixFmtDescriptor *desc;
> > >  mfxSession session = NULL;
> > >  int iopattern = 0;
> > > -mfxVideoParam param = { 0 };
> > > -int frame_width  = avctx->coded_width;
> > > -int frame_height = avctx->coded_height;
> > >  int ret;
> > > 
> > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > -if (!desc)
> > > -return AVERROR_BUG;
> > > +ret = ff_get_format(avctx, pix_fmts);
> > > +if (ret < 0) {
> > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > +return ret;
> > > +}
> > > 
> > >  if (!q->async_fifo) {
> > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > >  return ret;
> > >  }
> > > 
> > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > -if (ret < 0)
> > > -return ret;
> > > +param->IOPattern   = q->iopattern;
> > > +param->AsyncDepth  = q->async_depth;
> > > +param->ExtParam= q->ext_buffers;
> > > +param->NumExtParam = q->nb_ext_buffers;
> > > 
> > > -param.mfx.CodecId  = ret;
> > > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx-
> > > >codec_id,
> > > avctx->profile);
> > > -param.mfx.CodecLevel   = avctx->level ==
> > 
> > FF_LEVEL_UNKNOWN ?
> > > MFX_LEVEL_UNKNOWN : avctx->level;
> > > -
> > > -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> > > -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> > > -param.mfx.FrameInfo.Shift  = desc->comp[0].depth >
> > 
> > 8;
> > > -param.mfx.FrameInfo.FourCC = q->fourcc;
> > > -param.mfx.FrameInfo.Width  = frame_width;
> > > -param.mfx.FrameInfo.Height = frame_height;
> > > -param.mfx.FrameInfo.ChromaFormat   =
> > 
> > MFX_CHROMAFORMAT_YUV420;
> > > -
> > > -swi

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-15 Thread Rogozhkin, Dmitry V
On Thu, 2019-03-14 at 19:03 +0800, Li, Zhong wrote:
> > From: Rogozhkin, Dmitry V
> > Sent: Tuesday, March 12, 2019 7:37 AM
> > To: Li, Zhong ; ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > current
> > parser with MFXVideoDECODE_DecodeHeader()
> > 
> > On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > > > -Original Message-
> > > > From: Rogozhkin, Dmitry V
> > > > Sent: Saturday, March 9, 2019 8:48 AM
> > > > To: ffmpeg-devel@ffmpeg.org
> > > > Cc: Li, Zhong 
> > > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > > current parser with MFXVideoDECODE_DecodeHeader()
> > > > 
> > > > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > > > Using MSDK parser can improve qsv decoder pass rate in some
> > > > > cases
> > > > > (E.g:
> > > > > sps declares a wrong level_idc, smaller than it should be).
> > > > > And it is necessary for adding new qsv decoders such as MJPEG
> > > > > and
> > > > > VP9
> > > > > since current parser can't provide enough information.
> > > > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed
> > > > > at
> > > > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.ht
> > > > > ml
> > > > > and
> > > > > merged as commit 1acb19d, but was overwritten when merged
> > > > > libav
> > > > > patches (commit: 1f26a23) without any explain.
> > > > > 
> > > > > v2: split decode header from decode_init, and call it for
> > > > > everyframe to detect format/resoultion change. It can fix
> > > > > some
> > > > > regression issues such as hevc 10bits decoding.
> > > > > 
> > > > > Signed-off-by: Zhong Li 
> > > > > ---
> > > > >  libavcodec/qsvdec.c   | 172
> > 
> > --
> > > > > 
> > > > > 
> > > > >  libavcodec/qsvdec.h   |   2 +
> > > > >  libavcodec/qsvdec_h2645.c |   1 +
> > > > >  libavcodec/qsvdec_other.c |   1 +
> > > > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > > > 
> > > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > > > 4a0be811fb..b78026e14d 100644
> > > > > --- a/libavcodec/qsvdec.c
> > > > > +++ b/libavcodec/qsvdec.c
> > > > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > > > qsv_fifo_size(const
> > > > > AVFifoBuffer* fifo)
> > > > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > > > >  }
> > > > > 
> > > > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext
> > > > > *q)
> > > > > +static int qsv_decode_preinit(AVCodecContext *avctx,
> > > > > QSVContext
> > > > > *q,
> > > > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > > > >  {
> > > > > -const AVPixFmtDescriptor *desc;
> > > > >  mfxSession session = NULL;
> > > > >  int iopattern = 0;
> > > > > -mfxVideoParam param = { 0 };
> > > > > -int frame_width  = avctx->coded_width;
> > > > > -int frame_height = avctx->coded_height;
> > > > >  int ret;
> > > > > 
> > > > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > > > -if (!desc)
> > > > > -return AVERROR_BUG;
> > > > > +ret = ff_get_format(avctx, pix_fmts);
> > > > > +if (ret < 0) {
> > > > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > > > +return ret;
> > > > > +}
> > > > > 
> > > > >  if (!q->async_fifo) {
> > > > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > > >  return ret;
> > > > >  }
> > > > > 
> > > > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > > > -if (ret <

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-15 Thread Rogozhkin, Dmitry V
On Thu, 2019-03-14 at 19:16 +0800, Li, Zhong wrote:
> > From: Rogozhkin, Dmitry V
> > Sent: Tuesday, March 12, 2019 8:04 AM
> > To: Li, Zhong ; ffmpeg-devel@ffmpeg.org
> > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > current
> > parser with MFXVideoDECODE_DecodeHeader()
> > 
> > pix_fmts[1] is misleading. And I think it can be quite easily
> > avoided.
> > 
> > If I understand the code correctly, qsv_decode_preinit is the place
> > (and the
> > only place) where you need an array of pix_fmts. You actually
> > request
> > ffmpeg to select one of the formats and program it into avctx.
> > Is that right?
> > 
> > If so, could we try to define the array exactly in this function
> > and avoid
> > passing the whole array around? See comments below for
> > suggestions...
> > 
> > 
> > On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > > > -Original Message-
> > > > From: Rogozhkin, Dmitry V
> > > > Sent: Saturday, March 9, 2019 8:48 AM
> > > > To: ffmpeg-devel@ffmpeg.org
> > > > Cc: Li, Zhong 
> > > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > > current parser with MFXVideoDECODE_DecodeHeader()
> > > > 
> > > > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > > > Using MSDK parser can improve qsv decoder pass rate in some
> > > > > cases
> > > > > (E.g:
> > > > > sps declares a wrong level_idc, smaller than it should be).
> > > > > And it is necessary for adding new qsv decoders such as MJPEG
> > > > > and
> > > > > VP9
> > > > > since current parser can't provide enough information.
> > > > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed
> > > > > at
> > > > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.ht
> > > > > ml
> > > > > and
> > > > > merged as commit 1acb19d, but was overwritten when merged
> > > > > libav
> > > > > patches (commit: 1f26a23) without any explain.
> > > > > 
> > > > > v2: split decode header from decode_init, and call it for
> > > > > everyframe to detect format/resoultion change. It can fix
> > > > > some
> > > > > regression issues such as hevc 10bits decoding.
> > > > > 
> > > > > Signed-off-by: Zhong Li 
> > > > > ---
> > > > >  libavcodec/qsvdec.c   | 172
> > 
> > --
> > > > > 
> > > > > 
> > > > >  libavcodec/qsvdec.h   |   2 +
> > > > >  libavcodec/qsvdec_h2645.c |   1 +
> > > > >  libavcodec/qsvdec_other.c |   1 +
> > > > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > > > 
> > > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > > > 4a0be811fb..b78026e14d 100644
> > > > > --- a/libavcodec/qsvdec.c
> > > > > +++ b/libavcodec/qsvdec.c
> > > > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > > > qsv_fifo_size(const
> > > > > AVFifoBuffer* fifo)
> > > > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > > > >  }
> > > > > 
> > > > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext
> > > > > *q)
> > > > > +static int qsv_decode_preinit(AVCodecContext *avctx,
> > > > > QSVContext
> > > > > *q,
> > > > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > 
> > Just: enum AVPixelFormat pix_fmt. Single one we need.
> 
> No, it must be array, and the last element of this array must be
> AV_PIX_FMT_NONE (else function ff_get_format() doesn't know how many
> elements contained by this array). 
> The first element of pix_fmt[] is HW pixel format, the second element
> of pix_fmt[] is SW pixel format. 
> Once again, I would like you to take a look the implementation detail
> of ff_get_format ().
> 

I understand that, but what you have in your patch is overcomplicate
design. You pass the whole array around from one function to another
while you just use single element from this array, i.e. pix_fmt[1] -
you need to pass only it and construct array when you will actually use
it. Original code had this closer together and was ok. But in your
refactor it you step into problem.

Here is the patch which I think you need to amend into this change: htt
ps://github.com/lizhong1008/ffmpeg-1/pull/1
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-14 Thread Li, Zhong
> From: Rogozhkin, Dmitry V
> Sent: Tuesday, March 12, 2019 8:04 AM
> To: Li, Zhong ; ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current
> parser with MFXVideoDECODE_DecodeHeader()
> 
> pix_fmts[1] is misleading. And I think it can be quite easily avoided.
> 
> If I understand the code correctly, qsv_decode_preinit is the place (and the
> only place) where you need an array of pix_fmts. You actually request
> ffmpeg to select one of the formats and program it into avctx.
> Is that right?
> 
> If so, could we try to define the array exactly in this function and avoid
> passing the whole array around? See comments below for suggestions...
> 
> 
> On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > > -Original Message-
> > > From: Rogozhkin, Dmitry V
> > > Sent: Saturday, March 9, 2019 8:48 AM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Li, Zhong 
> > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > current parser with MFXVideoDECODE_DecodeHeader()
> > >
> > > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > > (E.g:
> > > > sps declares a wrong level_idc, smaller than it should be).
> > > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > > VP9
> > > > since current parser can't provide enough information.
> > > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > > and
> > > > merged as commit 1acb19d, but was overwritten when merged libav
> > > > patches (commit: 1f26a23) without any explain.
> > > >
> > > > v2: split decode header from decode_init, and call it for
> > > > everyframe to detect format/resoultion change. It can fix some
> > > > regression issues such as hevc 10bits decoding.
> > > >
> > > > Signed-off-by: Zhong Li 
> > > > ---
> > > >  libavcodec/qsvdec.c   | 172
> --
> > > > 
> > > > 
> > > >  libavcodec/qsvdec.h   |   2 +
> > > >  libavcodec/qsvdec_h2645.c |   1 +
> > > >  libavcodec/qsvdec_other.c |   1 +
> > > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > >
> > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > > 4a0be811fb..b78026e14d 100644
> > > > --- a/libavcodec/qsvdec.c
> > > > +++ b/libavcodec/qsvdec.c
> > > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > > qsv_fifo_size(const
> > > > AVFifoBuffer* fifo)
> > > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > > >  }
> > > >
> > > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > > *q,
> > > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> 
> Just: enum AVPixelFormat pix_fmt. Single one we need.

No, it must be array, and the last element of this array must be 
AV_PIX_FMT_NONE (else function ff_get_format() doesn't know how many elements 
contained by this array). 
The first element of pix_fmt[] is HW pixel format, the second element of 
pix_fmt[] is SW pixel format. 
Once again, I would like you to take a look the implementation detail of 
ff_get_format ().

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-14 Thread Li, Zhong
> From: Rogozhkin, Dmitry V
> Sent: Tuesday, March 12, 2019 7:37 AM
> To: Li, Zhong ; ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current
> parser with MFXVideoDECODE_DecodeHeader()
> 
> On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > > -Original Message-
> > > From: Rogozhkin, Dmitry V
> > > Sent: Saturday, March 9, 2019 8:48 AM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Li, Zhong 
> > > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > > current parser with MFXVideoDECODE_DecodeHeader()
> > >
> > > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > > (E.g:
> > > > sps declares a wrong level_idc, smaller than it should be).
> > > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > > VP9
> > > > since current parser can't provide enough information.
> > > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > > and
> > > > merged as commit 1acb19d, but was overwritten when merged libav
> > > > patches (commit: 1f26a23) without any explain.
> > > >
> > > > v2: split decode header from decode_init, and call it for
> > > > everyframe to detect format/resoultion change. It can fix some
> > > > regression issues such as hevc 10bits decoding.
> > > >
> > > > Signed-off-by: Zhong Li 
> > > > ---
> > > >  libavcodec/qsvdec.c   | 172
> --
> > > > 
> > > > 
> > > >  libavcodec/qsvdec.h   |   2 +
> > > >  libavcodec/qsvdec_h2645.c |   1 +
> > > >  libavcodec/qsvdec_other.c |   1 +
> > > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > >
> > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > > 4a0be811fb..b78026e14d 100644
> > > > --- a/libavcodec/qsvdec.c
> > > > +++ b/libavcodec/qsvdec.c
> > > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > > qsv_fifo_size(const
> > > > AVFifoBuffer* fifo)
> > > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > > >  }
> > > >
> > > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > > *q,
> > > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > > >  {
> > > > -const AVPixFmtDescriptor *desc;
> > > >  mfxSession session = NULL;
> > > >  int iopattern = 0;
> > > > -mfxVideoParam param = { 0 };
> > > > -int frame_width  = avctx->coded_width;
> > > > -int frame_height = avctx->coded_height;
> > > >  int ret;
> > > >
> > > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > > -if (!desc)
> > > > -return AVERROR_BUG;
> > > > +ret = ff_get_format(avctx, pix_fmts);
> > > > +if (ret < 0) {
> > > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > > +return ret;
> > > > +}
> > > >
> > > >  if (!q->async_fifo) {
> > > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > >  return ret;
> > > >  }
> > > >
> > > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > > -if (ret < 0)
> > > > -return ret;
> > > > +param->IOPattern   = q->iopattern;
> > > > +param->AsyncDepth  = q->async_depth;
> > > > +param->ExtParam= q->ext_buffers;
> > > > +param->NumExtParam = q->nb_ext_buffers;
> > > >
> > > > -param.mfx.CodecId  = ret;
> > > > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx-
> > > > >codec_id,
> > > > avctx->profile);
> > > > -param.mfx.CodecLevel   = avctx->level ==
> > >
> > > FF_LEVEL_UNKNOWN ?
> > > > MFX_LE

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-11 Thread Rogozhkin, Dmitry V
pix_fmts[1] is misleading. And I think it can be quite easily
avoided.

If I understand the code correctly, qsv_decode_preinit is the place
(and the only place) where you need an array of pix_fmts. You actually
request ffmpeg to select one of the formats and program it into avctx.
Is that right?

If so, could we try to define the array exactly in this function and
avoid passing the whole array around? See comments below for
suggestions...


On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > -Original Message-
> > From: Rogozhkin, Dmitry V
> > Sent: Saturday, March 9, 2019 8:48 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Li, Zhong 
> > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > current
> > parser with MFXVideoDECODE_DecodeHeader()
> > 
> > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > (E.g:
> > > sps declares a wrong level_idc, smaller than it should be).
> > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > VP9
> > > since current parser can't provide enough information.
> > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > and
> > > merged as commit 1acb19d, but was overwritten when merged libav
> > > patches (commit: 1f26a23) without any explain.
> > > 
> > > v2: split decode header from decode_init, and call it for
> > > everyframe
> > > to detect format/resoultion change. It can fix some regression
> > > issues
> > > such as hevc 10bits decoding.
> > > 
> > > Signed-off-by: Zhong Li 
> > > ---
> > >  libavcodec/qsvdec.c   | 172 --
> > > 
> > > 
> > >  libavcodec/qsvdec.h   |   2 +
> > >  libavcodec/qsvdec_h2645.c |   1 +
> > >  libavcodec/qsvdec_other.c |   1 +
> > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > 
> > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > 4a0be811fb..b78026e14d 100644
> > > --- a/libavcodec/qsvdec.c
> > > +++ b/libavcodec/qsvdec.c
> > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > qsv_fifo_size(const
> > > AVFifoBuffer* fifo)
> > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > >  }
> > > 
> > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > *q,
> > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)

Just: enum AVPixelFormat pix_fmt. Single one we need.

> > >  {
> > > -const AVPixFmtDescriptor *desc;
> > >  mfxSession session = NULL;
> > >  int iopattern = 0;
> > > -mfxVideoParam param = { 0 };
> > > -int frame_width  = avctx->coded_width;
> > > -int frame_height = avctx->coded_height;
> > >  int ret;
> > > 
> > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > -if (!desc)
> > > -return AVERROR_BUG;

enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
   pix_fmt,  // <<< use the one we got
in function call
   AV_PIX_FMT_NONE };

> > > +ret = ff_get_format(avctx, pix_fmts);
> > > +if (ret < 0) {
> > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > +return ret;
> > > +}
> > > 
> > >  if (!q->async_fifo) {
> > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > >  return ret;
> > >  }
> > > 
> > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > -if (ret < 0)
> > > -return ret;
> > > +param->IOPattern   = q->iopattern;
> > > +param->AsyncDepth  = q->async_depth;
> > > +param->ExtParam= q->ext_buffers;
> > > +param->NumExtParam = q->nb_ext_buffers;
> > > 
> > > -param.mfx.CodecId  = ret;
> > > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx-
> > > >codec_id,
> > > avctx->profile);
> > > -param.mfx.CodecLevel   = avctx->level ==
> > 
> > FF_LEV

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-11 Thread Rogozhkin, Dmitry V
On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > -Original Message-
> > From: Rogozhkin, Dmitry V
> > Sent: Saturday, March 9, 2019 8:48 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Li, Zhong 
> > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > current
> > parser with MFXVideoDECODE_DecodeHeader()
> > 
> > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > (E.g:
> > > sps declares a wrong level_idc, smaller than it should be).
> > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > VP9
> > > since current parser can't provide enough information.
> > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > and
> > > merged as commit 1acb19d, but was overwritten when merged libav
> > > patches (commit: 1f26a23) without any explain.
> > > 
> > > v2: split decode header from decode_init, and call it for
> > > everyframe
> > > to detect format/resoultion change. It can fix some regression
> > > issues
> > > such as hevc 10bits decoding.
> > > 
> > > Signed-off-by: Zhong Li 
> > > ---
> > >  libavcodec/qsvdec.c   | 172 --
> > > 
> > > 
> > >  libavcodec/qsvdec.h   |   2 +
> > >  libavcodec/qsvdec_h2645.c |   1 +
> > >  libavcodec/qsvdec_other.c |   1 +
> > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > 
> > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > 4a0be811fb..b78026e14d 100644
> > > --- a/libavcodec/qsvdec.c
> > > +++ b/libavcodec/qsvdec.c
> > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > qsv_fifo_size(const
> > > AVFifoBuffer* fifo)
> > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > >  }
> > > 
> > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > *q,
> > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > >  {
> > > -const AVPixFmtDescriptor *desc;
> > >  mfxSession session = NULL;
> > >  int iopattern = 0;
> > > -mfxVideoParam param = { 0 };
> > > -int frame_width  = avctx->coded_width;
> > > -int frame_height = avctx->coded_height;
> > >  int ret;
> > > 
> > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > -if (!desc)
> > > -return AVERROR_BUG;
> > > +ret = ff_get_format(avctx, pix_fmts);
> > > +if (ret < 0) {
> > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > +return ret;
> > > +}
> > > 
> > >  if (!q->async_fifo) {
> > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > >  return ret;
> > >  }
> > > 
> > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > -if (ret < 0)
> > > -return ret;
> > > +param->IOPattern   = q->iopattern;
> > > +param->AsyncDepth  = q->async_depth;
> > > +param->ExtParam= q->ext_buffers;
> > > +param->NumExtParam = q->nb_ext_buffers;
> > > 
> > > -param.mfx.CodecId  = ret;
> > > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx-
> > > >codec_id,
> > > avctx->profile);
> > > -param.mfx.CodecLevel   = avctx->level ==
> > 
> > FF_LEVEL_UNKNOWN ?
> > > MFX_LEVEL_UNKNOWN : avctx->level;
> > > -
> > > -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> > > -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> > > -param.mfx.FrameInfo.Shift  = desc->comp[0].depth >
> > 
> > 8;
> > > -param.mfx.FrameInfo.FourCC = q->fourcc;
> > > -param.mfx.FrameInfo.Width  = frame_width;
> > > -param.mfx.FrameInfo.Height = frame_height;
> > > -param.mfx.FrameInfo.ChromaFormat   =
> > 
> > MFX_CHROMAFORMAT_YUV420;
> > > -
> > > -swi

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-11 Thread Rogozhkin, Dmitry V
On Mon, 2019-03-11 at 17:23 +0800, Li, Zhong wrote:
> > -Original Message-
> > From: Rogozhkin, Dmitry V
> > Sent: Saturday, March 9, 2019 8:48 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Li, Zhong 
> > Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace
> > current
> > parser with MFXVideoDECODE_DecodeHeader()
> > 
> > On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > > Using MSDK parser can improve qsv decoder pass rate in some cases
> > > (E.g:
> > > sps declares a wrong level_idc, smaller than it should be).
> > > And it is necessary for adding new qsv decoders such as MJPEG and
> > > VP9
> > > since current parser can't provide enough information.
> > > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html
> > > and
> > > merged as commit 1acb19d, but was overwritten when merged libav
> > > patches (commit: 1f26a23) without any explain.
> > > 
> > > v2: split decode header from decode_init, and call it for
> > > everyframe
> > > to detect format/resoultion change. It can fix some regression
> > > issues
> > > such as hevc 10bits decoding.
> > > 
> > > Signed-off-by: Zhong Li 
> > > ---
> > >  libavcodec/qsvdec.c   | 172 --
> > > 
> > > 
> > >  libavcodec/qsvdec.h   |   2 +
> > >  libavcodec/qsvdec_h2645.c |   1 +
> > >  libavcodec/qsvdec_other.c |   1 +
> > >  4 files changed, 93 insertions(+), 83 deletions(-)
> > > 
> > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > > 4a0be811fb..b78026e14d 100644
> > > --- a/libavcodec/qsvdec.c
> > > +++ b/libavcodec/qsvdec.c
> > > @@ -120,19 +120,17 @@ static inline unsigned int
> > > qsv_fifo_size(const
> > > AVFifoBuffer* fifo)
> > >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> > >  }
> > > 
> > > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext
> > > *q,
> > > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> > >  {
> > > -const AVPixFmtDescriptor *desc;
> > >  mfxSession session = NULL;
> > >  int iopattern = 0;
> > > -mfxVideoParam param = { 0 };
> > > -int frame_width  = avctx->coded_width;
> > > -int frame_height = avctx->coded_height;
> > >  int ret;
> > > 
> > > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > > -if (!desc)
> > > -return AVERROR_BUG;
> > > +ret = ff_get_format(avctx, pix_fmts);
> > > +if (ret < 0) {
> > > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > > +return ret;
> > > +}
> > > 
> > >  if (!q->async_fifo) {
> > >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > >  return ret;
> > >  }
> > > 
> > > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > > -if (ret < 0)
> > > -return ret;
> > > +param->IOPattern   = q->iopattern;
> > > +param->AsyncDepth  = q->async_depth;
> > > +param->ExtParam= q->ext_buffers;
> > > +param->NumExtParam = q->nb_ext_buffers;
> > > 
> > > -param.mfx.CodecId  = ret;
> > > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx-
> > > >codec_id,
> > > avctx->profile);
> > > -param.mfx.CodecLevel   = avctx->level ==
> > 
> > FF_LEVEL_UNKNOWN ?
> > > MFX_LEVEL_UNKNOWN : avctx->level;
> > > -
> > > -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> > > -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> > > -param.mfx.FrameInfo.Shift  = desc->comp[0].depth >
> > 
> > 8;
> > > -param.mfx.FrameInfo.FourCC = q->fourcc;
> > > -param.mfx.FrameInfo.Width  = frame_width;
> > > -param.mfx.FrameInfo.Height = frame_height;
> > > -param.mfx.FrameInfo.ChromaFormat   =
> > 
> > MFX_CHROMAFORMAT_YUV420;
> > > -
> > > -swi

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-11 Thread Li, Zhong


> -Original Message-
> From: Rogozhkin, Dmitry V
> Sent: Saturday, March 9, 2019 8:48 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Li, Zhong 
> Subject: Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current
> parser with MFXVideoDECODE_DecodeHeader()
> 
> On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> > Using MSDK parser can improve qsv decoder pass rate in some cases
> > (E.g:
> > sps declares a wrong level_idc, smaller than it should be).
> > And it is necessary for adding new qsv decoders such as MJPEG and VP9
> > since current parser can't provide enough information.
> > Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> > https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html and
> > merged as commit 1acb19d, but was overwritten when merged libav
> > patches (commit: 1f26a23) without any explain.
> >
> > v2: split decode header from decode_init, and call it for everyframe
> > to detect format/resoultion change. It can fix some regression issues
> > such as hevc 10bits decoding.
> >
> > Signed-off-by: Zhong Li 
> > ---
> >  libavcodec/qsvdec.c   | 172 --
> > 
> >  libavcodec/qsvdec.h   |   2 +
> >  libavcodec/qsvdec_h2645.c |   1 +
> >  libavcodec/qsvdec_other.c |   1 +
> >  4 files changed, 93 insertions(+), 83 deletions(-)
> >
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > 4a0be811fb..b78026e14d 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -120,19 +120,17 @@ static inline unsigned int qsv_fifo_size(const
> > AVFifoBuffer* fifo)
> >  return av_fifo_size(fifo) / qsv_fifo_item_size();
> >  }
> >
> > -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> > +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q,
> > enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
> >  {
> > -const AVPixFmtDescriptor *desc;
> >  mfxSession session = NULL;
> >  int iopattern = 0;
> > -mfxVideoParam param = { 0 };
> > -int frame_width  = avctx->coded_width;
> > -int frame_height = avctx->coded_height;
> >  int ret;
> >
> > -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> > -if (!desc)
> > -return AVERROR_BUG;
> > +ret = ff_get_format(avctx, pix_fmts);
> > +if (ret < 0) {
> > +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> > +return ret;
> > +}
> >
> >  if (!q->async_fifo) {
> >  q->async_fifo = av_fifo_alloc(q->async_depth *
> > qsv_fifo_item_size()); @@ -170,48 +168,72 @@ static int
> > qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> >  return ret;
> >  }
> >
> > -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> > -if (ret < 0)
> > -return ret;
> > +param->IOPattern   = q->iopattern;
> > +param->AsyncDepth  = q->async_depth;
> > +param->ExtParam= q->ext_buffers;
> > +param->NumExtParam = q->nb_ext_buffers;
> >
> > -param.mfx.CodecId  = ret;
> > -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id,
> > avctx->profile);
> > -param.mfx.CodecLevel   = avctx->level ==
> FF_LEVEL_UNKNOWN ?
> > MFX_LEVEL_UNKNOWN : avctx->level;
> > -
> > -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> > -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> > -param.mfx.FrameInfo.Shift  = desc->comp[0].depth >
> 8;
> > -param.mfx.FrameInfo.FourCC = q->fourcc;
> > -param.mfx.FrameInfo.Width  = frame_width;
> > -param.mfx.FrameInfo.Height = frame_height;
> > -param.mfx.FrameInfo.ChromaFormat   =
> MFX_CHROMAFORMAT_YUV420;
> > -
> > -switch (avctx->field_order) {
> > -case AV_FIELD_PROGRESSIVE:
> > -param.mfx.FrameInfo.PicStruct =
> MFX_PICSTRUCT_PROGRESSIVE;
> > -break;
> > -case AV_FIELD_TT:
> > -param.mfx.FrameInfo.PicStruct =
> MFX_PICSTRUCT_FIELD_TFF;
> > -break;
> > -case AV_FIELD_BB:
> > -param.mfx.FrameInfo.PicStruct =
> MFX_PICSTRUCT_FIELD_BFF;
> > -break;
> > -default:
> > -param.mfx.FrameInfo.PicStruct =
> MFX_PICSTRUCT_UNKNOWN;
> > -break;
> > -}
> > +return 0;
> > + }
> >
> > -param.IOPattern 

Re: [FFmpeg-devel] [PATCH v3 3/6] lavc/qsvdec: Replace current parser with MFXVideoDECODE_DecodeHeader()

2019-03-08 Thread Rogozhkin, Dmitry V
On Fri, 2019-03-08 at 15:40 +0800, Zhong Li wrote:
> Using MSDK parser can improve qsv decoder pass rate in some cases
> (E.g:
> sps declares a wrong level_idc, smaller than it should be).
> And it is necessary for adding new qsv decoders such as MJPEG and VP9
> since current parser can't provide enough information.
> Actually using MFXVideoDECODE_DecodeHeader() was disscussed at
> https://ffmpeg.org/pipermail/ffmpeg-devel/2015-July/175734.html and
> merged as commit 1acb19d,
> but was overwritten when merged libav patches (commit: 1f26a23)
> without any explain.
> 
> v2: split decode header from decode_init, and call it for everyframe
> to
> detect format/resoultion change. It can fix some regression issues
> such
> as hevc 10bits decoding.
> 
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvdec.c   | 172 --
> 
>  libavcodec/qsvdec.h   |   2 +
>  libavcodec/qsvdec_h2645.c |   1 +
>  libavcodec/qsvdec_other.c |   1 +
>  4 files changed, 93 insertions(+), 83 deletions(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 4a0be811fb..b78026e14d 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -120,19 +120,17 @@ static inline unsigned int qsv_fifo_size(const
> AVFifoBuffer* fifo)
>  return av_fifo_size(fifo) / qsv_fifo_item_size();
>  }
>  
> -static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
> +static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q,
> enum AVPixelFormat *pix_fmts, mfxVideoParam *param)
>  {
> -const AVPixFmtDescriptor *desc;
>  mfxSession session = NULL;
>  int iopattern = 0;
> -mfxVideoParam param = { 0 };
> -int frame_width  = avctx->coded_width;
> -int frame_height = avctx->coded_height;
>  int ret;
>  
> -desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
> -if (!desc)
> -return AVERROR_BUG;
> +ret = ff_get_format(avctx, pix_fmts);
> +if (ret < 0) {
> +q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;
> +return ret;
> +}
>  
>  if (!q->async_fifo) {
>  q->async_fifo = av_fifo_alloc(q->async_depth *
> qsv_fifo_item_size());
> @@ -170,48 +168,72 @@ static int qsv_decode_init(AVCodecContext
> *avctx, QSVContext *q)
>  return ret;
>  }
>  
> -ret = ff_qsv_codec_id_to_mfx(avctx->codec_id);
> -if (ret < 0)
> -return ret;
> +param->IOPattern   = q->iopattern;
> +param->AsyncDepth  = q->async_depth;
> +param->ExtParam= q->ext_buffers;
> +param->NumExtParam = q->nb_ext_buffers;
>  
> -param.mfx.CodecId  = ret;
> -param.mfx.CodecProfile = ff_qsv_profile_to_mfx(avctx->codec_id,
> avctx->profile);
> -param.mfx.CodecLevel   = avctx->level == FF_LEVEL_UNKNOWN ?
> MFX_LEVEL_UNKNOWN : avctx->level;
> -
> -param.mfx.FrameInfo.BitDepthLuma   = desc->comp[0].depth;
> -param.mfx.FrameInfo.BitDepthChroma = desc->comp[0].depth;
> -param.mfx.FrameInfo.Shift  = desc->comp[0].depth > 8;
> -param.mfx.FrameInfo.FourCC = q->fourcc;
> -param.mfx.FrameInfo.Width  = frame_width;
> -param.mfx.FrameInfo.Height = frame_height;
> -param.mfx.FrameInfo.ChromaFormat   = MFX_CHROMAFORMAT_YUV420;
> -
> -switch (avctx->field_order) {
> -case AV_FIELD_PROGRESSIVE:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
> -break;
> -case AV_FIELD_TT:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
> -break;
> -case AV_FIELD_BB:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
> -break;
> -default:
> -param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_UNKNOWN;
> -break;
> -}
> +return 0;
> + }
>  
> -param.IOPattern   = q->iopattern;
> -param.AsyncDepth  = q->async_depth;
> -param.ExtParam= q->ext_buffers;
> -param.NumExtParam = q->nb_ext_buffers;
> +static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q,
> mfxVideoParam *param)
> +{
> +int ret;
>  
> -ret = MFXVideoDECODE_Init(q->session, );
> +avctx->width= param->mfx.FrameInfo.CropW;
> +avctx->height   = param->mfx.FrameInfo.CropH;
> +avctx->coded_width  = param->mfx.FrameInfo.Width;
> +avctx->coded_height = param->mfx.FrameInfo.Height;
> +avctx->level= param->mfx.CodecLevel;
> +avctx->profile  = param->mfx.CodecProfile;
> +avctx->field_order  = ff_qsv_map_picstruct(param-
> >mfx.FrameInfo.PicStruct);
> +avctx->pix_fmt  = ff_qsv_map_fourcc(param-
> >mfx.FrameInfo.FourCC);
> +
> +ret = MFXVideoDECODE_Init(q->session, param);
>  if (ret < 0)
>  return ff_qsv_print_error(avctx, ret,
>    "Error initializing the MFX video
> decoder");
>  
> -q->frame_info = param.mfx.FrameInfo;
> +q->frame_info = param->mfx.FrameInfo;
> +
> +return 0;
> +}
> +
> +static int qsv_decode_header(AVCodecContext *avctx,