From patchwork Tue Nov 16 08:16:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 31439 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp7038100iob; Tue, 16 Nov 2021 00:20:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDemdCxBH4U8SAvu8wCA+tw8yBmP9emG2K7kaV8v0h/6CNN+8fd+20JVcSNOK5BKJh/fTU X-Received: by 2002:a05:6402:5216:: with SMTP id s22mr7720715edd.291.1637050828101; Tue, 16 Nov 2021 00:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637050828; cv=none; d=google.com; s=arc-20160816; b=XgADVwGYDNziUe7MvaOAB5AfgSZAPuVF3FLsfxysvK1lD4e34DlwBVT+MKe3/oVAPI l6tnSovB+qzooHlfQg0L70o9o5t0NiAzQBEDTyxE7grjj0xdZvL5sc9slIX/ST93ebz+ 7uxTlDRhFHyhVzQQAmyMEQcf9W231hpzCCuhhwJCkbLKkksgeJZic2j+8ikZpn2u0HoA XNrwGoVpAT2vIs1f8lODU0TkFqDCbgzIACU1bBZBTAZ24s40IBOy3UZv/0bMjFd+1+Xy N3VPPklk/ZXG9QS1kuJq82GhC0NTqhu8EJYNLnXhKop5TIsUZf10RBLVUBi+iZlvRhSg wBiA== 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=leAEyl5rfU5cEXbKEZifPnTEDv442u2xdNddKBQJz3KxDDhYd7e1RCziMdNOQGVA7R eIvCL/WSa0B98ZzeFKgr9CfIvDRpFfrJ6YkO4+JusQZmVO427+R4KFryt46PvxUDUMBH LvwFiuAAVKVp4pG1xDhMiW+4VWo9VPMRfGvtsNQLpV6isOfxBUjfWW2DxQ+dKfpWmp1G Rxqiy//fQSEtV5YAZvgN0kRipr/NH0dj3eA4rMzd5QoeIIYMaTSh7ue9XYwA/3nKipy4 j0aM/Ru0Qzms4KjAaS7JiFIBXGM4SKoOoz7mmeQawINNXmZg2kS2pOpjHdGMUW87Kwfh nxuw== 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 z21si10966910edd.365.2021.11.16.00.20.27; Tue, 16 Nov 2021 00:20:28 -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 361B268AD93; Tue, 16 Nov 2021 10:20:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE91F689D0A for ; Tue, 16 Nov 2021 10:20:16 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10169"; a="233482527" X-IronPort-AV: E=Sophos;i="5.87,238,1631602800"; d="scan'208";a="233482527" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2021 00:20:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,238,1631602800"; d="scan'208";a="454362219" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by orsmga006.jf.intel.com with ESMTP; 16 Nov 2021 00:20:13 -0800 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Nov 2021 16:16:21 +0800 Message-Id: <20211116081623.3081766-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: hzbTmpFNUWLl 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; + } } }