libcvd
v4lcontrol.h
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 {
18  namespace V4LControl
19  {
21  struct All : public CVD::Exceptions::All
22  {
23  using CVD::Exceptions::All::All;
24  };
27  struct DeviceOpen : public All
28  {
29  DeviceOpen(std::string dev);
30  };
31 
34  struct ParameterNotSupported : public All
35  {
36  ParameterNotSupported(std::string);
37  ParameterNotSupported(unsigned int);
38  };
39 
42  struct GetValue : public All
43  {
44  GetValue(std::string);
45  };
46 
49  struct SetValue : public All
50  {
51  SetValue(std::string);
52  };
53 
56  struct QueryParameters : public All
57  {
58  QueryParameters(std::string);
59  };
60 
61  }
62 }
63 
75 {
76  public:
77  V4LControl(int fd, bool report = true);
78  V4LControl(const std::string& name, bool report = true);
79 
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);
109 
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;
168 
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;
177 
179  inline int getFile(void) const { return device; }
180 
182  inline const std::string& getDevice(void) const { return deviceName; }
183 
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
All classes and functions are within the CVD namespace.
Definition: argb.h:6
exposes the V4L2 API to set parameters on a capture device.
Definition: v4lcontrol.h:74
Definition: v4lcontrol.h:21
Error querying value.
Definition: v4lcontrol.h:42
Error querying device parameters.
Definition: v4lcontrol.h:56
Unsupported parameter.
Definition: v4lcontrol.h:34
Error setting value.
Definition: v4lcontrol.h:49
Base class for all CVD exceptions.
Definition: exceptions.h:15
Error opening the device.
Definition: v4lcontrol.h:27
void setReportErrors(bool report)
set error reporting
Definition: v4lcontrol.h:185
int getFile(void) const
return file descriptor for the opened device
Definition: v4lcontrol.h:179
const std::string & getDevice(void) const
return file name of the opened device
Definition: v4lcontrol.h:182