summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gst/legacyresample/gstlegacyresample.c30
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;
}