ViSP  2.8.0
vp1394Grabber.cpp
1 /****************************************************************************
2  *
3  * $Id: vp1394Grabber.cpp 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 
42 
48 #include <iostream>
49 
50 #include <visp/vpConfig.h>
51 
52 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
53 #if defined(VISP_HAVE_DC1394_1)
54 
55 
56 
57 #include <visp/vp1394Grabber.h>
58 #include <visp/vpFrameGrabberException.h>
59 #include <visp/vpImageIo.h>
60 #include <visp/vpImageConvert.h>
61 
62 const int vp1394Grabber::DROP_FRAMES = 1;
63 const int vp1394Grabber::NUM_BUFFERS = 8;
64 const int vp1394Grabber::MAX_PORTS = 4;
65 const int vp1394Grabber::MAX_CAMERAS = 8;
67 const char * vp1394Grabber::strFormats[NUM_FORMATS]= {
68  "Format_0",
69  "Format_1",
70  "Format_2",
71  "Reserved", // 3 reserved formats
72  "Reserved",
73  "Reserved",
74  "Format_6",
75  "Format_7"
76 };
77 
78 const char * vp1394Grabber::strModesInFormat0[NUM_FORMAT0_MODES]= {
79  "Format_0, Mode_0: 160x120 YUV (4:4:4)",
80  "Format_0, Mode_1: 320x240 YUV (4:2:2)",
81  "Format_0, Mode_2: 640x480 YUV (4:1:1)",
82  "Format_0, Mode_3: 640x480 YUV (4:2:2)",
83  "Format_0, Mode_4: 640x480 RGB 24bpp",
84  "Format_0, Mode_5: 640x480 Mono 8bpp",
85  "Format_0, Mode_6: 640x480 Mono 16bpp"
86 };
87 
88 const char * vp1394Grabber::strModesInFormat1[NUM_FORMAT1_MODES]= {
89  "Format_1, Mode_0: 800x600 YUV (4:2:2)",
90  "Format_1, Mode_1: 800x600 RGB 24bpp",
91  "Format_1, Mode_2: 800x600 Mono 8bpp",
92  "Format_1, Mode_3: 1024x768 YUV (4:2:2)",
93  "Format_1, Mode_4: 1024x768 RGB 24bpp",
94  "Format_1, Mode_5: 1024x768 Mono 8bpp",
95  "Format_1, Mode_6: 800x600 Mono 16bpp",
96  "Format_1, Mode_7: 1024x768 Mono 16bpp"
97 };
98 
99 const char * vp1394Grabber::strModesInFormat2[NUM_FORMAT2_MODES]= {
100  "Format_2, Mode_0: 1280x960 YUV (4:2:2)",
101  "Format_2, Mode_1: 1280x960 RGB 24bpp",
102  "Format_2, Mode_2: 1280x960 Mono 8bpp",
103  "Format_2, Mode_3: 1600x1200 YUV (4:2:2)",
104  "Format_2, Mode_4: 1600x1200 RGB 24bpp",
105  "Format_2, Mode_5: 1600x1200 Mono 8bpp",
106  "Format_2, Mode_6: 1280x960 Mono 16bpp",
107  "Format_2, Mode_7: 1600x1200 Mono 16bpp"
108 };
109 
110 const char * vp1394Grabber::strModesInFormat6[NUM_FORMAT6_MODES]= {
111  "Format6, Mode_0: EXIT (not supported)"
112 };
113 
114 const char * vp1394Grabber::strModesInFormat7[NUM_MODE_FORMAT7]= {
115  "Format_7, Mode_0",
116  "Format_7, Mode_1",
117  "Format_7, Mode_2",
118  "Format_7, Mode_3",
119  "Format_7, Mode_4",
120  "Format_7, Mode_5",
121  "Format_7, Mode_6",
122  "Format_7, Mode_7"
123 };
124 
125 const char * vp1394Grabber::strColorsInFormat7[NUM_COLOR_FORMAT7] = {
126  "Format_7 Color, Mono 8bpp",
127  "Format_7 Color, YUV 4:1:1",
128  "Format_7 Color, YUV 4:2:2",
129  "Format_7 Color, YUV 4:4:4",
130  "Format_7 Color, RGB 24bpp",
131  "Format_7 Color, Mono 16bpp",
132  "Format_7 Color, RGB 48bpp"
133 };
134 
135 const char * vp1394Grabber::strFramerates[NUM_FRAMERATES] = {
136  "1.875 Hz",
137  "3.75 Hz",
138  "7.5 Hz",
139  "15 Hz",
140  "30 Hz",
141  "60 Hz"
142 };
143 
173 {
174  sprintf(device_name, "/dev/video1394/0");
175 
176  // allocations
177  handles = new raw1394handle_t [vp1394Grabber::MAX_CAMERAS];
178  cameras = new dc1394_cameracapture [vp1394Grabber::MAX_CAMERAS];
179  cam_count = new int [vp1394Grabber::MAX_CAMERAS];
180  pformat = new int [vp1394Grabber::MAX_CAMERAS];
181  pmode = new int [vp1394Grabber::MAX_CAMERAS];
182  pframerate = new int [vp1394Grabber::MAX_CAMERAS];
183  _width = new int [vp1394Grabber::MAX_CAMERAS];
184  _height = new int [vp1394Grabber::MAX_CAMERAS];
186 
187  // Camera settings initialisation
188  for (int i=0; i < vp1394Grabber::MAX_CAMERAS; i ++) {
189  pformat[i] = 0;
190  pmode[i] = 0;
191  pframerate[i] = 0;
192  }
193  verbose = false;
194 
195  iso_transmission_started = false;
196  handle_created = false;
197  camera_found = false;
198  dma_started = false;
199  num_cameras = 0;
200  camera = 0; // the first camera on the bus
201 
202  // Image settings
203  for (int i=0; i < vp1394Grabber::MAX_CAMERAS; i ++) {
204  _width[i] = 0;
205  _height[i] = 0;
206  image_format[i] = RGB;
207  }
208 
209  init = false ;
210 }
211 
241 {
242  sprintf(device_name, "/dev/video1394/0");
243 
244  // allocations
245  handles = new raw1394handle_t [vp1394Grabber::MAX_CAMERAS];
246  cameras = new dc1394_cameracapture [vp1394Grabber::MAX_CAMERAS];
247  cam_count = new int [vp1394Grabber::MAX_CAMERAS];
248  pformat = new int [vp1394Grabber::MAX_CAMERAS];
249  pmode = new int [vp1394Grabber::MAX_CAMERAS];
250  pframerate = new int [vp1394Grabber::MAX_CAMERAS];
251  _width = new int [vp1394Grabber::MAX_CAMERAS];
252  _height = new int [vp1394Grabber::MAX_CAMERAS];
254 
255  // Camera settings
256  for (int i=0; i < vp1394Grabber::MAX_CAMERAS; i ++) {
257  pformat[i] = 0;
258  pmode[i] = 0;
259  pframerate[i] = 0;
260  }
261  verbose = false;
262 
263  iso_transmission_started = false;
264  handle_created = false;
265  camera_found = false;
266  num_cameras = 0;
267  camera = 0; // the first camera on the bus
268 
269  // Image settings
270  for (int i=0; i < vp1394Grabber::MAX_CAMERAS; i ++) {
271  _width[i] = 0;
272  _height[i] = 0;
273  image_format[i] = RGB;
274  }
275 
276  init = false ;
277 
278  open ( I ) ;
279 }
280 
291 {
292  close();
293 }
294 
323 void
324 vp1394Grabber::setCamera(unsigned int camera)
325 {
326  if (camera >= num_cameras) {
327  close();
328  vpERROR_TRACE("The required camera is not present");
330  "The required camera is not present") );
331  }
332 
333  this->camera = camera;
334 
335 }
347 void
348 vp1394Grabber::getCamera(unsigned int &camera)
349 {
350  camera = this->camera;
351 
352 }
379 void
381 {
382  if (iso_transmission_started == true) {
383 
384  stopIsoTransmission();
385 
386  for (unsigned int i=0; i < num_cameras; i++)
387  dc1394_dma_unlisten( handles[i], &cameras[i] );
388  iso_transmission_started = false;
389  }
390 
391  this->pformat[camera] = format;
392 
393  setup();
394  startIsoTransmission();
395 }
396 
420 void
422 {
423  if (handle_created == false) {
424  close();
425  vpERROR_TRACE("To set the shutter the handle must be created");
427  "To set the shutter the handle must be created") );
428  }
429  if (camera_found == false) {
430  close();
431  vpERROR_TRACE("To set the shutter a camera must be connected");
433  "To set the shutter a camera must be connected") );
434  }
435 
436  if(dc1394_get_camera_misc_info(handles[camera],
437  cameras[camera].node,
438  &miscinfo) !=DC1394_SUCCESS) {
439  vpERROR_TRACE("Unable to get misc info");
441  "Unable to get misc info") );
442  }
443 
444  format = miscinfo.format;
445 }
446 
465 int
467 {
468  int nb = 0; // Number of supported formats
469 
470  // Refresh the list of supported formats
471  formats.kill();
472 
473  if (handle_created == false) {
474  close();
475  vpERROR_TRACE("To set the shutter the handle must be created");
477  "To set the shutter the handle must be created") );
478  }
479  if (camera_found == false) {
480  close();
481  vpERROR_TRACE("To set the shutter a camera must be connected");
483  "To set the shutter a camera must be connected") );
484  }
485 
486  quadlet_t value;
487  if (dc1394_query_supported_formats(handles[camera],
488  cameras[camera].node,
489  &value) != DC1394_SUCCESS) {
490  vpERROR_TRACE("Could not query supported formats");
492  "Could not query supported formats") );
493  }
494 
495  if (value & (0x1<<31)) {
496  formats.addRight(FORMAT_VGA_NONCOMPRESSED);
497  nb ++;
498  }
499  if (value & (0x1<<30)) {
500  formats.addRight(FORMAT_SVGA_NONCOMPRESSED_1);
501  nb ++;
502  }
503  if (value & (0x1<<29)) {
504  formats.addRight(FORMAT_SVGA_NONCOMPRESSED_2);
505  nb ++;
506  }
507  if (value & (0x1<<25)) {
508  formats.addRight(FORMAT_STILL_IMAGE);
509  nb ++;
510  }
511  if (value & (0x1<<24)) {
512  formats.addRight(FORMAT_SCALABLE_IMAGE_SIZE);
513  nb ++;
514  }
515 
516  return nb;
517 }
518 
553 void
555 {
556  if (iso_transmission_started == true) {
557 
558  stopIsoTransmission();
559 
560  for (unsigned int i=0; i < num_cameras; i++)
561  dc1394_dma_unlisten( handles[i], &cameras[i] );
562  iso_transmission_started = false;
563  }
564 
565  this->pmode[camera] = mode;
566 
567  setup();
568  startIsoTransmission();
569 }
570 
587 void
589 {
590 
591  if (handle_created == false) {
592  close();
593  vpERROR_TRACE("To set the shutter the handle must be created");
595  "To set the shutter the handle must be created") );
596  }
597  if (camera_found == false) {
598  close();
599  vpERROR_TRACE("To set the shutter a camera must be connected");
601  "To set the shutter a camera must be connected") );
602  }
603  if(dc1394_get_camera_misc_info(handles[camera],
604  cameras[camera].node,
605  &miscinfo) !=DC1394_SUCCESS) {
606  vpERROR_TRACE("Unable to get misc info");
608  "Unable to get misc info") );
609  }
610 
611  mode = miscinfo.mode;
612 }
613 
639 int
641 {
642  int nb = 0; // Number of supported modes
643 
644  // Refresh the list of supported modes
645  modes.kill();
646 
647  if (handle_created == false) {
648  close();
649  vpERROR_TRACE("To set the shutter the handle must be created");
651  "To set the shutter the handle must be created") );
652  }
653  if (camera_found == false) {
654  close();
655  vpERROR_TRACE("To set the shutter a camera must be connected");
657  "To set the shutter a camera must be connected") );
658  }
659 
660  quadlet_t value;
661  if (dc1394_query_supported_modes(handles[camera],
662  cameras[camera].node,
663  format, &value) != DC1394_SUCCESS) {
664  vpERROR_TRACE("Could not query supported modes for format %d\n", format);
666  "Could not query supported mode") );
667  }
668 
669  switch (format) {
670  case FORMAT_VGA_NONCOMPRESSED:
671  for (int m = MODE_FORMAT0_MIN; m <= MODE_FORMAT0_MAX; m ++) {
672  if (value & (0x1<<(31-(m-MODE_FORMAT0_MIN)))) {
673  modes.addRight(m);
674  nb ++;
675  }
676  }
677  break;
678 
679  case FORMAT_SVGA_NONCOMPRESSED_1:
680  for (int m = MODE_FORMAT1_MIN; m <= MODE_FORMAT1_MAX; m ++) {
681  if (value & (0x1<<(31-(m-MODE_FORMAT1_MIN)))) {
682  modes.addRight(m);
683  nb ++;
684  }
685  }
686  break;
687 
688  case FORMAT_SVGA_NONCOMPRESSED_2:
689  for (int m = MODE_FORMAT2_MIN; m <= MODE_FORMAT2_MAX; m ++) {
690  if (value & (0x1<<(31-(m-MODE_FORMAT2_MIN)))) {
691  modes.addRight(m);
692  nb ++;
693  }
694  }
695  break;
696 
697  case FORMAT_STILL_IMAGE:
698  for (int m = MODE_FORMAT6_MIN; m <= MODE_FORMAT6_MAX; m ++) {
699  if (value & (0x1<<(31-(m-MODE_FORMAT6_MIN)))) {
700  modes.addRight(m);
701  nb ++;
702  }
703  }
704  break;
705 
706  case FORMAT_SCALABLE_IMAGE_SIZE:
707  for (int m = MODE_FORMAT7_MIN; m <= MODE_FORMAT7_MAX; m ++) {
708  if (value & (0x1<<(31-(m-MODE_FORMAT7_MIN)))) {
709  modes.addRight(m);
710  nb ++;
711  }
712  }
713  break;
714  }
715 
716  return nb;
717 }
718 
745 void
747 {
748  if (iso_transmission_started == true) {
749 
750  stopIsoTransmission();
751 
752  for (unsigned int i=0; i < num_cameras; i++)
753  dc1394_dma_unlisten( handles[i], &cameras[i] );
754  iso_transmission_started = false;
755  }
756 
757  this->pframerate[camera] = framerate;
758 
759  setup();
760  startIsoTransmission();
761 }
762 
782 void
784 {
785  if (handle_created == false) {
786  close();
787  vpERROR_TRACE("To set the shutter the handle must be created");
789  "To set the shutter the handle must be created") );
790  }
791  if (camera_found == false) {
792  close();
793  vpERROR_TRACE("To set the shutter a camera must be connected");
795  "To set the shutter a camera must be connected") );
796  }
797 
798  if(dc1394_get_camera_misc_info(handles[camera],
799  cameras[camera].node,
800  &miscinfo) !=DC1394_SUCCESS) {
801  vpERROR_TRACE("Unable to get misc info");
803  "Unable to get misc info") );
804  }
805 
806  framerate = miscinfo.framerate;
807 }
808 
835 int
837  vpList<int> & framerates)
838 {
839  int nb = 0; // Number of supported framerates
840 
841  // Refresh the list of supported framerates
842  framerates.kill();
843 
844  if (handle_created == false) {
845  close();
846  vpERROR_TRACE("To set the shutter the handle must be created");
848  "To set the shutter the handle must be created") );
849  }
850  if (camera_found == false) {
851  close();
852  vpERROR_TRACE("To set the shutter a camera must be connected");
854  "To set the shutter a camera must be connected") );
855  }
856 
857  switch(format) {
858  case FORMAT_VGA_NONCOMPRESSED:
859  case FORMAT_SVGA_NONCOMPRESSED_1:
860  case FORMAT_SVGA_NONCOMPRESSED_2:
861  {
862 
863  quadlet_t value;
864  if (dc1394_query_supported_framerates(handles[camera],
865  cameras[camera].node,
866  format, mode,
867  &value) != DC1394_SUCCESS) {
868  vpERROR_TRACE("Could not query supported frametates for format %d\n"
869  "and mode %d\n", format, mode);
871  "Could not query supported framerates") );
872  }
873 
874  for (int f = FRAMERATE_MIN; f <= FRAMERATE_MAX; f ++) {
875  if (value & (0x1<<(31-(f-FRAMERATE_MIN)))) {
876  framerates.addRight(f);
877  nb ++;
878  }
879  }
880  }
881  break;
882  default:
883  // Framerate not available for:
884  // - FORMAT_STILL_IMAGE for the Format_6
885  // - FORMAT_SCALABLE_IMAGE_SIZE for the Format_7
886  return 0;
887  }
888 
889  return nb;
890 }
891 
911 int vp1394Grabber::convertFormat(std::string format)
912 {
913  for (int i = FORMAT_MIN; i <= FORMAT_MAX; i ++) {
914  // if (format.compare(0, format(i).length(), format(i)) == 0) {
915  if (format.compare(0, convertFormat(i).length(), convertFormat(i)) == 0) {
916  return i;
917  }
918  };
919 
920  return 0;
921 }
936 int vp1394Grabber::convertMode(std::string mode)
937 {
938  for (int i = MODE_FORMAT0_MIN; i <= MODE_FORMAT0_MAX; i ++) {
939  if (mode.compare(convertMode(i)) == 0)
940  return i;
941  };
942  for (int i = MODE_FORMAT1_MIN; i <= MODE_FORMAT1_MAX; i ++) {
943  if (mode.compare(convertMode(i)) == 0)
944  return i;
945  };
946  for (int i = MODE_FORMAT2_MIN; i <= MODE_FORMAT2_MAX; i ++) {
947  if (mode.compare(convertMode(i)) == 0)
948  return i;
949  };
950  for (int i = MODE_FORMAT6_MIN; i <= MODE_FORMAT6_MAX; i ++) {
951  if (mode.compare(convertMode(i)) == 0)
952  return i;
953  };
954  for (int i = MODE_FORMAT7_MIN; i <= MODE_FORMAT7_MAX; i ++) {
955  if (mode.compare(convertMode(i)) == 0)
956  return i;
957  };
958  for (int i = COLOR_FORMAT7_MIN; i <= COLOR_FORMAT7_MAX; i ++) {
959  if (mode.compare(convertMode(i)) == 0)
960  return i;
961  };
962 
963  return 0;
964 }
980 int vp1394Grabber::convertFramerate(std::string framerate)
981 {
982  for (int i = FRAMERATE_MIN; i <= FRAMERATE_MAX; i ++) {
983  if (framerate.compare(convertFramerate(i)) == 0)
984  return i;
985  };
986 
987  return 0;
988 }
989 
990 
1009 std::string vp1394Grabber::convertFormat(int format)
1010 {
1011  std::string _format;
1012  if ((format >= FORMAT_MIN) && (format <= FORMAT_MAX)) {
1013  switch (format) {
1014  case FORMAT_VGA_NONCOMPRESSED: _format = strFormats[0]; break;
1015  case FORMAT_SVGA_NONCOMPRESSED_1: _format = strFormats[1]; break;
1016  case FORMAT_SVGA_NONCOMPRESSED_2: _format = strFormats[2]; break;
1017  // 3 reserved formats
1018  case FORMAT_SVGA_NONCOMPRESSED_2 + 1: _format = strFormats[3]; break;
1019  case FORMAT_SVGA_NONCOMPRESSED_2 + 2: _format = strFormats[4]; break;
1020  case FORMAT_SVGA_NONCOMPRESSED_2 + 3: _format = strFormats[5]; break;
1021 
1022  case FORMAT_STILL_IMAGE: _format = strFormats[6]; break;
1023  case FORMAT_SCALABLE_IMAGE_SIZE: _format = strFormats[7]; break;
1024  default:
1025  break;
1026  }
1027  }
1028  else {
1029  std::cout << "The format " << format
1030  << " is not supported by the camera" << std::endl;
1031  _format = "Not Valid";
1032  }
1033 
1034  return _format;
1035 }
1049 std::string vp1394Grabber::convertMode(int mode)
1050 {
1051  std::string _mode;
1052 
1053  if ((mode >= MODE_FORMAT0_MIN) && (mode <= MODE_FORMAT0_MAX)) {
1054  switch (mode) {
1055  case MODE_160x120_YUV444: _mode = strModesInFormat0[0]; break;
1056  case MODE_320x240_YUV422: _mode = strModesInFormat0[1]; break;
1057  case MODE_640x480_YUV411: _mode = strModesInFormat0[2]; break;
1058  case MODE_640x480_YUV422: _mode = strModesInFormat0[3]; break;
1059  case MODE_640x480_RGB: _mode = strModesInFormat0[4]; break;
1060  case MODE_640x480_MONO: _mode = strModesInFormat0[5]; break;
1061  case MODE_640x480_MONO16: _mode = strModesInFormat0[6]; break;
1062  default: break;
1063  }
1064  }
1065  else if ((mode >= MODE_FORMAT1_MIN) && (mode <= MODE_FORMAT1_MAX)) {
1066  switch (mode) {
1067  case MODE_800x600_YUV422: _mode = strModesInFormat1[0]; break;
1068  case MODE_800x600_RGB: _mode = strModesInFormat1[1]; break;
1069  case MODE_800x600_MONO: _mode = strModesInFormat1[2]; break;
1070  case MODE_1024x768_YUV422: _mode = strModesInFormat1[3]; break;
1071  case MODE_1024x768_RGB: _mode = strModesInFormat1[4]; break;
1072  case MODE_1024x768_MONO: _mode = strModesInFormat1[5]; break;
1073  case MODE_800x600_MONO16: _mode = strModesInFormat1[6]; break;
1074  case MODE_1024x768_MONO16: _mode = strModesInFormat1[7]; break;
1075  default: break;
1076  }
1077  }
1078  else if ((mode >= MODE_FORMAT2_MIN) && (mode <= MODE_FORMAT2_MAX)) {
1079  switch (mode) {
1080  case MODE_1280x960_YUV422: _mode = strModesInFormat2[0]; break;
1081  case MODE_1280x960_RGB: _mode = strModesInFormat2[1]; break;
1082  case MODE_1280x960_MONO: _mode = strModesInFormat2[2]; break;
1083  case MODE_1600x1200_YUV422: _mode = strModesInFormat2[3]; break;
1084  case MODE_1600x1200_RGB: _mode = strModesInFormat2[4]; break;
1085  case MODE_1600x1200_MONO: _mode = strModesInFormat2[5]; break;
1086  case MODE_1280x960_MONO16: _mode = strModesInFormat2[6]; break;
1087  case MODE_1600x1200_MONO16: _mode = strModesInFormat2[7]; break;
1088  default: break;
1089  }
1090  }
1091  else if ((mode >= MODE_FORMAT6_MIN) && (mode <= MODE_FORMAT6_MAX)) {
1092  switch (mode) {
1093  case MODE_EXIF: _mode = strModesInFormat6[0]; break;
1094  default: break;
1095  }
1096  }
1097  else if ((mode >= MODE_FORMAT7_MIN) && (mode <= MODE_FORMAT7_MAX)) {
1098  switch (mode) {
1099  case MODE_FORMAT7_0: _mode = strModesInFormat7[0]; break;
1100  case MODE_FORMAT7_1: _mode = strModesInFormat7[1]; break;
1101  case MODE_FORMAT7_2: _mode = strModesInFormat7[2]; break;
1102  case MODE_FORMAT7_3: _mode = strModesInFormat7[3]; break;
1103  case MODE_FORMAT7_4: _mode = strModesInFormat7[4]; break;
1104  case MODE_FORMAT7_5: _mode = strModesInFormat7[5]; break;
1105  case MODE_FORMAT7_6: _mode = strModesInFormat7[6]; break;
1106  case MODE_FORMAT7_7: _mode = strModesInFormat7[7]; break;
1107  default: break;
1108  }
1109  }
1110  else if ((mode >= COLOR_FORMAT7_MIN) && (mode <= COLOR_FORMAT7_MAX)) {
1111  switch (mode) {
1112  case COLOR_FORMAT7_MONO8: _mode = strColorsInFormat7[0]; break;
1113  case COLOR_FORMAT7_YUV411: _mode = strColorsInFormat7[1]; break;
1114  case COLOR_FORMAT7_YUV422: _mode = strColorsInFormat7[2]; break;
1115  case COLOR_FORMAT7_YUV444: _mode = strColorsInFormat7[3]; break;
1116  case COLOR_FORMAT7_RGB8: _mode = strColorsInFormat7[4]; break;
1117  case COLOR_FORMAT7_MONO16: _mode = strColorsInFormat7[5]; break;
1118  case COLOR_FORMAT7_RGB16: _mode = strColorsInFormat7[6]; break;
1119  default: break;
1120  }
1121  }
1122  else {
1123  std::cout << "The mode " << mode << " is not supported by the camera" << std::endl;
1124  _mode = "Not valid";
1125  }
1126 
1127  return _mode;
1128 }
1129 
1143 std::string vp1394Grabber::convertFramerate(int framerate)
1144 {
1145  std::string _framerate;
1146 
1147  if ((framerate >= FRAMERATE_MIN) && (framerate <= FRAMERATE_MAX)) {
1148  switch (framerate) {
1149  case FRAMERATE_1_875: _framerate = strFramerates[0]; break;
1150  case FRAMERATE_3_75: _framerate = strFramerates[1]; break;
1151  case FRAMERATE_7_5: _framerate = strFramerates[2]; break;
1152  case FRAMERATE_15: _framerate = strFramerates[3]; break;
1153  case FRAMERATE_30: _framerate = strFramerates[4]; break;
1154  case FRAMERATE_60: _framerate = strFramerates[5]; break;
1155  default: break;
1156  }
1157  }
1158  else {
1159  std::cout << "The framerate " << framerate
1160  << " is not supported by the camera" << std::endl;
1161  _framerate = "Not valid";
1162  }
1163 
1164  return _framerate;
1165 
1166 }
1167 
1182 void
1183 vp1394Grabber::setShutter(unsigned int shutter)
1184 {
1185  unsigned int min_shutter = 0;
1186  unsigned int max_shutter = 0;
1187 
1188 
1189  if (handle_created == false) {
1190  close();
1191  vpERROR_TRACE("To set the shutter the handle must be created");
1193  "To set the shutter the handle must be created") );
1194  }
1195  if (camera_found == false) {
1196  close();
1197  vpERROR_TRACE("To set the shutter a camera must be connected");
1199  "To set the shutter a camera must be connected") );
1200  }
1201 
1202  if(dc1394_get_min_value(handles[camera],
1203  cameras[camera].node,
1204  FEATURE_SHUTTER, &min_shutter) !=DC1394_SUCCESS) {
1205  close();
1206  vpERROR_TRACE("Unable to get min shutter value");
1208  "Unable to get min shutter value") );
1209  }
1210 
1211  if(dc1394_get_max_value(handles[camera],
1212  cameras[camera].node,
1213  FEATURE_SHUTTER, &max_shutter) !=DC1394_SUCCESS) {
1214  close();
1215  vpERROR_TRACE("Unable to get max shutter value");
1217  "Unable to get max shutter value") );
1218  }
1219 
1220  if (shutter < min_shutter || shutter > max_shutter) {
1221  vpCERROR << "The requested shutter " << shutter
1222  << " must be comprised between " << min_shutter
1223  << " and " << max_shutter << std::endl;
1225  "Cannot set shutter: bad value") );
1226  }
1227 
1228  if ( dc1394_set_shutter(handles[camera],
1229  cameras[camera].node,
1230  shutter) != DC1394_SUCCESS) {
1231  vpERROR_TRACE("Unable to set shutter");
1233  "Cannot set shutter") );
1234  }
1235 }
1236 
1259 void
1260 vp1394Grabber::getShutter(unsigned int &min_shutter,
1261  unsigned int &shutter,
1262  unsigned int &max_shutter)
1263 {
1264  shutter = 0;
1265  min_shutter = 0;
1266  max_shutter = 0;
1267 
1268  if (handle_created == false) {
1269  close();
1270  vpERROR_TRACE("To set the shutter the handle must be created");
1272  "To set the shutter the handle must be created") );
1273  }
1274  if (camera_found == false) {
1275  close();
1276  vpERROR_TRACE("To set the shutter a camera must be connected");
1278  "To set the shutter a camera must be connected") );
1279  }
1280  if(dc1394_get_shutter(handles[camera],
1281  cameras[camera].node,
1282  &shutter) !=DC1394_SUCCESS) {
1283  close();
1284  vpERROR_TRACE("Unable to get shutter value");
1286  "Unable to get shutter value") );
1287 
1288  }
1289 
1290  if(dc1394_get_min_value(handles[camera],
1291  cameras[camera].node,
1292  FEATURE_SHUTTER, &min_shutter) !=DC1394_SUCCESS) {
1293  close();
1294  vpERROR_TRACE("Unable to get min shutter value");
1296  "Unable to get min shutter value") );
1297  }
1298 
1299  if(dc1394_get_max_value(handles[camera],
1300  cameras[camera].node,
1301  FEATURE_SHUTTER, &max_shutter) !=DC1394_SUCCESS) {
1302  close();
1303  vpERROR_TRACE("Unable to get max shutter value");
1305  "Unable to get max shutter value") );
1306  }
1307 }
1308 
1322 void
1323 vp1394Grabber::setGain(unsigned int gain)
1324 {
1325  unsigned int min_gain = 0;
1326  unsigned int max_gain = 0;
1327 
1328 
1329  if (handle_created == false) {
1330  close();
1331  vpERROR_TRACE("To set the shutter the handle must be created");
1333  "To set the shutter the handle must be created") );
1334  }
1335  if (camera_found == false) {
1336  close();
1337  vpERROR_TRACE("To set the shutter a camera must be connected");
1339  "To set the shutter a camera must be connected") );
1340  }
1341  if(dc1394_get_min_value(handles[camera],
1342  cameras[camera].node,
1343  FEATURE_GAIN, &min_gain) !=DC1394_SUCCESS) {
1344  close();
1345  vpERROR_TRACE("Unable to get min gain value");
1347  "Unable to get min gain value") );
1348  }
1349 
1350  if(dc1394_get_max_value(handles[camera],
1351  cameras[camera].node,
1352  FEATURE_GAIN, &max_gain) !=DC1394_SUCCESS) {
1353  close();
1354  vpERROR_TRACE("Unable to get max gain value");
1356  "Unable to get max gain value") );
1357  }
1358 
1359  if (gain < min_gain || gain > max_gain) {
1360  vpCERROR << "The requested gain " << gain
1361  << " must be comprised between " << min_gain
1362  << " and " << max_gain << std::endl;
1364  "Cannot set shutter: bad value") );
1365  }
1366 
1367  if ( dc1394_set_gain(handles[camera],
1368  cameras[camera].node,
1369  gain) != DC1394_SUCCESS) {
1370  vpERROR_TRACE("Unable to set gain");
1372  "Cannot set gain") );
1373  }
1374 }
1375 
1397 void
1398 vp1394Grabber::getGain(unsigned int &min_gain,
1399  unsigned int &gain,
1400  unsigned int &max_gain)
1401 {
1402  gain = 0;
1403  min_gain = 0;
1404  max_gain = 0;
1405 
1406  if (handle_created == false) {
1407  close();
1408  vpERROR_TRACE("To set the shutter the handle must be created");
1410  "To set the shutter the handle must be created") );
1411  }
1412  if (camera_found == false) {
1413  close();
1414  vpERROR_TRACE("To set the shutter a camera must be connected");
1416  "To set the shutter a camera must be connected") );
1417  }
1418 
1419  if(dc1394_get_gain(handles[camera],
1420  cameras[camera].node,
1421  &gain) !=DC1394_SUCCESS) {
1422  close();
1423  vpERROR_TRACE("Unable to get gain value");
1425  "Unable to get gain value") );
1426 
1427  }
1428 
1429  if(dc1394_get_min_value(handles[camera],
1430  cameras[camera].node,
1431  FEATURE_GAIN, &min_gain) !=DC1394_SUCCESS) {
1432  close();
1433  vpERROR_TRACE("Unable to get min gain value");
1435  "Unable to get min gain value") );
1436  }
1437 
1438  if(dc1394_get_max_value(handles[camera],
1439  cameras[camera].node,
1440  FEATURE_GAIN, &max_gain) !=DC1394_SUCCESS) {
1441  close();
1442  vpERROR_TRACE("Unable to get max gain value");
1444  "Unable to get max gain value") );
1445 
1446  }
1447 }
1448 
1464 void vp1394Grabber::getWidth(unsigned int &width)
1465 {
1466  if (camera >= num_cameras) {
1467  width = 0;
1468  close();
1470  "The required camera is not present") );
1471  }
1472 
1473  width = this->_width[camera];
1474  this->width = width;
1475 }
1476 
1493 void vp1394Grabber::getHeight(unsigned int &height)
1494 {
1495  if (camera >= num_cameras) {
1496  height = 0;
1497  close();
1499  "The required camera is not present") );
1500  }
1501 
1502  height = this->_height[camera];
1503  this->height = height;
1504 }
1505 
1514 void
1515 vp1394Grabber::getNumCameras(unsigned int &cameras)
1516 {
1517  if (camera_found == false) {
1518  vpCTRACE << "No camera found..."<< std::endl;
1519  cameras = 0;
1520  }
1521 
1522  cameras = num_cameras;
1523 }
1524 
1525 
1532 void
1534 {
1535 
1536  open();
1537 
1538  // Get the actual camera format, mode and framerate
1539  getFormat(pformat[camera]);
1540  getMode(pmode[camera]);
1541  getFramerate(pframerate[camera]);
1542 
1543  setup();
1544  startIsoTransmission();
1545 
1546  unsigned int w, h;
1547  getWidth( w ) ;
1548  getHeight( h ) ;
1549 
1550  vpDEBUG_TRACE(10, "%d %d", h, w ) ;
1551 
1552  I.resize(h, w) ;
1553 
1554  init = true ;
1555 
1556 }
1557 
1564 void
1566 {
1567 
1568  open();
1569 
1570  // Get the actual camera format, mode and framerate
1571  getFormat(pformat[camera]);
1572  getMode(pmode[camera]);
1573  getFramerate(pframerate[camera]);
1574 
1575  setup();
1576  startIsoTransmission();
1577 
1578  unsigned int w, h;
1579  getWidth( w ) ;
1580  getHeight( h ) ;
1581 
1582  vpDEBUG_TRACE(10, "%d %d", h, w ) ;
1583 
1584  I.resize(h, w) ;
1585 
1586  init = true ;
1587 
1588 }
1589 
1600 void
1602 {
1603 
1604  if (init==false)
1605  {
1606  close();
1608  "Initialization not done") );
1609  }
1610 
1611  int *bitmap = NULL ;
1612  bitmap = dmaCapture();
1613 
1614  unsigned int w, h;
1615  getWidth( w ) ;
1616  getHeight( h ) ;
1617 
1618  if ((I.getWidth() != w)||(I.getHeight() != h))
1619  I.resize(h, w) ;
1620 
1621  int size = I.getHeight()*I.getWidth();
1622  switch (image_format[camera])
1623  {
1624  case MONO:
1625  memcpy(I.bitmap, (unsigned char *) bitmap, size*sizeof(unsigned char));
1626  break;
1627  case YUV411: {
1628  vpImageConvert::YUV411ToGrey( (unsigned char *) bitmap, I.bitmap, size);
1629  break;
1630  }
1631  case YUV422: {
1632  vpImageConvert::YUV422ToGrey( (unsigned char *) bitmap, I.bitmap, size);
1633  break;
1634  }
1635  case RGB: {
1636  vpImageConvert::RGBToGrey((unsigned char *) bitmap, I.bitmap, size);
1637  break;
1638  }
1639  case RGBa: {
1640  vpImageConvert::RGBaToGrey((unsigned char *) bitmap, I.bitmap, size);
1641  break;
1642  }
1643  default:
1645  "Format conversion not implemented. Acquisition failed.") );
1646  break;
1647  };
1648 
1649  dmaDoneWithBuffer();
1650 
1651 }
1652 
1663 void
1665 {
1666 
1667  if (init==false)
1668  {
1669  close();
1671  "Initialization not done") );
1672  }
1673 
1674  int *bitmap = NULL ;
1675  bitmap = dmaCapture();
1676 
1677  unsigned int w, h;
1678  getWidth( w ) ;
1679  getHeight( h ) ;
1680 
1681  if ((I.getWidth() != w)||(I.getHeight() != h))
1682  I.resize(h, w) ;
1683 
1684  int size = I.getHeight()*I.getWidth();
1685  switch (image_format[camera])
1686  {
1687  case MONO:
1688  vpImageConvert::GreyToRGBa((unsigned char *) bitmap,
1689  (unsigned char *) I.bitmap, size);
1690  break;
1691  case YUV411: {
1692  vpImageConvert::YUV411ToRGBa( (unsigned char *) bitmap,
1693  (unsigned char *) I.bitmap, size);
1694  break;
1695  }
1696  case YUV422: {
1697  vpImageConvert::YUV422ToRGBa( (unsigned char *) bitmap,
1698  (unsigned char *) I.bitmap, size);
1699  break;
1700  }
1701  case RGB: {
1702  vpImageConvert::RGBToRGBa((unsigned char *) bitmap,
1703  (unsigned char *) I.bitmap, size);
1704  break;
1705  }
1706  case RGBa: {
1707  memcpy((unsigned char *) I.bitmap, (unsigned char *) bitmap, size);
1708  break;
1709  }
1710  default:
1712  "Format conversion not implemented. Acquisition failed.") );
1713  break;
1714  };
1715 
1716  dmaDoneWithBuffer();
1717 
1718 }
1719 
1720 
1731 void
1732 vp1394Grabber::open()
1733 {
1734  //int num_nodes;
1735  int num_ports = vp1394Grabber::MAX_PORTS;
1736  struct raw1394_portinfo ports[vp1394Grabber::MAX_PORTS];
1737  raw1394handle_t raw_handle;
1738 
1739  if (handles == NULL)
1740  handles = new raw1394handle_t [vp1394Grabber::MAX_CAMERAS];
1741  if (cameras == NULL)
1742  cameras = new dc1394_cameracapture [vp1394Grabber::MAX_CAMERAS];
1743  if (cam_count == NULL)
1744  cam_count = new int [vp1394Grabber::MAX_CAMERAS];
1745  if (pformat == NULL)
1746  pformat = new int [vp1394Grabber::MAX_CAMERAS];
1747  if (pmode == NULL)
1748  pmode = new int [vp1394Grabber::MAX_CAMERAS];
1749  if (pframerate == NULL)
1750  pframerate = new int [vp1394Grabber::MAX_CAMERAS];
1751  if (_width == NULL)
1752  _width = new int [vp1394Grabber::MAX_CAMERAS];
1753  if (_height == NULL)
1754  _height = new int [vp1394Grabber::MAX_CAMERAS];
1755  if (image_format == NULL)
1757 
1758  raw_handle = raw1394_new_handle();
1759 
1760  if (raw_handle==NULL) {
1761  close();
1762  vpERROR_TRACE("Unable to aquire a raw1394 handle\n\n"
1763  "Please check \n"
1764  " - if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded \n"
1765  " - if you have read/write access to /dev/raw1394\n\n");
1767  "Unable to aquire a raw1394 handle") );
1768  }
1769 
1770  num_ports = raw1394_get_port_info(raw_handle, ports, num_ports);
1771  raw1394_destroy_handle(raw_handle);
1772  if (verbose)
1773  printf("number of ports detected: %d\n", num_ports);
1774 
1775  if (num_ports < 1) {
1776  close();
1778  "no ports found") );
1779  }
1780 
1781  //num_nodes = raw1394_get_nodecount(raw_handle);
1782  num_cameras = 0;
1783 
1784  /* get dc1394 handle to each port */
1785  for (int p = 0; p < num_ports; p++) {
1786 
1787  /* get the camera nodes and describe them as we find them */
1788  raw_handle = raw1394_new_handle();
1789  raw1394_set_port( raw_handle, p );
1790 
1791  camera_nodes = NULL;
1792  camera_nodes = dc1394_get_camera_nodes(raw_handle, &cam_count[p], 0);
1793  raw1394_destroy_handle(raw_handle);
1794  if (verbose)
1795  fprintf(stdout, "%d camera(s) on port %d\n", cam_count[p], p);
1796 
1797  for (int i = 0; i < cam_count[p]; i++, num_cameras ++) {
1798  handles[num_cameras] = dc1394_create_handle(p);
1799  if (handles[num_cameras]==NULL) {
1800  close();
1801  vpERROR_TRACE("Unable to aquire a raw1394 handle\n");
1802  vpERROR_TRACE("did you load the drivers?\n");
1804  "Unable to aquire a raw1394 handle.") );
1805  }
1806  cameras[num_cameras].node = camera_nodes[i];
1807 
1808  }
1809  if (cam_count[p])
1810  dc1394_free_camera_nodes(camera_nodes);
1811  }
1812 
1813  if (num_cameras < 1) {
1814  close();
1816  "no cameras found") );
1817  }
1818  vpDEBUG_TRACE(10, "%d cameras detected\n", num_cameras);
1819 
1820  camera_found = true;
1821 
1822  handle_created = true;
1823 
1824  // Get the actual camera format, mode and framerate
1825  getFormat(pformat[camera]);
1826  getMode(pmode[camera]);
1827  getFramerate(pframerate[camera]);
1828 }
1829 
1844 void
1845 vp1394Grabber::setup()
1846 {
1847  unsigned int channel;
1848  unsigned int speed;
1849 
1850  if ( handle_created == true && camera_found == true) {
1851 
1852  for (unsigned int i = 0; i < num_cameras; i++) {
1853  if (verbose) {
1854  dc1394_feature_set features;
1855 
1856  if(dc1394_get_camera_feature_set(handles[i],
1857  cameras[i].node,
1858  &features) != DC1394_SUCCESS) {
1859  close();
1860 
1862  "Unable to get feature set") );
1863  }
1864  else {
1865  dc1394_print_feature_set(&features);
1866  }
1867  }
1868 
1869  // After setting the camera format and mode we update the image size
1870  getImageCharacteristics(pformat[i],
1871  pmode[i],
1872  _width[i],
1873  _height[i],
1874  image_format[i]);
1875 
1876  if (dc1394_get_iso_channel_and_speed(handles[i],
1877  cameras[i].node,
1878  &channel,
1879  &speed) != DC1394_SUCCESS) {
1880  close();
1882  "Unable to get the iso channel number") );
1883  }
1884 
1885  if (pformat[i] == FORMAT_SCALABLE_IMAGE_SIZE) {
1886  if( dc1394_dma_setup_format7_capture(handles[i],
1887  cameras[i].node,
1888  channel,
1889  pmode[i],
1890  speed,
1891  USE_MAX_AVAIL, /*max packet size*/
1892  0, 0, /* left, top */
1893  _width[i],
1894  _height[i],
1897  device_name,
1898  &cameras[i]) != DC1394_SUCCESS) {
1899  close();
1900 
1901  vpERROR_TRACE("Unable to setup camera in format 7 mode 0-\n"
1902  "check line %d of %s to"
1903  "make sure that the video mode,framerate and format are "
1904  "supported by your camera.\n",
1905  __LINE__,__FILE__);
1906 
1908  "Unable to setup camera in format 7 ") );
1909 
1910  }
1911  if (verbose) {
1912  unsigned int qpp; // packet bytes
1913  if (dc1394_query_format7_byte_per_packet(handles[i],
1914  cameras[i].node,
1915  pmode[i],
1916  &qpp) != DC1394_SUCCESS) {
1917  close();
1918 
1920  "Unable to query format7 byte_per_packet ") );
1921  }
1922  //std::cout << "Format 7: byte per packet : " << qpp << std::endl;
1923  }
1924 
1925  } else {
1926 
1927  if (dc1394_dma_setup_capture(handles[i],
1928  cameras[i].node,
1929  channel,
1930  pformat[i],
1931  pmode[i],
1932  speed,
1933  pframerate[i],
1936  device_name,
1937  &cameras[i]) != DC1394_SUCCESS) {
1938  vpERROR_TRACE("Unable to setup camera- check line %d of %s to"
1939  "make sure that the video mode,framerate and format are "
1940  "supported by your camera.\n",
1941  __LINE__,__FILE__);
1942  close();
1943 
1945  "Unable to setup camera ") );
1946  }
1947  }
1948  }
1949  }
1950 }
1951 
1973 void
1974 vp1394Grabber::getImageCharacteristics(int _format, int _mode,
1975  int &width, int &height,
1976  vp1394ImageFormatType &_image_format)
1977 {
1978  switch(_format)
1979  {
1980  case FORMAT_VGA_NONCOMPRESSED:
1981  switch(_mode)
1982  {
1983  case MODE_160x120_YUV444:
1984  width = 160; height = 120;
1985  _image_format = YUV444;
1986  break;
1987  case MODE_320x240_YUV422:
1988  width = 320; height = 240;
1989  _image_format = YUV422;
1990  break;
1991  case MODE_640x480_YUV411:
1992  width = 640; height = 480;
1993  _image_format = YUV411;
1994  break;
1995  case MODE_640x480_YUV422:
1996  width = 640; height = 480;
1997  _image_format = YUV422;
1998  break;
1999  case MODE_640x480_RGB:
2000  width = 640; height = 480;
2001  _image_format = RGB;
2002  break;
2003  case MODE_640x480_MONO:
2004  width = 640; height = 480;
2005  _image_format = MONO;
2006  break;
2007  case MODE_640x480_MONO16:
2008  width = 640; height = 480;
2009  _image_format = MONO;
2010  break;
2011  default:
2012  close();
2013  vpERROR_TRACE("Error: camera image format and camera mode are uncompatible...\n");
2014  vpERROR_TRACE("format: %d and mode: %d\n", _format, _mode);
2016  "Wrong mode for format 0") );
2017  break;
2018  }
2019  break;
2020  case FORMAT_SVGA_NONCOMPRESSED_1:
2021  switch(_mode)
2022  {
2023  case MODE_800x600_YUV422:
2024  width = 800; height = 600;
2025  _image_format = YUV422;
2026  break;
2027  case MODE_800x600_RGB:
2028  width = 800; height = 600;
2029  _image_format = RGB;
2030  break;
2031  case MODE_800x600_MONO:
2032  width = 800; height = 600;
2033  _image_format = MONO;
2034  break;
2035  case MODE_800x600_MONO16:
2036  width = 800; height = 600;
2037  _image_format = MONO16;
2038  break;
2039  case MODE_1024x768_YUV422:
2040  width = 1024; height = 768;
2041  _image_format = YUV422;
2042  break;
2043  case MODE_1024x768_RGB:
2044  width = 1024; height = 768;
2045  _image_format = RGB;
2046  break;
2047  case MODE_1024x768_MONO:
2048  width = 1024; height = 768;
2049  _image_format = MONO;
2050  break;
2051  case MODE_1024x768_MONO16:
2052  width = 1024; height = 768;
2053  _image_format = MONO16;
2054  break;
2055  default:
2056  close();
2057  vpERROR_TRACE("Error: camera image format and camera mode are uncompatible...\n");
2058  vpERROR_TRACE("format: %d and mode: %d\n", _format, _mode);
2060  "Wrong mode for format 1") );
2061  break;
2062  }
2063  break;
2064  case FORMAT_SVGA_NONCOMPRESSED_2:
2065  switch(_mode)
2066  {
2067  case MODE_1280x960_YUV422:
2068  width = 1280; height = 960;
2069  _image_format = YUV422;
2070  break;
2071  case MODE_1280x960_RGB:
2072  width = 1280; height = 960;
2073  _image_format = RGB;
2074  break;
2075  case MODE_1280x960_MONO:
2076  width = 1280; height = 960;
2077  _image_format = MONO;
2078  break;
2079  case MODE_1280x960_MONO16:
2080  width = 1280; height = 960;
2081  _image_format = MONO16;
2082  break;
2083  case MODE_1600x1200_YUV422:
2084  width = 1600; height = 1200;
2085  _image_format = YUV422;
2086  break;
2087  case MODE_1600x1200_RGB:
2088  width = 1600; height = 1200;
2089  _image_format = RGB;
2090  break;
2091  case MODE_1600x1200_MONO:
2092  width = 1600; height = 1200;
2093  _image_format = MONO;
2094  break;
2095  case MODE_1600x1200_MONO16:
2096  width = 1600; height = 1200;
2097  _image_format = MONO16;
2098  break;
2099  default:
2100  close();
2101  vpERROR_TRACE("Error: camera image format and camera mode are uncompatible...\n");
2102  vpERROR_TRACE("format: %d and mode: %d\n", _format, _mode);
2104  "Wrong mode for format 2") );
2105  break;
2106  }
2107  break;
2108  case FORMAT_SCALABLE_IMAGE_SIZE:
2109 #if 1
2110  switch(_mode)
2111  {
2112  case MODE_FORMAT7_0:
2113  width = 656; height = 492;
2114  _image_format = YUV422;
2115  break;
2116 
2117  case MODE_FORMAT7_1:
2118  width = 328; height = 492;
2119  _image_format = MONO;
2120  break;
2121  case MODE_FORMAT7_2:
2122  width = 656; height = 244;
2123  _image_format = MONO;
2124  break;
2125  case MODE_FORMAT7_3:
2126  case MODE_FORMAT7_4:
2127  case MODE_FORMAT7_5:
2128  case MODE_FORMAT7_6:
2129  case MODE_FORMAT7_7:
2130  width = 656; height = 244;
2131  _image_format = MONO;
2132  break;
2133  }
2134 
2135 
2136 #else
2137  // Did not work. Even if subsampling is activated in MODE_FORMAT7_1, image
2138  // max size is the size of the image without considering the subsampling
2139  switch(_mode)
2140  {
2141  case MODE_FORMAT7_0:
2142  // _width = 656; _height = 492;
2143  _image_format = YUV422;
2144  break;
2145 
2146  case MODE_FORMAT7_1:
2147  // _width = 328; _height = 492;
2148  _image_format = MONO;
2149  break;
2150  case MODE_FORMAT7_2:
2151  // _width = 656; _height = 244;
2152  _image_format = MONO;
2153  break;
2154  }
2155 
2156  // In format 7 we query set the image size to the maximal image size
2157  if (dc1394_query_format7_max_image_size(handles[camera],
2158  cameras[camera].node,
2159  _mode,
2160  &width,
2161  &_eight) != DC1394_SUCCESS) {
2162  close();
2163  vpERROR_TRACE("Unable to get maximal image size for format 7\n");
2165  "Unable to get maximal image size for format 7 ") );
2166  }
2167  std::cout << "max width=" << width << " height: " << height << std::endl;
2168 #endif
2169 
2170  break;
2171  default:
2172  close();
2173  vpERROR_TRACE("Error: camera image format and camera mode are uncompatible...\n");
2174  vpERROR_TRACE("format: %d and mode: %d\n", _format, _mode);
2176  "Wrong format") );
2177  break;
2178  }
2179 }
2180 
2181 
2204 int*
2205 vp1394Grabber::dmaCapture(bool waiting)
2206 {
2207 
2208  if (camera >= num_cameras) {
2209  std::cout << "The required camera is not present..."
2210  << std::endl;
2211  return NULL;
2212  }
2213 
2214  if ( handle_created == true && camera_found == true) {
2215  if (waiting) {
2216  if (num_cameras == 1) {
2217  // Only one camera on the bus
2218  if (dc1394_dma_single_capture(&cameras[camera]) != DC1394_SUCCESS) {
2219  close();
2221  "No frame is available...") );
2222  return NULL;
2223  }
2224  }
2225  else {
2226  // More than one camera on the bus.
2227  if (dc1394_dma_multi_capture(cameras, num_cameras) != DC1394_SUCCESS) {
2228  close();
2230  "No frame is available...") );
2231  return NULL;
2232  }
2233  // std::cout << "-";
2234  }
2235  }
2236  else {
2237  if (num_cameras == 1) {
2238  // Only one camera on the bus
2239  if (dc1394_dma_single_capture_poll(&cameras[camera]) != DC1394_SUCCESS) {
2240  close();
2242  "No frame is available...") );
2243  return NULL;
2244  }
2245  }
2246  else {
2247  // More than one camera on the bus.
2248  if (dc1394_dma_multi_capture_poll(cameras, num_cameras)
2249  != DC1394_SUCCESS) {
2250  close();
2252  "No frame is available...") );
2253  return NULL;
2254  }
2255 
2256  }
2257  }
2258  }
2259 
2260  return cameras[camera].capture_buffer;
2261 }
2262 
2279 void
2280 vp1394Grabber::dmaDoneWithBuffer()
2281 {
2282 
2283  if (camera >= num_cameras) {
2284  close();
2285  vpERROR_TRACE("The required camera is not present");
2287  "The required camera is not present") );
2288  }
2289 
2290  if ( handle_created == true && camera_found == true) {
2291  if (dc1394_dma_done_with_buffer(&cameras[camera]) != DC1394_SUCCESS) {
2293  "Can't done the dma") );
2294  }
2295  }
2296 }
2297 
2298 
2299 
2305 void
2307 {
2308  if (iso_transmission_started == true) {
2309 
2310  stopIsoTransmission();
2311 
2312  for (unsigned int i=0; i < num_cameras; i++)
2313  dc1394_dma_unlisten( handles[i], &cameras[i] );
2314  iso_transmission_started = false;
2315  }
2316  if ((camera_found == true) && (dma_started == true)) {
2317  for (unsigned int i=0; i < num_cameras; i++)
2318  dc1394_dma_release_camera( handles[i], &cameras[i]);
2319  camera_found = false;
2320  dma_started = false;
2321  }
2322  if (handle_created == true) {
2323  for (unsigned int i=0; i < num_cameras; i++)
2324  dc1394_destroy_handle(handles[i]);
2325  handle_created = false;
2326  }
2327 
2328  if (handles != NULL) { delete [] handles; handles = NULL; }
2329  if (cameras != NULL) { delete [] cameras; cameras = NULL; }
2330  if (cam_count != NULL) { delete [] cam_count; cam_count = NULL; }
2331  if (pformat != NULL) { delete [] pformat; pformat = NULL; }
2332  if (pmode != NULL) { delete [] pmode; pmode = NULL; }
2333  if (pframerate != NULL) { delete [] pframerate; pframerate = NULL; }
2334  if (_width != NULL) { delete [] _width; _width = NULL; }
2335  if (_height != NULL) { delete [] _height; _height = NULL; }
2336  if (image_format != NULL) { delete [] image_format; image_format = NULL; }
2337 
2338 }
2348 void vp1394Grabber::startIsoTransmission()
2349 {
2350  if ( handle_created == true && camera_found == true) {
2351 
2352  for (unsigned int i = 0; i < num_cameras; i ++) {
2353  if (dc1394_start_iso_transmission(handles[i],
2354  cameras[i].node) !=DC1394_SUCCESS) {
2355  close();
2357  "Unable to start camera iso transmission") );
2358  }
2359  }
2360  iso_transmission_started = true;
2361  }
2362 }
2363 
2373 void vp1394Grabber::stopIsoTransmission()
2374 {
2375 
2376  if (iso_transmission_started == true) {
2377  if (handle_created == true && camera_found == true) {
2378  for (unsigned int i = 0; i < num_cameras; i ++) {
2379  if (dc1394_stop_iso_transmission(handles[i],
2380  cameras[i].node) != DC1394_SUCCESS) {
2381  close();
2383  "Can't stop the camera") );
2384  }
2385 
2386  }
2387  iso_transmission_started = false;
2388  }
2389  }
2390 }
2391 
2392 
2393 #endif
2394 #endif
void setGain(unsigned int gain)
static const char * strModesInFormat2[NUM_FORMAT2_MODES]
#define vpDEBUG_TRACE
Definition: vpDebug.h:454
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int size)
void getMode(int &mode)
unsigned int getWidth() const
Definition: vpImage.h:159
void getFormat(int &format)
#define vpERROR_TRACE
Definition: vpDebug.h:379
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Provide simple list management.
Definition: vpList.h:112
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
static const char * strModesInFormat7[NUM_MODE_FORMAT7]
void getShutter(unsigned int &min_shutter, unsigned int &shutter, unsigned int &max_shutter)
#define vpCERROR
Definition: vpDebug.h:354
static const char * strModesInFormat0[NUM_FORMAT0_MODES]
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:535
static const int MAX_PORTS
void getFramerate(int &framerate)
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int size)
vp_deprecated vp1394Grabber()
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
void kill()
Destroy the list.
Definition: vpList.h:694
static const char * strModesInFormat6[NUM_FORMAT6_MODES]
Class for firewire ieee1394 video devices using libdc1394-1.x api.
int getModeSupported(int format, vpList< int > &modes)
void open(vpImage< unsigned char > &I)
static const char * strColorsInFormat7[NUM_COLOR_FORMAT7]
static const int DROP_FRAMES
Error that can be emited by the vpFrameGrabber class and its derivates.
void setFramerate(int framerate)
int getFormatSupported(vpList< int > &formats)
#define vpCTRACE
Definition: vpDebug.h:327
int convertMode(std::string mode)
void getCamera(unsigned int &camera)
static void YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
void getGain(unsigned int &min_gain, unsigned int &gain, unsigned int &max_gain)
static const char * strFramerates[NUM_FRAMERATES]
unsigned int getWidth() const
Return the number of columns in the image.
unsigned int height
Number of rows in the image.
static const int MAX_CAMERAS
int getFramerateSupported(int format, int mode, vpList< int > &framerates)
void getNumCameras(unsigned int &cameras)
void addRight(const type &el)
add a new element in the list, at the right of the current one
Definition: vpList.h:480
static const char * strModesInFormat1[NUM_FORMAT1_MODES]
static const char * strFormats[NUM_FORMATS]
bool init
Set to true if the frame grabber has been initialized.
void setMode(int mode)
int convertFormat(std::string format)
static void YUV411ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
virtual ~vp1394Grabber()
unsigned int getHeight() const
Definition: vpImage.h:150
int convertFramerate(std::string framerate)
static void YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
void acquire(vpImage< unsigned char > &I)
unsigned int width
Number of columns in the image.
static void RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int size)
unsigned int getHeight() const
Return the number of rows in the image.
void setCamera(unsigned int camera)
static const int NUM_BUFFERS
void setFormat(int format)
void setShutter(unsigned int shutter)