Debian Codegraph @

cvd/Linux/v4lcontrol.h

raw symbols SCIP
1 #ifndef CVD_V4LCONTROL_H
2 #define CVD_V4LCONTROL_H
3
4 #include <map>
5 #include <string>
6 #include <vector>
7
8 #include <linux/videodev2.h>
9
10 #include <cvd/exceptions.h>
11
12 namespace CVD
13 {
14
15 namespace Exceptions
16 {
17 /// @ingroup gException
18 namespace V4LControl
19 {
20 /// @ingroup gException
21 struct All : public CVD::Exceptions::All
22 {
23 using CVD::Exceptions::All::All;
24 };
25 /// Error opening the device
26 /// @ingroup gException
27 struct DeviceOpen : public All
28 {
29 DeviceOpen(std::string dev); ///< Construct from the device name
30 };
31
32 /// Unsupported parameter
33 /// @ingroup gException
34 struct ParameterNotSupported : public All
35 {
36 ParameterNotSupported(std::string); ///< Construct from parameter name
37 ParameterNotSupported(unsigned int); ///< Construct from parameter id
38 };
39
40 /// Error querying value
41 /// @ingroup gException
42 struct GetValue : public All
43 {
44 GetValue(std::string); ///< Construct from parameter name
45 };
46
47 /// Error setting value
48 /// @ingroup gException
49 struct SetValue : public All
50 {
51 SetValue(std::string); ///< Construct from parameter name
52 };
53
54 /// Error querying device parameters
55 /// @ingroup gException
56 struct QueryParameters : public All
57 {
58 QueryParameters(std::string); ///< Construct from message
59 };
60
61 }
62 }
63
64 /**
65 exposes the V4L2 API to set parameters on a capture device. It can be used
66 in parallel to a v4lbuffer object to control and query all parameters supported.
67 Several abstraction levels are supported. On the highest there are individual
68 member functions for various fixed parameters. The next level supports querying and
69 setting/getting values for all parameters supported by the driver. Finally,
70 low-level access using V4L2 structs is supported as well.
71
72 @ingroup gVideo
73 */
74 class V4LControl
75 {
76 public:
77 V4LControl(int fd, bool report = true);
78 V4LControl(const std::string& name, bool report = true);
79
80 /// @name HighLevel
81 /// High level interface to set specific parameters without much hassle.
82 /// These might fail if the parameter is not supported by the device and do
83 /// not throw exceptions. Moreover ranges of parameter values are abstracted
84 /// to lie within the intervall [0,1].
85 /// If you want to have more control, use the lower level interface described in
86 /// @ref Generic .
87 //@{
88 void exposure(int);
89 int exposure(void);
90
91 void autoexposure(bool);
92 bool autoexposure();
93
94 void gain(double);
95 double gain(void);
96
97 void autogain(bool);
98 bool autogain(void);
99
100 void brightness(double);
101 double brightness(void);
102
103 void contrast(double);
104 double contrast(void);
105
106 void saturation(double);
107 double saturation(void);
108 //@}
109
110 /// @name Generic
111 /// generic high level interface abstracting the v4l2 structs
112 //@{
113 unsigned int getId(const std::string& name) const;
114 std::string getName(unsigned int id) const;
115 std::vector<unsigned int> supportedParameters(void) const;
116 std::vector<std::string> supportedParameterNames(void) const;
117
118 inline bool isSupported(const std::string& name) const
119 {
120 return (controlNames.find(name) != controlNames.end());
121 }
122 inline void set(const std::string& name, int value)
123 {
124 set(getId(name), value);
125 }
126 inline int get(const std::string& name)
127 {
128 return get(getId(name));
129 }
130 inline int type(const std::string& name)
131 {
132 return type(getId(name));
133 }
134 inline std::map<unsigned int, std::string> menuValues(const std::string& name)
135 {
136 return menuValues(getId(name));
137 }
138 inline int defaultValue(const std::string& name)
139 {
140 return defaultValue(getId(name));
141 }
142 inline int min(const std::string& name)
143 {
144 return min(getId(name));
145 }
146 inline int max(const std::string& name)
147 {
148 return max(getId(name));
149 }
150 inline int step(const std::string& name)
151 {
152 return step(getId(name));
153 }
154
155 inline bool isSupported(unsigned int id) const
156 {
157 return (controlData.find(id) != controlData.end());
158 }
159 void set(unsigned int id, int value);
160 int get(unsigned int id);
161 int type(unsigned int id);
162 std::map<unsigned int, std::string> menuValues(unsigned int id) const;
163 int defaultValue(unsigned int id) const;
164 int min(unsigned int id) const;
165 int max(unsigned int id) const;
166 int step(unsigned int id) const;
167 //@}
168
169 /// @name LowLevel
170 /// low level interface using v4l2 structs
171 //@{
172 int getQueryStruct(v4l2_queryctrl& query) const;
173 void getMenuStruct(unsigned int id, std::vector<v4l2_querymenu>& menu) const;
174 int setControlStruct(v4l2_control& value);
175 int getControlStruct(v4l2_control& value) const;
176 //@}
177
178 /// return file descriptor for the opened device
179 inline int getFile(void) const { return device; }
180
181 /// return file name of the opened device
182 inline const std::string& getDevice(void) const { return deviceName; }
183
184 /// set error reporting
185 inline void setReportErrors(bool report) { reportErrors = report; }
186 inline bool getReportErrors(void) const { return reportErrors; }
187
188 protected:
189 int device;
190 std::string deviceName;
191 struct v4l2_control control;
192 bool reportErrors;
193
194 void queryControls(void);
195
196 std::map<std::string, unsigned int> controlNames;
197 std::map<unsigned int, v4l2_queryctrl> controlData;
198 std::map<unsigned int, std::vector<v4l2_querymenu>> menuData;
199 };
200
201 } // namespace CVD
202
203 #endif