value: Add support for GstAllocationParams comparision
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Tue, 6 May 2014 20:59:34 +0000 (16:59 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 8 May 2014 17:08:21 +0000 (13:08 -0400)
This is useful to compare buffer pool configuaration.

https://bugzilla.gnome.org/show_bug.cgi?id=728268

gst/gstvalue.c
tests/check/gst/gstvalue.c

index 9e52f8a..86f6154 100644 (file)
@@ -5840,6 +5840,33 @@ gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
   return GST_VALUE_UNORDERED;
 }
 
+
+/***********************
+ * GstAllocationParams *
+ ***********************/
+static gint
+gst_value_compare_allocation_params (const GValue * value1,
+    const GValue * value2)
+{
+  GstAllocationParams *v1, *v2;
+
+  v1 = value1->data[0].v_pointer;
+  v2 = value2->data[0].v_pointer;
+
+  if (v1 == NULL && v1 == v2)
+    return GST_VALUE_EQUAL;
+
+  if (v1 == NULL || v2 == NULL)
+    return GST_VALUE_UNORDERED;
+
+  if (v1->flags == v2->flags && v1->align == v2->align &&
+      v1->prefix == v2->prefix && v1->padding == v2->padding)
+    return GST_VALUE_EQUAL;
+
+  return GST_VALUE_UNORDERED;
+}
+
+
 /************
  * GObject *
  ************/
@@ -6260,6 +6287,18 @@ _priv_gst_value_initialize (void)
   {
     static GstValueTable gst_value = {
       0,
+      gst_value_compare_allocation_params,
+      NULL,
+      NULL,
+    };
+
+    gst_value.type = gst_allocation_params_get_type ();
+    gst_value_register (&gst_value);
+  }
+
+  {
+    static GstValueTable gst_value = {
+      0,
       gst_value_compare_object,
       NULL,
       NULL,
index 774fecc..c833561 100644 (file)
@@ -584,6 +584,7 @@ GST_START_TEST (test_value_compare)
   GValue value1 = { 0 };
   GValue value2 = { 0 };
   GValue tmp = { 0 };
+  GstAllocationParams alloc_params = { 0 };
 
   g_value_init (&value1, G_TYPE_INT);
   g_value_set_int (&value1, 10);
@@ -781,6 +782,17 @@ GST_START_TEST (test_value_compare)
   fail_unless (gst_value_compare (&value1, &value1) == GST_VALUE_EQUAL);
   g_value_unset (&value1);
   g_value_unset (&value2);
+
+  /* Check that we can compare allocation params */
+  g_value_init (&value1, GST_TYPE_ALLOCATION_PARAMS);
+  g_value_set_boxed (&value1, &alloc_params);
+  g_value_init (&value2, GST_TYPE_ALLOCATION_PARAMS);
+  alloc_params.align = 1;
+  g_value_set_boxed (&value2, &alloc_params);
+  fail_unless (gst_value_compare (&value1, &value2) == GST_VALUE_UNORDERED);
+  fail_unless (gst_value_compare (&value1, &value1) == GST_VALUE_EQUAL);
+  g_value_unset (&value1);
+  g_value_unset (&value2);
 }
 
 GST_END_TEST;