From: Sebastian Dröge Date: Fri, 27 May 2011 12:20:08 +0000 (+0200) Subject: audioresample: Optimize transform_caps() X-Git-Tag: RELEASE-0.11.0~239 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2162b07ada4bb145cc6dc4142410af6ac2492d5;p=platform%2Fupstream%2Fgst-plugins-base.git audioresample: Optimize transform_caps() If the second and next caps structures are a subset of the already existing transformed caps we can safely skip them because we would transform them to the same caps again. --- diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c index 1d0462f..7bf3980 100644 --- a/gst/audioresample/gstaudioresample.c +++ b/gst/audioresample/gstaudioresample.c @@ -293,10 +293,16 @@ gst_audio_resample_transform_caps (GstBaseTransform * base, /* transform single caps into input_caps + input_caps with the rate * field set to our supported range. This ensures that upstream knows * about downstream's prefered rate(s) and can negotiate accordingly. */ - res = gst_caps_copy (caps); - - n = gst_caps_get_size (res); + res = gst_caps_new_empty (); + n = gst_caps_get_size (caps); for (i = 0; i < n; i++) { + s = gst_caps_get_structure (caps, i); + + /* If this is already expressed by the existing caps + * skip this structure */ + if (i > 0 && gst_caps_is_subset_structure (res, s)) + continue; + /* first, however, check if the caps contain a range for the rate field, in * which case that side isn't going to care much about the exact sample rate * chosen and we should just assume things will get fixated to something sane @@ -305,17 +311,17 @@ gst_audio_resample_transform_caps (GstBaseTransform * base, * real preference or limitation and we should maintain that structure as * preference by putting it first into the transformed caps, and only add * our full rate range as second option */ - s = gst_caps_get_structure (res, i); + s = gst_structure_copy (s); val = gst_structure_get_value (s, "rate"); if (val == NULL || GST_VALUE_HOLDS_INT_RANGE (val)) { /* overwrite existing range, or add field if it doesn't exist yet */ gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); } else { /* append caps with full range to existing caps with non-range rate field */ - s = gst_structure_copy (s); + gst_caps_append_structure (res, gst_structure_copy (s)); gst_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); - gst_caps_merge_structure (res, s); } + gst_caps_append_structure (res, s); } if (filter) {