ViSP  2.6.2
vp1394TwoGrabber.h
1 /****************************************************************************
2  *
3  * $Id: vp1394TwoGrabber.h 3577 2012-03-01 09:57:29Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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 
193 /*
194  * Interface with libdc1394 2.x
195  */
196 #include <string.h>
197 
198 #include <dc1394/control.h>
199 #include <dc1394/utils.h>
200 #include <dc1394/vendor/avt.h>
201 
202 #include <visp/vpImage.h>
203 #include <visp/vpFrameGrabber.h>
204 #include <visp/vpRGBa.h>
205 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
206 # include <visp/vpList.h>
207 #endif
208 
209 
210 class VISP_EXPORT vp1394TwoGrabber : public vpFrameGrabber
211 {
212 
213  public:
214  static const char * strVideoMode[DC1394_VIDEO_MODE_NUM];
215  static const char * strFramerate[DC1394_FRAMERATE_NUM];
216  static const char * strColorCoding[DC1394_COLOR_CODING_NUM];
217 
222  typedef enum {
223  vpISO_SPEED_100 = DC1394_ISO_SPEED_100,
224  vpISO_SPEED_200 = DC1394_ISO_SPEED_200,
225  vpISO_SPEED_400 = DC1394_ISO_SPEED_400,
226  vpISO_SPEED_800 = DC1394_ISO_SPEED_800,
227  vpISO_SPEED_1600 = DC1394_ISO_SPEED_1600,
228  vpISO_SPEED_3200 = DC1394_ISO_SPEED_3200
229  } vp1394TwoIsoSpeedType;
230 
235  typedef enum {
236  vpVIDEO_MODE_160x120_YUV444 = DC1394_VIDEO_MODE_160x120_YUV444,
237  vpVIDEO_MODE_320x240_YUV422 = DC1394_VIDEO_MODE_320x240_YUV422,
238  vpVIDEO_MODE_640x480_YUV411 = DC1394_VIDEO_MODE_640x480_YUV411,
239  vpVIDEO_MODE_640x480_YUV422 = DC1394_VIDEO_MODE_640x480_YUV422,
240  vpVIDEO_MODE_640x480_RGB8 = DC1394_VIDEO_MODE_640x480_RGB8,
241  vpVIDEO_MODE_640x480_MONO8 = DC1394_VIDEO_MODE_640x480_MONO8,
242  vpVIDEO_MODE_640x480_MONO16 = DC1394_VIDEO_MODE_640x480_MONO16,
243  vpVIDEO_MODE_800x600_YUV422 = DC1394_VIDEO_MODE_800x600_YUV422,
244  vpVIDEO_MODE_800x600_RGB8 = DC1394_VIDEO_MODE_800x600_RGB8,
245  vpVIDEO_MODE_800x600_MONO8 = DC1394_VIDEO_MODE_800x600_MONO8,
246  vpVIDEO_MODE_1024x768_YUV422 = DC1394_VIDEO_MODE_1024x768_YUV422,
247  vpVIDEO_MODE_1024x768_RGB8 = DC1394_VIDEO_MODE_1024x768_RGB8,
248  vpVIDEO_MODE_1024x768_MONO8 = DC1394_VIDEO_MODE_1024x768_MONO8,
249  vpVIDEO_MODE_800x600_MONO16 = DC1394_VIDEO_MODE_800x600_MONO16,
250  vpVIDEO_MODE_1024x768_MONO16 = DC1394_VIDEO_MODE_1024x768_MONO16,
251  vpVIDEO_MODE_1280x960_YUV422 = DC1394_VIDEO_MODE_1280x960_YUV422,
252  vpVIDEO_MODE_1280x960_RGB8 = DC1394_VIDEO_MODE_1280x960_RGB8,
253  vpVIDEO_MODE_1280x960_MONO8 = DC1394_VIDEO_MODE_1280x960_MONO8,
254  vpVIDEO_MODE_1600x1200_YUV422 = DC1394_VIDEO_MODE_1600x1200_YUV422,
255  vpVIDEO_MODE_1600x1200_RGB8 = DC1394_VIDEO_MODE_1600x1200_RGB8,
256  vpVIDEO_MODE_1600x1200_MONO8 = DC1394_VIDEO_MODE_1600x1200_MONO8,
257  vpVIDEO_MODE_1280x960_MONO16 = DC1394_VIDEO_MODE_1280x960_MONO16,
258  vpVIDEO_MODE_1600x1200_MONO16 = DC1394_VIDEO_MODE_1600x1200_MONO16,
259  vpVIDEO_MODE_EXIF = DC1394_VIDEO_MODE_EXIF,
260  vpVIDEO_MODE_FORMAT7_0 = DC1394_VIDEO_MODE_FORMAT7_0,
261  vpVIDEO_MODE_FORMAT7_1 = DC1394_VIDEO_MODE_FORMAT7_1,
262  vpVIDEO_MODE_FORMAT7_2 = DC1394_VIDEO_MODE_FORMAT7_2,
263  vpVIDEO_MODE_FORMAT7_3 = DC1394_VIDEO_MODE_FORMAT7_3,
264  vpVIDEO_MODE_FORMAT7_4 = DC1394_VIDEO_MODE_FORMAT7_4,
265  vpVIDEO_MODE_FORMAT7_5 = DC1394_VIDEO_MODE_FORMAT7_5,
266  vpVIDEO_MODE_FORMAT7_6 = DC1394_VIDEO_MODE_FORMAT7_6,
267  vpVIDEO_MODE_FORMAT7_7 = DC1394_VIDEO_MODE_FORMAT7_7
268  } vp1394TwoVideoModeType;
269 
274  typedef enum {
275  vpFRAMERATE_1_875 = DC1394_FRAMERATE_1_875,
276  vpFRAMERATE_3_75 = DC1394_FRAMERATE_3_75,
277  vpFRAMERATE_7_5 = DC1394_FRAMERATE_7_5,
278  vpFRAMERATE_15 = DC1394_FRAMERATE_15,
279  vpFRAMERATE_30 = DC1394_FRAMERATE_30,
280  vpFRAMERATE_60 = DC1394_FRAMERATE_60,
281  vpFRAMERATE_120 = DC1394_FRAMERATE_120,
282  vpFRAMERATE_240 = DC1394_FRAMERATE_240
283  } vp1394TwoFramerateType;
284 
289  typedef enum {
290  vpCOLOR_CODING_MONO8 = DC1394_COLOR_CODING_MONO8,
291  vpCOLOR_CODING_YUV411 = DC1394_COLOR_CODING_YUV411,
292  vpCOLOR_CODING_YUV422 = DC1394_COLOR_CODING_YUV422,
293  vpCOLOR_CODING_YUV444 = DC1394_COLOR_CODING_YUV444,
294  vpCOLOR_CODING_RGB8 = DC1394_COLOR_CODING_RGB8,
295  vpCOLOR_CODING_MONO16 = DC1394_COLOR_CODING_MONO16,
296  vpCOLOR_CODING_RGB16 = DC1394_COLOR_CODING_RGB16,
297  vpCOLOR_CODING_MONO16S = DC1394_COLOR_CODING_MONO16S,
298  vpCOLOR_CODING_RGB16S = DC1394_COLOR_CODING_RGB16S,
299  vpCOLOR_CODING_RAW8 = DC1394_COLOR_CODING_RAW8,
300  vpCOLOR_CODING_RAW16 = DC1394_COLOR_CODING_RAW16
301  } vp1394TwoColorCodingType;
302 
307  typedef enum {
308  vpFEATURE_BRIGHTNESS = DC1394_FEATURE_BRIGHTNESS,
309  vpFEATURE_EXPOSURE = DC1394_FEATURE_EXPOSURE,
310  vpFEATURE_SHARPNESS = DC1394_FEATURE_SHARPNESS,
311 // vpFEATURE_WHITE_BALANCE = DC1394_FEATURE_WHITE_BALANCE,
312  vpFEATURE_HUE = DC1394_FEATURE_HUE,
313  vpFEATURE_SATURATION = DC1394_FEATURE_SATURATION,
314  vpFEATURE_GAMMA = DC1394_FEATURE_GAMMA,
315  vpFEATURE_SHUTTER = DC1394_FEATURE_SHUTTER,
316  vpFEATURE_GAIN = DC1394_FEATURE_GAIN,
317  vpFEATURE_IRIS = DC1394_FEATURE_IRIS,
318 // vpFEATURE_FOCUS = DC1394_FEATURE_FOCUS,
319 // vpFEATURE_TEMPERATURE = DC1394_FEATURE_TEMPERATURE,
320 // vpFEATURE_TRIGGER = DC1394_FEATURE_TRIGGER,
321 // vpFEATURE_TRIGGER_DELAY = DC1394_FEATURE_TRIGGER_DELAY,
322 // vpFEATURE_WHITE_SHADING = DC1394_FEATURE_WHITE_SHADING,
323 // vpFEATURE_FRAME_RATE = DC1394_FEATURE_FRAME_RATE,
324 // vpFEATURE_ZOOM = DC1394_FEATURE_ZOOM,
325 // vpFEATURE_PAN = DC1394_FEATURE_PAN,
326 // vpFEATURE_TILT = DC1394_FEATURE_TILT,
327 // vpFEATURE_OPTICAL_FILTER = DC1394_FEATURE_OPTICAL_FILTER,
328 // vpFEATURE_CAPTURE_SIZE = DC1394_FEATURE_CAPTURE_SIZE,
329 // vpFEATURE_CAPTURE_QUALITY = DC1394_FEATURE_CAPTURE_QUALITY
330  } vp1394TwoParametersType;
331 
332 
333  private:
334 
338  typedef struct{
339  uint32_t brightness ;
340  uint32_t exposure;
341  uint32_t sharpness;
342 // uint32_t whiteBalance;
343  uint32_t hue;
344  uint32_t saturation;
345  uint32_t gamma;
346  uint32_t shutter ;
347  uint32_t gain ;
348  uint32_t iris;
349 // uint32_t focus;
350 // uint32_t temperature ;
351 // uint32_t trigger ;
352 // uint32_t triggerDelay ;
353 // uint32_t whiteShadding ;
354 // uint32_t frameRate ;
355 // uint32_t zoom;
356 // uint32_t pan;
357 // uint32_t tilt ;
358 // uint32_t opticalFilter ;
359 // uint32_t captureSize;
360 // uint32_t captureQuality ;
361  } vpDc1394TwoCameraParametersData;
362 
363 
364  public:
365  vp1394TwoGrabber(bool reset=true);
366  virtual ~vp1394TwoGrabber();
367 
368 
369  uint64_t getCamera();
370  void getCamera(uint64_t &camera);
371  uint64_t getGuid();
372  void getGuid(uint64_t &guid);
373  void getColorCoding(vp1394TwoColorCodingType & coding);
374  uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode,
375  std::list<vp1394TwoColorCodingType> & codings);
376  void getFramerate(vp1394TwoFramerateType & fps);
377  uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode,
378  std::list<vp1394TwoFramerateType> & fps);
379  void getHeight(unsigned int &height);
380  unsigned int getHeight();
381  void getNumCameras(unsigned int &ncameras);
382  unsigned int getNumCameras();
383  unsigned int getParameterValue(vp1394TwoParametersType param);
384  unsigned int getRingBufferSize();
385  void getVideoMode(vp1394TwoVideoModeType & videomode);
386  uint32_t getVideoModeSupported(std::list<vp1394TwoVideoModeType> & videomodes);
387  void getWidth(unsigned int &width);
388  unsigned int getWidth();
389 
390  bool isColor();
391  bool isColorCodingSupported(vp1394TwoVideoModeType videomode,
392  vp1394TwoColorCodingType coding);
393  bool isFramerateSupported(vp1394TwoVideoModeType videomode,
394  vp1394TwoFramerateType fps);
395  bool isVideoModeSupported(vp1394TwoVideoModeType videomode) ;
396  bool isVideoModeFormat7(vp1394TwoVideoModeType videomode);
397 
398  void setAutoShutter(unsigned int minvalue, unsigned int maxvalue);
399  void setCamera(uint64_t camera);
400  void setColorCoding(vp1394TwoColorCodingType coding);
401  void setFormat7ROI(unsigned int left=0, unsigned int top=0,
402  unsigned int width=0, unsigned int height=0);
403  void setFramerate(vp1394TwoFramerateType fps);
404  void setIsoTransmissionSpeed(vp1394TwoIsoSpeedType isospeed);
405  void setPanControl(unsigned int panControlValue);
406  void setParameterValue(vp1394TwoParametersType param, unsigned int val);
407  void setRingBufferSize(unsigned int size);
408  void setVideoMode(vp1394TwoVideoModeType videomode);
409 
410  void open(vpImage<unsigned char> &I);
411  void open(vpImage<vpRGBa> &I);
412 
413  void printCameraInfo();
414 
415 
416  dc1394video_frame_t *dequeue();
417  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I);
418  dc1394video_frame_t *dequeue(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
419  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I);
420  dc1394video_frame_t *dequeue(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
421  void enqueue(dc1394video_frame_t *frame);
422 
424  void acquire(vpImage<unsigned char> &I, uint64_t &timestamp, uint32_t &id);
425  void acquire(vpImage<vpRGBa> &I);
426  void acquire(vpImage<vpRGBa> &I, uint64_t &timestamp, uint32_t &id);
427  void close();
428  void resetBus();
429 
430  static std::string videoMode2string(vp1394TwoVideoModeType videomode);
431  static std::string framerate2string(vp1394TwoFramerateType fps);
432  static std::string colorCoding2string(vp1394TwoColorCodingType colorcoding);
433  static vp1394TwoVideoModeType string2videoMode(std::string videomode);
434  static vp1394TwoFramerateType string2framerate(std::string fps);
435  static vp1394TwoColorCodingType string2colorCoding(std::string colorcoding);
436 
437 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
438 
441  vp_deprecated uint32_t getColorCodingSupported(vp1394TwoVideoModeType videomode,
443  vp_deprecated uint32_t getFramerateSupported(vp1394TwoVideoModeType videomode,
445  vp_deprecated uint32_t getVideoModeSupported(vpList<vp1394TwoVideoModeType> & videomodes);
446 
447 #endif
448 
449  private:
450  void open();
451  void initialize(bool reset);
452  void setCapture(dc1394switch_t _switch);
453  void setTransmission(dc1394switch_t _switch);
454  inline void updateDataCamToStruct();
455  inline void updateDataStructToCam();
456 
457  private:
458  dc1394camera_t *camera, **cameras;
459  unsigned int num_cameras;
460  unsigned int camera_id;
461 
462  bool verbose;
463  bool *camIsOpen;
464  unsigned int num_buffers;
465 
466  /* parameters for the cameras */
467  bool* isDataModified;
468  dc1394feature_mode_t* initialShutterMode;
469  vpDc1394TwoCameraParametersData* dataCam;
470 
471 #ifdef VISP_HAVE_DC1394_2_CAMERA_ENUMERATE
472  dc1394_t * d;
473  dc1394camera_list_t * list;
474 #endif
475 };
476 
477 
478 #endif
479 #endif
480 
Provide simple list management.
Definition: vpList.h:112
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.