From patchwork Thu Nov 18 04:05:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Guangxin" X-Patchwork-Id: 31465 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp220883iob; Wed, 17 Nov 2021 20:11:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzT5Bb8u8CjY38ch7uwTdS2YA7AVYepooVMf/omX5A7XQ2f/+slMcaXT9KYudInoXOIpQ/j X-Received: by 2002:a17:907:7e88:: with SMTP id qb8mr28240873ejc.535.1637208679321; Wed, 17 Nov 2021 20:11:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637208679; cv=none; d=google.com; s=arc-20160816; b=NSFfZ/Q1MD8VHem0x3kenEbXIyTReGfJu3TApku+LA1xdVJ8fo2xB1lL3pmxiedLVU +hDOeqY5AY3oz1ZgDr4Rq1C9pI7IIz8Ydfu35tzvg0G1/JK5/zUAoYBAjOfGfrux+UBP P1wEHBi68OuyFzVaUytg9xLTQ2GTsZedoFahpR2HyXJCEu7TR+Q3fAjaXI6/dAC63Bap rqtS45N/Oxc74vriIN+Rs/yQhYXMeYM2hWp+oKx6YbaHvvs6P6tDEKICP96Gh12IyP2E LIAJDoJTJe1mm1wS2vKdXO3xQ/Os4Y4bNQrI6cQtjCw4yFuRyjbzW5MTGlJ4EGIZ5/ED nduw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=EmKMjLHl9tnBK5msa8AQdqQd87jgyrVj5RhL5zthnwM=; b=jT0X7WkVI73N1uFp6vJaCBMPvwWKQlKAkktoLioHxf+6BW3dsVpuCO4fYfXYlo1rja V2FbsE1Wk5V85NPF0ANSwc6DCR85DuTU841CqoxOIeXPykB+fsQJWhaRg07ND0epC+G7 pF1XOS4eJPYoJm7LA4bPl9ua/CyKAy7cDSGpMVh15wJSI8ab3QHDjFdk3fePQE83pOXa vSzIFcq/h8X8CED/lmjXrEJrXQikDIi3pJO/f5WS84s0hlbvmKVRkk5KNzF0uPkA7q3q R4e0f3e+BeAgZz03obS5PPwpS2DhnEKq8/mrUV9lTTLygVH/vImGO7qix0uVWbGA1ivu u4DQ== 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 s5si6060227edd.286.2021.11.17.20.11.19; Wed, 17 Nov 2021 20:11:19 -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 3A38868AE3F; Thu, 18 Nov 2021 06:10:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 73B8F68AE3F for ; Thu, 18 Nov 2021 06:10:43 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10171"; a="220991795" X-IronPort-AV: E=Sophos;i="5.87,243,1631602800"; d="scan'208";a="220991795" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2021 20:10:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,243,1631602800"; d="scan'208";a="455154637" Received: from trinity.sh.intel.com ([10.239.159.156]) by orsmga006.jf.intel.com with ESMTP; 17 Nov 2021 20:10:40 -0800 From: Xu Guangxin To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Nov 2021 12:05:49 +0800 Message-Id: <20211118040549.3871537-4-guangxin.xu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211118040549.3871537-1-guangxin.xu@intel.com> References: <20211118040549.3871537-1-guangxin.xu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec: vaapi_decode, do not set initial_pool_size if driver supports frame pool resizing 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 Cc: Xu Guangxin Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AApurdyYl+1v Two benifites of this commit: 1. Save memory. If we play an 8k hevc, previous code we allocate 50M * 20(1 + 16 + 3) = 1G memory. 4 may enough for most of playback usecases. 16 is a waste. 2. Allow downstream cache more frames. A downstream lookahead encoder will cache some frames. 20 may not enough for it. This commit will fix the following command ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -i 100frames.264 -vf reverse -an -f null - --- 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..177949c36d 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 (hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_FRAME_POOL_RESIZING) { + 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; + } } }