From 067fe7b9bc8ef3c17767348e9c1892b46916b121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Fri, 4 Oct 2024 11:19:46 +0200 Subject: [PATCH] gst: structure: add more GstIdStr methods Part-of: --- girs/Gst-1.0.gir | 88 ++++++++++++++++- subprojects/gstreamer/gst/gststructure.c | 114 +++++++++++++++++++++++ subprojects/gstreamer/gst/gststructure.h | 14 +++ 3 files changed, 212 insertions(+), 4 deletions(-) diff --git a/girs/Gst-1.0.gir b/girs/Gst-1.0.gir index 8acd4f075f..fb6b5e921a 100644 --- a/girs/Gst-1.0.gir +++ b/girs/Gst-1.0.gir @@ -42160,7 +42160,7 @@ Free-function: gst_structure_free Creates a new #GstStructure with the given name as a GQuark, followed by -fieldname quark, GType, argument(s) "triplets" in the same format as +fieldname GstIdStr, GType, argument(s) "triplets" in the same format as gst_structure_id_set(). Basically a convenience wrapper around gst_structure_new_id_empty() and gst_structure_id_set(). @@ -43066,7 +43066,7 @@ function returns %FALSE. Get the name of @structure as a GstIdStr. - the quark representing the name of the structure. + the name of the structure. @@ -43565,11 +43565,91 @@ name. + + Get the name (as a GstIdStr) of the given field number, +counting from 0 onwards. + + + the name of the given field number + + + + + a #GstStructure + + + + the index to get the name of + + + + + + Removes the field with the given name. If the field with the given +name does not exist, the structure is unchanged. + + + + + + + a #GstStructure + + + + the name of the field to remove + + + + + + Removes the fields with the given names. If a field does not exist, the +argument is ignored. + + + + + + + a #GstStructure + + + + the name of the field to remove + + + + %NULL-terminated list of more fieldnames to remove + + + + + + va_list form of gst_structure_id_str_remove_fields(). + + + + + + + a #GstStructure + + + + the name of the field to remove + + + + %NULL-terminated list of more fieldnames to remove + + + + Identical to gst_structure_set, except that field names are passed using a GstIdStr for the field name. This allows more efficient -setting of the structure if the caller already knows the associated -quark values. +setting of the structure if the caller already owns the associated +GstIdStr values or if they can be built from static literals. The last variable argument must be %NULL. diff --git a/subprojects/gstreamer/gst/gststructure.c b/subprojects/gstreamer/gst/gststructure.c index f5b117350c..fdec12c690 100644 --- a/subprojects/gstreamer/gst/gststructure.c +++ b/subprojects/gstreamer/gst/gststructure.c @@ -1827,6 +1827,94 @@ gst_structure_remove_fields_valist (GstStructure * structure, } } +/** + * gst_structure_id_str_remove_field: + * @structure: a #GstStructure + * @fieldname: the name of the field to remove + * + * Removes the field with the given name. If the field with the given + * name does not exist, the structure is unchanged. + * + * Since: 1.26 + */ +void +gst_structure_id_str_remove_field (GstStructure * structure, + const GstIdStr * fieldname) +{ + GstStructureField *field; + guint i, len; + + g_return_if_fail (structure != NULL); + g_return_if_fail (fieldname != NULL); + g_return_if_fail (IS_MUTABLE (structure)); + + len = GST_STRUCTURE_LEN (structure); + for (i = 0; i < len; i++) { + field = GST_STRUCTURE_FIELD (structure, i); + + if (gst_id_str_is_equal (&field->name, fieldname)) { + if (G_IS_VALUE (&field->value)) { + g_value_unset (&field->value); + } + gst_id_str_clear (&field->name); + _structure_remove_index (structure, i); + return; + } + } +} + +/** + * gst_structure_id_str_remove_fields: + * @structure: a #GstStructure + * @fieldname: the name of the field to remove + * @...: %NULL-terminated list of more fieldnames to remove + * + * Removes the fields with the given names. If a field does not exist, the + * argument is ignored. + * + * Since: 1.26 + */ +void +gst_structure_id_str_remove_fields (GstStructure * structure, + const GstIdStr * fieldname, ...) +{ + va_list varargs; + + g_return_if_fail (structure != NULL); + g_return_if_fail (fieldname != NULL); + /* mutability checked in remove_field */ + + va_start (varargs, fieldname); + gst_structure_id_str_remove_fields_valist (structure, fieldname, varargs); + va_end (varargs); +} + +/** + * gst_structure_id_str_remove_fields_valist: + * @structure: a #GstStructure + * @fieldname: the name of the field to remove + * @varargs: %NULL-terminated list of more fieldnames to remove + * + * va_list form of gst_structure_id_str_remove_fields(). + * + * Since: 1.26 + */ +void +gst_structure_id_str_remove_fields_valist (GstStructure * structure, + const GstIdStr * fieldname, va_list varargs) +{ + const GstIdStr *field = fieldname; + + g_return_if_fail (structure != NULL); + g_return_if_fail (fieldname != NULL); + /* mutability checked in remove_field */ + + while (field) { + gst_structure_id_str_remove_field (structure, field); + field = va_arg (varargs, const GstIdStr *); + } +} + /** * gst_structure_remove_all_fields: * @structure: a #GstStructure @@ -1918,6 +2006,32 @@ gst_structure_nth_field_name (const GstStructure * structure, guint index) return gst_id_str_as_str (&field->name); } +/** + * gst_structure_id_str_nth_field_name: + * @structure: a #GstStructure + * @index: the index to get the name of + * + * Get the name (as a GstIdStr) of the given field number, + * counting from 0 onwards. + * + * Returns: the name of the given field number + * + * Since: 1.26 + */ +const GstIdStr * +gst_structure_id_str_nth_field_name (const GstStructure * structure, + guint index) +{ + GstStructureField *field; + + g_return_val_if_fail (structure != NULL, NULL); + g_return_val_if_fail (index < GST_STRUCTURE_LEN (structure), NULL); + + field = GST_STRUCTURE_FIELD (structure, index); + + return &field->name; +} + typedef struct { GstStructureForeachFunc func; diff --git a/subprojects/gstreamer/gst/gststructure.h b/subprojects/gstreamer/gst/gststructure.h index 982c1ca091..9e4578b353 100644 --- a/subprojects/gstreamer/gst/gststructure.h +++ b/subprojects/gstreamer/gst/gststructure.h @@ -377,6 +377,17 @@ void gst_structure_remove_fields_valist (GstStructure * const gchar * fieldname, va_list varargs); GST_API +void gst_structure_id_str_remove_field (GstStructure * structure, + const GstIdStr * fieldname); +GST_API +void gst_structure_id_str_remove_fields (GstStructure * structure, + const GstIdStr * fieldname, + ...) G_GNUC_NULL_TERMINATED; +GST_API +void gst_structure_id_str_remove_fields_valist(GstStructure * structure, + const GstIdStr * fieldname, + va_list varargs); +GST_API void gst_structure_remove_all_fields (GstStructure * structure); GST_API @@ -412,6 +423,9 @@ gint gst_structure_n_fields (const GstStructure * GST_API const gchar * gst_structure_nth_field_name (const GstStructure * structure, guint index); +GST_API +const GstIdStr * gst_structure_id_str_nth_field_name(const GstStructure * structure, + guint index); GST_DEPRECATED_FOR(gst_structure_id_str_has_field) gboolean gst_structure_id_has_field (const GstStructure * structure, GQuark field);