diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-05-27 14:20:08 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-05-27 14:31:02 +0200 |
commit | a2162b07ada4bb145cc6dc4142410af6ac2492d5 (patch) | |
tree | d4f5c415cbc835d050d0ba9fc9968692d7a20f00 /gst/audioresample | |
parent | 4fcd621101a089727b7a66387b2db18fe9c116ab (diff) | |
download | gstreamer-plugins-base-a2162b07ada4bb145cc6dc4142410af6ac2492d5.tar.gz |
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.
Diffstat (limited to 'gst/audioresample')
-rw-r--r-- | gst/audioresample/gstaudioresample.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c index 1d0462f47..7bf39807a 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) { |