diff mbox series

[FFmpeg-devel,10/10] libavcodec/qsvdec: move unref before get_format

Message ID 20210126023213.146185-10-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel,01/10] libavcodec/qsvenc.c: add max_frame_size support for hevc_qsv | expand


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

Wenbin Chen Jan. 26, 2021, 2:32 a.m. UTC
From: Wenbinc-Bin <wenbin.chen@intel.com>

Qsv decoder needs to call preinit() twice to get NumFrameSuggest
to config init_pool_size. The hw_frame_ctx is released at the
second time calling preinit(). The hw_frame_ctx is AVBufferRef, so
it release the source when the last unref is called. When the old
context is released, the new one is already created, and somehow the device
memory is stil be taken, even if the destory memory function is called.
Moving unref before creating new context can solve this problem.

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


diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index fba7d9cee6..23494c217d 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -179,6 +179,8 @@  static int qsv_decode_preinit(AVCodecContext *avctx, QSVContext *q, enum AVPixel
         pix_fmt,        /* system memory format obtained from bitstream parser */
         AV_PIX_FMT_NONE };
+    av_buffer_unref(&q->frames_ctx.mids_buf);
+    av_buffer_unref(&q->frames_ctx.hw_frames_ctx);
     ret = ff_get_format(avctx, pix_fmts);
     if (ret < 0) {
         q->orig_pix_fmt = avctx->pix_fmt = AV_PIX_FMT_NONE;