[FFmpeg-devel] [PATCH 1/3] avutil/hwcontext: add av_hwframe_transfer_wait_all()
Niklas Haas
ffmpeg at haasn.xyz
Sat Mar 1 18:46:19 EET 2025
From: Niklas Haas <git at 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
More information about the ffmpeg-devel
mailing list