1From c2a42551d026a7d5145612d8645fb21ed551882b Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Fri, 17 Sep 2021 13:20:24 +0800
4Subject: [PATCH 11/11] videoconvert: Support preferred formats
5
6Set env "GST_VIDEO_CONVERT_PREFERRED_FORMAT" to specify preferred
7formats, for example:
8export GST_VIDEO_CONVERT_PREFERRED_FORMAT=NV12:NV16
9
10Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
11---
12 gst/videoconvert/gstvideoconvert.c | 22 ++++++++++++++++++++++
13 1 file changed, 22 insertions(+)
14
15diff --git a/gst/videoconvert/gstvideoconvert.c b/gst/videoconvert/gstvideoconvert.c
16index 0f65ee2..0aab69e 100644
17--- a/gst/videoconvert/gstvideoconvert.c
18+++ b/gst/videoconvert/gstvideoconvert.c
19@@ -268,6 +268,28 @@ score_value (GstBaseTransform * base, const GstVideoFormatInfo * in_info,
20       loss += SCORE_DEPTH_LOSS;
21   }
22
23+  {
24+    const char *buf = g_getenv ("GST_VIDEO_CONVERT_PREFERRED_FORMAT");
25+    if (buf) {
26+      const char *name = GST_VIDEO_FORMAT_INFO_NAME (t_info);
27+      int preferred_loss = 1;
28+
29+      /* lower other formats */
30+      loss += 1024;
31+
32+      while (buf) {
33+        if (buf[0] == ':')
34+          buf++;
35+
36+        if (!strncmp (buf, name, strlen (name)))
37+          loss = preferred_loss;
38+
39+        buf = strchr (buf, ':');
40+        preferred_loss++;
41+      }
42+    }
43+  }
44+
45   GST_DEBUG_OBJECT (base, "score %s -> %s = %d",
46       GST_VIDEO_FORMAT_INFO_NAME (in_info),
47       GST_VIDEO_FORMAT_INFO_NAME (t_info), loss);
48--
492.20.1
50
51