video: 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/video/video-format.h

index c73513c..ecacb85 100644 (file)
@@ -578,17 +578,50 @@ gconstpointer  gst_video_format_get_palette          (GstVideoFormat format, gsi
 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_LE"
 #endif
 
-#define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, VUYA, RGBx, "  \
-  "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, YVYU, " \
-  "Y444, v210, v216, Y210, Y410, NV12, NV21, GRAY8, GRAY16_BE, GRAY16_LE, v308, RGB16, " \
-  "BGR16, RGB15, BGR15, UYVP, A420, RGB8P, YUV9, YVU9, IYU1, ARGB64, " \
-  "AYUV64, r210, I420_10BE, I420_10LE, I422_10BE, I422_10LE, Y444_10BE, " \
-  "Y444_10LE, GBR, GBR_10BE, GBR_10LE, NV16, NV24, NV12_64Z32, A420_10BE, " \
-  "A420_10LE, A422_10BE, A422_10LE, A444_10BE, A444_10LE, NV61, P010_10BE, " \
-  "P010_10LE, IYU2, VYUY, GBRA, GBRA_10BE, GBRA_10LE, BGR10A2_LE, RGB10A2_LE, GBR_12BE, GBR_12LE, " \
-  "GBRA_12BE, GBRA_12LE, P012_BE, P012_LE, I420_12BE, I420_12LE, Y212_BE, Y212_LE, I422_12BE, I422_12LE, " \
-  "Y412_BE, Y412_LE, Y444_12BE, Y444_12LE, GRAY10_LE32, NV12_10LE32, NV16_10LE32, NV12_10LE40, " \
-  "Y444_16BE, Y444_16LE, P016_BE, P016_LE }"
+/**
+ * GST_VIDEO_FORMATS_ALL:
+ *
+ * List of all video formats, for use in template caps strings.
+ *
+ * Formats are sorted by decreasing "quality", using these criteria by priority:
+ *   - number of components
+ *   - depth
+ *   - subsampling factor of the width
+ *   - subsampling factor of the height
+ *   - number of planes
+ *   - native endianness preferred
+ *   - pixel stride
+ *   - poffset
+ *   - prefer non-complex formats
+ *   - prefer YUV formats over RGB ones
+ *   - prefer I420 over YV12
+ *   - format name
+ */
+#if G_BYTE_ORDER == G_BIG_ENDIAN
+#define GST_VIDEO_FORMATS_ALL "{ AYUV64, ARGB64, GBRA_12BE, GBRA_12LE, Y412_BE, " \
+    "Y412_LE, A444_10BE, GBRA_10BE, A444_10LE, GBRA_10LE, A422_10BE, A422_10LE, " \
+    "A420_10BE, A420_10LE, Y410, RGB10A2_LE, BGR10A2_LE, GBRA, ABGR, VUYA, BGRA, " \
+    "AYUV, ARGB, RGBA, A420, Y444_16BE, Y444_16LE, v216, P016_BE, P016_LE, Y444_12BE, " \
+    "GBR_12BE, Y444_12LE, GBR_12LE, I422_12BE, I422_12LE, Y212_BE, Y212_LE, I420_12BE, " \
+    "I420_12LE, P012_BE, P012_LE, Y444_10BE, GBR_10BE, Y444_10LE, GBR_10LE, r210, " \
+    "I422_10BE, I422_10LE, NV16_10LE32, Y210, v210, UYVP, I420_10BE, I420_10LE, " \
+    "P010_10BE, P010_10LE, NV12_10LE32, NV12_10LE40, Y444, GBR, NV24, xBGR, BGRx, " \
+    "xRGB, RGBx, BGR, IYU2, v308, RGB, Y42B, NV61, NV16, VYUY, UYVY, YVYU, YUY2, I420, " \
+    "YV12, NV21, NV12, NV12_64Z32, Y41B, IYU1, YVU9, YUV9, RGB16, BGR16, RGB15, BGR15, " \
+    "RGB8P, GRAY16_BE, GRAY16_LE, GRAY10_LE32, GRAY8 }"
+#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define GST_VIDEO_FORMATS_ALL "{ AYUV64, ARGB64, GBRA_12LE, GBRA_12BE, Y412_LE, " \
+    "Y412_BE, A444_10LE, GBRA_10LE, A444_10BE, GBRA_10BE, A422_10LE, A422_10BE, " \
+    "A420_10LE, A420_10BE, RGB10A2_LE, BGR10A2_LE, Y410, GBRA, ABGR, VUYA, BGRA, " \
+    "AYUV, ARGB, RGBA, A420, Y444_16LE, Y444_16BE, v216, P016_LE, P016_BE, Y444_12LE, " \
+    "GBR_12LE, Y444_12BE, GBR_12BE, I422_12LE, I422_12BE, Y212_LE, Y212_BE, I420_12LE, " \
+    "I420_12BE, P012_LE, P012_BE, Y444_10LE, GBR_10LE, Y444_10BE, GBR_10BE, r210, " \
+    "I422_10LE, I422_10BE, NV16_10LE32, Y210, v210, UYVP, I420_10LE, I420_10BE, " \
+    "P010_10LE, NV12_10LE32, NV12_10LE40, P010_10BE, Y444, GBR, NV24, xBGR, BGRx, " \
+    "xRGB, RGBx, BGR, IYU2, v308, RGB, Y42B, NV61, NV16, VYUY, UYVY, YVYU, YUY2, I420, " \
+    "YV12, NV21, NV12, NV12_64Z32, Y41B, IYU1, YVU9, YUV9, RGB16, BGR16, RGB15, BGR15, " \
+    "RGB8P, GRAY16_LE, GRAY16_BE, GRAY10_LE32, GRAY8 }"
+#endif
 
 GST_VIDEO_API
 const GstVideoFormat * gst_video_formats_raw (guint * len);