From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 47F5D4B82F for ; Sat, 1 Mar 2025 16:46:49 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE79968E0E9; Sat, 1 Mar 2025 18:46:33 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7BA0768DAF0 for ; Sat, 1 Mar 2025 18:46:24 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with ESMTP id 29ACF4197E; Sat, 1 Mar 2025 17:46:24 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Mar 2025 17:46:20 +0100 Message-ID: <20250301164621.130530-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250301164621.130530-1-ffmpeg@haasn.xyz> References: <20250301164621.130530-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/hwupload: wait for all pending transfers on uninit() 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: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas Uploads can be asynchronous, so we need to wait for them on unit to prevent a cyclic reference from keeping the hwfc alive indefinitely, since there is no other way for the hwfc to know when prior commands should be cleaned up. In theory, it might be possible for this to be signalled backwards by downstream consumers of the corresponding AVFrames, but this is very nontrivial as there may be multiple, or even no downstream consumers, such as in the degenerate case of: ffmpeg ... -vf hwupload -f null - Waiting for outstanding transfers to have completed explicitly in uninit is the only solution that is both robust, simple, and comes without a performance penalty. --- libavfilter/vf_hwupload.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c index 6aafac4d4d..3142aabb17 100644 --- a/libavfilter/vf_hwupload.c +++ b/libavfilter/vf_hwupload.c @@ -222,6 +222,15 @@ static av_cold void hwupload_uninit(AVFilterContext *avctx) { HWUploadContext *ctx = avctx->priv; + /** + * Ensure that all outstanding asynchronous uploads are properly completed. + * This is to avoid leaking the context, because nobody else will clean up + * after the hwfc while there are still pending asynchronous transfers + * referencing it. + */ + if (ctx->hwframes_ref) + av_hwframe_transfer_wait_all(ctx->hwframes_ref, 0); + av_buffer_unref(&ctx->hwframes_ref); av_buffer_unref(&ctx->hwdevice_ref); } -- 2.47.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".