From: Niklas Haas <ffmpeg@haasn.xyz> To: ffmpeg-devel@ffmpeg.org Cc: Niklas Haas <git@haasn.dev> Subject: [FFmpeg-devel] [PATCH 1/3] avutil/hwcontext: add av_hwframe_transfer_wait_all() Date: Sat, 1 Mar 2025 17:46:19 +0100 Message-ID: <20250301164621.130530-1-ffmpeg@haasn.xyz> (raw) From: Niklas Haas <git@haasn.dev> 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".
next reply other threads:[~2025-03-01 16:46 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-03-01 16:46 Niklas Haas [this message] 2025-03-01 16:46 ` [FFmpeg-devel] [PATCH 2/3] avfilter/hwupload: wait for all pending transfers on uninit() Niklas Haas 2025-03-01 16:46 ` [FFmpeg-devel] [PATCH 3/3] avutil/hwcontext_vulkan: add frames_sync() implementation Niklas Haas
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250301164621.130530-1-ffmpeg@haasn.xyz \ --to=ffmpeg@haasn.xyz \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=git@haasn.dev \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git