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 06F2B4DBC7 for ; Sat, 1 Mar 2025 16:46:36 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E11AA68E0BD; Sat, 1 Mar 2025 18:46:30 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 70E0468DA46 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 E3A4D40E94; Sat, 1 Mar 2025 17:46:23 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Mar 2025 17:46:19 +0100 Message-ID: <20250301164621.130530-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avutil/hwcontext: add av_hwframe_transfer_wait_all() 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 When hardware device contexts perform asynchronous operations, there is nobody to clean up after asynchronous commands emitted by av_hwframe_transfer_data(). In this case, the only way to cleanly uninit without leaving device resources and memory hanging, is to add some sort of explicit synchronization point on uninit. This command adds the public API function for accomplishing this from the point of view of an av_hwframe_transfer_data() user. --- doc/APIchanges | 3 +++ libavutil/hwcontext.c | 9 +++++++++ libavutil/hwcontext.h | 10 ++++++++++ libavutil/hwcontext_internal.h | 1 + libavutil/version.h | 2 +- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index ac506f4b56..ade4ff1159 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 API changes, most recent first: +2025-03-xx - xxxxxxxxxx - lavu 59.58.100 - hwcontext.h + Add av_hwframe_transfer_wait_all(). + 2025-02-xx - xxxxxxxxxx - lavu 59.57.100 - log.h Add flags AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME. diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index f06d49c45c..05c77ac7be 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -492,6 +492,15 @@ int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags) return 0; } +int av_hwframe_transfer_wait_all(AVBufferRef *hwframe_ref, int flags) +{ + FFHWFramesContext *ctx = (FFHWFramesContext*) hwframe_ref->data; + if (!ctx->hw_type->frames_sync) + return 0; + + return ctx->hw_type->frames_sync(&ctx->p); +} + int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags) { FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data; diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 96042ba197..7a0d826e61 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -401,6 +401,16 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ctx, AVFrame *frame, int flags); */ int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags); +/** + * Explicitly wait for all preceding (possibly asynchronous) transfers to be + * completed. No-op for synchronous hardware device types. + * + * @param hwframe_ctx a reference to an AVHWFramesContext + * @param flags currently unused, should be set to zero + * @return 0 on success, a negative AVERROR error code on failure. + */ +int av_hwframe_transfer_wait_all(AVBufferRef *hwframe_ctx, int flags); + enum AVHWFrameTransferDirection { /** * Transfer the data from the queried hw frame. diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h index db23579c9e..e1b8c12424 100644 --- a/libavutil/hwcontext_internal.h +++ b/libavutil/hwcontext_internal.h @@ -69,6 +69,7 @@ typedef struct HWContextType { int (*frames_init)(AVHWFramesContext *ctx); void (*frames_uninit)(AVHWFramesContext *ctx); + int (*frames_sync)(AVHWFramesContext *ctx); int (*frames_get_buffer)(AVHWFramesContext *ctx, AVFrame *frame); int (*transfer_get_formats)(AVHWFramesContext *ctx, diff --git a/libavutil/version.h b/libavutil/version.h index ee4a36cb17..4b584fd569 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 59 -#define LIBAVUTIL_VERSION_MINOR 57 +#define LIBAVUTIL_VERSION_MINOR 58 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- 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".