From patchwork Mon Dec 5 22:25:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 39622 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp3614414pzb; Mon, 5 Dec 2022 14:26:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf5sCWxsC3a81LTAuUD5/JXv0yQmC49iHjnR5Iyl+NE8Ul+ytPcBfu/rQdHUJPvNR7AJMrpQ X-Received: by 2002:a05:6402:1381:b0:468:5b78:6381 with SMTP id b1-20020a056402138100b004685b786381mr63781166edv.373.1670279191888; Mon, 05 Dec 2022 14:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670279191; cv=none; d=google.com; s=arc-20160816; b=QJSyM7rktGRDyNJ0RmwZ293Wmr+DIW+1a4bIUWGt2ezlFzJaQjU3Rrm7bYQM8N/o+H JHzV6S93gLZAFQlEXUJ9nOvpJfLJe2kZLxUiYsQ3NhOCw7Pn5s6Mj2vCXxSep3KDw8UC Gz2Sy0DXh5chmJcbd3wwbih6+rCqa7Sdauh+iFqb102x/5F7uixCdafd3MshMp23er8q uAqdGsOc6oxLk7yTkAG2ATzu4I+5ycTB8jeIbEH/NbmfaWk4mZya1w0LAa4xrJyvyN/r S+I2W0KHqxdG1QJY5A5KitRuf3fZY2X2ylPFH4Nrw6hLVbXF6WufA/fmKZmIrLHwOgN9 HlRg== 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:dkim-signature:delivered-to; bh=ooecOgN4sABJCpy7J66908XgtV2MtHjV/PZiGF+0k8o=; b=HM2PkTLhCztJemZ/UVZqLUwVi3Tn81UGxSRbkhJ0U44i1P2KsHaHm3DXrncvsGJWug JW/DvNScok5GSUGfbGUMl+HxBr07vJHsrcm0hdfktvCGms+7oZMjUz/uxwcV/TuI2k1Z 311JivqEHiQIcRTPpZziAnxiI/0rZ8AaU9KBZXTUv8XaAS+Ucn0Up0C7DsfBpLzrCshg spm/TKplo3ft4KNR2RSOL0TK1JJ7jijWvt5p24PNKEEWpqG7Cw8zVQrPms6aB9UbaGk9 e/zzPQBgsY92pTCR4ciL7le0vn0AOK3zaUuHwlZFHYSVFDIoM1SDNxAcj40I7Wuyv9x1 71Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=aZF0FK0V; 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=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t18-20020a056402525200b0046194b2dd53si639614edd.119.2022.12.05.14.26.31; Mon, 05 Dec 2022 14:26:31 -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; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=aZF0FK0V; 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=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9AD8568BD08; Tue, 6 Dec 2022 00:26:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [136.243.74.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32C3B68B1B3 for ; Tue, 6 Dec 2022 00:26:14 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 8528A3632ED; Mon, 5 Dec 2022 23:26:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1670279173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fI2lYwCdSA/3SsQvFFOVCXzq0Wjv4qkfGy+vFzf+xOI=; b=aZF0FK0VjJzYGASVG9swwBbXEFNbU31bMfgs53tEP7eGQ4mdZFWvq/UoJvKed8qEBQFC4p HgXuQPc/CTugx3dH5PFriBHYFSbi9paoPg56O1H/xcjvJ346eTjdu1eBi/NNW4c9atUqKi Q0pvYz/gzVRdX5zIVTbGNk7Hi2bIjkwqLKReBy7sGve4JnA5BAgONFTIRMgY5rxpnzjzZx V1nW0v6Pqpd8vdpBGesqJIGTvCBxjam7mJzd65qrvsBSFjeAUclxuUBpuaY5fs7BseNkr2 9kOfhEQ4sCHQHEr9yj3FsGErF+NQGZ+n2KVdXNHTCks1zkQwxOKTic1Zg/jYVQ== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Dec 2022 23:25:59 +0100 Message-Id: <20221205222559.107006-2-timo@rothenpieler.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221205222559.107006-1-timo@rothenpieler.org> References: <20221205222559.107006-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/nvdec: make explicit copy of frames unless user requested otherwise 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: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wbArsxiL2eVi --- libavcodec/nvdec.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index fbaedf0b6b..76ee395734 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -51,6 +51,8 @@ typedef struct NVDECDecoder { CudaFunctions *cudl; CuvidFunctions *cvdl; + + int minimize_copies; } NVDECDecoder; typedef struct NVDECFramePool { @@ -344,6 +346,8 @@ int ff_nvdec_decode_init(AVCodecContext *avctx) int cuvid_codec_type, cuvid_chroma_format, chroma_444; int ret = 0; + int minimize_copies = !!(avctx->hwaccel_flags & AV_HWACCEL_FLAG_MINIMIZE_COPIES); + sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); if (!sw_desc) return AVERROR_BUG; @@ -402,7 +406,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx) params.CodecType = cuvid_codec_type; params.ChromaFormat = cuvid_chroma_format; params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size; - params.ulNumOutputSurfaces = frames_ctx->initial_pool_size; + params.ulNumOutputSurfaces = minimize_copies ? frames_ctx->initial_pool_size : 1; ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, ¶ms, avctx); if (ret < 0) { @@ -417,6 +421,7 @@ int ff_nvdec_decode_init(AVCodecContext *avctx) } decoder = (NVDECDecoder*)ctx->decoder_ref->data; + decoder->minimize_copies = minimize_copies; decoder->real_hw_frames_ref = real_hw_frames_ref; real_hw_frames_ref = NULL; @@ -554,7 +559,11 @@ copy_fail: finish: CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy)); - return ret; + + if (ret < 0 || decoder->minimize_copies) + return ret; + + return av_frame_make_writable(frame); } int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)