hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
From d5691344cee9285725b0128e11438155bf15bd9a Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Wed, 6 Nov 2019 15:07:44 +0800
Subject: [PATCH 4/5] v4l2: Support preferred formats
 
Set env "GST_V4L2_PREFERRED_FOURCC" to specify preferred formats, for
example:
export GST_V4L2SRC_PREFERRED_FOURCC=YU12:NV12
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 sys/v4l2/gstv4l2object.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index cf32bd6..37e1244 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
@@ -1135,6 +1136,22 @@ gst_v4l2_object_format_get_rank (const struct v4l2_fmtdesc *fmt)
       break;
   }
 
+  {
+    const char *buf = g_getenv ("GST_V4L2_PREFERRED_FOURCC");
+    int max_rank = YUV_BASE_RANK * 2;
+
+    while (buf) {
+      if (buf[0] == ':')
+        buf++;
+
+      if (!strncmp (buf, (char *) &fourcc, 4))
+        rank = max_rank;
+
+      buf = strchr (buf, ':');
+      max_rank--;
+    }
+  }
+
   /* All ranks are below 1<<15 so a shift by 15
    * will a) make all non-emulated formats larger
    * than emulated and b) will not overflow
-- 
2.17.1