mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 20:51:13 +00:00
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.
This commit is contained in:
parent
4fcd621101
commit
a2162b07ad
1 changed files with 12 additions and 6 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue