From aa7333fe430683ce12136058cb2435fcb2c3a786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 1 Sep 2023 17:29:50 -0400 Subject: [PATCH] meta: Add a new "clear" transform to avoid re-allocations In the buffer pool, try to clear metas before freeing them so we avoid constant reallocations on every frame. Part-of: --- subprojects/gstreamer/gst/gstbufferpool.c | 8 ++++++++ subprojects/gstreamer/gst/gstmeta.c | 2 ++ subprojects/gstreamer/gst/gstmeta.h | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/subprojects/gstreamer/gst/gstbufferpool.c b/subprojects/gstreamer/gst/gstbufferpool.c index a1bfd3cba9..72e10e04c5 100644 --- a/subprojects/gstreamer/gst/gstbufferpool.c +++ b/subprojects/gstreamer/gst/gstbufferpool.c @@ -1217,6 +1217,14 @@ remove_meta_unpooled (GstBuffer * buffer, GstMeta ** meta, gpointer user_data) if (!GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) { GST_META_FLAG_UNSET (*meta, GST_META_FLAG_LOCKED); *meta = NULL; + } else { + const GstMetaInfo *info = (*meta)->info; + + /* If we can clear it, don't free it */ + if (info->transform_func) { + info->transform_func (NULL, *meta, buffer, _gst_meta_transform_clear, + NULL); + } } return TRUE; } diff --git a/subprojects/gstreamer/gst/gstmeta.c b/subprojects/gstreamer/gst/gstmeta.c index ec01035887..1b395c9fee 100644 --- a/subprojects/gstreamer/gst/gstmeta.c +++ b/subprojects/gstreamer/gst/gstmeta.c @@ -56,6 +56,7 @@ static GHashTable *metainfo = NULL; static GRWLock lock; GQuark _gst_meta_transform_copy; +GQuark _gst_meta_transform_clear; GQuark _gst_meta_tag_memory; GQuark _gst_meta_tag_memory_reference; @@ -81,6 +82,7 @@ _priv_gst_meta_initialize (void) metainfo = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_info); _gst_meta_transform_copy = g_quark_from_static_string ("gst-copy"); + _gst_meta_transform_clear = g_quark_from_static_string ("gst-clear"); _gst_meta_tag_memory = g_quark_from_static_string ("memory"); _gst_meta_tag_memory_reference = g_quark_from_static_string ("memory-reference"); diff --git a/subprojects/gstreamer/gst/gstmeta.h b/subprojects/gstreamer/gst/gstmeta.h index c80d6b14b4..708d76b80d 100644 --- a/subprojects/gstreamer/gst/gstmeta.h +++ b/subprojects/gstreamer/gst/gstmeta.h @@ -80,6 +80,7 @@ typedef enum { * @flag: the #GstMetaFlags to clear. * * Clears a metadata flag. + * */ #define GST_META_FLAG_UNSET(meta,flag) (GST_META_FLAGS (meta) &= ~(flag)) @@ -189,6 +190,28 @@ typedef struct { gsize size; } GstMetaTransformCopy; +/** + * gst_meta_transform_clear: + * + * GQuark for the "gst-clear" transform. + * + * Since: 1.24 + */ + +GST_API GQuark _gst_meta_transform_clear; + +/** + * GST_META_TRANSFORM_IS_CLEAR: + * @type: a transform type + * + * Check if the transform type is clearing the content of the meta without + * freeing it. + * + * Since: 1.24 + */ +#define GST_META_TRANSFORM_IS_CLEAR(type) ((type) == _gst_meta_transform_clear) + + /** * GstMetaTransformFunction: * @transbuf: a #GstBuffer