gstructure: New API: gst_structure_is_equal
authorEdward Hervey <bilboed@bilboed.com>
Fri, 10 Sep 2010 16:14:05 +0000 (18:14 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Tue, 17 May 2011 07:28:00 +0000 (09:28 +0200)
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

docs/gst/gstreamer-sections.txt
gst/gstcaps.c
gst/gststructure.c
gst/gststructure.h
win32/common/libgstreamer.def

index 47e8d7f..25633e5 100644 (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
index 84fce69..dc7735d 100644 (file)
@@ -566,22 +566,6 @@ gst_caps_steal_structure (GstCaps * caps, guint 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);
 }
 
 /**
index f0ff914..7b962c7 100644 (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);
+}
index 48c81c4..1d0d812 100644 (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
index 021e92a..0fcebc8 100644 (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