* [FFmpeg-devel] [PATCH v2 1/3] libavcodec/qsvdec: reinit decoder according to decode() return value
@ 2022-03-18 6:25 Wenbin Chen
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 2/3] libavcodec/qsvdec: remove redundant decodeHeader() Wenbin Chen
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size Wenbin Chen
0 siblings, 2 replies; 7+ messages in thread
From: Wenbin Chen @ 2022-03-18 6:25 UTC (permalink / raw)
To: ffmpeg-devel
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>
Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
---
libavcodec/qsvdec.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 1b5bf85cb6..0b5e416867 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -630,6 +630,13 @@ 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_DEBUG, "Video parameter change\n");
+ av_freep(&sync);
+ return 0;
+ }
+
if (ret != MFX_ERR_NONE &&
ret != MFX_ERR_MORE_DATA &&
ret != MFX_WRN_VIDEO_PARAM_CHANGED &&
@@ -782,9 +789,9 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
- 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) {
--
2.32.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/3] libavcodec/qsvdec: remove redundant decodeHeader()
2022-03-18 6:25 [FFmpeg-devel] [PATCH v2 1/3] libavcodec/qsvdec: reinit decoder according to decode() return value Wenbin Chen
@ 2022-03-18 6:25 ` Wenbin Chen
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size Wenbin Chen
1 sibling, 0 replies; 7+ messages in thread
From: Wenbin Chen @ 2022-03-18 6:25 UTC (permalink / raw)
To: ffmpeg-devel
Since ffmpeg-qsv uses return value to reinit decoder, it doesn't need to
decode header each time. Move qsv_decode_header's position so that
it will be called only if codec needed to be reinitialized.
Rearrange the code of flushing decoder and re-init decoder operation.
Remove the buffer_count and use the got_frame to decide whether the
decoder is drain.
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
---
libavcodec/qsvdec.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 0b5e416867..210bd0c1d5 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -82,7 +82,6 @@ typedef struct QSVContext {
AVFifo *async_fifo;
int zero_consume_run;
- int buffered_count;
int reinit_flag;
enum AVPixelFormat orig_pix_fmt;
@@ -653,8 +652,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
++q->zero_consume_run;
if (q->zero_consume_run > 1)
ff_qsv_print_warning(avctx, ret, "A decode call did not consume any data");
- } else if (!*sync && bs.DataOffset) {
- ++q->buffered_count;
} else {
q->zero_consume_run = 0;
}
@@ -787,20 +784,24 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
if (!avctx->coded_height)
avctx->coded_height = 720;
- ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
-
- 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))) {
+ /* decode zero-size pkt to flush the buffered pkt before reinit */
+ if (q->reinit_flag) {
AVPacket zero_pkt = {0};
+ ret = qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
+ if (ret < 0 || *got_frame)
+ return ret;
+ }
- if (q->buffered_count) {
- q->reinit_flag = 1;
- /* decode zero-size pkt to flush the buffered pkt before reinit */
- q->buffered_count--;
- return qsv_decode(avctx, q, frame, got_frame, &zero_pkt);
- }
+ if (q->reinit_flag || !q->session || !q->initialized) {
q->reinit_flag = 0;
+ ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
+ if (ret < 0) {
+ if (ret == AVERROR(EAGAIN))
+ av_log(avctx, AV_LOG_INFO, "More data is required to decode header\n");
+ else
+ av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
+ goto reinit_fail;
+ }
q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
--
2.32.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size
2022-03-18 6:25 [FFmpeg-devel] [PATCH v2 1/3] libavcodec/qsvdec: reinit decoder according to decode() return value Wenbin Chen
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 2/3] libavcodec/qsvdec: remove redundant decodeHeader() Wenbin Chen
@ 2022-03-18 6:25 ` Wenbin Chen
2022-03-18 7:40 ` Soft Works
1 sibling, 1 reply; 7+ messages in thread
From: Wenbin Chen @ 2022-03-18 6:25 UTC (permalink / raw)
To: ffmpeg-devel
The init_pool_size is set to be 64 and it is too many.
Use IOSurfQuery to get NumFrameSuggest which is the suggested
number of frame that needed to be allocated when initializing the decoder.
Considering that the hevc_qsv encoder uses the most frame buffer,
async is 4 (default) and max_b_frames is 8 (default) and decoder
may followed by VPP, use NumFrameSuggest + 16 to set init_pool_size.
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
---
libavcodec/qsvdec.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index 210bd0c1d5..9875d3d632 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -88,7 +88,7 @@ typedef struct QSVContext {
uint32_t fourcc;
mfxFrameInfo frame_info;
AVBufferPool *pool;
-
+ int suggest_pool_size;
int initialized;
// options set by the caller
@@ -275,7 +275,7 @@ static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
hwframes_ctx->height = FFALIGN(avctx->coded_height, 32);
hwframes_ctx->format = AV_PIX_FMT_QSV;
hwframes_ctx->sw_format = avctx->sw_pix_fmt;
- hwframes_ctx->initial_pool_size = 64 + avctx->extra_hw_frames;
+ hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 + avctx->extra_hw_frames;
frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
@@ -793,6 +793,9 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
}
if (q->reinit_flag || !q->session || !q->initialized) {
+ mfxFrameAllocRequest request;
+ memset(&request, 0, sizeof(request));
+
q->reinit_flag = 0;
ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
if (ret < 0) {
@@ -802,12 +805,19 @@ static int qsv_process_data(AVCodecContext *avctx, QSVContext *q,
av_log(avctx, AV_LOG_ERROR, "Error decoding header\n");
goto reinit_fail;
}
+ param.IOPattern = q->iopattern;
q->orig_pix_fmt = avctx->pix_fmt = pix_fmt = ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
avctx->coded_width = param.mfx.FrameInfo.Width;
avctx->coded_height = param.mfx.FrameInfo.Height;
+ ret = MFXVideoDECODE_QueryIOSurf(q->session, ¶m, &request);
+ if (ret < 0)
+ return ff_qsv_print_error(avctx, ret, "Error querying IO surface");
+
+ q->suggest_pool_size = request.NumFrameSuggested;
+
ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
if (ret < 0)
goto reinit_fail;
--
2.32.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size Wenbin Chen
@ 2022-03-18 7:40 ` Soft Works
2022-03-28 2:26 ` Xiang, Haihao
0 siblings, 1 reply; 7+ messages in thread
From: Soft Works @ 2022-03-18 7:40 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Wenbin Chen
> Sent: Friday, March 18, 2022 7:25 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using
> suggested num to set init_pool_size
>
> The init_pool_size is set to be 64 and it is too many.
> Use IOSurfQuery to get NumFrameSuggest which is the suggested
> number of frame that needed to be allocated when initializing the
> decoder.
> Considering that the hevc_qsv encoder uses the most frame buffer,
> async is 4 (default) and max_b_frames is 8 (default) and decoder
> may followed by VPP, use NumFrameSuggest + 16 to set init_pool_size.
>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
> ---
> libavcodec/qsvdec.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 210bd0c1d5..9875d3d632 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -88,7 +88,7 @@ typedef struct QSVContext {
> uint32_t fourcc;
> mfxFrameInfo frame_info;
> AVBufferPool *pool;
> -
> + int suggest_pool_size;
> int initialized;
>
> // options set by the caller
> @@ -275,7 +275,7 @@ static int qsv_decode_preinit(AVCodecContext
> *avctx, QSVContext *q, enum AVPixel
> hwframes_ctx->height = FFALIGN(avctx-
> >coded_height, 32);
> hwframes_ctx->format = AV_PIX_FMT_QSV;
> hwframes_ctx->sw_format = avctx->sw_pix_fmt;
> - hwframes_ctx->initial_pool_size = 64 + avctx-
> >extra_hw_frames;
> + hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 +
> avctx->extra_hw_frames;
> frames_hwctx->frame_type =
> MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
>
> ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
> @@ -793,6 +793,9 @@ static int qsv_process_data(AVCodecContext *avctx,
> QSVContext *q,
> }
>
> if (q->reinit_flag || !q->session || !q->initialized) {
> + mfxFrameAllocRequest request;
> + memset(&request, 0, sizeof(request));
> +
> q->reinit_flag = 0;
> ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
> if (ret < 0) {
> @@ -802,12 +805,19 @@ static int qsv_process_data(AVCodecContext
> *avctx, QSVContext *q,
> av_log(avctx, AV_LOG_ERROR, "Error decoding
> header\n");
> goto reinit_fail;
> }
> + param.IOPattern = q->iopattern;
>
> q->orig_pix_fmt = avctx->pix_fmt = pix_fmt =
> ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
>
> avctx->coded_width = param.mfx.FrameInfo.Width;
> avctx->coded_height = param.mfx.FrameInfo.Height;
>
> + ret = MFXVideoDECODE_QueryIOSurf(q->session, ¶m,
> &request);
> + if (ret < 0)
> + return ff_qsv_print_error(avctx, ret, "Error querying IO
> surface");
> +
> + q->suggest_pool_size = request.NumFrameSuggested;
> +
> ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
> if (ret < 0)
> goto reinit_fail;
> --
Thanks for the patch! I have that on my list for quite a while.
Will look at it shortly.
softworkz
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size
2022-03-18 7:40 ` Soft Works
@ 2022-03-28 2:26 ` Xiang, Haihao
2022-04-02 8:52 ` Xiang, Haihao
0 siblings, 1 reply; 7+ messages in thread
From: Xiang, Haihao @ 2022-03-28 2:26 UTC (permalink / raw)
To: ffmpeg-devel
On Fri, 2022-03-18 at 07:40 +0000, Soft Works wrote:
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Wenbin Chen
> > Sent: Friday, March 18, 2022 7:25 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Subject: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using
> > suggested num to set init_pool_size
> >
> > The init_pool_size is set to be 64 and it is too many.
> > Use IOSurfQuery to get NumFrameSuggest which is the suggested
> > number of frame that needed to be allocated when initializing the
> > decoder.
> > Considering that the hevc_qsv encoder uses the most frame buffer,
> > async is 4 (default) and max_b_frames is 8 (default) and decoder
> > may followed by VPP, use NumFrameSuggest + 16 to set init_pool_size.
> >
> > Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> > Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
> > ---
> > libavcodec/qsvdec.c | 14 ++++++++++++--
> > 1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > index 210bd0c1d5..9875d3d632 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -88,7 +88,7 @@ typedef struct QSVContext {
> > uint32_t fourcc;
> > mfxFrameInfo frame_info;
> > AVBufferPool *pool;
> > -
> > + int suggest_pool_size;
> > int initialized;
> >
> > // options set by the caller
> > @@ -275,7 +275,7 @@ static int qsv_decode_preinit(AVCodecContext
> > *avctx, QSVContext *q, enum AVPixel
> > hwframes_ctx->height = FFALIGN(avctx-
> > > coded_height, 32);
> >
> > hwframes_ctx->format = AV_PIX_FMT_QSV;
> > hwframes_ctx->sw_format = avctx->sw_pix_fmt;
> > - hwframes_ctx->initial_pool_size = 64 + avctx-
> > > extra_hw_frames;
> >
> > + hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 +
> > avctx->extra_hw_frames;
> > frames_hwctx->frame_type =
> > MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
> >
> > ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
> > @@ -793,6 +793,9 @@ static int qsv_process_data(AVCodecContext *avctx,
> > QSVContext *q,
> > }
> >
> > if (q->reinit_flag || !q->session || !q->initialized) {
> > + mfxFrameAllocRequest request;
> > + memset(&request, 0, sizeof(request));
> > +
> > q->reinit_flag = 0;
> > ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
> > if (ret < 0) {
> > @@ -802,12 +805,19 @@ static int qsv_process_data(AVCodecContext
> > *avctx, QSVContext *q,
> > av_log(avctx, AV_LOG_ERROR, "Error decoding
> > header\n");
> > goto reinit_fail;
> > }
> > + param.IOPattern = q->iopattern;
> >
> > q->orig_pix_fmt = avctx->pix_fmt = pix_fmt =
> > ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
> >
> > avctx->coded_width = param.mfx.FrameInfo.Width;
> > avctx->coded_height = param.mfx.FrameInfo.Height;
> >
> > + ret = MFXVideoDECODE_QueryIOSurf(q->session, ¶m,
> > &request);
> > + if (ret < 0)
> > + return ff_qsv_print_error(avctx, ret, "Error querying IO
> > surface");
> > +
> > + q->suggest_pool_size = request.NumFrameSuggested;
> > +
> > ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
> > if (ret < 0)
> > goto reinit_fail;
> > --
>
> Thanks for the patch! I have that on my list for quite a while.
> Will look at it shortly.
Hi Softworz,
This patchset LGTM and works well, do you have any comment ?
Thanks
Haihao
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size
2022-03-28 2:26 ` Xiang, Haihao
@ 2022-04-02 8:52 ` Xiang, Haihao
2022-04-06 12:01 ` Xiang, Haihao
0 siblings, 1 reply; 7+ messages in thread
From: Xiang, Haihao @ 2022-04-02 8:52 UTC (permalink / raw)
To: ffmpeg-devel
On Mon, 2022-03-28 at 02:26 +0000, Xiang, Haihao wrote:
> On Fri, 2022-03-18 at 07:40 +0000, Soft Works wrote:
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Wenbin Chen
> > > Sent: Friday, March 18, 2022 7:25 AM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using
> > > suggested num to set init_pool_size
> > >
> > > The init_pool_size is set to be 64 and it is too many.
> > > Use IOSurfQuery to get NumFrameSuggest which is the suggested
> > > number of frame that needed to be allocated when initializing the
> > > decoder.
> > > Considering that the hevc_qsv encoder uses the most frame buffer,
> > > async is 4 (default) and max_b_frames is 8 (default) and decoder
> > > may followed by VPP, use NumFrameSuggest + 16 to set init_pool_size.
> > >
> > > Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> > > Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
> > > ---
> > > libavcodec/qsvdec.c | 14 ++++++++++++--
> > > 1 file changed, 12 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > > index 210bd0c1d5..9875d3d632 100644
> > > --- a/libavcodec/qsvdec.c
> > > +++ b/libavcodec/qsvdec.c
> > > @@ -88,7 +88,7 @@ typedef struct QSVContext {
> > > uint32_t fourcc;
> > > mfxFrameInfo frame_info;
> > > AVBufferPool *pool;
> > > -
> > > + int suggest_pool_size;
> > > int initialized;
> > >
> > > // options set by the caller
> > > @@ -275,7 +275,7 @@ static int qsv_decode_preinit(AVCodecContext
> > > *avctx, QSVContext *q, enum AVPixel
> > > hwframes_ctx->height = FFALIGN(avctx-
> > > > coded_height, 32);
> > >
> > > hwframes_ctx->format = AV_PIX_FMT_QSV;
> > > hwframes_ctx->sw_format = avctx->sw_pix_fmt;
> > > - hwframes_ctx->initial_pool_size = 64 + avctx-
> > > > extra_hw_frames;
> > >
> > > + hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 +
> > > avctx->extra_hw_frames;
> > > frames_hwctx->frame_type =
> > > MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
> > >
> > > ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
> > > @@ -793,6 +793,9 @@ static int qsv_process_data(AVCodecContext *avctx,
> > > QSVContext *q,
> > > }
> > >
> > > if (q->reinit_flag || !q->session || !q->initialized) {
> > > + mfxFrameAllocRequest request;
> > > + memset(&request, 0, sizeof(request));
> > > +
> > > q->reinit_flag = 0;
> > > ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
> > > if (ret < 0) {
> > > @@ -802,12 +805,19 @@ static int qsv_process_data(AVCodecContext
> > > *avctx, QSVContext *q,
> > > av_log(avctx, AV_LOG_ERROR, "Error decoding
> > > header\n");
> > > goto reinit_fail;
> > > }
> > > + param.IOPattern = q->iopattern;
> > >
> > > q->orig_pix_fmt = avctx->pix_fmt = pix_fmt =
> > > ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
> > >
> > > avctx->coded_width = param.mfx.FrameInfo.Width;
> > > avctx->coded_height = param.mfx.FrameInfo.Height;
> > >
> > > + ret = MFXVideoDECODE_QueryIOSurf(q->session, ¶m,
> > > &request);
> > > + if (ret < 0)
> > > + return ff_qsv_print_error(avctx, ret, "Error querying IO
> > > surface");
> > > +
> > > + q->suggest_pool_size = request.NumFrameSuggested;
> > > +
> > > ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
> > > if (ret < 0)
> > > goto reinit_fail;
> > > --
> >
> > Thanks for the patch! I have that on my list for quite a while.
> > Will look at it shortly.
>
> Hi Softworz,
>
> This patchset LGTM and works well, do you have any comment ?
Ping, I'll apply this patchset in a few days if no more comment.
Regards
Haihao
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size
2022-04-02 8:52 ` Xiang, Haihao
@ 2022-04-06 12:01 ` Xiang, Haihao
0 siblings, 0 replies; 7+ messages in thread
From: Xiang, Haihao @ 2022-04-06 12:01 UTC (permalink / raw)
To: ffmpeg-devel
On Sat, 2022-04-02 at 08:52 +0000, Xiang, Haihao wrote:
> On Mon, 2022-03-28 at 02:26 +0000, Xiang, Haihao wrote:
> > On Fri, 2022-03-18 at 07:40 +0000, Soft Works wrote:
> > > > -----Original Message-----
> > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > > Wenbin Chen
> > > > Sent: Friday, March 18, 2022 7:25 AM
> > > > To: ffmpeg-devel@ffmpeg.org
> > > > Subject: [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using
> > > > suggested num to set init_pool_size
> > > >
> > > > The init_pool_size is set to be 64 and it is too many.
> > > > Use IOSurfQuery to get NumFrameSuggest which is the suggested
> > > > number of frame that needed to be allocated when initializing the
> > > > decoder.
> > > > Considering that the hevc_qsv encoder uses the most frame buffer,
> > > > async is 4 (default) and max_b_frames is 8 (default) and decoder
> > > > may followed by VPP, use NumFrameSuggest + 16 to set init_pool_size.
> > > >
> > > > Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> > > > Signed-off-by: Guangxin Xu <guangxin.xu@intel.com>
> > > > ---
> > > > libavcodec/qsvdec.c | 14 ++++++++++++--
> > > > 1 file changed, 12 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > > > index 210bd0c1d5..9875d3d632 100644
> > > > --- a/libavcodec/qsvdec.c
> > > > +++ b/libavcodec/qsvdec.c
> > > > @@ -88,7 +88,7 @@ typedef struct QSVContext {
> > > > uint32_t fourcc;
> > > > mfxFrameInfo frame_info;
> > > > AVBufferPool *pool;
> > > > -
> > > > + int suggest_pool_size;
> > > > int initialized;
> > > >
> > > > // options set by the caller
> > > > @@ -275,7 +275,7 @@ static int qsv_decode_preinit(AVCodecContext
> > > > *avctx, QSVContext *q, enum AVPixel
> > > > hwframes_ctx->height = FFALIGN(avctx-
> > > > > coded_height, 32);
> > > >
> > > > hwframes_ctx->format = AV_PIX_FMT_QSV;
> > > > hwframes_ctx->sw_format = avctx->sw_pix_fmt;
> > > > - hwframes_ctx->initial_pool_size = 64 + avctx-
> > > > > extra_hw_frames;
> > > >
> > > > + hwframes_ctx->initial_pool_size = q->suggest_pool_size + 16 +
> > > > avctx->extra_hw_frames;
> > > > frames_hwctx->frame_type =
> > > > MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
> > > >
> > > > ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
> > > > @@ -793,6 +793,9 @@ static int qsv_process_data(AVCodecContext *avctx,
> > > > QSVContext *q,
> > > > }
> > > >
> > > > if (q->reinit_flag || !q->session || !q->initialized) {
> > > > + mfxFrameAllocRequest request;
> > > > + memset(&request, 0, sizeof(request));
> > > > +
> > > > q->reinit_flag = 0;
> > > > ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
> > > > if (ret < 0) {
> > > > @@ -802,12 +805,19 @@ static int qsv_process_data(AVCodecContext
> > > > *avctx, QSVContext *q,
> > > > av_log(avctx, AV_LOG_ERROR, "Error decoding
> > > > header\n");
> > > > goto reinit_fail;
> > > > }
> > > > + param.IOPattern = q->iopattern;
> > > >
> > > > q->orig_pix_fmt = avctx->pix_fmt = pix_fmt =
> > > > ff_qsv_map_fourcc(param.mfx.FrameInfo.FourCC);
> > > >
> > > > avctx->coded_width = param.mfx.FrameInfo.Width;
> > > > avctx->coded_height = param.mfx.FrameInfo.Height;
> > > >
> > > > + ret = MFXVideoDECODE_QueryIOSurf(q->session, ¶m,
> > > > &request);
> > > > + if (ret < 0)
> > > > + return ff_qsv_print_error(avctx, ret, "Error querying IO
> > > > surface");
> > > > +
> > > > + q->suggest_pool_size = request.NumFrameSuggested;
> > > > +
> > > > ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
> > > > if (ret < 0)
> > > > goto reinit_fail;
> > > > --
> > >
> > > Thanks for the patch! I have that on my list for quite a while.
> > > Will look at it shortly.
> >
> > Hi Softworz,
> >
> > This patchset LGTM and works well, do you have any comment ?
>
> Ping, I'll apply this patchset in a few days if no more comment.
>
Applied, thx
-Haihao
_______________________________________________
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".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-06 12:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-18 6:25 [FFmpeg-devel] [PATCH v2 1/3] libavcodec/qsvdec: reinit decoder according to decode() return value Wenbin Chen
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 2/3] libavcodec/qsvdec: remove redundant decodeHeader() Wenbin Chen
2022-03-18 6:25 ` [FFmpeg-devel] [PATCH v2 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size Wenbin Chen
2022-03-18 7:40 ` Soft Works
2022-03-28 2:26 ` Xiang, Haihao
2022-04-02 8:52 ` Xiang, Haihao
2022-04-06 12:01 ` Xiang, Haihao
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git