From fffc3ba7704877f5ea8640170b1385fdb06a4efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 1 Apr 2009 15:45:22 +0100 Subject: 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. --- gst/legacyresample/gstlegacyresample.c | 30 +++++++++++++++++++++++++----- 1 file 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; } -- cgit v1.2.1