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
This commit is contained in:
Edward Hervey 2010-07-01 17:56:33 +02:00
parent cda5a353d2
commit 70d1f1f177
2 changed files with 69 additions and 3 deletions

View file

@ -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,

View file

@ -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;
}