audiomixmatrix: Fix negotiation in first-channels mode if downstream does not allow the same number of channels

This commit is contained in:
Sebastian Dröge 2017-03-03 15:17:15 +02:00
parent ffbe690656
commit c3d21053aa

View file

@ -680,7 +680,7 @@ gst_audio_mix_matrix_fixate_caps (GstBaseTransform * trans,
/* Try to keep channel configuration as much as possible */ /* Try to keep channel configuration as much as possible */
if (gst_structure_get_int (s2, "channels", &channels)) { if (gst_structure_get_int (s2, "channels", &channels)) {
gint mindiff = channels; gint mindiff = -1;
othercaps = gst_caps_make_writable (othercaps); othercaps = gst_caps_make_writable (othercaps);
for (i = 0; i < capssize; i++) { for (i = 0; i < capssize; i++) {
s = gst_caps_get_structure (othercaps, i); s = gst_caps_get_structure (othercaps, i);
@ -694,26 +694,31 @@ gst_audio_mix_matrix_fixate_caps (GstBaseTransform * trans,
gst_structure_fixate_field_nearest_int (s, "channels", channels); gst_structure_fixate_field_nearest_int (s, "channels", channels);
if (gst_structure_get_int (s, "channels", &outchannels)) { if (gst_structure_get_int (s, "channels", &outchannels)) {
diff = ABS (channels - outchannels); diff = ABS (channels - outchannels);
if (diff < mindiff) if (mindiff < 0 || diff < mindiff)
mindiff = diff; mindiff = diff;
} }
} }
} }
for (i = 0; i < capssize; i++) { if (mindiff >= 0) {
gint outchannels, diff; for (i = 0; i < capssize; i++) {
s = gst_caps_get_structure (othercaps, i); gint outchannels, diff;
if (gst_structure_get_int (s, "channels", &outchannels)) { s = gst_caps_get_structure (othercaps, i);
diff = ABS (channels - outchannels); if (gst_structure_get_int (s, "channels", &outchannels)) {
if (diff > mindiff) { diff = ABS (channels - outchannels);
gst_caps_remove_structure (othercaps, i--); if (diff > mindiff) {
capssize--; gst_caps_remove_structure (othercaps, i--);
capssize--;
}
} }
} }
} }
} }
} }
if (gst_caps_is_empty (othercaps))
return othercaps;
othercaps = othercaps =
GST_BASE_TRANSFORM_CLASS (gst_audio_mix_matrix_parent_class)->fixate_caps GST_BASE_TRANSFORM_CLASS (gst_audio_mix_matrix_parent_class)->fixate_caps
(trans, direction, caps, othercaps); (trans, direction, caps, othercaps);