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

wenbin.chen at intel.com wenbin.chen at intel.com
Tue Jan 26 04:32:13 EET 2021


From: Wenbinc-Bin <wenbin.chen at 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 at intel.com>
---
 libavcodec/qsvdec.c | 2 ++
 1 file changed, 2 insertions(+)

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;
-- 
2.25.1



More information about the ffmpeg-devel mailing list