audioconvert: Always prefer the input format if possible
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 1 Nov 2012 15:44:05 +0000 (16:44 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 1 Nov 2012 15:44:05 +0000 (16:44 +0100)
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.

gst/audioconvert/gstaudioconvert.c

index 6ff7ff4..492d35f 100644 (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 */
+              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;
-            break;
           } else if ((GST_AUDIO_FORMAT_INFO_DEPTH (t_info) >=
-                  GST_AUDIO_FORMAT_INFO_DEPTH (in_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;
           }
         }