}
gst_caps_unref (src);
- gst_caps_do_simplify (dest);
+ dest = gst_caps_do_simplify (dest);
return dest;
}
dest1 = _gst_caps_copy (caps1);
gst_caps_append (dest1, gst_caps_ref (caps2));
- gst_caps_do_simplify (dest1);
+ dest1 = gst_caps_do_simplify (dest1);
return dest1;
}
/**
* gst_caps_do_simplify:
- * @caps: a #GstCaps to simplify
+ * @caps: (transfer full): a #GstCaps to simplify
*
* Modifies the given @caps inplace into a representation that represents the
* same set of formats, but in a simpler form. Component structures that are
* identical are merged. Component structures that have values that can be
* merged are also merged.
*
- * Returns: TRUE, if the caps could be simplified
+ * Returns: The simplified caps.
*/
-gboolean
+GstCaps *
gst_caps_do_simplify (GstCaps * caps)
{
GstStructure *simplify, *compare, *result = NULL;
gint i, j, start;
- gboolean changed = FALSE;
- g_return_val_if_fail (caps != NULL, FALSE);
- g_return_val_if_fail (IS_WRITABLE (caps), FALSE);
+ g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
- if (gst_caps_get_size (caps) < 2)
- return FALSE;
+ if (gst_caps_is_fixed (caps))
+ return caps;
+
+ caps = gst_caps_make_writable (caps);
g_ptr_array_sort (GST_CAPS_ARRAY (caps), gst_caps_compare_structures);
start = GST_CAPS_LEN (caps) - 1;
- for (i = GST_CAPS_LEN (caps) - 1; i >= 0; i--) {
+ for (i = start; i >= 0; i--) {
simplify = gst_caps_get_structure_unchecked (caps, i);
+ compare = gst_caps_get_structure_unchecked (caps, start);
if (gst_structure_get_name_id (simplify) !=
- gst_structure_get_name_id (gst_caps_get_structure_unchecked (caps,
- start)))
+ gst_structure_get_name_id (compare))
start = i;
for (j = start; j >= 0; j--) {
if (j == i)
start--;
break;
}
- changed = TRUE;
}
}
}
-
- if (!changed)
- return FALSE;
-
- /* gst_caps_do_simplify (caps); */
- return TRUE;
+ return caps;
}
/**
GstCaps * gst_caps_union (GstCaps *caps1,
GstCaps *caps2) G_GNUC_WARN_UNUSED_RESULT;
GstCaps * gst_caps_normalize (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
-gboolean gst_caps_do_simplify (GstCaps *caps);
+GstCaps * gst_caps_do_simplify (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
GstCaps * gst_caps_fixate (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
}
/* save caps */
if (factory->caps) {
- /* we copy the caps here so we can simplify them before saving. This
- * is a lot faster when loading them later on */
- if (!gst_caps_is_fixed (factory->caps)) {
- GstCaps *copy = gst_caps_copy (factory->caps);
- gst_caps_do_simplify (copy);
- str = gst_caps_to_string (copy);
- gst_caps_unref (copy);
- } else {
- str = gst_caps_to_string (factory->caps);
- }
+ GstCaps *fcaps = gst_caps_ref (factory->caps);
+ /* we simplify the caps before saving. This is a lot faster
+ * when loading them later on */
+ fcaps = gst_caps_do_simplify (fcaps);
+ str = gst_caps_to_string (fcaps);
+ gst_caps_unref (fcaps);
+
gst_registry_chunks_save_string (list, str);
} else {
gst_registry_chunks_save_const_string (list, "");
GST_START_TEST (test_simplify)
{
GstStructure *s1;
- gboolean did_simplify;
GstCaps *caps;
caps = gst_caps_from_string (non_simple_caps_string);
fail_unless (caps != NULL,
"gst_caps_from_string (non_simple_caps_string) failed");
- did_simplify = gst_caps_do_simplify (caps);
- fail_unless (did_simplify == TRUE,
- "gst_caps_do_simplify() should have worked");
+ caps = gst_caps_do_simplify (caps);
+ fail_unless (caps != NULL, "gst_caps_do_simplify() should have worked");
/* check simplified caps, should be:
*