gst: structure: Use GstIdStr for structure field names

And add corresponding API with GstIdStr parameters, static string parameters and
deprecate the old GQuark based API.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3567

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7432>
This commit is contained in:
Sebastian Dröge 2024-08-29 20:07:13 +03:00
parent 0c1611d31d
commit 2df9c4739e
4 changed files with 896 additions and 147 deletions

View file

@ -183,7 +183,7 @@ gboolean priv_gst_structure_append_to_gstring (const GstStructure * structure,
GString * s,
GstSerializeFlags flags);
G_GNUC_INTERNAL
gboolean priv__gst_structure_append_template_to_gstring (GQuark field_id,
gboolean priv__gst_structure_append_template_to_gstring (const gchar * field,
const GValue *value,
gpointer user_data);

File diff suppressed because it is too large Load diff

View file

@ -115,6 +115,61 @@ typedef gboolean (*GstStructureFilterMapFunc) (GQuark field_id,
GValue * value,
gpointer user_data);
/**
* GstStructureForeachIdStrFunc:
* @fieldname: the #GstIdStr field name
* @value: the #GValue of the field
* @user_data: user data
*
* A function that will be called in gst_structure_foreach_id_str(). The
* function may not modify @value.
*
* Returns: %TRUE if the foreach operation should continue, %FALSE if
* the foreach operation should stop with %FALSE.
*
* Since: 1.26
*/
typedef gboolean (*GstStructureForeachIdStrFunc) (const GstIdStr * fieldname,
const GValue * value,
gpointer user_data);
/**
* GstStructureMapIdStrFunc:
* @fieldname: the #GstIdStr field name
* @value: the #GValue of the field
* @user_data: user data
*
* A function that will be called in gst_structure_map_in_place_id_str(). The
* function may modify @value.
*
* Returns: %TRUE if the map operation should continue, %FALSE if
* the map operation should stop with %FALSE.
*
* Since: 1.26
*/
typedef gboolean (*GstStructureMapIdStrFunc) (const GstIdStr * fieldname,
GValue * value,
gpointer user_data);
/**
* GstStructureFilterMapIdStrFunc:
* @fieldname: the #GstIdStr field name
* @value: the #GValue of the field
* @user_data: user data
*
* A function that will be called in gst_structure_filter_and_map_in_place_id_str().
* The function may modify @value, and the value will be removed from the
* structure if %FALSE is returned.
*
* Returns: %TRUE if the field should be preserved, %FALSE if it
* should be removed.
*
* Since: 1.26
*/
typedef gboolean (*GstStructureFilterMapIdStrFunc) (const GstIdStr * fieldname,
GValue * value,
gpointer user_data);
/**
* GstStructure:
* @type: the GType of a structure
@ -166,8 +221,8 @@ GstStructure * gst_structure_new_id (GQuark name_quark,
GST_API
GstStructure * gst_structure_new_id_str (const GstIdStr *name,
GQuark field_quark,
...) G_GNUC_MALLOC;
const GstIdStr *fieldname,
...) G_GNUC_NULL_TERMINATED G_GNUC_MALLOC;
GST_API
GstStructure * gst_structure_new_from_string (const gchar * string);
@ -205,15 +260,23 @@ void gst_structure_set_name (GstStructure *
const gchar * name);
void gst_structure_set_name_static_str (GstStructure * structure,
const gchar * name);
GST_API
GST_DEPRECATED_FOR(gst_structure_id_str_set_value)
void gst_structure_id_set_value (GstStructure * structure,
GQuark field,
const GValue * value);
GST_API
void gst_structure_id_str_set_value (GstStructure * structure,
const GstIdStr * fieldname,
const GValue * value);
GST_API
void gst_structure_set_value (GstStructure * structure,
const gchar * fieldname,
const GValue * value);
GST_API
void gst_structure_set_value_static_str (GstStructure * structure,
const gchar * fieldname,
const GValue * value);
GST_API
void gst_structure_set_array (GstStructure * structure,
const gchar * fieldname,
const GValueArray * array);
@ -221,31 +284,55 @@ GST_API
void gst_structure_set_list (GstStructure * structure,
const gchar * fieldname,
const GValueArray * array);
GST_API
GST_DEPRECATED_FOR(gst_structure_id_str_take_value)
void gst_structure_id_take_value (GstStructure * structure,
GQuark field,
GValue * value);
GST_API
void gst_structure_id_str_take_value (GstStructure * structure,
const GstIdStr * fieldname,
GValue * value);
GST_API
void gst_structure_take_value (GstStructure * structure,
const gchar * fieldname,
GValue * value);
GST_API
void gst_structure_take_value_static_str(GstStructure * structure,
const gchar * fieldname,
GValue * value);
GST_API
void gst_structure_set (GstStructure * structure,
const gchar * fieldname,
...) G_GNUC_NULL_TERMINATED;
GST_API
void gst_structure_set_static_str (GstStructure * structure,
const gchar * fieldname,
...) G_GNUC_NULL_TERMINATED;
GST_API
void gst_structure_set_valist (GstStructure * structure,
const gchar * fieldname,
va_list varargs);
GST_API
void gst_structure_set_static_str_valist(GstStructure * structure,
const gchar * fieldname,
va_list varargs);
GST_DEPRECATED_FOR(gst_structure_id_str_set)
void gst_structure_id_set (GstStructure * structure,
GQuark fieldname,
...) G_GNUC_NULL_TERMINATED;
GST_API
void gst_structure_id_str_set (GstStructure * structure,
const GstIdStr * fieldname,
...) G_GNUC_NULL_TERMINATED;
GST_DEPRECATED_FOR(gst_structure_id_str_set_valist)
void gst_structure_id_set_valist (GstStructure * structure,
GQuark fieldname,
va_list varargs);
GST_API
void gst_structure_id_str_set_valist (GstStructure * structure,
const GstIdStr * fieldname,
va_list varargs);
GST_API
gboolean gst_structure_get_valist (const GstStructure * structure,
const char * first_fieldname,
va_list args);
@ -254,17 +341,28 @@ gboolean gst_structure_get (const GstStructure *
const char * first_fieldname,
...) G_GNUC_NULL_TERMINATED;
GST_API
gboolean gst_structure_id_str_get_valist (const GstStructure * structure,
const GstIdStr * first_fieldname,
va_list args);
GST_API
gboolean gst_structure_id_str_get (const GstStructure * structure,
const GstIdStr * first_fieldname,
...) G_GNUC_NULL_TERMINATED;
GST_DEPRECATED_FOR(gst_structure_id_str_get_valist)
gboolean gst_structure_id_get_valist (const GstStructure * structure,
GQuark first_field_id,
va_list args);
GST_API
GST_DEPRECATED_FOR(gst_structure_id_str_get)
gboolean gst_structure_id_get (const GstStructure * structure,
GQuark first_field_id,
...) G_GNUC_NULL_TERMINATED;
GST_API
GST_DEPRECATED_FOR(gst_structure_id_str_get_value)
const GValue * gst_structure_id_get_value (const GstStructure * structure,
GQuark field);
GST_API
const GValue * gst_structure_id_str_get_value (const GstStructure * structure,
const GstIdStr * fieldname);
GST_API
const GValue * gst_structure_get_value (const GstStructure * structure,
const gchar * fieldname);
GST_API
@ -284,28 +382,40 @@ void gst_structure_remove_all_fields (GstStructure *
GST_API
GType gst_structure_get_field_type (const GstStructure * structure,
const gchar * fieldname);
GST_API
GST_DEPRECATED_FOR(gst_structure_foreach_id_str)
gboolean gst_structure_foreach (const GstStructure * structure,
GstStructureForeachFunc func,
gpointer user_data);
GST_API
GST_DEPRECATED_FOR(gst_structure_map_in_place_id_str)
gboolean gst_structure_map_in_place (GstStructure * structure,
GstStructureMapFunc func,
gpointer user_data);
GST_API
GST_DEPRECATED_FOR(gst_structure_filter_and_map_in_place_id_str)
void gst_structure_filter_and_map_in_place (GstStructure * structure,
GstStructureFilterMapFunc func,
gpointer user_data);
GST_API
gboolean gst_structure_foreach_id_str (const GstStructure * structure,
GstStructureForeachIdStrFunc func,
gpointer user_data);
GST_API
gboolean gst_structure_map_in_place_id_str (GstStructure * structure,
GstStructureMapIdStrFunc func,
gpointer user_data);
GST_API
void gst_structure_filter_and_map_in_place_id_str (GstStructure * structure,
GstStructureFilterMapIdStrFunc func,
gpointer user_data);
GST_API
gint gst_structure_n_fields (const GstStructure * structure);
GST_API
const gchar * gst_structure_nth_field_name (const GstStructure * structure,
guint index);
GST_API
GST_DEPRECATED_FOR(gst_structure_id_str_has_field)
gboolean gst_structure_id_has_field (const GstStructure * structure,
GQuark field);
GST_API
GST_DEPRECATED_FOR(gst_structure_id_str_has_field_typed)
gboolean gst_structure_id_has_field_typed (const GstStructure * structure,
GQuark field,
GType type);
@ -316,6 +426,13 @@ GST_API
gboolean gst_structure_has_field_typed (const GstStructure * structure,
const gchar * fieldname,
GType type);
GST_API
gboolean gst_structure_id_str_has_field (const GstStructure * structure,
const GstIdStr * fieldname);
GST_API
gboolean gst_structure_id_str_has_field_typed(const GstStructure * structure,
const GstIdStr * fieldname,
GType type);
/* utility functions */

View file

@ -82,14 +82,13 @@ build_field_template (GQuark field_id, const GValue * value, gpointer user_data)
/* add a boolean field, that indicates the presence of the next field */
g_value_init (&template_value, G_TYPE_BOOLEAN);
priv__gst_structure_append_template_to_gstring (g_quark_from_string
(opt_name), &template_value, s);
priv__gst_structure_append_template_to_gstring (opt_name, &template_value, s);
g_value_unset (&template_value);
g_free (opt_name);
}
g_value_init (&template_value, type);
res = priv__gst_structure_append_template_to_gstring (field_id,
res = priv__gst_structure_append_template_to_gstring (g_quark_to_string (field_id),
&template_value, s);
g_value_unset (&template_value);
return res;