gstructure: New API: gst_structure_is_equal

Allows checking equality of GstStructure without having to create
intermediary GstCaps.

API: gst_structure_is_equal

https://bugzilla.gnome.org/show_bug.cgi?id=629300
This commit is contained in:
Edward Hervey 2010-09-10 18:14:05 +02:00 committed by Sebastian Dröge
parent fe1dcbe6fa
commit ae46eb3a38
5 changed files with 51 additions and 25 deletions

View file

@ -2209,6 +2209,7 @@ gst_structure_foreach
gst_structure_n_fields
gst_structure_has_field
gst_structure_has_field_typed
gst_structure_is_equal
gst_structure_id_has_field
gst_structure_id_has_field_typed
gst_structure_get_boolean

View file

@ -565,22 +565,6 @@ gst_caps_steal_structure (GstCaps * caps, guint index)
return gst_caps_remove_and_get_structure (caps, index);
}
static gboolean
gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
gpointer data)
{
GstStructure *struct1 = (GstStructure *) data;
const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
if (G_UNLIKELY (val1 == NULL))
return FALSE;
if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
return TRUE;
}
return FALSE;
}
static gboolean
gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
gpointer user_data)
@ -1117,15 +1101,7 @@ gst_caps_is_equal_fixed (const GstCaps * caps1, const GstCaps * caps2)
struct1 = gst_caps_get_structure_unchecked (caps1, 0);
struct2 = gst_caps_get_structure_unchecked (caps2, 0);
if (struct1->name != struct2->name) {
return FALSE;
}
if (struct1->fields->len != struct2->fields->len) {
return FALSE;
}
return gst_structure_foreach (struct1, gst_structure_is_equal_foreach,
struct2);
return gst_structure_is_equal (struct1, struct2);
}
/**

View file

@ -2916,3 +2916,48 @@ gst_structure_id_get (const GstStructure * structure, GQuark first_field_id,
return ret;
}
static gboolean
gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
gpointer data)
{
GstStructure *struct1 = (GstStructure *) data;
const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
if (G_UNLIKELY (val1 == NULL))
return FALSE;
if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
return TRUE;
}
return FALSE;
}
/**
* gst_structure_is_equal:
* @structure1: a #GstStructure.
* @structure2: a #GstStructure.
*
* Tests if the two #GstStructure are equal.
*
* Returns: TRUE if the two structures have the same name and field.
*
* Since: 0.10.31
**/
gboolean
gst_structure_is_equal (const GstStructure * structure1,
GstStructure * structure2)
{
g_return_val_if_fail (GST_IS_STRUCTURE (structure1), FALSE);
g_return_val_if_fail (GST_IS_STRUCTURE (structure2), FALSE);
if (structure1->name != structure2->name) {
return FALSE;
}
if (structure1->fields->len != structure2->fields->len) {
return FALSE;
}
return gst_structure_foreach (structure1, gst_structure_is_equal_foreach,
structure2);
}

View file

@ -248,6 +248,9 @@ gboolean gst_structure_fixate_field_nearest_fraction (GstStructu
const gint target_numerator,
const gint target_denominator);
gboolean gst_structure_is_equal(const GstStructure *structure1,
GstStructure *structure2);
G_END_DECLS
#endif

View file

@ -1007,6 +1007,7 @@ EXPORTS
gst_structure_id_set_valist
gst_structure_id_set_value
gst_structure_id_take_value
gst_structure_is_equal
gst_structure_map_in_place
gst_structure_n_fields
gst_structure_new