diff options
author | Tim-Philipp Müller <tim.muller@collabora.co.uk> | 2009-04-01 15:45:22 +0100 |
---|---|---|
committer | Dave Robillard <dave@drobilla.net> | 2009-05-03 12:03:13 -0400 |
commit | 8b596690b54eb2c21dff577fddd2f8d0738a1071 (patch) | |
tree | e6d08a2046a68bc9888a8816cdfe613e459b5715 | |
parent | c6ca9781affed8dcec987f409a65a903f2663958 (diff) | |
download | gst-plugins-bad-8b596690b54eb2c21dff577fddd2f8d0738a1071.tar.gz gst-plugins-bad-8b596690b54eb2c21dff577fddd2f8d0738a1071.tar.bz2 gst-plugins-bad-8b596690b54eb2c21dff577fddd2f8d0738a1071.zip |
legacyresample: fix negotiation so that upstream can actually fixate to downstream's rate
If one side has a preference for a particular sample rate or set of sample rates, we
should honour this in the caps we advertise and transform to and from, so that elements
actually know about the other side's sample rate preference and can negotiate to it
if supported. Also add unit test for this.
-rw-r--r-- | gst/legacyresample/gstlegacyresample.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/gst/legacyresample/gstlegacyresample.c b/gst/legacyresample/gstlegacyresample.c index 908b6ad9..cbcd6fdd 100644 --- a/gst/legacyresample/gstlegacyresample.c +++ b/gst/legacyresample/gstlegacyresample.c @@ -265,14 +265,34 @@ static GstCaps * legacyresample_transform_caps (GstBaseTransform * base, GstPadDirection direction, GstCaps * caps) { + const GValue *val; + GstStructure *s; GstCaps *res; - GstStructure *structure; - /* transform caps gives one single caps so we can just replace - * the rate property with our range. */ + /* 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); - structure = gst_caps_get_structure (res, 0); - gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + + /* 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 + * and we may just as well offer our full range instead of the range in the + * caps. If the rate is not an int range value, it's likely to express a + * 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, 0); + 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_structure_set (s, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL); + gst_caps_append_structure (res, s); + } return res; } |