audioconvert: Always prefer the input format if possible

Previously we could've chosen another format with the same
depth even if the input format was possible.

Also make sure to chose according to the order in the
caps.
This commit is contained in:
Sebastian Dröge 2012-11-01 16:44:05 +01:00
parent bc4389806d
commit 9e6021fe4b

View file

@ -478,23 +478,37 @@ gst_audio_convert_fixate_format (GstBaseTransform * base, GstStructure * ins,
gst_audio_format_get_info (gst_audio_format_from_string (fname));
if (!t_info)
continue;
/* accept input format */
if (strcmp (fname, in_format) == 0)
/* accept input format immediately */
if (strcmp (fname, in_format) == 0) {
out_info = t_info;
break;
}
out_flags = GST_AUDIO_FORMAT_INFO_FLAGS (t_info);
out_flags &= ~(GST_AUDIO_FORMAT_FLAG_UNPACK);
out_flags &= ~(GST_AUDIO_FORMAT_FLAG_SIGNED);
/* or another format without losing precision */
if (in_flags == out_flags) {
if (GST_AUDIO_FORMAT_INFO_DEPTH (t_info) ==
GST_AUDIO_FORMAT_INFO_DEPTH (in_info)) {
/* exact match. We are done */
out_info = t_info;
break;
} else if ((GST_AUDIO_FORMAT_INFO_DEPTH (t_info) >=
GST_AUDIO_FORMAT_INFO_DEPTH (in_info) &&
(!out_info
|| GST_AUDIO_FORMAT_INFO_DEPTH (out_info) >=
GST_AUDIO_FORMAT_INFO_DEPTH (in_info))) {
/* exact match of depth, we still continue
* to iterate to see if we can get exactly
* the same format.
* Only go here if we don't have another
* format with the same depth already. We
* always take the first to prefer caps
* order. */
out_info = t_info;
} else if ((GST_AUDIO_FORMAT_INFO_DEPTH (t_info) >=
GST_AUDIO_FORMAT_INFO_DEPTH (in_info)) && !out_info) {
/* match where we do not lose precision. This could
be ok, but keep searching for an exact match */
* be ok, but keep searching for an exact match.
* Only go here if we don't have another format with
* a bigger/equal depth already. We always take the
* first to prefer caps order. */
out_info = t_info;
}
}