hc
2023-02-14 0cc9b7c44253c93447ddf73e206fbdbb3d9f16b1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
From f2a4ff0e078fd26bd3cfc8707515ffec71b234eb Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Wed, 11 May 2022 17:24:49 +0800
Subject: [PATCH 8/8] v4l2src: Support setting max resolution
 
Set env "GST_V4L2SRC_MAX_RESOLUTION" to limit resolution, for example:
export GST_V4L2SRC_MAX_RESOLUTION=1920x1080
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 sys/v4l2/gstv4l2object.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
 
diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c
index a7b7ea7..fd1909d 100644
--- a/sys/v4l2/gstv4l2object.c
+++ b/sys/v4l2/gstv4l2object.c
@@ -2770,6 +2770,7 @@ gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
   gint fd = v4l2object->video_fd;
   struct v4l2_frmsizeenum size;
   GList *results = NULL;
+  guint32 max_width = G_MAXINT, max_height = G_MAXINT;
   guint32 w, h;
 
   if (pixelformat == GST_MAKE_FOURCC ('M', 'P', 'E', 'G')) {
@@ -2777,6 +2778,12 @@ gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
     return ret;
   }
 
+  if (!V4L2_TYPE_IS_OUTPUT (v4l2object->type)) {
+    const gchar *buf = g_getenv ("GST_V4L2SRC_MAX_RESOLUTION");
+    if (buf)
+      sscanf (buf, "%ux%u", &max_width, &max_height);
+  }
+
   memset (&size, 0, sizeof (struct v4l2_frmsizeenum));
   size.index = 0;
   size.pixel_format = pixelformat;
@@ -2793,8 +2800,8 @@ gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
       GST_LOG_OBJECT (v4l2object->dbg_obj, "got discrete frame size %dx%d",
           size.discrete.width, size.discrete.height);
 
-      w = MIN (size.discrete.width, G_MAXINT);
-      h = MIN (size.discrete.height, G_MAXINT);
+      w = MIN (size.discrete.width, max_width);
+      h = MIN (size.discrete.height, max_height);
 
       if (w && h) {
         tmp =
@@ -2828,8 +2835,8 @@ gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
 
     w = MAX (size.stepwise.min_width, 1);
     h = MAX (size.stepwise.min_height, 1);
-    maxw = MIN (size.stepwise.max_width, G_MAXINT);
-    maxh = MIN (size.stepwise.max_height, G_MAXINT);
+    maxw = MIN (size.stepwise.max_width, max_width);
+    maxh = MIN (size.stepwise.max_height, max_height);
 
     step_w = MAX (size.stepwise.step_width, 1);
     step_h = MAX (size.stepwise.step_height, 1);
@@ -2869,8 +2876,8 @@ gst_v4l2_object_probe_caps_for_format (GstV4l2Object * v4l2object,
 
     w = MAX (size.stepwise.min_width, 1);
     h = MAX (size.stepwise.min_height, 1);
-    maxw = MIN (size.stepwise.max_width, G_MAXINT);
-    maxh = MIN (size.stepwise.max_height, G_MAXINT);
+    maxw = MIN (size.stepwise.max_width, max_width);
+    maxh = MIN (size.stepwise.max_height, max_height);
 
     tmp =
         gst_v4l2_object_probe_caps_for_format_and_size (v4l2object, pixelformat,
-- 
2.20.1