/* copies the given caps */
static GstCaps *
-gst_audio_convert_caps_remove_format_info (GstCaps * caps)
+gst_audio_convert_caps_remove_format_info (GstCaps * caps, gboolean channels)
{
GstStructure *st;
gint i, n;
n = gst_caps_get_size (caps);
for (i = 0; i < n; i++) {
+ gboolean remove_channels = FALSE;
+
st = gst_caps_get_structure (caps, i);
/* If this is already expressed by the existing caps
if (gst_structure_get (st, "channel-mask", GST_TYPE_BITMASK, &channel_mask,
NULL)) {
if (channel_mask != 0)
- gst_structure_remove_fields (st, "channel-mask", "channels", NULL);
+ remove_channels = TRUE;
} else {
- gst_structure_remove_fields (st, "channel-mask", "channels", NULL);
+ remove_channels = TRUE;
}
+ if (remove_channels && channels)
+ gst_structure_remove_fields (st, "channel-mask", "channels", NULL);
+
gst_caps_append_structure (res, st);
}
GstCaps *result;
/* Get all possible caps that we can transform to */
- tmp = gst_audio_convert_caps_remove_format_info (caps);
+ tmp = gst_audio_convert_caps_remove_format_info (caps, TRUE);
if (filter) {
tmp2 = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
result = gst_caps_intersect (othercaps, caps);
if (gst_caps_is_empty (result)) {
+ GstCaps *removed;
+
if (result)
gst_caps_unref (result);
- result = othercaps;
+ /* try to preserve channels */
+ removed = gst_audio_convert_caps_remove_format_info (caps, FALSE);
+ result = gst_caps_intersect (othercaps, removed);
+ gst_caps_unref (removed);
+ if (gst_caps_is_empty (result)) {
+ if (result)
+ gst_caps_unref (result);
+ result = othercaps;
+ }
} else {
gst_caps_unref (othercaps);
}
+ GST_DEBUG_OBJECT (base, "now fixating %" GST_PTR_FORMAT, result);
+
/* fixate remaining fields */
result = gst_caps_make_writable (result);