audio: sort formats by quality
authorGuillaume Desmottes <guillaume.desmottes@collabora.com>
Thu, 4 Jun 2020 14:40:44 +0000 (16:40 +0200)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 9 Jun 2020 08:09:58 +0000 (08:09 +0000)
Will ensure that we pick the "best" format when negotiating caps.

Fix #649

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/689>

gst-libs/gst/audio/audio-format.h

index b917d154359f6b1b366033c709e2065be0b11e80..ccad5cf6f523dce43624bb584e8f464401011d7d 100644 (file)
@@ -326,15 +326,32 @@ void           gst_audio_format_fill_silence     (const GstAudioFormatInfo *info
  * GST_AUDIO_FORMATS_ALL:
  *
  * List of all audio formats, for use in template caps strings.
+ *
+ * Formats are sorted by decreasing "quality", using these criteria by priority:
+ *   - depth
+ *   - width
+ *   - Float > Signed > Unsigned
+ *   - native endianness preferred
  */
-#define GST_AUDIO_FORMATS_ALL "{ S8, U8, " \
-    "S16LE, S16BE, U16LE, U16BE, " \
+#if G_BYTE_ORDER == G_BIG_ENDIAN
+#define GST_AUDIO_FORMATS_ALL "{ F64BE, F64LE, " \
+    "F32BE, F32LE, S32BE, S32LE, U32BE, U32LE, " \
+    "S24_32BE, S24_32LE, U24_32BE, U24_32LE, " \
+    "S24BE, S24LE, U24BE, U24LE, " \
+    "S20BE, S20LE, U20BE, U20LE, " \
+    "S18BE, S18LE, U18BE, U18LE, " \
+    "S16BE, S16LE, U16BE, U16LE, " \
+    "S8,U8 }"
+#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define GST_AUDIO_FORMATS_ALL "{ F64LE, F64BE, " \
+    "F32LE, F32BE, S32LE, S32BE, U32LE, U32BE, " \
     "S24_32LE, S24_32BE, U24_32LE, U24_32BE, " \
-    "S32LE, S32BE, U32LE, U32BE, " \
     "S24LE, S24BE, U24LE, U24BE, " \
     "S20LE, S20BE, U20LE, U20BE, " \
     "S18LE, S18BE, U18LE, U18BE, " \
-    "F32LE, F32BE, F64LE, F64BE }"
+    "S16LE, S16BE, U16LE, U16BE, " \
+    "S8, U8 }"
+#endif
 
 GST_AUDIO_API
 const GstAudioFormat * gst_audio_formats_raw (guint * len);