diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 044db84f96..ee6d19af83 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -1979,13 +1979,14 @@ gst_value_deserialize_structure (GValue * dest, const gchar * s) *************/ 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); @@ -2004,8 +2005,13 @@ gst_value_compare_buffer (const GValue * value1, const GValue * value2) 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); @@ -2013,6 +2019,15 @@ gst_value_compare_buffer (const GValue * value1, const GValue * value2) 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) { @@ -2094,6 +2109,20 @@ wrong_char: } } +/************* + * 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 * @@ -5763,6 +5792,17 @@ _priv_gst_value_initialize (void) gst_value.type = GST_TYPE_BUFFER; gst_value_register (&gst_value); } + { + 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, diff --git a/tests/check/gst/gsttag.c b/tests/check/gst/gsttag.c index 9dcca2d80d..a8e612e99f 100644 --- a/tests/check/gst/gsttag.c +++ b/tests/check/gst/gsttag.c @@ -452,6 +452,8 @@ GST_END_TEST; 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); @@ -482,6 +484,48 @@ GST_START_TEST (test_equal) 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;