*************/
static gint
-gst_value_compare_buffer (const GValue * value1, const GValue * value2)
+compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
{
- GstBuffer *buf1 = gst_value_get_buffer (value1);
- GstBuffer *buf2 = gst_value_get_buffer (value2);
gsize size1, size2;
GstMapInfo info1, info2;
- gint result = GST_VALUE_UNORDERED;
+ gint result, mret;
+
+ if (buf1 == buf2)
+ return GST_VALUE_EQUAL;
size1 = gst_buffer_get_size (buf1);
size2 = gst_buffer_get_size (buf2);
return GST_VALUE_UNORDERED;
}
- if (memcmp (info1.data, info2.data, info1.size) == 0)
+ mret = memcmp (info1.data, info2.data, info1.size);
+ if (mret == 0)
result = GST_VALUE_EQUAL;
+ else if (mret < 0)
+ result = GST_VALUE_LESS_THAN;
+ else
+ result = GST_VALUE_GREATER_THAN;
gst_buffer_unmap (buf1, &info1);
gst_buffer_unmap (buf2, &info2);
return result;
}
+static gint
+gst_value_compare_buffer (const GValue * value1, const GValue * value2)
+{
+ GstBuffer *buf1 = gst_value_get_buffer (value1);
+ GstBuffer *buf2 = gst_value_get_buffer (value2);
+
+ return compare_buffer (buf1, buf2);
+}
+
static gchar *
gst_value_serialize_buffer (const GValue * value)
{
}
}
+/*************
+ * GstSample *
+ *************/
+
+/* This function is mostly used for comparing image/buffer tags in taglists */
+static gint
+gst_value_compare_sample (const GValue * value1, const GValue * value2)
+{
+ GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
+ GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
+
+ /* FIXME: should we take into account anything else such as caps? */
+ return compare_buffer (buf1, buf2);
+}
/***********
* boolean *
{
static GstValueTable gst_value = {
0,
+ gst_value_compare_sample,
+ NULL,
+ NULL,
+ };
+
+ gst_value.type = GST_TYPE_SAMPLE;
+ gst_value_register (&gst_value);
+ }
+ {
+ static GstValueTable gst_value = {
+ 0,
gst_value_compare_fraction,
gst_value_serialize_fraction,
gst_value_deserialize_fraction,
GST_START_TEST (test_equal)
{
GstTagList *tags, *tags2;
+ GstSample *sample1, *sample2, *sample11;
+ GstBuffer *buf;
tags = gst_tag_list_new_empty ();
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_ARTIST, "Foo", NULL);
gst_tag_list_unref (tags);
gst_tag_list_unref (tags2);
+
+ /* samples */
+ buf = gst_buffer_new_wrapped (g_strdup ("test 1-2-3"), 10);
+ sample1 = gst_sample_new (buf, NULL, NULL, NULL);
+ gst_buffer_unref (buf);
+
+ buf = gst_buffer_new_wrapped (g_strdup ("test 1-2-3"), 10);
+ sample11 = gst_sample_new (buf, NULL, NULL, NULL);
+ gst_buffer_unref (buf);
+
+ buf = gst_buffer_new_wrapped (g_strdup ("test 2-3-4-5"), 12);
+ sample2 = gst_sample_new (buf, NULL, NULL, NULL);
+ gst_buffer_unref (buf);
+
+ tags = gst_tag_list_new_empty ();
+ gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_IMAGE, sample1, NULL);
+
+ tags2 = gst_tag_list_new_empty ();
+ fail_unless (!gst_tag_list_is_equal (tags2, tags));
+
+ /* sample sample, should be very equal now */
+ gst_tag_list_add (tags2, GST_TAG_MERGE_APPEND, GST_TAG_IMAGE, sample1, NULL);
+ fail_unless (gst_tag_list_is_equal (tags2, tags));
+ gst_tag_list_unref (tags2);
+
+ /* same buffer content, but different buffer instances, still rather equal */
+ tags2 = gst_tag_list_new_empty ();
+ gst_tag_list_add (tags2, GST_TAG_MERGE_APPEND, GST_TAG_IMAGE, sample11, NULL);
+ fail_unless (gst_tag_list_is_equal (tags2, tags));
+ gst_tag_list_unref (tags2);
+
+ /* different buffer content, should not be equal */
+ tags2 = gst_tag_list_new_empty ();
+ gst_tag_list_add (tags2, GST_TAG_MERGE_APPEND, GST_TAG_IMAGE, sample2, NULL);
+ fail_unless (!gst_tag_list_is_equal (tags2, tags));
+ gst_tag_list_unref (tags2);
+
+ gst_tag_list_unref (tags);
+
+ gst_sample_unref (sample1);
+ gst_sample_unref (sample11);
+ gst_sample_unref (sample2);
}
GST_END_TEST;