From patchwork Tue Jan 26 02:32:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 25190 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2010D44BD9F for ; Tue, 26 Jan 2021 04:36:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 048AD68A33F; Tue, 26 Jan 2021 04:36:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42B9368A2BB for ; Tue, 26 Jan 2021 04:36:19 +0200 (EET) IronPort-SDR: 7FbL69pOsqp95Ev4ZGAo8JERN3+i3SZscfrkMt2Qvk9DSCD18qd9DxCCKDQEv+zT3A/hXP1EC/ lfWowMGGYjfg== X-IronPort-AV: E=McAfee;i="6000,8403,9875"; a="159015241" X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="159015241" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2021 18:36:18 -0800 IronPort-SDR: 8qkA7nV1ZBQDbYqMzg7qPFOcVcmIVy+XeuS55YuqOoIvKGJ7FfXqs0S5oG8LSInE9J1/5nO0tF EtoNBRAZAqSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="361797239" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.3]) by fmsmga008.fm.intel.com with ESMTP; 25 Jan 2021 18:36:17 -0800 From: wenbin.chen@intel.com To: ffmpeg-devel@ffmpeg.org Date: Tue, 26 Jan 2021 10:32:13 +0800 Message-Id: <20210126023213.146185-10-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126023213.146185-1-wenbin.chen@intel.com> References: <20210126023213.146185-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/10] libavcodec/qsvdec: move unref before get_format X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Wenbinc-Bin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Wenbinc-Bin 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 --- 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;