From 70d1f1f177fae7c5743ec7614d152f5cbe80a9d9 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 1 Jul 2010 17:56:33 +0200 Subject: [PATCH] gstcaps: Make sure _normalize() is applied on all structures. We need to use gst_caps_get_size() in the loop counter since some structures could be added while iterating. Fixes #623301 --- gst/gstcaps.c | 5 ++-- tests/check/gst/gstcaps.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 26a7dbd..14f9f74 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -1763,15 +1763,14 @@ gst_caps_normalize (const GstCaps * caps) { NormalizeForeach nf; GstCaps *newcaps; - guint i, nlen; + guint i; g_return_val_if_fail (GST_IS_CAPS (caps), NULL); newcaps = gst_caps_copy (caps); nf.caps = newcaps; - nlen = newcaps->structs->len; - for (i = 0; i < nlen; i++) { + for (i = 0; i < gst_caps_get_size (newcaps); i++) { nf.structure = gst_caps_get_structure_unchecked (newcaps, i); while (!gst_structure_foreach (nf.structure, diff --git a/tests/check/gst/gstcaps.c b/tests/check/gst/gstcaps.c index 1bdca29..6fb35e1 100644 --- a/tests/check/gst/gstcaps.c +++ b/tests/check/gst/gstcaps.c @@ -728,6 +728,72 @@ GST_START_TEST (test_intersect2) GST_END_TEST; +static gboolean +_caps_is_fixed_foreach (GQuark field_id, const GValue * value, gpointer unused) +{ + return gst_value_is_fixed (value); +} + + +GST_START_TEST (test_normalize) +{ + GstCaps *in, *norm, *out; + guint i; + + in = gst_caps_from_string ("some/type, foo=(int){ 1 , 2 }"); + out = gst_caps_from_string ("some/type, foo=(int) 1; some/type, foo=(int) 2"); + norm = gst_caps_normalize (in); + fail_if (gst_caps_is_empty (norm)); + fail_unless (gst_caps_is_equal (norm, out)); + for (i = 0; i < gst_caps_get_size (norm); i++) { + GstStructure *st = gst_caps_get_structure (norm, i); + /* Make sure all fields of all structures are fixed */ + fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL)); + } + + gst_caps_unref (in); + gst_caps_unref (out); + gst_caps_unref (norm); + + in = gst_caps_from_string + ("some/type, foo=(int){ 1 , 2 }, bar=(int){ 3, 4 }"); + out = + gst_caps_from_string + ("some/type, foo=(int) 1, bar=(int) 3; some/type, foo=(int) 2, bar=(int) 3;" + "some/type, foo=(int) 1, bar=(int) 4; some/type, foo=(int) 2, bar=(int) 4;"); + norm = gst_caps_normalize (in); + fail_if (gst_caps_is_empty (norm)); + fail_unless (gst_caps_is_equal (norm, out)); + for (i = 0; i < gst_caps_get_size (norm); i++) { + GstStructure *st = gst_caps_get_structure (norm, i); + /* Make sure all fields of all structures are fixed */ + fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL)); + } + + gst_caps_unref (in); + gst_caps_unref (out); + gst_caps_unref (norm); + + in = gst_caps_from_string + ("some/type, foo=(string){ 1 , 2 }, bar=(string) { 3 }"); + out = + gst_caps_from_string + ("some/type, foo=(string) 1, bar=(string) 3; some/type, foo=(string) 2, bar=(string) 3"); + norm = gst_caps_normalize (in); + fail_if (gst_caps_is_empty (norm)); + fail_unless (gst_caps_is_equal (norm, out)); + for (i = 0; i < gst_caps_get_size (norm); i++) { + GstStructure *st = gst_caps_get_structure (norm, i); + /* Make sure all fields of all structures are fixed */ + fail_unless (gst_structure_foreach (st, _caps_is_fixed_foreach, NULL)); + } + + gst_caps_unref (in); + gst_caps_unref (out); + gst_caps_unref (norm); +} + +GST_END_TEST; static Suite * gst_caps_suite (void) @@ -748,6 +814,7 @@ gst_caps_suite (void) tcase_add_test (tc_chain, test_merge_subset); tcase_add_test (tc_chain, test_intersect); tcase_add_test (tc_chain, test_intersect2); + tcase_add_test (tc_chain, test_normalize); return s; } -- 2.7.4