Fawkes API  Fawkes Development Version
v4l2.h
1 
2 /***************************************************************************
3  * v4l2.h - Video4Linux 2 camera access
4  *
5  * Generated: Sat Jul 5 20:40:20 2008
6  * Copyright 2008 Tobias Kellner
7  * 2010-2014 Tim Niemueller
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_CAMS_V4L2_H_
25 #define __FIREVISION_CAMS_V4L2_H_
26 
27 #include <fvcams/camera.h>
28 
29 #include <linux/types.h>
30 #include <linux/videodev2.h>
31 
32 #include <fvcams/control/color.h>
33 #include <fvcams/control/image.h>
34 
35 /* Number of buffers to use for memory mapped IO */
36 #define MMAP_NUM_BUFFERS 4;
37 
38 namespace firevision {
39 #if 0 /* just to make Emacs auto-indent happy */
40 }
41 #endif
42 
43 class CameraArgumentParser;
44 class V4L2CameraData;
45 
46 class V4L2Camera:
47  public Camera,
48  public CameraControlColor,
49  public CameraControlImage
50 {
51  friend class V4LCamera;
52 
53  public:
54  V4L2Camera(const char *device_name = "/dev/video0");
55  V4L2Camera(const CameraArgumentParser *cap);
56  virtual ~V4L2Camera();
57 
58  virtual void open();
59  virtual void start();
60  virtual void stop();
61  virtual void close();
62  virtual void flush();
63  virtual void capture();
64  virtual void print_info();
65  virtual bool ready();
66 
67  virtual unsigned char *buffer();
68  virtual unsigned int buffer_size();
69  virtual void dispose_buffer();
70 
71  virtual unsigned int pixel_width();
72  virtual unsigned int pixel_height();
73  virtual colorspace_t colorspace();
74  virtual fawkes::Time * capture_time();
75 
76  virtual void set_image_number(unsigned int n);
77 
78  virtual bool auto_gain();
79  virtual void set_auto_gain(bool enabled);
80  virtual bool auto_white_balance();
81  virtual void set_auto_white_balance(bool enabled);
82  virtual unsigned int exposure_auto();
83  virtual void set_exposure_auto(unsigned int exposure_auto);
84  virtual int red_balance();
85  virtual void set_red_balance(int red_balance);
86  virtual int blue_balance();
87  virtual void set_blue_balance(int blue_balance);
88  virtual int u_balance();
89  virtual void set_u_balance(int u_balance);
90  virtual int v_balance();
91  virtual void set_v_balance(int v_balance);
92  virtual unsigned int brightness();
93  virtual void set_brightness(unsigned int brightness);
94  virtual unsigned int contrast();
95  virtual void set_contrast(unsigned int contrast);
96  virtual unsigned int saturation();
97  virtual void set_saturation(unsigned int saturation);
98  virtual int hue();
99  virtual void set_hue(int hue);
100  virtual unsigned int exposure();
101  virtual void set_exposure(unsigned int exposure);
102  virtual unsigned int gain();
103  virtual void set_gain(unsigned int gain);
104 
105  virtual const char * format();
106  virtual void set_format(const char *format);
107  virtual unsigned int width();
108  virtual unsigned int height();
109  virtual void set_size(unsigned int width,
110  unsigned int height);
111  virtual bool horiz_mirror();
112  virtual bool vert_mirror();
113  virtual void set_horiz_mirror(bool enabled);
114  virtual void set_vert_mirror(bool enabled);
115  virtual unsigned int fps();
116  virtual void set_fps(unsigned int fps);
117  virtual unsigned int lens_x_corr();
118  virtual unsigned int lens_y_corr();
119  virtual void set_lens_x_corr(unsigned int x_corr);
120  virtual void set_lens_y_corr(unsigned int y_corr);
121 
122  virtual bool exposure_auto_priority();
123  virtual void set_exposure_auto_priority(bool enabled);
124  virtual unsigned int white_balance_temperature();
125  virtual void set_white_balance_temperature(unsigned int white_balance_temperature);
126  virtual unsigned int exposure_absolute();
127  virtual void set_exposure_absolute(unsigned int exposure_absolute);
128  virtual unsigned int sharpness();
129  virtual void set_sharpness(unsigned int sharpness);
130 
131 
132  protected:
133  V4L2Camera(const char *device_name, int dev);
134  virtual void set_one_control(const char *ctrl, unsigned int id, int value);
135  virtual int get_one_control(const char *ctrl, unsigned int id);
136 
137  private:
138  virtual void post_open();
139  virtual void select_read_method();
140  virtual void select_standard();
141  virtual void select_input();
142  virtual void select_format();
143  virtual void set_fps();
144  virtual void set_controls();
145  virtual void create_buffer();
146  virtual void reset_cropping();
147 
148  protected:
149  char *_device_name; ///< Device name
150 
151  private:
152  enum ReadMethod
153  {
154  READ, ///< read() input
155  MMAP, ///< Memory mapping input
156  UPTR ///< User pointer input
157  };
158 
159  enum TriState
160  {
161  NOT_SET, ///< parameter not set
162  TRUE, ///< parameter set to true
163  FALSE ///< parameter set to false
164  };
165 
166  struct FrameBuffer
167  {
168  unsigned char *buffer; ///< buffer
169  unsigned int size; ///< buffer size
170  };
171 
172  struct ControlParameterInt
173  {
174  bool set; ///< true if set
175  int value; ///< value
176  };
177 
178  int _dev; ///< Device file descriptor
179 
180  V4L2CameraData *_data;
181 
182  ReadMethod _read_method; ///< Used read method
183  bool _opened; ///< Device has been open()ed
184  bool _started; ///< Device has been start()ed
185  char *_standard; ///< Desired video standard
186  char *_input; ///< Desired video input
187  char _format[5]; ///< FourCC of the image format
188  colorspace_t _colorspace; ///< Used colorspace_t
189 
190  unsigned int _width; ///< Image width
191  unsigned int _height; ///< Image height
192  unsigned int _bytes_per_line; ///< Image bytes per line
193  FrameBuffer *_frame_buffers; ///< Image buffers
194  unsigned int _buffers_length; ///< Image buffer size
195  int _current_buffer; ///< Current Image buffer (-1 if not set)
196  fawkes::Time *_capture_time; ///< Time when last picture was captured
197 
198  bool _switch_u_v; ///< Switch U and V channels
199  unsigned int _fps; ///< Capture FPS
200 
201  TriState _awb; ///< Auto White Balance enabled
202  TriState _agc; ///< Auto Gain enabled
203  TriState _h_flip; ///< Horizontal mirror
204  TriState _v_flip; ///< Vertical mirror
205  ControlParameterInt _brightness; ///< Brightness [0-255] (def. 128)
206  ControlParameterInt _contrast; ///< Contrast [0-127] (def. 64)
207  ControlParameterInt _saturation; ///< Saturation [0-256] (def. 128)
208  ControlParameterInt _hue; ///< Hue [-180-180] (def. 0)
209  ControlParameterInt _red_balance; ///< Red Balance [0-255] (def. 128)
210  ControlParameterInt _blue_balance; ///< Blue Balance [0-255] (def. 128)
211  ControlParameterInt _exposure; ///< Exposure [0-65535] (def. 60)
212  ControlParameterInt _gain; ///< Gain [0-255] (def. 0)
213  ControlParameterInt _lens_x; ///< Lens Correction X [0-255] (def. 0)
214  ControlParameterInt _lens_y; ///< Lens Correction Y [0-255] (def. 0)
215 
216  ControlParameterInt _white_balance_temperature;
217  TriState _exposure_auto_priority;
218  ControlParameterInt _exposure_auto;
219  ControlParameterInt _exposure_absolute;
220  ControlParameterInt _sharpness;
221 
222 
223  bool _nao_hacks; ///< Nao-specific hacks (bad driver)
224 
225 };
226 
227 } // end namespace firevision
228 
229 #endif //__FIREVISION_CAMS_V4L2_H_
char * _device_name
Device name.
Definition: v4l2.h:149
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:35
Camera color control interface.
Definition: color.h:35
Video4Linux 2 camera access implementation.
Definition: v4l2.h:46
A class for handling time.
Definition: time.h:91
Camera image control interface.
Definition: image.h:35
Camera argument parser.
Definition: camargp.h:38
General Video4Linux camera implementation.
Definition: v4l.h:37