[FFmpeg-devel] [PATCH 3/3] libavcodec/qsvdec: using suggested num to set init_pool_size
Chen, Wenbin
wenbin.chen at intel.com
Thu May 6 06:07:08 EEST 2021
Ping on this patch.
> -----Original Message-----
> From: Chen, Wenbin <wenbin.chen at intel.com>
> Sent: Monday, April 26, 2021 11:04 AM
> To: ffmpeg-devel at ffmpeg.org
> Cc: Chen, Wenbin <wenbin.chen at intel.com>
> Subject: [PATCH 3/3] libavcodec/qsvdec: using suggested num to set
> init_pool_size
>
> From: Wenbinc-Bin <wenbin.chen at intel.com>
>
> 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.
>
> Sigend-off-by Wenbin Chen <wenbin.chen at intel.com>
> Signed-off-by Guangxin Xu <guangxin.xu at intel.com>
> ---
> fftools/ffmpeg_qsv.c | 9 ++++++++-
> libavcodec/qsvdec.c | 14 ++++++++++++++
> 2 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/fftools/ffmpeg_qsv.c b/fftools/ffmpeg_qsv.c
> index 960c88b69d..3862dc1e7d 100644
> --- a/fftools/ffmpeg_qsv.c
> +++ b/fftools/ffmpeg_qsv.c
> @@ -74,6 +74,7 @@ int qsv_init(AVCodecContext *s)
> InputStream *ist = s->opaque;
> AVHWFramesContext *frames_ctx;
> AVQSVFramesContext *frames_hwctx;
> + int suggest_pool_size;
> int ret;
>
> if (!hw_device_ctx) {
> @@ -82,6 +83,12 @@ int qsv_init(AVCodecContext *s)
> return ret;
> }
>
> + suggest_pool_size = 0;
> + if (ist->hw_frames_ctx) {
> + frames_ctx = (AVHWFramesContext *)ist->hw_frames_ctx->data;
> + suggest_pool_size = frames_ctx->initial_pool_size;
> + }
> +
> av_buffer_unref(&ist->hw_frames_ctx);
> ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
> if (!ist->hw_frames_ctx)
> @@ -94,7 +101,7 @@ int qsv_init(AVCodecContext *s)
> frames_ctx->height = FFALIGN(s->coded_height, 32);
> frames_ctx->format = AV_PIX_FMT_QSV;
> frames_ctx->sw_format = s->sw_pix_fmt;
> - frames_ctx->initial_pool_size = 64 + s->extra_hw_frames;
> + frames_ctx->initial_pool_size = suggest_pool_size + 16 + s-
> >extra_hw_frames;
> frames_hwctx->frame_type =
> MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
>
> ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index fe416e74ca..f7cd33cc74 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -643,18 +643,32 @@ static int qsv_process_data(AVCodecContext
> *avctx, QSVContext *q,
> }
>
> if (q->reinit_flag || !q->session) {
> + mfxFrameAllocRequest request;
> + AVHWFramesContext *hw_frames_ctx;
> + memset(&request, 0, sizeof(request));
> +
> q->reinit_flag = 0;
> ret = qsv_decode_header(avctx, q, pkt, pix_fmt, ¶m);
> if (ret < 0) {
> 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");
> +
> + if (avctx->hw_frames_ctx) {
> + hw_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx-
> >data;
> + hw_frames_ctx->initial_pool_size = request.NumFrameSuggested;
> + }
> +
> ret = qsv_decode_preinit(avctx, q, pix_fmt, ¶m);
> if (ret < 0)
> goto reinit_fail;
> --
> 2.25.1
More information about the ffmpeg-devel
mailing list