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  *
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 bool auto_exposure();
83  virtual void set_auto_exposure(bool enabled);
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 
123  protected:
124  V4L2Camera(const char *device_name, int dev);
125  virtual void set_one_control(const char *ctrl, unsigned int id, int value);
126  virtual int get_one_control(const char *ctrl, unsigned int id);
127 
128  private:
129  virtual void post_open();
130  virtual void select_read_method();
131  virtual void select_format();
132  virtual void set_fps();
133  virtual void set_controls();
134  virtual void create_buffer();
135  virtual void reset_cropping();
136 
137  protected:
138  char *_device_name; ///< Device name
139 
140  private:
141  enum ReadMethod
142  {
143  READ, ///< read() input
144  MMAP, ///< Memory mapping input
145  UPTR ///< User pointer input
146  };
147 
148  enum TriState
149  {
150  NOT_SET, ///< parameter not set
151  TRUE, ///< parameter set to true
152  FALSE ///< parameter set to false
153  };
154 
155  struct FrameBuffer
156  {
157  unsigned char *buffer; ///< buffer
158  unsigned int size; ///< buffer size
159  };
160 
161  struct ControlParameterInt
162  {
163  bool set; ///< true if set
164  int value; ///< value
165  };
166 
167  int _dev; ///< Device file descriptor
168 
169  V4L2CameraData *_data;
170 
171  ReadMethod _read_method; ///< Used read method
172  bool _opened; ///< Device has been open()ed
173  bool _started; ///< Device has been start()ed
174  char _format[5]; ///< FourCC of the image format
175  colorspace_t _colorspace; ///< Used colorspace_t
176 
177  unsigned int _width; ///< Image width
178  unsigned int _height; ///< Image height
179  unsigned int _bytes_per_line; ///< Image bytes per line
180  FrameBuffer *_frame_buffers; ///< Image buffers
181  unsigned int _buffers_length; ///< Image buffer size
182  int _current_buffer; ///< Current Image buffer (-1 if not set)
183  fawkes::Time *_capture_time; ///< Time when last picture was captured
184 
185  bool _switch_u_v; ///< Switch U and V channels
186  unsigned int _fps; ///< Capture FPS
187 
188  TriState _aec; ///< Auto Exposition enabled
189  TriState _awb; ///< Auto White Balance enabled
190  TriState _agc; ///< Auto Gain enabled
191  TriState _h_flip; ///< Horizontal mirror
192  TriState _v_flip; ///< Vertical mirror
193  ControlParameterInt _brightness; ///< Brightness [0-255] (def. 128)
194  ControlParameterInt _contrast; ///< Contrast [0-127] (def. 64)
195  ControlParameterInt _saturation; ///< Saturation [0-256] (def. 128)
196  ControlParameterInt _hue; ///< Hue [-180-180] (def. 0)
197  ControlParameterInt _red_balance; ///< Red Balance [0-255] (def. 128)
198  ControlParameterInt _blue_balance; ///< Blue Balance [0-255] (def. 128)
199  ControlParameterInt _exposure; ///< Exposure [0-65535] (def. 60)
200  ControlParameterInt _gain; ///< Gain [0-255] (def. 0)
201  ControlParameterInt _lens_x; ///< Lens Correction X [0-255] (def. 0)
202  ControlParameterInt _lens_y; ///< Lens Correction Y [0-255] (def. 0)
203 
204  bool _nao_hacks; ///< Nao-specific hacks (bad driver)
205 
206 };
207 
208 } // end namespace firevision
209 
210 #endif //__FIREVISION_CAMS_V4L2_H_
char * _device_name
Device name.
Definition: v4l2.h:138
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