summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2012-03-12 10:42:23 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2012-03-12 10:42:23 +0100
commit9cdbffea9474d8cd5a810ab536af65ec00a37a36 (patch)
tree2b51dca173f155e8ba75c6441d00ee1dd5a232ea
parent6886be59f539537037d9dadfba98170122bd249f (diff)
caps: improve _do_simplify
Make gst_caps_do_simplify() take ownership of the input caps and produce a simplified output caps. This removes the requirement of having writable input caps and the method can make the caps writable only when needed.
-rw-r--r--gst/gstcaps.c34
-rw-r--r--gst/gstcaps.h2
-rw-r--r--gst/gstregistrychunks.c17
-rw-r--r--plugins/elements/gstcapsfilter.c3
-rw-r--r--tests/check/gst/gstcaps.c6
5 files changed, 25 insertions, 37 deletions
diff --git a/gst/gstcaps.c b/gst/gstcaps.c
index bd40eda65..e14ba947d 100644
--- a/gst/gstcaps.c
+++ b/gst/gstcaps.c
@@ -1498,7 +1498,7 @@ gst_caps_subtract (GstCaps * minuend, GstCaps * subtrahend)
}
gst_caps_unref (src);
- gst_caps_do_simplify (dest);
+ dest = gst_caps_do_simplify (dest);
return dest;
}
@@ -1575,7 +1575,7 @@ gst_caps_union (GstCaps * caps1, GstCaps * caps2)
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;
}
@@ -1765,36 +1765,36 @@ gst_caps_switch_structures (GstCaps * caps, GstStructure * old,
/**
* 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)
@@ -1813,16 +1813,10 @@ gst_caps_do_simplify (GstCaps * caps)
start--;
break;
}
- changed = TRUE;
}
}
}
-
- if (!changed)
- return FALSE;
-
- /* gst_caps_do_simplify (caps); */
- return TRUE;
+ return caps;
}
/**
diff --git a/gst/gstcaps.h b/gst/gstcaps.h
index 442083565..9563b3abb 100644
--- a/gst/gstcaps.h
+++ b/gst/gstcaps.h
@@ -438,7 +438,7 @@ GstCaps * gst_caps_subtract (GstCaps *minuend,
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;
diff --git a/gst/gstregistrychunks.c b/gst/gstregistrychunks.c
index dacacd439..b377b9456 100644
--- a/gst/gstregistrychunks.c
+++ b/gst/gstregistrychunks.c
@@ -321,16 +321,13 @@ gst_registry_chunks_save_feature (GList ** list, GstPluginFeature * feature)
}
/* 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, "");
diff --git a/plugins/elements/gstcapsfilter.c b/plugins/elements/gstcapsfilter.c
index 172c55241..685e04dbc 100644
--- a/plugins/elements/gstcapsfilter.c
+++ b/plugins/elements/gstcapsfilter.c
@@ -298,8 +298,7 @@ gst_capsfilter_prepare_buf (GstBaseTransform * trans, GstBuffer * input,
g_return_val_if_fail (out_caps != NULL, GST_FLOW_ERROR);
}
- out_caps = gst_caps_make_writable (out_caps);
- gst_caps_do_simplify (out_caps);
+ out_caps = gst_caps_do_simplify (out_caps);
if (gst_caps_is_fixed (out_caps) && !gst_caps_is_empty (out_caps)) {
GST_DEBUG_OBJECT (trans, "Have fixed output caps %"
diff --git a/tests/check/gst/gstcaps.c b/tests/check/gst/gstcaps.c
index cede2cd65..281ddf29e 100644
--- a/tests/check/gst/gstcaps.c
+++ b/tests/check/gst/gstcaps.c
@@ -190,16 +190,14 @@ check_string_list (const GValue * format_value)
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:
*