From patchwork Tue Nov 30 08:44:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 31833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp7352175iob; Tue, 30 Nov 2021 00:48:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVpmkYGfRBUpqXB8Q7vpjp+k6Xm7YdFCSLStmf93iH0IZcxjNVaK7z9vHSPzOI4aZNDVPq X-Received: by 2002:a17:906:c7c9:: with SMTP id dc9mr66080927ejb.34.1638262101012; Tue, 30 Nov 2021 00:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638262101; cv=none; d=google.com; s=arc-20160816; b=V2L3JfwCFMTCnYNGPG0WJyL7GLQQKFHPTc03+h23otqjKv/s/Lc6sWsYeHUL7JD5ni L08AG3FmLDYShtDjKmCdv/lHLjIbHVfKkUVl+2rdHasw4BkcG2ao69fBJ+0XXx9s2Svd qt90/Ztq/LavT0QRlxcvWM+J8Zd8jVDLxJs7AjLM3TzWT7osY0APWeGncn6CQBiZtoXX DrQiLy8km4KykuzJ9VyCOLYqph3/0wEWssl4Ns2nsJdDV3eJLaLmTE/n8CXPPA9gpaL5 8yFBsYM4Dc72qQaXpYm+QozjfeqqSJEZJHybe2jVpLEtTJnMmKoIlmxRDW2pfkelF3Tf iFJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=LRXGlpjjHvBrX/DWO8HYzt8WvMi9GMXIuVSD8VgmwHE=; b=0zr1ewSFxw6DeJH2yOqjQITJOugoZYkbNrIQhk5+XTU93Zsqbt3EkbV2TMR8CaBPk5 QwX9sLjCpfSaZItJ+qWwqUbmSUkZADIAO26MhlgFXLcVSfVl2j1qwygHhYdYL1DOM6SF 3NnQXvraLJH1EtXQjn3CCWQBcN8rqUV0qmLvMwFQlTswjxKdwMY/5UFzTTrs2dMv8q3+ oyy+UaTBwGp0nQrJh5L8omdsK+xJL0UwEgNiJemepBdv8rXiwuu+yltbYMo+mnTBBl85 Ehv0gGX4ED1tiQ+Mcg3X4RrpSHr8tmrivCUNuDVlnjkfd+ldp0CnZc7LUW9cdT3WbL/b qqPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q7si34238459edd.487.2021.11.30.00.48.19; Tue, 30 Nov 2021 00:48:21 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 12FCA68078A; Tue, 30 Nov 2021 10:48:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26501689BC6 for ; Tue, 30 Nov 2021 10:48:08 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10183"; a="299567448" X-IronPort-AV: E=Sophos;i="5.87,275,1631602800"; d="scan'208";a="299567448" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2021 00:48:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,275,1631602800"; d="scan'208";a="676745633" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2021 00:48:05 -0800 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Nov 2021 16:44:04 +0800 Message-Id: <20211130084406.758250-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH V2 1/3] libavcodec/vaapi_decode: fix the problem that init_pool_size < nb_surface X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: pORn1loonbYd For vaapi if the init_pool_size is not zero, the pool size is fixed. This means max surfaces is init_pool_size, but when mapping vaapi frame to qsv frame, the init_pool_size < nb_surface. The cause is that vaapi_decode_make_config() config the init_pool_size and it is called twice. The first time is to init frame_context and the second time is to init codec. On the second time the init_pool_size is changed to original value so the init_pool_size is lower than the reall size because pool_size used to initialize frame_context need to plus thread_count and 3 (guarantee 4 base work surfaces). Now add code to make sure init_pool_size is only set once. Now the following commandline works: ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \ -hwaccel_output_format vaapi -i input.264 \ -vf "hwmap=derive_device=qsv,format=qsv" \ -c:v h264_qsv output.264 Signed-off-by: Wenbin Chen --- libavcodec/vaapi_decode.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 665af370ed..aab8162989 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -572,22 +572,24 @@ static int vaapi_decode_make_config(AVCodecContext *avctx, if (err < 0) goto fail; - frames->initial_pool_size = 1; - // Add per-codec number of surfaces used for storing reference frames. - switch (avctx->codec_id) { - case AV_CODEC_ID_H264: - case AV_CODEC_ID_HEVC: - case AV_CODEC_ID_AV1: - frames->initial_pool_size += 16; - break; - case AV_CODEC_ID_VP9: - frames->initial_pool_size += 8; - break; - case AV_CODEC_ID_VP8: - frames->initial_pool_size += 3; - break; - default: - frames->initial_pool_size += 2; + if (!frames->initial_pool_size) { + frames->initial_pool_size = 1; + // Add per-codec number of surfaces used for storing reference frames. + switch (avctx->codec_id) { + case AV_CODEC_ID_H264: + case AV_CODEC_ID_HEVC: + case AV_CODEC_ID_AV1: + frames->initial_pool_size += 16; + break; + case AV_CODEC_ID_VP9: + frames->initial_pool_size += 8; + break; + case AV_CODEC_ID_VP8: + frames->initial_pool_size += 3; + break; + default: + frames->initial_pool_size += 2; + } } }