From 2a9c4e32703da4de36bd1b9982e5b66e3393483d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Mon, 18 Dec 2023 13:40:53 -0500 Subject: [PATCH] meta: Move the clear operation to its own vfunc Some transforms always assumed that the transformation was some kind of copy. So adding a "clear" operation didn't work out in practice. Part-of: --- girs/Gst-1.0.gir | 34 +++++++++----- .../gst-libs/gst/analytics/gstanalyticsmeta.c | 34 +++++++------- subprojects/gstreamer/gst/gstbufferpool.c | 6 +-- subprojects/gstreamer/gst/gstmeta.c | 4 +- subprojects/gstreamer/gst/gstmeta.h | 44 ++++++++++--------- 5 files changed, 68 insertions(+), 54 deletions(-) diff --git a/girs/Gst-1.0.gir b/girs/Gst-1.0.gir index 9fa22f0b76..24483b2730 100644 --- a/girs/Gst-1.0.gir +++ b/girs/Gst-1.0.gir @@ -22164,16 +22164,6 @@ In hindsight, this tag should have been called "memory-layout". - - Check if the transform type is clearing the content of the meta without -freeing it. - - - - a transform type - - - Check if the transform type is a copy transform @@ -26093,6 +26083,24 @@ transform function. + + Clears the content of the meta. This will be called by the GstBufferPool +when a pooled buffer is returned. + + + + + + + a #GstBuffer + + + + a #GstMeta + + + + Recreate a #GstMeta from serialized data returned by #GstMetaSerializeFunction and add it to @buffer. @@ -26196,6 +26204,12 @@ meta. meta. + + Function for clearing the metadata, or %NULL if not supported by this +meta. This is called by the buffer pool when a buffer is returned for +pooled metas. + + diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gstanalyticsmeta.c b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gstanalyticsmeta.c index 6e1a1a6630..d3892fc581 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gstanalyticsmeta.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gstanalyticsmeta.c @@ -344,39 +344,41 @@ gst_analytics_relation_meta_transform (GstBuffer * transbuf, return FALSE; } - } else if (GST_META_TRANSFORM_IS_CLEAR (type)) { - GstAnalyticsRelationMeta *rmeta = (GstAnalyticsRelationMeta *) meta; - gsize adj_mat_data_size = - (sizeof (guint8) * rmeta->rel_order * rmeta->rel_order); - - rmeta->next_id = 0; - rmeta->offset = 0; - rmeta->length = 0; - if (adj_mat_data_size) { - /* Only clear data and not lines addresses occupying begining of this - * array. */ - memset (rmeta->adj_mat + rmeta->rel_order, 0, adj_mat_data_size); - } - - return TRUE; } return FALSE; } +static void +gst_analytics_relation_meta_clear (GstBuffer * buffer, GstMeta * meta) +{ + GstAnalyticsRelationMeta *rmeta = (GstAnalyticsRelationMeta *) meta; + gsize adj_mat_data_size = + (sizeof (guint8) * rmeta->rel_order * rmeta->rel_order); + + rmeta->next_id = 0; + rmeta->offset = 0; + rmeta->length = 0; + if (adj_mat_data_size) { + /* Only clear data and not lines addresses occupying begining of this + * array. */ + memset (rmeta->adj_mat + rmeta->rel_order, 0, adj_mat_data_size); + } +} const GstMetaInfo * gst_analytics_relation_meta_get_info (void) { static const GstMetaInfo *info = NULL; if (g_once_init_enter ((GstMetaInfo **) & info)) { - const GstMetaInfo *meta = + GstMetaInfo *meta = (GstMetaInfo *) gst_meta_register (GST_ANALYTICS_RELATION_META_API_TYPE, "GstAnalyticsRelationMeta", sizeof (GstAnalyticsRelationMeta), gst_analytics_relation_meta_init, gst_analytics_relation_meta_free, gst_analytics_relation_meta_transform); + meta->clear_func = gst_analytics_relation_meta_clear; g_once_init_leave ((GstMetaInfo **) & info, (GstMetaInfo *) meta); } return info; diff --git a/subprojects/gstreamer/gst/gstbufferpool.c b/subprojects/gstreamer/gst/gstbufferpool.c index 72e10e04c5..d7da0cd4ad 100644 --- a/subprojects/gstreamer/gst/gstbufferpool.c +++ b/subprojects/gstreamer/gst/gstbufferpool.c @@ -1221,10 +1221,8 @@ remove_meta_unpooled (GstBuffer * buffer, GstMeta ** meta, gpointer user_data) 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); - } + if (info->clear_func) + info->clear_func (buffer, *meta); } return TRUE; } diff --git a/subprojects/gstreamer/gst/gstmeta.c b/subprojects/gstreamer/gst/gstmeta.c index e3f65fa9fc..d113f32901 100644 --- a/subprojects/gstreamer/gst/gstmeta.c +++ b/subprojects/gstreamer/gst/gstmeta.c @@ -56,7 +56,6 @@ 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; @@ -82,7 +81,6 @@ _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"); @@ -430,7 +428,7 @@ gst_meta_register_internal (GType api, const gchar * impl, gsize size, if (type == G_TYPE_INVALID) return NULL; - info = (GstMetaInfo *) g_new (GstMetaInfoImpl, 1); + info = (GstMetaInfo *) g_new0 (GstMetaInfoImpl, 1); info->api = api; info->type = type; info->size = size; diff --git a/subprojects/gstreamer/gst/gstmeta.h b/subprojects/gstreamer/gst/gstmeta.h index 5314995e00..d949b71039 100644 --- a/subprojects/gstreamer/gst/gstmeta.h +++ b/subprojects/gstreamer/gst/gstmeta.h @@ -197,27 +197,6 @@ 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 @@ -301,6 +280,18 @@ typedef gboolean (*GstMetaSerializeFunction) (const GstMeta *meta, typedef GstMeta *(*GstMetaDeserializeFunction) (const GstMetaInfo *info, GstBuffer *buffer, const guint8 *data, gsize size, guint8 version); +/** + * GstMetaClearFunction: + * @buffer: a #GstBuffer + * @meta: a #GstMeta + * + * Clears the content of the meta. This will be called by the GstBufferPool + * when a pooled buffer is returned. + * + * Since: 1.24 + */ +typedef void (*GstMetaClearFunction) (GstBuffer *buffer, GstMeta *meta); + /** * GstMetaInfo.serialize_func: * @@ -319,6 +310,16 @@ typedef GstMeta *(*GstMetaDeserializeFunction) (const GstMetaInfo *info, * Since: 1.24 */ +/** + * GstMetaInfo.clear_func: + * + * Function for clearing the metadata, or %NULL if not supported by this + * meta. This is called by the buffer pool when a buffer is returned for + * pooled metas. + * + * Since: 1.24 + */ + /** * GstMetaInfo: * @api: tag identifying the metadata structure and api @@ -345,6 +346,7 @@ struct _GstMetaInfo { GstMetaTransformFunction transform_func; GstMetaSerializeFunction serialize_func; GstMetaDeserializeFunction deserialize_func; + GstMetaClearFunction clear_func; /* No padding needed, GstMetaInfo is always allocated by GStreamer and is * not subclassable or stack-allocatable, so we can extend it as we please