GstCustomMeta: simplify API

Move the GstStructure field into public struct for direct access, that's
easier than having to call a function to get it. It is not an API/ABI
breakage to extend the public structure of a GstMeta because they are
always allocated by inside GStreamer. The structure is exposed already
by gst_custom_meta_get_structure() which does not return a copy/ref, so
it is locked into holding a GstStructure forever anyway.

Also add gst_meta_register_custom_simple() because most of the time only
a name is required, tags and transform functions are more niche
use-case.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5385>
This commit is contained in:
Xavier Claessens 2023-09-23 13:12:57 -04:00 committed by GStreamer Marge Bot
parent 4a9a9ed9fc
commit 452ab184cb
3 changed files with 79 additions and 19 deletions

View file

@ -10501,11 +10501,17 @@ this functionality yet.</doc>
</function> </function>
</enumeration> </enumeration>
<record name="CustomMeta" c:type="GstCustomMeta" version="1.20"> <record name="CustomMeta" c:type="GstCustomMeta" version="1.20">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.h">Simple typing wrapper around #GstMeta</doc> <doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.h">Extra custom metadata. The @structure field is the same as returned by
gst_custom_meta_get_structure().</doc>
<source-position filename="../subprojects/gstreamer/gst/gstmeta.h"/> <source-position filename="../subprojects/gstreamer/gst/gstmeta.h"/>
<field name="meta" writable="1"> <field name="meta" writable="1">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.h">parent #GstMeta</doc>
<type name="Meta" c:type="GstMeta"/> <type name="Meta" c:type="GstMeta"/>
</field> </field>
<field name="structure" writable="1">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.h">a #GstStructure containing custom metadata. (Since: 1.24)</doc>
<type name="Structure" c:type="GstStructure*"/>
</field>
<method name="get_structure" c:identifier="gst_custom_meta_get_structure" version="1.20"> <method name="get_structure" c:identifier="gst_custom_meta_get_structure" version="1.20">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">Retrieve the #GstStructure backing a custom meta, the structure's mutability <doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">Retrieve the #GstStructure backing a custom meta, the structure's mutability
is conditioned to the writability of the #GstBuffer @meta is attached to.</doc> is conditioned to the writability of the #GstBuffer @meta is attached to.</doc>
@ -25863,6 +25869,21 @@ access metadata.</doc>
</parameter> </parameter>
</parameters> </parameters>
</function> </function>
<function name="register_custom_simple" c:identifier="gst_meta_register_custom_simple" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">Simplified version of gst_meta_register_custom(), with no tags and no
transform function.</doc>
<source-position filename="../subprojects/gstreamer/gst/gstmeta.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">a #GstMetaInfo that can be used to access metadata.</doc>
<type name="MetaInfo" c:type="const GstMetaInfo*"/>
</return-value>
<parameters>
<parameter name="name" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">the name of the #GstMeta implementation</doc>
<type name="utf8" c:type="const gchar*"/>
</parameter>
</parameters>
</function>
</record> </record>
<bitfield name="MetaFlags" glib:type-name="GstMetaFlags" glib:get-type="gst_meta_flags_get_type" c:type="GstMetaFlags"> <bitfield name="MetaFlags" glib:type-name="GstMetaFlags" glib:get-type="gst_meta_flags_get_type" c:type="GstMetaFlags">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.h">Extra metadata flags.</doc> <doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.h">Extra metadata flags.</doc>
@ -51649,6 +51670,21 @@ access metadata.</doc>
</parameter> </parameter>
</parameters> </parameters>
</function> </function>
<function name="meta_register_custom_simple" c:identifier="gst_meta_register_custom_simple" moved-to="Meta.register_custom_simple" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">Simplified version of gst_meta_register_custom(), with no tags and no
transform function.</doc>
<source-position filename="../subprojects/gstreamer/gst/gstmeta.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">a #GstMetaInfo that can be used to access metadata.</doc>
<type name="MetaInfo" c:type="const GstMetaInfo*"/>
</return-value>
<parameters>
<parameter name="name" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstmeta.c">the name of the #GstMeta implementation</doc>
<type name="utf8" c:type="const gchar*"/>
</parameter>
</parameters>
</function>
<function name="mini_object_replace" c:identifier="gst_mini_object_replace" moved-to="MiniObject.replace"> <function name="mini_object_replace" c:identifier="gst_mini_object_replace" moved-to="MiniObject.replace">
<doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstminiobject.c">Atomically modifies a pointer to point to a new mini-object. <doc xml:space="preserve" filename="../subprojects/gstreamer/gst/gstminiobject.c">Atomically modifies a pointer to point to a new mini-object.
The reference count of @olddata is decreased and the reference count of The reference count of @olddata is decreased and the reference count of

View file

@ -59,13 +59,6 @@ GQuark _gst_meta_transform_copy;
GQuark _gst_meta_tag_memory; GQuark _gst_meta_tag_memory;
GQuark _gst_meta_tag_memory_reference; GQuark _gst_meta_tag_memory_reference;
typedef struct
{
GstCustomMeta meta;
GstStructure *structure;
} GstCustomMetaImpl;
typedef struct typedef struct
{ {
GstMetaInfo info; GstMetaInfo info;
@ -154,7 +147,7 @@ gst_meta_api_type_register (const gchar * api, const gchar ** tags)
static gboolean static gboolean
custom_init_func (GstMeta * meta, gpointer params, GstBuffer * buffer) custom_init_func (GstMeta * meta, gpointer params, GstBuffer * buffer)
{ {
GstCustomMetaImpl *cmeta = (GstCustomMetaImpl *) meta; GstCustomMeta *cmeta = (GstCustomMeta *) meta;
cmeta->structure = gst_structure_new_empty (g_type_name (meta->info->type)); cmeta->structure = gst_structure_new_empty (g_type_name (meta->info->type));
@ -167,7 +160,7 @@ custom_init_func (GstMeta * meta, gpointer params, GstBuffer * buffer)
static void static void
custom_free_func (GstMeta * meta, GstBuffer * buffer) custom_free_func (GstMeta * meta, GstBuffer * buffer)
{ {
GstCustomMetaImpl *cmeta = (GstCustomMetaImpl *) meta; GstCustomMeta *cmeta = (GstCustomMeta *) meta;
gst_structure_set_parent_refcount (cmeta->structure, NULL); gst_structure_set_parent_refcount (cmeta->structure, NULL);
gst_structure_free (cmeta->structure); gst_structure_free (cmeta->structure);
@ -177,16 +170,15 @@ static gboolean
custom_transform_func (GstBuffer * transbuf, GstMeta * meta, custom_transform_func (GstBuffer * transbuf, GstMeta * meta,
GstBuffer * buffer, GQuark type, gpointer data) GstBuffer * buffer, GQuark type, gpointer data)
{ {
GstCustomMetaImpl *custom, *cmeta = (GstCustomMetaImpl *) meta; GstCustomMeta *custom, *cmeta = (GstCustomMeta *) meta;
GstMetaInfoImpl *info = (GstMetaInfoImpl *) meta->info; GstMetaInfoImpl *info = (GstMetaInfoImpl *) meta->info;
if (info->custom_transform_func) if (info->custom_transform_func)
return info->custom_transform_func (transbuf, (GstCustomMeta *) meta, return info->custom_transform_func (transbuf, cmeta,
buffer, type, data, info->custom_transform_user_data); buffer, type, data, info->custom_transform_user_data);
if (GST_META_TRANSFORM_IS_COPY (type)) { if (GST_META_TRANSFORM_IS_COPY (type)) {
custom = custom = (GstCustomMeta *) gst_buffer_add_meta (transbuf, meta->info, NULL);
(GstCustomMetaImpl *) gst_buffer_add_meta (transbuf, meta->info, NULL);
gst_structure_set_parent_refcount (custom->structure, NULL); gst_structure_set_parent_refcount (custom->structure, NULL);
gst_structure_take (&custom->structure, gst_structure_take (&custom->structure,
gst_structure_copy (cmeta->structure)); gst_structure_copy (cmeta->structure));
@ -215,7 +207,7 @@ gst_custom_meta_get_structure (GstCustomMeta * meta)
g_return_val_if_fail (gst_meta_info_is_custom (((GstMeta *) meta)->info), g_return_val_if_fail (gst_meta_info_is_custom (((GstMeta *) meta)->info),
NULL); NULL);
return ((GstCustomMetaImpl *) meta)->structure; return meta->structure;
} }
/** /**
@ -233,7 +225,7 @@ gst_custom_meta_has_name (GstCustomMeta * meta, const gchar * name)
g_return_val_if_fail (gst_meta_info_is_custom (((GstMeta *) meta)->info), g_return_val_if_fail (gst_meta_info_is_custom (((GstMeta *) meta)->info),
FALSE); FALSE);
return gst_structure_has_name (((GstCustomMetaImpl *) meta)->structure, name); return gst_structure_has_name (meta->structure, name);
} }
/** /**
@ -281,7 +273,7 @@ gst_meta_register_custom (const gchar * name, const gchar ** tags,
goto done; goto done;
info = (GstMetaInfoImpl *) gst_meta_register (api, name, info = (GstMetaInfoImpl *) gst_meta_register (api, name,
sizeof (GstCustomMetaImpl), sizeof (GstCustomMeta),
custom_init_func, custom_free_func, custom_transform_func); custom_init_func, custom_free_func, custom_transform_func);
if (!info) if (!info)
@ -298,6 +290,23 @@ done:
return ret; return ret;
} }
/**
* gst_meta_register_custom_simple:
* @name: the name of the #GstMeta implementation
*
* Simplified version of gst_meta_register_custom(), with no tags and no
* transform function.
*
* Returns: (transfer none): a #GstMetaInfo that can be used to access metadata.
* Since: 1.24
*/
const GstMetaInfo *
gst_meta_register_custom_simple (const gchar * name)
{
const gchar *tags[] = { NULL };
return gst_meta_register_custom (name, tags, NULL, NULL, NULL);
}
/** /**
* gst_meta_info_is_custom: * gst_meta_info_is_custom:
* *

View file

@ -116,14 +116,26 @@ struct _GstMeta {
}; };
/** /**
* GstCustomMeta: * GstCustomMeta.structure:
* *
* Simple typing wrapper around #GstMeta * #GstStructure containing custom metadata.
*
* Since: 1.24
*/
/**
* GstCustomMeta:
* @meta: parent #GstMeta
* @structure: a #GstStructure containing custom metadata. (Since: 1.24)
*
* Extra custom metadata. The @structure field is the same as returned by
* gst_custom_meta_get_structure().
* *
* Since: 1.20 * Since: 1.20
*/ */
typedef struct { typedef struct {
GstMeta meta; GstMeta meta;
GstStructure *structure;
} GstCustomMeta; } GstCustomMeta;
#include <gst/gstbuffer.h> #include <gst/gstbuffer.h>
@ -267,6 +279,9 @@ const GstMetaInfo * gst_meta_register_custom (const gchar *name, const gchar
GstCustomMetaTransformFunction transform_func, GstCustomMetaTransformFunction transform_func,
gpointer user_data, GDestroyNotify destroy_data); gpointer user_data, GDestroyNotify destroy_data);
GST_API
const GstMetaInfo * gst_meta_register_custom_simple (const gchar *name);
GST_API GST_API
gboolean gst_meta_info_is_custom (const GstMetaInfo *info); gboolean gst_meta_info_is_custom (const GstMetaInfo *info);