ViSP  2.9.0
vp1394TwoGrabber.h
1 /****************************************************************************
2  *
3  * $Id: vp1394TwoGrabber.h 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Firewire cameras video capture.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
60 #ifndef vp1394TwoGrabber_h
61 #define vp1394TwoGrabber_h
62 
63 #include <visp/vpConfig.h>
64 
65 #include <list>
66 
67 #if defined(VISP_HAVE_DC1394_2)
68 
69 
177 /*
178  * Interface with libdc1394 2.x
179  */
180 #include <string.h>
181 
182 #include <dc1394/control.h>
183 #include <dc1394/utils.h>
184 #include <dc1394/vendor/avt.h>
185 
186 #include <visp/vpImage.h>
187 #include <visp/vpFrameGrabber.h>
188 #include <visp/vpRGBa.h>
189 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
190 # include <visp/vpList.h>
191 #endif
192 
193 
194 class VISP_EXPORT vp1394TwoGrabber : public vpFrameGrabber
195 {
196 
197  public:
198  static const char * strVideoMode[DC1394_VIDEO_MODE_NUM];
199  static const char * strFramerate[DC1394_FRAMERATE_NUM];
200  static const char * strColorCoding[DC1394_COLOR_CODING_NUM];
201 
206  typedef enum {
207  vpISO_SPEED_100 = DC1394_ISO_SPEED_100,
208  vpISO_SPEED_200 = DC1394_ISO_SPEED_200,
209  vpISO_SPEED_400 = DC1394_ISO_SPEED_400,
210  vpISO_SPEED_800 = DC1394_ISO_SPEED_800,
211  vpISO_SPEED_1600 = DC1394_ISO_SPEED_1600,
212  vpISO_SPEED_3200 = DC1394_ISO_SPEED_3200
213  } vp1394TwoIsoSpeedType;
214 
219  typedef enum {
220  vpVIDEO_MODE_160x120_YUV444 = DC1394_VIDEO_MODE_160x120_YUV444,
221  vpVIDEO_MODE_320x240_YUV422 = DC1394_VIDEO_MODE_320x240_YUV422,
222  vpVIDEO_MODE_640x480_YUV411 = DC1394_VIDEO_MODE_640x480_YUV411,
223  vpVIDEO_MODE_640x480_YUV422 = DC1394_VIDEO_MODE_640x480_YUV422,
224  vpVIDEO_MODE_640x480_RGB8 = DC1394_VIDEO_MODE_640x480_RGB8,
225  vpVIDEO_MODE_640x480_MONO8 = DC1394_VIDEO_MODE_640x480_MONO8,
226  vpVIDEO_MODE_640x480_MONO16 = DC1394_VIDEO_MODE_640x480_MONO16,
227  vpVIDEO_MODE_800x600_YUV422 = DC1394_VIDEO_MODE_800x600_YUV422,
228  vpVIDEO_MODE_800x600_RGB8 = DC1394_VIDEO_MODE_800x600_RGB8,
229  vpVIDEO_MODE_800x600_MONO8 = DC1394_VIDEO_MODE_800x600_MONO8,
230  vpVIDEO_MODE_1024x768_YUV422 = DC1394_VIDEO_MODE_1024x768_YUV422,
231  vpVIDEO_MODE_1024x768_RGB8 = DC1394_VIDEO_MODE_1024x768_RGB8,
232  vpVIDEO_MODE_1024x768_MONO8 = DC1394_VIDEO_MODE_1024x768_MONO8,
233  vpVIDEO_MODE_800x600_MONO16 = DC1394_VIDEO_MODE_800x600_MONO16,
234  vpVIDEO_MODE_1024x768_MONO16 = DC1394_VIDEO_MODE_1024x768_MONO16,
235  vpVIDEO_MODE_1280x960_YUV422 = DC1394_VIDEO_MODE_1280x960_YUV422,
236  vpVIDEO_MODE_1280x960_RGB8 = DC1394_VIDEO_MODE_1280x960_RGB8,
237  vpVIDEO_MODE_1280x960_MONO8 = DC1394_VIDEO_MODE_1280x960_MONO8,
238  vpVIDEO_MODE_1600x1200_YUV422 = DC1394_VIDEO_MODE_1600x1200_YUV422,
239  vpVIDEO_MODE_1600x1200_RGB8 = DC1394_VIDEO_MODE_1600x1200_RGB8,
240  vpVIDEO_MODE_1600x1200_MONO8 = DC1394_VIDEO_MODE_1600x1200_MONO8,
241  vpVIDEO_MODE_1280x960_MONO16 = DC1394_VIDEO_MODE_1280x960_MONO16,
242  vpVIDEO_MODE_1600x1200_MONO16 = DC1394_VIDEO_MODE_1600x1200_MONO16,
243  vpVIDEO_MODE_EXIF = DC1394_VIDEO_MODE_EXIF,
244  vpVIDEO_MODE_FORMAT7_0 = DC1394_VIDEO_MODE_FORMAT7_0,
245  vpVIDEO_MODE_FORMAT7_1 = DC1394_VIDEO_MODE_FORMAT7_1,
246  vpVIDEO_MODE_FORMAT7_2 = DC1394_VIDEO_MODE_FORMAT7_2,
247  vpVIDEO_MODE_FORMAT7_3 = DC1394_VIDEO_MODE_FORMAT7_3,
248  vpVIDEO_MODE_FORMAT7_4 = DC1394_VIDEO_MODE_FORMAT7_4,
249  vpVIDEO_MODE_FORMAT7_5 = DC1394_VIDEO_MODE_FORMAT7_5,
250  vpVIDEO_MODE_FORMAT7_6 = DC1394_VIDEO_MODE_FORMAT7_6,
251  vpVIDEO_MODE_FORMAT7_7 = DC1394_VIDEO_MODE_FORMAT7_7
252  } vp1394TwoVideoModeType;
253 
258  typedef enum {
259  vpFRAMERATE_1_875 = DC1394_FRAMERATE_1_875,
260  vpFRAMERATE_3_75 = DC1394_FRAMERATE_3_75,
261  vpFRAMERATE_7_5 = DC1394_FRAMERATE_7_5,
262  vpFRAMERATE_15 = DC1394_FRAMERATE_15,
263  vpFRAMERATE_30 = DC1394_FRAMERATE_30,
264  vpFRAMERATE_60 = DC1394_FRAMERATE_60,
265  vpFRAMERATE_120 = DC1394_FRAMERATE_120,
266  vpFRAMERATE_240 = DC1394_FRAMERATE_240
267  } vp1394TwoFramerateType;
268 
273  typedef enum {
274  vpCOLOR_CODING_MONO8 = DC1394_COLOR_CODING_MONO8,
275  vpCOLOR_CODING_YUV411 = DC1394_COLOR_CODING_YUV411,
276  vpCOLOR_CODING_YUV422 = DC1394_COLOR_CODING_YUV422,
277  vpCOLOR_CODING_YUV444 = DC1394_COLOR_CODING_YUV444,
278  vpCOLOR_CODING_RGB8 = DC1394_COLOR_CODING_RGB8,
279  vpCOLOR_CODING_MONO16 = DC1394_COLOR_CODING_MONO16,
280  vpCOLOR_CODING_RGB16 = DC1394_COLOR_CODING_RGB16,
281  vpCOLOR_CODING_MONO16S = DC1394_COLOR_CODING_MONO16S,
282  vpCOLOR_CODING_RGB16S = DC1394_COLOR_CODING_RGB16S,
283  vpCOLOR_CODING_RAW8 = DC1394_COLOR_CODING_RAW8,
284  vpCOLOR_CODING_RAW16 = DC1394_COLOR_CODING_RAW16
285  } vp1394TwoColorCodingType;
286 
291  typedef enum {
292  vpFEATURE_BRIGHTNESS = DC1394_FEATURE_BRIGHTNESS,
293  vpFEATURE_EXPOSURE = DC1394_FEATURE_EXPOSURE,
294  vpFEATURE_SHARPNESS = DC1394_FEATURE_SHARPNESS,
295 // vpFEATURE_WHITE_BALANCE = DC1394_FEATURE_WHITE_BALANCE,
296  vpFEATURE_HUE = DC1394_FEATURE_HUE,
297  vpFEATURE_SATURATION = DC1394_FEATURE_SATURATION,
298  vpFEATURE_GAMMA = DC1394_FEATURE_GAMMA,
299  vpFEATURE_SHUTTER = DC1394_FEATURE_SHUTTER,
300  vpFEATURE_GAIN = DC1394_FEATURE_GAIN,
301  vpFEATURE_IRIS = DC1394_FEATURE_IRIS,
302 // vpFEATURE_FOCUS = DC1394_FEATURE_FOCUS,
303 // vpFEATURE_TEMPERATURE = DC1394_FEATURE_TEMPERATURE,
304 // vpFEATURE_TRIGGER = DC1394_FEATURE_TRIGGER,
305 // vpFEATURE_TRIGGER_DELAY = DC1394_FEATURE_TRIGGER_DELAY,
306 // vpFEATURE_WHITE_SHADING = DC1394_FEATURE_WHITE_SHADING,
307 // vpFEATURE_FRAME_RATE = DC1394_FEATURE_FRAME_RATE,
308 // vpFEATURE_ZOOM = DC1394_FEATURE_ZOOM,
309 // vpFEATURE_PAN = DC1394_FEATURE_PAN,
310 // vpFEATURE_TILT = DC1394_FEATURE_TILT,
311 // vpFEATURE_OPTICAL_FILTER = DC1394_FEATURE_OPTICAL_FILTER,
312 // vpFEATURE_CAPTURE_SIZE = DC1394_FEATURE_CAPTURE_SIZE,
313 // vpFEATURE_CAPTURE_QUALITY = DC1394_FEATURE_CAPTURE_QUALITY
314  } vp1394TwoParametersType;
315 
316 
317  private:
318 
322  typedef struct{
323  uint32_t brightness ;
324  uint32_t exposure;
325  uint32_t sharpness;
326 // uint32_t whiteBalance;
327  uint32_t hue;
328  uint32_t saturation;
329  uint32_t gamma;
330  uint32_t shutter ;
331  uint32_t gain ;
332  uint32_t iris;
333 // uint32_t focus;
334 // uint32_t temperature ;
335 // uint32_t trigger ;
336 // uint32_t triggerDelay ;
337 // uint32_t whiteShadding ;
338 // uint32_t frameRate ;
339 // uint32_t zoom;
340 // uint32_t pan;
341 // uint32_t tilt ;
342 // uint32_t opticalFilter ;
343 // uint32_t captureSize;
344 // uint32_t captureQuality ;
345  } vpDc1394TwoCameraParametersData;
346 
347 
348  public:
349  vp1394TwoGrabber(bool reset=true);
350  virtual ~vp1394TwoGrabber();
351 
353  void acquire(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
354  void acquire(vpImage<vpRGBa> &I);
355  void acquire(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
356 
357  void close();
358 
359  static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding);
360 
361  dc1394video_frame_t *dequeue();
362  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I);
363  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
364  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I);
365  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
366  void enqueue(dc1394video_frame_t *frame);
367 
368  static std::string framerate2string(vp1394TwoFramerateType fps);
369 
370  void getAutoGain(unsigned int &minvalue, unsigned int &maxvalue);
371  void getAutoShutter(unsigned int &minvalue, unsigned int &maxvalue);
372 
373  uint64_t getCamera();
374  void getCamera(uint64_t &camera);
375  void getColorCoding(vp1394TwoColorCodingType & coding);
376  uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode,
377  std::list<vp1394TwoColorCodingType> & codings);
378  void getFramerate(vp1394TwoFramerateType & fps);
379  uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode,
380  std::list<vp1394TwoFramerateType> & fps);
381  uint64_t getGuid();
382  void getGuid(uint64_t &guid);
383  void getHeight(unsigned int &height);
384  unsigned int getHeight();
385  void getNumCameras(unsigned int &ncameras) const;
386  unsigned int getNumCameras() const;
387  unsigned int getParameterValue(vp1394TwoParametersType param);
388  unsigned int getRingBufferSize() const;
389  void getVideoMode(vp1394TwoVideoModeType & videomode);
390  uint32_t getVideoModeSupported(std::list<vp1394TwoVideoModeType> & videomodes);
391  void getWidth(unsigned int &width);
392  unsigned int getWidth();
393 
394  bool isColor();
395  bool isColorCodingSupported(vp1394TwoVideoModeType videomode,
396  vp1394TwoColorCodingType coding);
397  bool isFramerateSupported(vp1394TwoVideoModeType videomode,
398  vp1394TwoFramerateType fps);
399  bool isVideoModeSupported(vp1394TwoVideoModeType videomode) ;
400  bool isVideoModeFormat7(vp1394TwoVideoModeType videomode);
401 
402  void open(vpImage<unsigned char> &I);
403  void open(vpImage<vpRGBa> &I);
404 
405  void printCameraInfo();
406 
407  void resetBus();
408 
409  void setAutoGain(bool enable = true);
410  void setAutoGain(unsigned int minvalue, unsigned int maxvalue);
411  void setAutoShutter(bool enable = true);
412  void setAutoShutter(unsigned int minvalue, unsigned int maxvalue);
413  void setCamera(uint64_t camera);
414  void setColorCoding(vp1394TwoColorCodingType coding);
415  void setFormat7ROI(unsigned int left=0, unsigned int top=0,
416  unsigned int width=0, unsigned int height=0);
417  void setFramerate(vp1394TwoFramerateType fps);
418  void setIsoTransmissionSpeed(vp1394TwoIsoSpeedType isospeed);
419  void setPanControl(unsigned int panControlValue);
420  void setParameterValue(vp1394TwoParametersType param, unsigned int val);
421  void setRingBufferSize(unsigned int size);
422  void setVideoMode(vp1394TwoVideoModeType videomode);
423 
424  static vp1394TwoVideoModeType string2videoMode(std::string videomode);
425  static vp1394TwoFramerateType string2framerate(std::string fps);
426  static vp1394TwoColorCodingType string2colorCoding(std::string colorcoding);
427 
428  static std::string videoMode2string(vp1394TwoVideoModeType videomode);
429 
430 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
431 
434  vp_deprecated uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode,
436  vp_deprecated uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode,
438  vp_deprecated uint32_t getVideoModeSupported(vpList<vp1394TwoVideoModeType> & videomodes);
439 
440 #endif
441 
442  private:
443  void open();
444  void initialize(bool reset);
445  void setCapture(dc1394switch_t _switch);
446  void setTransmission(dc1394switch_t _switch);
447  inline void updateDataCamToStruct();
448  inline void updateDataStructToCam();
449 
450  private:
451  dc1394camera_t *camera, **cameras;
452  unsigned int num_cameras;
453  unsigned int camera_id;
454 
455  bool verbose;
456  bool *camIsOpen;
457  unsigned int num_buffers;
458 
459  /* parameters for the cameras */
460  bool* isDataModified;
461  dc1394feature_mode_t* initialShutterMode;
462  vpDc1394TwoCameraParametersData* dataCam;
463 
464 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE
465  dc1394_t * d;
466  dc1394camera_list_t * list;
467 #endif
468 };
469 
470 
471 #endif
472 #endif
473 
Provide simple list management.
Definition: vpList.h:113
virtual void open(vpImage< unsigned char > &I)=0
unsigned int getWidth() const
Return the number of columns in the image.
Base class for all video devices. It is designed to provide a front end to video sources.
virtual void close()=0
Class for firewire ieee1394 video devices using libdc1394-2.x api.
virtual void acquire(vpImage< unsigned char > &I)=0
unsigned int getHeight() const
Return the number of rows in the image.