summaryrefslogtreecommitdiff
path: root/graphics/opencv/patches/patch-modules_videoio_src_cap__v4l.cpp
blob: 384bb4e8eec7c4907b2d2b51e0eb096ae8e7def1 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
$NetBSD: patch-modules_videoio_src_cap__v4l.cpp,v 1.2 2017/03/16 21:59:13 prlw1 Exp $

Conditionalize settings not available in NetBSD's v4l2 emulation.

--- modules/videoio/src/cap_v4l.cpp.orig	2016-12-23 12:54:44.000000000 +0000
+++ modules/videoio/src/cap_v4l.cpp
@@ -216,6 +216,7 @@ make & enjoy!
 #include <fcntl.h>
 #include <errno.h>
 #include <sys/ioctl.h>
+#include <inttypes.h>
 #include <sys/types.h>
 #include <sys/mman.h>
 
@@ -469,9 +470,13 @@ static int autosetup_capture_mode_v4l2(C
             V4L2_PIX_FMT_UYVY,
             V4L2_PIX_FMT_SN9C10X,
             V4L2_PIX_FMT_SBGGR8,
+#ifdef V4L2_PIX_FMT_SGBRG8
             V4L2_PIX_FMT_SGBRG8,
-            V4L2_PIX_FMT_RGB24,
-            V4L2_PIX_FMT_Y16
+#endif
+            V4L2_PIX_FMT_RGB24
+#ifdef V4L2_PIX_FMT_Y16
+            ,V4L2_PIX_FMT_Y16
+#endif
     };
 
     for (size_t i = 0; i < sizeof(try_order) / sizeof(__u32); i++) {
@@ -520,12 +525,16 @@ static void v4l2_control_range(CvCapture
     case V4L2_CID_GAIN:
         cap->gain = range;
         break;
+#ifdef V4L2_CID_EXPOSURE_ABSOLUTE
     case V4L2_CID_EXPOSURE_ABSOLUTE:
         cap->exposure = range;
         break;
+#endif
+#ifdef V4L2_CID_FOCUS_ABSOLUTE
     case V4L2_CID_FOCUS_ABSOLUTE:
         cap->focus = range;
         break;
+#endif
     }
 }
 
@@ -547,7 +556,9 @@ static void v4l2_scan_controls(CvCapture
         break;
   }
 
+#ifdef V4L2_CID_FOCUS_ABSOLUTE
   v4l2_control_range(capture, V4L2_CID_FOCUS_ABSOLUTE);
+#endif
 }
 
 static int v4l2_set_fps(CvCaptureCAM_V4L* capture) {
@@ -563,8 +574,10 @@ static int v4l2_num_channels(__u32 palet
     case V4L2_PIX_FMT_YVU420:
     case V4L2_PIX_FMT_MJPEG:
     case V4L2_PIX_FMT_JPEG:
+#ifdef V4L2_PIX_FMT_Y16
     case V4L2_PIX_FMT_Y16:
         return 1;
+#endif
     case V4L2_PIX_FMT_YUYV:
     case V4L2_PIX_FMT_UYVY:
         return 2;
@@ -592,11 +605,13 @@ static void v4l2_create_frame(CvCaptureC
         case V4L2_PIX_FMT_YVU420:
             size.height = size.height * 3 / 2; // "1.5" channels
             break;
+#ifdef V4L2_PIX_FMT_Y16
         case V4L2_PIX_FMT_Y16:
             if(!capture->convert_rgb){
                 depth = IPL_DEPTH_16U;
             }
             break;
+#endif
         }
     }
 
@@ -1555,18 +1570,21 @@ static IplImage* icvRetrieveFrameCAM_V4L
                 (unsigned char*)capture->frame.imageData);
         break;
 
+#ifdef V4L2_PIX_FMT_SGBRG8
     case V4L2_PIX_FMT_SGBRG8:
         sgbrg2rgb24(capture->form.fmt.pix.width,
                 capture->form.fmt.pix.height,
                 (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start,
                 (unsigned char*)capture->frame.imageData);
         break;
+#endif
     case V4L2_PIX_FMT_RGB24:
         rgb24_to_rgb24(capture->form.fmt.pix.width,
                 capture->form.fmt.pix.height,
                 (unsigned char*)capture->buffers[(capture->bufferIndex+1) % capture->req.count].start,
                 (unsigned char*)capture->frame.imageData);
         break;
+#ifdef V4L2_PIX_FMT_Y16
     case V4L2_PIX_FMT_Y16:
         if(capture->convert_rgb){
             y16_to_rgb24(capture->form.fmt.pix.width,
@@ -1579,6 +1597,7 @@ static IplImage* icvRetrieveFrameCAM_V4L
                    capture->frame.imageSize);
         }
         break;
+#endif
     }
 
     return(&capture->frame);
@@ -1596,14 +1615,22 @@ static inline __u32 capPropertyToV4L2(in
         return V4L2_CID_HUE;
     case CV_CAP_PROP_GAIN:
         return V4L2_CID_GAIN;
+#ifdef V4L2_CID_EXPOSURE_AUTO
     case CV_CAP_PROP_AUTO_EXPOSURE:
         return V4L2_CID_EXPOSURE_AUTO;
+#endif
+#ifdef V4L2_CID_EXPOSURE_ABSOLUTE
     case CV_CAP_PROP_EXPOSURE:
         return V4L2_CID_EXPOSURE_ABSOLUTE;
+#endif
+#ifdef V4L2_CID_FOCUS_AUTO
     case CV_CAP_PROP_AUTOFOCUS:
         return V4L2_CID_FOCUS_AUTO;
+#endif
+#ifdef V4L2_CID_FOCUS_ABSOLUTE
     case CV_CAP_PROP_FOCUS:
         return V4L2_CID_FOCUS_ABSOLUTE;
+#endif
     default:
         return -1;
     }
@@ -1749,12 +1776,14 @@ static bool icvSetControl (CvCaptureCAM_
         return false;
     }
 
+#if defined(V4L2_CID_EXPOSURE_AUTO) && defined(V4L2_EXPOSURE_MANUAL) && defined(V4L2_CID_EXPOSURE_ABSOLUTE)
     if(control.id == V4L2_CID_EXPOSURE_AUTO && control.value == V4L2_EXPOSURE_MANUAL) {
         // update the control range for expose after disabling autoexposure
         // as it is not read correctly at startup
         // TODO check this again as it might be fixed with Linux 4.5
         v4l2_control_range(capture, V4L2_CID_EXPOSURE_ABSOLUTE);
     }
+#endif
 
     /* all was OK */
     return true;