iCub-main
Loading...
Searching...
No Matches
FirewireCameraDC1394-DR2_2.cpp
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3/*
4 * Copyright (C) 2007 RobotCub Consortium
5 * Author: Alessandro Scalzo alessandro.scalzo@iit.it
6 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7 *
8 */
9
10// L I N N U U X X
11// L I NN N U U X X
12// L I N N N U U X
13// L I N NN U U X X
14// LLLLL I N N UUU X X
15
16#include <stdlib.h>
17#include <string>
19#include <arpa/inet.h>
20#include <yarp/os/Log.h>
21#include <yarp/os/LogStream.h>
22
23#include <sched.h>
24#include <unistd.h>
25
26
27#define POINTGREY_REGISTER_TIMESTAMP 0x12F8
28
29static dc1394error_t set_embedded_timestamp(dc1394camera_t *camera,
30 bool enable) {
31 uint32_t value;
32 dc1394error_t err;
33
34 err = dc1394_get_control_register(camera,
36 &value);
37 DC1394_ERR_RTN(err, "No embedded timestamp capability");
38
39 bool current = (value & 0x1U)!=0;
40
41 if(enable==current) {
42 return DC1394_SUCCESS;
43 }
44 value ^= 0x1;
45 err = dc1394_set_control_register(camera,
47 value);
48 DC1394_ERR_RTN(err, "Cannot configure embedded timestamp");
49 err = dc1394_get_control_register(camera,
51 &value);
52 DC1394_ERR_RTN(err, "Configuration for embedded timestamp won't stick");
53
54 current = value & 0x1;
55
56 return (enable==current)?DC1394_SUCCESS: DC1394_FAILURE;
57}
58
59CFWCamera_DR2_2::CFWCamera_DR2_2(bool raw): mRawDriver(raw),
60 m_pCamera(NULL),
61 m_pCameraList(NULL),
62 m_dc1394_handle(NULL),
63 m_LastSecond(0),
64 m_SecondOffset(0)
65{
66 configFx = false;
67 configFy = false;
68 configPPx = false;
69 configPPy =false;
70 configRet = false;
71 configDistM = false;
72 configIntrins = false;
73 m_ConvFrame.image=NULL;
74}
75
79
80const yarp::os::Stamp& CFWCamera_DR2_2::getLastInputStamp() { return m_Stamp; }
81
82double CFWCamera_DR2_2::bytesPerPixel(dc1394color_coding_t pixelFormat)
83{
84 switch (pixelFormat)
85 {
86 case DC1394_COLOR_CODING_MONO8: return 1.0;
87 case DC1394_COLOR_CODING_MONO16: return 2.0;
88 case DC1394_COLOR_CODING_YUV411: return 1.5;
89 case DC1394_COLOR_CODING_YUV422: return 2.0;
90 case DC1394_COLOR_CODING_YUV444: return 3.0;
91 case DC1394_COLOR_CODING_RGB8: return 3.0;
92 case DC1394_COLOR_CODING_RAW8: return 1.0;
93 case DC1394_COLOR_CODING_RAW16: return 2.0;
94 }
95
96 return 0.0;
97}
98
99int CFWCamera_DR2_2::maxFPS(dc1394video_mode_t mode,dc1394color_coding_t pixelFormat)
100{
101 if (mHires)
102 {
103 switch (mode)
104 {
105 case DC1394_VIDEO_MODE_FORMAT7_0:
106 switch (pixelFormat)
107 {
108 case DC1394_COLOR_CODING_MONO8: return 31;
109 case DC1394_COLOR_CODING_RAW8: return 31;
110 case DC1394_COLOR_CODING_YUV411: return 26;
111
112 case DC1394_COLOR_CODING_MONO16: return 15;
113 case DC1394_COLOR_CODING_RAW16: return 15;
114 case DC1394_COLOR_CODING_YUV422: return 15;
115
116 case DC1394_COLOR_CODING_YUV444: return 11;
117 case DC1394_COLOR_CODING_RGB8: return 11;
118 }
119 return 0;
120 case DC1394_VIDEO_MODE_FORMAT7_1:
121 switch (pixelFormat)
122 {
123 case DC1394_COLOR_CODING_MONO8: return 54;
124 case DC1394_COLOR_CODING_MONO16: return 54;
125
126 case DC1394_COLOR_CODING_YUV411: return 31;
127 case DC1394_COLOR_CODING_YUV422: return 31;
128 case DC1394_COLOR_CODING_YUV444: return 31;
129 case DC1394_COLOR_CODING_RGB8: return 31;
130 }
131 return 0;
132 case DC1394_VIDEO_MODE_FORMAT7_2:
133 switch (pixelFormat)
134 {
135 case DC1394_COLOR_CODING_MONO8: return 31;
136 case DC1394_COLOR_CODING_MONO16: return 26;
137 case DC1394_COLOR_CODING_YUV411: return 31;
138 case DC1394_COLOR_CODING_YUV422: return 26;
139 case DC1394_COLOR_CODING_YUV444: return 17;
140 case DC1394_COLOR_CODING_RGB8: return 17;
141 }
142 return 0;
143 }
144 }
145 else // lores
146 {
147 switch (mode)
148 {
149 case DC1394_VIDEO_MODE_FORMAT7_0:
150 switch (pixelFormat)
151 {
152 case DC1394_COLOR_CODING_MONO8:
153 case DC1394_COLOR_CODING_RAW8:
154 case DC1394_COLOR_CODING_YUV411: return 59;
155
156 case DC1394_COLOR_CODING_MONO16:
157 case DC1394_COLOR_CODING_RAW16:
158 case DC1394_COLOR_CODING_YUV422: return 47;
159
160 case DC1394_COLOR_CODING_YUV444:
161 case DC1394_COLOR_CODING_RGB8: return 31;
162 }
163 return 0;
164 case DC1394_VIDEO_MODE_FORMAT7_1:
165 switch (pixelFormat)
166 {
167 case DC1394_COLOR_CODING_MONO8:
168 case DC1394_COLOR_CODING_MONO16: return 100;
169
170 case DC1394_COLOR_CODING_YUV411:
171 case DC1394_COLOR_CODING_YUV422:
172 case DC1394_COLOR_CODING_YUV444:
173 case DC1394_COLOR_CODING_RGB8: return 59;
174 }
175 return 0;
176 case DC1394_VIDEO_MODE_FORMAT7_2:
177 switch (pixelFormat)
178 {
179 case DC1394_COLOR_CODING_MONO8:
180 case DC1394_COLOR_CODING_MONO16:
181 case DC1394_COLOR_CODING_YUV411:
182 case DC1394_COLOR_CODING_YUV422:
183 case DC1394_COLOR_CODING_YUV444:
184 case DC1394_COLOR_CODING_RGB8: return 59;
185 }
186 return 0;
187 }
188 }
189
190 return 0;
191}
192
193bool CFWCamera_DR2_2::Create(yarp::os::Searchable& config)
194{
195 //bool bDR2=config.check("DR2");
196
197 //bool bDR2=true;
198
199 //IVisualParams
200
201 yarp::os::Value* retM;
202 retM=yarp::os::Value::makeList("1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0");
203 configFx=config.check("horizontalFov");
204 configFy=config.check("verticalFov");
205 configPPx=config.check("principalPointX");
206 configPPy=config.check("principalPointY");
207 configRet=config.check("rectificationMatrix");
208 configDistM=config.check("distortionModel");
209 yarp::os::Bottle bt;
210 bt=config.findGroup("cameraDistortionModelGroup");
211 if(!bt.isNull())
212 {
213 if(bt.find("name").isNull() || bt.find("k1").isNull()
214 || bt.find("k2").isNull() || bt.find("k3").isNull()
215 || bt.find("t1").isNull() || bt.find("t2").isNull())
216 {
217 yError()<<"usbCamera: group cameraDistortionModelGroup incomplete, "
218 "fields k1, k2, k3, t1, t2, name are required when using cameraDistortionModelGroup";
219 configIntrins=false;
220 return false;
221 }
222 else
223 configIntrins=true;
224 }
225 else
226 configIntrins=false;
227 horizontalFov=config.check("horizontalFov",yarp::os::Value(0.0),
228 "desired horizontal fov of test image").asFloat64();
229 verticalFov=config.check("verticalFov",yarp::os::Value(0.0),
230 "desired vertical fov of test image").asFloat64();
231 if(config.check("mirror"))
232 {
233 if(!setRgbMirroring(config.check("mirror",
234 yarp::os::Value(false),
235 "mirroring disabled by default").asBool())){
236 yError("usbCamera: cannot set mirroring option");
237 return false;
238 }
239 }
240
241 intrinsic.put("focalLengthX",config.check("focalLengthX",yarp::os::Value(0.0),"Horizontal component of the focal lenght").asFloat64());
242 intrinsic.put("focalLengthY",config.check("focalLengthY",yarp::os::Value(0.0),"Vertical component of the focal lenght").asFloat64());
243 intrinsic.put("principalPointX",config.check("principalPointX",yarp::os::Value(0.0),"X coordinate of the principal point").asFloat64());
244 intrinsic.put("principalPointY",config.check("principalPointY",yarp::os::Value(0.0),"Y coordinate of the principal point").asFloat64());
245 intrinsic.put("rectificationMatrix",config.check("rectificationMatrix",*retM,"Matrix that describes the lens' distortion"));
246 intrinsic.put("distortionModel",config.check("distortionModel",yarp::os::Value(""),"Reference to group of parameters describing the distortion model").asString());
247 if(bt.isNull())
248 {
249 intrinsic.put("name","");
250 intrinsic.put("k1",0.0);
251 intrinsic.put("k2",0.0);
252 intrinsic.put("k3",0.0);
253 intrinsic.put("t1",0.0);
254 intrinsic.put("t2",0.0);
255 }
256 else{
257 intrinsic.put("name",bt.check("name",yarp::os::Value(""),"Name of the distortion model, see notes").asString());
258 intrinsic.put("k1",bt.check("k1",yarp::os::Value(0.0),"Radial distortion coefficient of the lens").asFloat64());
259 intrinsic.put("k2",bt.check("k2",yarp::os::Value(0.0),"Radial distortion coefficient of the lens").asFloat64());
260 intrinsic.put("k3",bt.check("k3",yarp::os::Value(0.0),"Radial distortion coefficient of the lens").asFloat64());
261 intrinsic.put("t1",bt.check("t1",yarp::os::Value(0.0),"Tangential distortion of the lens").asFloat64());
262 intrinsic.put("t2",bt.check("t2",yarp::os::Value(0.0),"Tangential distortion of the lens").asFloat64());
263 }
264 delete retM;
265
266 // check for CPU affinity
267 if(config.check("cpu_affinity")) {
268 cpu_set_t set;
269 CPU_ZERO(&set);
270 int affinity = config.find("cpu_affinity").asInt32();
271 CPU_SET(affinity, &set);
272 if (sched_setaffinity(getpid(), sizeof(set), &set) == -1) {
273 yWarning("failed to set the CPU affinity\n");
274 }
275 }
276
277 // check for real-time priority
278 if(config.check("rt_priority")) {
279 struct sched_param sch_param;
280 sch_param.__sched_priority = config.find("rt_priority").asInt32();
281 if( sched_setscheduler(0, SCHED_FIFO, &sch_param) != 0 ) {
282 yWarning("failed to set the real-time priority\n");
283 }
284 }
285
286 int size_x=checkInt(config,"width");
287 int size_y=checkInt(config,"height");
288 int off_x=checkInt(config,"xoff");
289 int off_y=checkInt(config,"yoff");
290 int format=checkInt(config,"video_type");
291
292 if (!config.check("use_network_time"))
293 {
294 mUseHardwareTimestamp = false;
295 }
296 else
297 {
298 mUseHardwareTimestamp = !checkInt(config,"use_network_time");
299 }
300
301 unsigned int idCamera=0;
302
303 m_Framerate=checkInt(config,"framerate");
304
305 yDebug("Format = %d\n",format);
306
307 m_XDim=m_YDim=0;
309
310 m_bCameraOn=false;
311 m_pCamera=NULL;
312 m_pCameraList=NULL;
313 m_dc1394_handle=NULL;
316 m_ConvFrame.image=new unsigned char[1032*776*3*2];
317 m_ConvFrame_tmp.image=new unsigned char[1032*776*2];
318
319 if (!(m_dc1394_handle=dc1394_new()))
320 {
321 yError("failed to open Firewire Bus Manager\n");
322 yError("LINE: %d\n",__LINE__);
323 return false;
324 }
325
326 dc1394error_t error;
327
328 error=dc1394_camera_enumerate(m_dc1394_handle,&m_pCameraList);
329 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
330
332
333 if (!m_nNumCameras)
334 {
335 yError("no active cameras\n");
336 yError("LINE: %d\n",__LINE__);
337 return false;
338 }
339
340 if (config.check("guid"))
341 {
342 std::string sguid=config.find("guid").asString();
343
344 uint64_t guid=strtoull(sguid.c_str(),NULL,16);
345
346 for (idCamera=0; idCamera<m_nNumCameras; ++idCamera)
347 {
348 if (guid==m_pCameraList->ids[idCamera].guid)
349 {
350 break;
351 }
352 }
353
354 if (idCamera==m_nNumCameras)
355 {
356 yError("GUID=%s camera not found\n",sguid.c_str());
357 yError("LINE: %d\n",__LINE__);
358 return false;
359 }
360 }
361 else if (config.check("d"))
362 {
363 yWarning("--d <unit_number> parameter is deprecated, use --guid <64_bit_global_unique_identifier> instead\n");
364 idCamera=config.find("d").asInt32();
365 }
366
367 if (idCamera<0 || idCamera>=m_nNumCameras)
368 {
369 yError("invalid camera number\n");
370 yError("LINE: %d\n",__LINE__);
371 return false;
372 }
373
374 if (!(m_pCamera=dc1394_camera_new(m_dc1394_handle,m_pCameraList->ids[idCamera].guid)))
375 {
376 yError("can't create camera\n");
377 yError("LINE: %d\n",__LINE__);
378 return false;
379 }
380
381 error=dc1394_camera_reset(m_pCamera);
382 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
383
384 uint32_t channel_in_use=0;
385 dc1394_video_get_iso_channel(m_pCamera,&channel_in_use);
386 dc1394_video_set_iso_channel(m_pCamera,idCamera);
387
388 /*
389 if (channel_in_use != 0)
390 {
391 dc1394_iso_release_channel(m_pCamera,idCamera);
392 const uint64_t ISO_CHANNEL_MASK=idCamera;
393 int allocated_channel;
394 dc1394_iso_allocate_channel(m_pCamera,ISO_CHANNEL_MASK,&allocated_channel);
395 dc1394_video_set_iso_channel(m_pCamera,idCamera);
396 dc1394_iso_release_channel(m_pCamera,channel_in_use);
397 }
398 */
399
400 // if previous instance crashed we need to clean up
401 // allocated bandwidth -- Added Lorenzo Natale, 9/2/2010.
402#ifdef _ENABLE_LEGACY_STACK_
403 // ifdeffed by Alberto Cardellino on 08/01/2014 in
404 // order to enable compatibility with new firewire stack into kernel
405 // and avoid recompiling the kernel itself with old legacy support.
406 // Pay attention to see if the cleanup problem shows up again
407 const int BANDWIDTH_MAX=0x7FFFFFFF;
408 error=dc1394_iso_release_bandwidth(m_pCamera, BANDWIDTH_MAX);
409 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
410#endif
411
412 dc1394speed_t isoSpeed;
413 error=dc1394_video_get_iso_speed(m_pCamera,&isoSpeed);
414 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
415
416 dc1394_video_set_operation_mode(m_pCamera,DC1394_OPERATION_MODE_1394B);
417 //if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
418
419 error=dc1394_video_set_iso_speed(m_pCamera,DC1394_ISO_SPEED_400);
420 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
421
422 error=dc1394_camera_print_info(m_pCamera,stdout);
423 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
424
425 // CONFIGURE
426
427 //error=m_pCamera->RestoreFromMemoryChannel(0);
428 //if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
429
430 mHires=(strcmp("Dragonfly2 DR2-08S2C-EX",m_pCamera->model)==0);
431
432 if (mHires) printf("Hires camera found\n");
433
434// formats
435/*
436#define DR_UNINIT 0
437#define DR_RGB_320x240 1
438#define DR_RGB_640x480 2
439#define DR_BAYER_640x480 3
440#define DR_BAYER_RAW16_640x480 4
441#define DR_YUV422_640x480 5
442
443#define DR_RGB_512x384 6
444
445#define DR_RGB_800x600 7
446#define DR_YUV_800x600 8
447
448#define DR_RGB_1024x768 8
449#define DR_YUV_1024x768 9
450#define DR_BAYER_1024x768 10
451*/
452
453 if (mHires)
454 {
455 if (!format) format=DR_BAYER_1024x768;
456
457 if (mRawDriver) format=DR_BAYER_1024x768;
458
459 switch (format)
460 {
461 case DR_UNINIT:
462 break;
463
464 case DR_RGB_512x384:
465 if (!size_x) { size_x=512; }
466 if (!size_y) { size_y=384; }
467 SetF7(DC1394_VIDEO_MODE_FORMAT7_1,size_x,size_y,DC1394_COLOR_CODING_RGB8,44,off_x,off_y);
468 break;
469
470 case DR_RGB_640x480:
471 SetVideoMode(DC1394_VIDEO_MODE_640x480_RGB8);
472 break;
473
474 case DR_YUV_640x480:
475 SetVideoMode(DC1394_VIDEO_MODE_640x480_YUV422);
476 break;
477
478 case DR_RGB_800x600:
479 SetVideoMode(DC1394_VIDEO_MODE_800x600_RGB8);
480 break;
481
482 case DR_YUV_800x600:
483 SetVideoMode(DC1394_VIDEO_MODE_800x600_YUV422);
484 break;
485
486 case DR_RGB_1024x768:
487 if (!size_x) { size_x=1024; }
488 if (!size_y) { size_y=768; }
489 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_RGB8,44,off_x,off_y);
490 break;
491
492 case DR_YUV_1024x768:
493 if (!size_x) { size_x=1024; }
494 if (!size_y) { size_y=768; }
495 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_YUV422,44,off_x,off_y);
496 break;
497
499 if (!size_x) { size_x=1024; }
500 if (!size_y) { size_y=768; }
501 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_RAW8,44,off_x,off_y);
502 break;
503
504 case DR_RGB_320x240:
505 SetVideoMode(DC1394_VIDEO_MODE_320x240_YUV422);
506 break;
507
508 default:
509 yError("Unsupported video format, camera configuration will be used.\n");
510 }
511 }
512 else // lores
513 {
514 if (!format) format=DR_BAYER_640x480;
515
516 if (mRawDriver) format=DR_BAYER_640x480;
517
518 switch (format)
519 {
520 case DR_UNINIT:
521 break;
522
523 case DR_RGB_320x240:
524 if (!size_x) { size_x=320; }
525 if (!size_y) { size_y=240; }
526 SetF7(DC1394_VIDEO_MODE_FORMAT7_1,size_x,size_y,DC1394_COLOR_CODING_RGB8,44,off_x,off_y);
527 break;
528
529 case DR_RGB_640x480:
530 if (!size_x) { size_x=640; }
531 if (!size_y) { size_y=480; }
532 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_RGB8,44,off_x,off_y);
533 break;
534
535 case DR_BAYER_640x480:
536 if (!size_x) { size_x=640; }
537 if (!size_y) { size_y=480; }
538 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_RAW8,44,off_x,off_y);
539 break;
540
542 if (!size_x) { size_x=640; }
543 if (!size_y) { size_y=480; }
544 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_RAW16,44,off_x,off_y);
545 break;
546
547 case DR_YUV_640x480:
548 if (!size_x) { size_x=640; }
549 if (!size_y) { size_y=480; }
550 SetF7(DC1394_VIDEO_MODE_FORMAT7_0,size_x,size_y,DC1394_COLOR_CODING_YUV422,44,off_x,off_y);
551 break;
552
553 default:
554 yError("Unsupported video format, camera configuration will be used.\n");
555 }
556 }
557
558 for (int f=DC1394_FEATURE_MIN; f<=DC1394_FEATURE_MAX; ++f)
559 {
560 dc1394bool_t bPresent;
561 error=dc1394_feature_is_present(m_pCamera,(dc1394feature_t)f,&bPresent);
562
563 if (error==DC1394_SUCCESS)
564 {
565 if (bPresent)
566 {
567 dc1394_feature_get_boundaries(m_pCamera,(dc1394feature_t)f,&m_iMin[f-DC1394_FEATURE_MIN],&m_iMax[f-DC1394_FEATURE_MIN]);
568
569 dc1394bool_t bSwitch;
570 dc1394_feature_is_switchable(m_pCamera,(dc1394feature_t)f,&bSwitch);
571
572 if (bSwitch)
573 {
574 dc1394switch_t turnOn=(dc1394switch_t)(f!=DC1394_FEATURE_EXPOSURE && f!=DC1394_FEATURE_IRIS && f<DC1394_FEATURE_TEMPERATURE);
575 dc1394_feature_set_power(m_pCamera,(dc1394feature_t)f,turnOn);
576 }
577 dc1394_feature_set_mode(m_pCamera,(dc1394feature_t)f,DC1394_FEATURE_MODE_MANUAL);
578 dc1394_feature_set_absolute_control(m_pCamera,(dc1394feature_t)f,DC1394_OFF);
579 }
580 else
581 {
582 yInfo("Feature %d not supported by this camera model.\n", f);
583 }
584 }
585 else
586 {
587 yError("Feature %d error %d\n",f,error);
588 }
589 }
590
591 error=dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT);
592 if (error!=DC1394_SUCCESS)
593 {
594 yError("%d can't setup capture\n",error);
595 dc1394_camera_free(m_pCamera);
596 m_pCamera=NULL;
597 return false;
598 }
599
600 error=dc1394_video_set_transmission(m_pCamera,DC1394_ON);
601 if (error!=DC1394_SUCCESS)
602 {
603 yError("%d can't start transmission\n",error);
604 dc1394_camera_free(m_pCamera);
605 m_pCamera=NULL;
606 return false;
607 }
608
609 setBroadcastDC1394(false);
610
611 m_bCameraOn=true;
612
613 // parameters
614
615 m_GainSaveModeAuto=DC1394_FEATURE_MODE_MANUAL;
616 m_ShutterSaveModeAuto=DC1394_FEATURE_MODE_MANUAL;
617
618 setBrightness(checkDouble(config,"brightness"));
619 setExposure(checkDouble(config,"exposure"));
620 setSharpness(checkDouble(config,"sharpness"));
621 yarp::os::Bottle& white_balance=config.findGroup("white_balance");
622 if (!white_balance.isNull())
623 {
624 setWhiteBalance(white_balance.get(2).asFloat64(),white_balance.get(1).asFloat64());
625 }
626 setHue(checkDouble(config,"hue"));
627 setSaturation(checkDouble(config,"saturation"));
628 setGamma(checkDouble(config,"gamma"));
629 setShutter(checkDouble(config,"shutter"));
630 setGain(checkDouble(config,"gain"));
631 setIris(checkDouble(config,"iris"));
632
633 dc1394_feature_get_value(m_pCamera,DC1394_FEATURE_SHUTTER,&m_ShutterSaveValue);
634 dc1394_feature_get_value(m_pCamera,DC1394_FEATURE_GAIN,&m_GainSaveValue);
635
638 }
639
640 return true;
641}
642
644{
645 if (m_pCamera)
646 {
647 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
648 dc1394_capture_stop(m_pCamera);
649 dc1394_iso_release_all(m_pCamera);
650 dc1394_camera_free(m_pCamera);
651 }
652 m_pCamera=NULL;
653
654 if (m_pCameraList) dc1394_camera_free_list(m_pCameraList);
655 m_pCameraList=NULL;
656
657 if (m_dc1394_handle) dc1394_free(m_dc1394_handle);
658 m_dc1394_handle=NULL;
659
660 if (m_ConvFrame.image) delete [] m_ConvFrame.image;
661 m_ConvFrame.image=NULL;
662}
663
664bool CFWCamera_DR2_2::CaptureImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image)
665{
666 return Capture(&image);
667}
668
669bool CFWCamera_DR2_2::CaptureImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image)
670{
671 return Capture(&image);
672}
673
674bool CFWCamera_DR2_2::CaptureRgb(unsigned char* pBuffer)
675{
676 return Capture(0,pBuffer);
677}
678
679bool CFWCamera_DR2_2::CaptureRaw(unsigned char* pBuffer)
680{
681 return Capture(0,pBuffer,true);
682}
683
684bool CFWCamera_DR2_2::SetVideoMode(dc1394video_mode_t videoMode)
685{
686 if (!m_pCamera) return false;
687
688 if (mRawDriver) return false;
689
690 int xdim,ydim,buffDim;
691 dc1394framerate_t maxFramerate;
692
693 // calculate raw image size at given video mode
694 if (mHires)
695 {
696 switch (videoMode)
697 {
698 case DC1394_VIDEO_MODE_160x120_YUV444:
699 xdim=160;
700 ydim=120;
701 buffDim=xdim*ydim*3;
702 maxFramerate=DC1394_FRAMERATE_30;
703 break;
704 case DC1394_VIDEO_MODE_320x240_YUV422:
705 xdim=320;
706 ydim=240;
707 buffDim=xdim*ydim*2;
708 maxFramerate=DC1394_FRAMERATE_30;
709 break;
710 case DC1394_VIDEO_MODE_640x480_YUV411:
711 xdim=640;
712 ydim=480;
713 buffDim=(xdim*ydim*3)/2;
714 maxFramerate=DC1394_FRAMERATE_30;
715 break;
716 case DC1394_VIDEO_MODE_640x480_YUV422:
717 xdim=640;
718 ydim=480;
719 buffDim=xdim*ydim*2;
720 maxFramerate=DC1394_FRAMERATE_30;
721 break;
722 case DC1394_VIDEO_MODE_640x480_RGB8:
723 xdim=640;
724 ydim=480;
725 buffDim=xdim*ydim*3;
726 maxFramerate=DC1394_FRAMERATE_30;
727 break;
728 case DC1394_VIDEO_MODE_640x480_MONO8:
729 xdim=640;
730 ydim=480;
731 buffDim=xdim*ydim;
732 maxFramerate=DC1394_FRAMERATE_30;
733 break;
734 case DC1394_VIDEO_MODE_640x480_MONO16:
735 xdim=640;
736 ydim=480;
737 buffDim=xdim*ydim*2;
738 maxFramerate=DC1394_FRAMERATE_30;
739 break;
740
741 case DC1394_VIDEO_MODE_800x600_YUV422:
742 xdim=800;
743 ydim=600;
744 buffDim=xdim*ydim*2;
745 maxFramerate=DC1394_FRAMERATE_30;
746 break;
747 case DC1394_VIDEO_MODE_800x600_RGB8:
748 xdim=800;
749 ydim=600;
750 buffDim=xdim*ydim*3;
751 maxFramerate=DC1394_FRAMERATE_15;
752 break;
753 case DC1394_VIDEO_MODE_800x600_MONO8:
754 xdim=800;
755 ydim=600;
756 buffDim=xdim*ydim;
757 maxFramerate=DC1394_FRAMERATE_30;
758 break;
759 case DC1394_VIDEO_MODE_800x600_MONO16:
760 xdim=800;
761 ydim=600;
762 buffDim=xdim*ydim*2;
763 maxFramerate=DC1394_FRAMERATE_30;
764 break;
765
766 case DC1394_VIDEO_MODE_1024x768_YUV422:
767 xdim=1024;
768 ydim=768;
769 buffDim=xdim*ydim*2;
770 maxFramerate=DC1394_FRAMERATE_15;
771 break;
772 case DC1394_VIDEO_MODE_1024x768_RGB8:
773 xdim=1024;
774 ydim=768;
775 buffDim=xdim*ydim*3;
776 maxFramerate=DC1394_FRAMERATE_7_5;
777 break;
778 case DC1394_VIDEO_MODE_1024x768_MONO8:
779 xdim=1024;
780 ydim=768;
781 buffDim=xdim*ydim;
782 maxFramerate=DC1394_FRAMERATE_30;
783 break;
784 case DC1394_VIDEO_MODE_1024x768_MONO16:
785 xdim=1024;
786 ydim=768;
787 buffDim=xdim*ydim*2;
788 maxFramerate=DC1394_FRAMERATE_15;
789 break;
790 /*
791 case DC1394_VIDEO_MODE_FORMAT7_0:
792 xdim=1024;
793 ydim=768;
794 buffDim=xdim*ydim*3;
795 maxFramerate=DC1394_FRAMERATE_;
796 break;
797 */
798 default: return false;
799 }
800 }
801 else
802 {
803 switch (videoMode)
804 {
805 case DC1394_VIDEO_MODE_160x120_YUV444:
806 xdim=160;
807 ydim=120;
808 buffDim=xdim*ydim*3;
809 maxFramerate=DC1394_FRAMERATE_60;
810 break;
811 case DC1394_VIDEO_MODE_320x240_YUV422:
812 xdim=320;
813 ydim=240;
814 buffDim=xdim*ydim*2;
815 maxFramerate=DC1394_FRAMERATE_60;
816 break;
817 case DC1394_VIDEO_MODE_640x480_YUV411:
818 xdim=640;
819 ydim=480;
820 buffDim=(xdim*ydim*3)/2;
821 maxFramerate=DC1394_FRAMERATE_60;
822 break;
823 case DC1394_VIDEO_MODE_640x480_YUV422:
824 xdim=640;
825 ydim=480;
826 buffDim=xdim*ydim*2;
827 maxFramerate=DC1394_FRAMERATE_30;
828 break;
829 case DC1394_VIDEO_MODE_640x480_RGB8:
830 xdim=640;
831 ydim=480;
832 buffDim=xdim*ydim*3;
833 maxFramerate=DC1394_FRAMERATE_30;
834 break;
835 case DC1394_VIDEO_MODE_640x480_MONO8:
836 xdim=640;
837 ydim=480;
838 buffDim=xdim*ydim;
839 maxFramerate=DC1394_FRAMERATE_30;
840 break;
841 case DC1394_VIDEO_MODE_640x480_MONO16:
842 xdim=640;
843 ydim=480;
844 buffDim=xdim*ydim*2;
845 maxFramerate=DC1394_FRAMERATE_60;
846 break;
847 /*
848 case DC1394_VIDEO_MODE_FORMAT7_0:
849 xdim=640;
850 ydim=480;
851 buffDim=xdim*ydim*3;
852 maxFramerate=DC1394_FRAMERATE_60;
853 break;
854 */
855 default: return false;
856 }
857 }
858
859 dc1394speed_t isoSpeed;
860 dc1394error_t error;
861 error=dc1394_video_get_iso_speed(m_pCamera,&isoSpeed);
862 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
863
864 // get ISO bandwidth
865 int busSpeed=10000000<<(isoSpeed-DC1394_ISO_SPEED_MIN);
866
867 // calculate maximum allowed framerate at given image format
868 static const double twoCams=0.5; // only half bandwith available with two cams
869 double fpsMax=twoCams*double(busSpeed)/double(buffDim);
870 printf("fpsMax = %f\n",fpsMax);
871
872 dc1394framerate_t framerate;
873
874 if (m_Framerate)
875 {
876 if (m_Framerate<(int)fpsMax)
877 {
878 fpsMax=double(m_Framerate);
879 }
880 else
881 {
882 yWarning("framerate %d is too high, it will be set to the maximum available\n",m_Framerate);
883 }
884
885 m_Framerate=0;
886 }
887
888 // choose framerate according to maximum allowed
889 if (fpsMax<1.785){ return false; }
890 else if (fpsMax<3.75) { framerate=DC1394_FRAMERATE_1_875; }
891 else if (fpsMax<7.5) { framerate=DC1394_FRAMERATE_3_75; }
892 else if (fpsMax<15.0) { framerate=DC1394_FRAMERATE_7_5; }
893 else if (fpsMax<30.0) { framerate=DC1394_FRAMERATE_15; }
894 else if (fpsMax<60.0) { framerate=DC1394_FRAMERATE_30; }
895 else if (fpsMax<120.0){ framerate=DC1394_FRAMERATE_60; }
896 else if (fpsMax<120.0){ framerate=DC1394_FRAMERATE_60; }
897 else if (fpsMax<240.0){ framerate=DC1394_FRAMERATE_120; }
898 else { framerate=DC1394_FRAMERATE_240; }
899
900 if (framerate>maxFramerate)
901 {
902 framerate=maxFramerate;
903 }
904
905 yDebug("Framerate = %f\n",1.875*double(1<<(framerate-DC1394_FRAMERATE_MIN)));
906
907 error=dc1394_video_set_mode(m_pCamera,videoMode);
908 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
909
910 m_XDim=xdim;
911 m_YDim=ydim;
912 m_RawBufferSize=buffDim;
913
914 error=dc1394_video_set_framerate(m_pCamera,framerate);
915 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
916
917 return true;
918}
919
920#define SKIP 0x80000000
921bool CFWCamera_DR2_2::SetF7(int newVideoMode,int newXdim,int newYdim,int newColorCoding,int newBandPercent,int x0,int y0)
922{
923 if (!m_pCamera) return false;
924
925 if (mRawDriver)
926 {
927 if (newVideoMode!=DC1394_VIDEO_MODE_FORMAT7_0 || newColorCoding!=DC1394_COLOR_CODING_RAW8) return false;
928 }
929
930 dc1394color_coding_t actColorCoding=DC1394_COLOR_CODING_RGB8;
931 unsigned int actPacketSize=0;
932
933 dc1394video_mode_t actVideoMode;
934 dc1394error_t error;
935 error=dc1394_video_get_mode(m_pCamera,&actVideoMode);
936 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
937
938 if (actVideoMode>=DC1394_VIDEO_MODE_FORMAT7_0 && actVideoMode<=DC1394_VIDEO_MODE_FORMAT7_2)
939 {
940 error=dc1394_format7_get_packet_size(m_pCamera,actVideoMode,&actPacketSize);
941 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
942 error=dc1394_format7_get_color_coding(m_pCamera,actVideoMode,&actColorCoding);
943 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
944 }
945 else if (newVideoMode==SKIP) // we're not in F7 mode and no mode is specified!
946 {
947 yError("no format 7 mode specified\n");
948 return false;
949 }
950
952 // is given video mode supported?
953 //
954 if (newVideoMode==SKIP)
955 {
956 newVideoMode=actVideoMode;
957 }
958 dc1394video_modes_t modes;
959 dc1394_video_get_supported_modes(m_pCamera,&modes);
960 bool bSupported=false;
961 for (unsigned int m=0; m<modes.num; ++m)
962 {
963 if (modes.modes[m]==(dc1394video_mode_t)newVideoMode)
964 {
965 bSupported=true;
966 break;
967 }
968 }
969 if (!bSupported)
970 {
971 yError("format 7 video mode %d not supported\n",newVideoMode-DC1394_VIDEO_MODE_FORMAT7_MIN);
972 return false;
973 }
974 //
976
978 // is given pixel format supported?
979 //
980 if (newColorCoding==SKIP)
981 {
982 newColorCoding=actColorCoding;
983 }
984 dc1394color_codings_t codings;
985 dc1394_format7_get_color_codings(m_pCamera,(dc1394video_mode_t)newVideoMode,&codings);
986 bSupported=false;
987 for (unsigned int m=0; m<codings.num; ++m)
988 {
989 if (codings.codings[m]==(dc1394color_coding_t)newColorCoding)
990 {
991 bSupported=true;
992 break;
993 }
994 }
995 if (!bSupported)
996 {
997 yError("invalid format 7 pixel format %d\n",newColorCoding-DC1394_COLOR_CODING_MIN);
998 return false;
999 }
1000 //
1002
1003 unsigned int maxWidth,maxHeight,wStep,hStep,xStep,yStep;
1004
1005 error=dc1394_format7_get_max_image_size(m_pCamera,(dc1394video_mode_t)newVideoMode,&maxWidth,&maxHeight);
1006 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1007
1008 error=dc1394_format7_get_unit_size(m_pCamera,(dc1394video_mode_t)newVideoMode,&wStep,&hStep);
1009 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1010
1011 error=dc1394_format7_get_unit_position(m_pCamera,(dc1394video_mode_t)newVideoMode,&xStep,&yStep);
1012 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1013
1014 if (newVideoMode==DC1394_VIDEO_MODE_FORMAT7_1)
1015 {
1016 wStep*=2;
1017 }
1018
1019 if (actVideoMode<DC1394_VIDEO_MODE_FORMAT7_0)
1020 {
1021 if (newXdim==SKIP) newXdim=(int)maxWidth;
1022 if (newYdim==SKIP) newYdim=(int)maxHeight;
1023 if (x0==SKIP) x0=0;
1024 if (y0==SKIP) y0=0;
1025 }
1026 else
1027 {
1028 unsigned int xdim,ydim,xpos,ypos;
1029 error=dc1394_format7_get_image_size(m_pCamera,actVideoMode,&xdim,&ydim);
1030 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1031 error=dc1394_format7_get_image_position(m_pCamera,actVideoMode,&xpos,&ypos);
1032 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1033
1034 if (newXdim==SKIP) newXdim=xdim;
1035 if (newYdim==SKIP) newYdim=ydim;
1036 if (x0==SKIP) x0=xpos;
1037 if (y0==SKIP) y0=ypos;
1038 }
1039
1040 // adjust image size to allowed in this format
1041 if (newXdim>(int)maxWidth) newXdim=(int)maxWidth;
1042 if (newYdim>(int)maxHeight) newYdim=(int)maxHeight;
1043
1044 newXdim=(newXdim/wStep)*wStep;
1045 newYdim=(newYdim/hStep)*hStep;
1046
1047 // calculate offset
1048 int xOff=(maxWidth -newXdim)/2+x0;
1049 int yOff=(maxHeight-newYdim)/2+y0;
1050 xOff=(xOff/xStep)*xStep;
1051 yOff=(yOff/yStep)*yStep;
1052
1053 if (xOff<0) xOff=0;
1054 if (yOff<0) yOff=0;
1055
1056 if (xOff+newXdim>maxWidth) xOff=maxWidth -newXdim;
1057 if (yOff+newYdim>maxHeight) yOff=maxHeight-newYdim;
1058
1059 error=dc1394_video_set_mode(m_pCamera,(dc1394video_mode_t)newVideoMode);
1060 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1061 error=dc1394_format7_set_color_coding(m_pCamera,(dc1394video_mode_t)newVideoMode,(dc1394color_coding_t)newColorCoding);
1062 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1063
1065 // speed
1067 if (newBandPercent<0)
1068 {
1069 newBandPercent=40;
1070 }
1071 else if (newBandPercent>100)
1072 {
1073 newBandPercent=100;
1074 }
1075
1076 dc1394speed_t isoSpeed;
1077 error=dc1394_video_get_iso_speed(m_pCamera,&isoSpeed);
1078 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1079
1080 // get ISO bandwidth
1081 int busBand=10000000<<(isoSpeed-DC1394_ISO_SPEED_MIN);
1082 int fpsMax=maxFPS((dc1394video_mode_t)newVideoMode,(dc1394color_coding_t)newColorCoding);
1083 double bpp=bytesPerPixel((dc1394color_coding_t)newColorCoding);
1084 double newBandOcc=double(fpsMax*newXdim*newYdim)*bpp;
1085
1086 int fps=fpsMax;
1087
1088 unsigned int roundUp=0;
1089 if (m_Framerate)
1090 {
1091 roundUp=1;
1092
1093 if (m_Framerate<fps)
1094 {
1095 fps=m_Framerate;
1096 }
1097 else
1098 {
1099 yWarning("framerate %d is too high, it will be set to the maximum available %d\n",m_Framerate,fps);
1100 }
1101
1102 m_Framerate=0;
1103 }
1104
1105 unsigned int bytesPerPacket,maxBytesPerPacket,unitBytesPerPacket;
1106 error=dc1394_format7_get_packet_parameters(m_pCamera,(dc1394video_mode_t)newVideoMode,&unitBytesPerPacket,&maxBytesPerPacket);
1107 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1108 bytesPerPacket=(unsigned int)(0.01*double(fps)/double(fpsMax)*double(newBandPercent)*double(busBand)*double(maxBytesPerPacket)/newBandOcc);
1109 bytesPerPacket=(roundUp+bytesPerPacket/unitBytesPerPacket)*unitBytesPerPacket;
1110
1111 if (bytesPerPacket>maxBytesPerPacket)
1112 {
1113 bytesPerPacket=maxBytesPerPacket;
1114 }
1115 else if (bytesPerPacket<unitBytesPerPacket)
1116 {
1117 bytesPerPacket=unitBytesPerPacket;
1118 }
1119
1120 printf("\nfps=%d newBandOcc=%f bpp=%f bytesPerPacket=%d maxBytesPerPacket=%d\n\n",fps,newBandOcc,bpp,bytesPerPacket,maxBytesPerPacket);
1121
1122 error=dc1394_format7_set_roi(m_pCamera,(dc1394video_mode_t)newVideoMode,(dc1394color_coding_t)newColorCoding,bytesPerPacket,xOff,yOff,newXdim,newYdim);
1123 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1124
1125 m_XDim=newXdim;
1126 m_YDim=newYdim;
1127 m_RawBufferSize=(unsigned int)(double(newXdim*newYdim)*bpp);
1128
1129 return true;
1130}
1131
1132bool CFWCamera_DR2_2::Capture(yarp::sig::ImageOf<yarp::sig::PixelRgb>* pImage,unsigned char *pBuffer,bool bRaw)
1133{
1134 std::lock_guard<std::mutex> lck(m_AcqMutex);
1135
1136 if (!m_bCameraOn)
1137 {
1138 return false;
1139 }
1140
1141 dc1394error_t ret=dc1394_capture_dequeue(m_pCamera,DC1394_CAPTURE_POLICY_WAIT,&m_pFrame);
1142
1143 if (ret!=DC1394_SUCCESS)
1144 {
1145 if (ret<0)
1146 {
1147 yWarning("dc1394_capture_dequeue returned %d\n\n",ret);
1148 }
1149 else
1150 {
1151 yError("dc1394_capture_dequeue returned %d\n\n",ret);
1152 }
1153 return false;
1154 }
1155
1156 m_pFramePoll=0;
1157 while (dc1394_capture_dequeue(m_pCamera,DC1394_CAPTURE_POLICY_POLL,&m_pFramePoll)==DC1394_SUCCESS && m_pFramePoll)
1158 {
1159 dc1394_capture_enqueue(m_pCamera,m_pFrame);
1161 m_pFramePoll=0;
1162 }
1163
1164 if (m_nInvalidFrames)
1165 {
1167 dc1394_capture_enqueue(m_pCamera,m_pFrame);
1168 return false;
1169 }
1170
1172 uint32_t v = ntohl(*((uint32_t*)m_pFrame->image));
1173 int nSecond = (v >> 25) & 0x7f;
1174 int nCycleCount = (v >> 12) & 0x1fff;
1175 int nCycleOffset = (v >> 0) & 0xfff;
1176
1177 if (m_LastSecond>nSecond) {
1178 // we got a wrap-around event, losing 128 seconds
1179 m_SecondOffset += 128;
1180 }
1181 m_LastSecond = nSecond;
1182
1183 m_Stamp.update(m_SecondOffset+(double)nSecond + (((double)nCycleCount+((double)nCycleOffset/3072.0))/8000.0));
1184 //m_Stamp.update(m_pFrame->timestamp/1000000.0);
1185 } else {
1186 m_Stamp.update();
1187 }
1188
1189 if (pImage)
1190 {
1191 pImage->resize(m_pFrame->size[0],m_pFrame->size[1]);
1192 pBuffer=pImage->getRawImage();
1193 }
1194
1195 if (m_pFrame->color_coding==DC1394_COLOR_CODING_RGB8 || bRaw)
1196 {
1197 memcpy(pBuffer,m_pFrame->image,m_pFrame->size[0]*m_pFrame->size[1]*(bRaw?1:3));
1198 }
1199 else if (m_pFrame->color_coding==DC1394_COLOR_CODING_RAW8)
1200 {
1201 dc1394_debayer_frames(m_pFrame,&m_ConvFrame,DC1394_BAYER_METHOD_BILINEAR);
1202 memcpy(pBuffer,m_ConvFrame.image,m_ConvFrame.size[0]*m_ConvFrame.size[1]*3);
1203 }
1204 else if (m_pFrame->color_coding==DC1394_COLOR_CODING_RAW16)
1205 {
1206 dc1394_debayer_frames(m_pFrame,&m_ConvFrame,DC1394_BAYER_METHOD_BILINEAR);
1207 m_ConvFrame_tmp.size[0]=m_pFrame->size[0];
1208 m_ConvFrame_tmp.size[1]=m_pFrame->size[1];
1209 m_ConvFrame_tmp.position[0]=0;
1210 m_ConvFrame_tmp.position[1]=0;
1211 m_ConvFrame_tmp.color_coding=DC1394_COLOR_CODING_RGB8;
1212 m_ConvFrame_tmp.data_depth=24;
1213 m_ConvFrame_tmp.image_bytes=m_ConvFrame_tmp.total_bytes=3*m_pFrame->size[0]*m_pFrame->size[1];
1214 m_ConvFrame_tmp.padding_bytes=0;
1215 m_ConvFrame_tmp.stride=3*m_pFrame->size[0];
1216 m_ConvFrame_tmp.data_in_padding=DC1394_FALSE;
1217 m_ConvFrame_tmp.little_endian=m_pFrame->little_endian;
1218 dc1394_convert_frames(&m_ConvFrame,&m_ConvFrame_tmp);
1219 memcpy(pBuffer,m_ConvFrame_tmp.image,m_ConvFrame_tmp.size[0]*m_ConvFrame_tmp.size[1]*3);
1220 }
1221 else
1222 {
1223 m_ConvFrame.size[0]=m_pFrame->size[0];
1224 m_ConvFrame.size[1]=m_pFrame->size[1];
1225 m_ConvFrame.position[0]=0;
1226 m_ConvFrame.position[1]=0;
1227 m_ConvFrame.color_coding=DC1394_COLOR_CODING_RGB8;
1228 m_ConvFrame.data_depth=24;
1229 m_ConvFrame.image_bytes=m_ConvFrame.total_bytes=3*m_pFrame->size[0]*m_pFrame->size[1];
1230 m_ConvFrame.padding_bytes=0;
1231 m_ConvFrame.stride=3*m_pFrame->size[0];
1232 m_ConvFrame.data_in_padding=DC1394_FALSE;
1233 m_ConvFrame.little_endian=m_pFrame->little_endian;
1234
1235 dc1394_convert_frames(m_pFrame,&m_ConvFrame);
1236
1237 memcpy(pBuffer,m_ConvFrame.image,m_ConvFrame.size[0]*m_ConvFrame.size[1]*3);
1238 }
1239
1240 dc1394_capture_enqueue(m_pCamera,m_pFrame);
1241 return true;
1242}
1243
1244bool CFWCamera_DR2_2::Capture(yarp::sig::ImageOf<yarp::sig::PixelMono>* pImage)
1245{
1246 std::lock_guard<std::mutex> lck(m_AcqMutex);
1247
1248 if (!m_bCameraOn || dc1394_capture_dequeue(m_pCamera,DC1394_CAPTURE_POLICY_WAIT,&m_pFrame)!=DC1394_SUCCESS)
1249 {
1250 return false;
1251 }
1252
1253 m_pFramePoll=0;
1254 while (dc1394_capture_dequeue(m_pCamera,DC1394_CAPTURE_POLICY_POLL,&m_pFramePoll)==DC1394_SUCCESS && m_pFramePoll)
1255 {
1256 dc1394_capture_enqueue(m_pCamera,m_pFrame);
1258 m_pFramePoll=0;
1259 }
1260
1261 if (m_nInvalidFrames)
1262 {
1264 dc1394_capture_enqueue(m_pCamera,m_pFrame);
1265 return false;
1266 }
1267
1269 uint32_t v = ntohl(*((uint32_t*)m_pFrame->image));
1270 int nSecond = (v >> 25) & 0x7f;
1271 int nCycleCount = (v >> 12) & 0x1fff;
1272 int nCycleOffset = (v >> 0) & 0xfff;
1273
1274 if (m_LastSecond>nSecond) {
1275 // we got a wrap-around event, losing 128 seconds
1276 m_SecondOffset += 128;
1277 }
1278 m_LastSecond = nSecond;
1279
1280 m_Stamp.update(m_SecondOffset+(double)nSecond + (((double)nCycleCount+((double)nCycleOffset/3072.0))/8000.0));
1281 //m_Stamp.update(m_pFrame->timestamp/1000000.0);
1282 } else {
1283 m_Stamp.update();
1284 }
1285
1286 if (pImage)
1287 {
1288 pImage->resize(m_pFrame->size[0],m_pFrame->size[1]);
1289 memcpy(pImage->getRawImage(),m_pFrame->image,m_pFrame->size[0]*m_pFrame->size[1]);
1290 }
1291
1292 dc1394_capture_enqueue(m_pCamera,m_pFrame);
1293 return true;
1294}
1295
1296uint32_t CFWCamera_DR2_2::NormToValue(double& dVal,int feature)
1297{
1298 int f=feature-DC1394_FEATURE_MIN;
1299
1300 if (dVal<0.0) dVal=0.0;
1301 if (dVal>1.0) dVal=1.0;
1302
1303 uint32_t iVal=m_iMin[f]+(uint32_t)(dVal*double(m_iMax[f]-m_iMin[f]));
1304
1305 if (iVal<m_iMin[f]) iVal=m_iMin[f];
1306 if (iVal>m_iMax[f]) iVal=m_iMax[f];
1307
1308 return iVal;
1309}
1310
1311double CFWCamera_DR2_2::ValueToNorm(uint32_t iVal,int feature)
1312{
1313 int f=feature-DC1394_FEATURE_MIN;
1314
1315 double dVal=double(iVal-m_iMin[f])/double(m_iMax[f]-m_iMin[f]);
1316
1317 if (dVal<0.0) return 0.0;
1318 if (dVal>1.0) return 1.0;
1319
1320 return dVal;
1321}
1322
1324// feature functions
1326
1327// 00
1329{
1330 if (!m_pCamera) return false;
1331 feature+=DC1394_FEATURE_MIN;
1332 dc1394bool_t value;
1333 dc1394_feature_is_present(m_pCamera,(dc1394feature_t)feature,&value);
1334 return value;
1335}
1336
1337// 01
1338bool CFWCamera_DR2_2::setFeatureDC1394(int feature,double value)
1339{
1340 if (value<0.0 || value>1.0) return false;
1341 if (!m_pCamera) return false;
1342 feature+=DC1394_FEATURE_MIN;
1343 return DC1394_SUCCESS==dc1394_feature_set_value(m_pCamera,(dc1394feature_t)feature,NormToValue(value,feature));
1344}
1345
1346// 02
1348{
1349 if (!m_pCamera) return -1.0;
1350 feature+=DC1394_FEATURE_MIN;
1351 uint32_t iVal;
1352 dc1394_feature_get_value(m_pCamera,(dc1394feature_t)feature,&iVal);
1353 return ValueToNorm(iVal,feature);
1354}
1355
1356// 03
1358{
1359 if (!m_pCamera) return false;
1360 feature+=DC1394_FEATURE_MIN;
1361 dc1394bool_t value;
1362 dc1394_feature_is_switchable(m_pCamera,(dc1394feature_t)feature,&value);
1363 return value;
1364}
1365
1366// 04
1367bool CFWCamera_DR2_2::setActiveDC1394(int feature, bool onoff)
1368{
1369 if (!m_pCamera) return false;
1370 feature+=DC1394_FEATURE_MIN;
1371
1372 if (feature==DC1394_FEATURE_EXPOSURE)
1373 {
1374 if (onoff)
1375 {
1376 dc1394_feature_set_power(m_pCamera,DC1394_FEATURE_GAIN,DC1394_ON);
1377 dc1394_feature_set_power(m_pCamera,DC1394_FEATURE_SHUTTER,DC1394_ON);
1378
1379 dc1394_feature_get_mode(m_pCamera,DC1394_FEATURE_GAIN,&m_GainSaveModeAuto);
1380 if (m_GainSaveModeAuto==DC1394_FEATURE_MODE_MANUAL)
1381 {
1382 dc1394_feature_get_value(m_pCamera,DC1394_FEATURE_GAIN,&m_GainSaveValue);
1383 }
1384
1385 dc1394_feature_get_mode(m_pCamera,DC1394_FEATURE_SHUTTER,&m_ShutterSaveModeAuto);
1386 if (m_ShutterSaveModeAuto==DC1394_FEATURE_MODE_MANUAL)
1387 {
1388 dc1394_feature_get_value(m_pCamera,DC1394_FEATURE_SHUTTER,&m_ShutterSaveValue);
1389 }
1390
1391 dc1394_feature_set_mode(m_pCamera,DC1394_FEATURE_GAIN,DC1394_FEATURE_MODE_AUTO);
1392 dc1394_feature_set_mode(m_pCamera,DC1394_FEATURE_SHUTTER,DC1394_FEATURE_MODE_AUTO);
1393 }
1394 else
1395 {
1396 dc1394_feature_set_mode(m_pCamera,DC1394_FEATURE_GAIN,m_GainSaveModeAuto);
1397 if (m_GainSaveModeAuto==DC1394_FEATURE_MODE_MANUAL)
1398 {
1399 dc1394_feature_set_value(m_pCamera,DC1394_FEATURE_GAIN,m_GainSaveValue);
1400 }
1401 dc1394_feature_set_mode(m_pCamera,DC1394_FEATURE_SHUTTER,m_ShutterSaveModeAuto);
1402 if (m_ShutterSaveModeAuto==DC1394_FEATURE_MODE_MANUAL)
1403 {
1404 dc1394_feature_set_value(m_pCamera,DC1394_FEATURE_SHUTTER,m_ShutterSaveValue);
1405 }
1406 }
1407 }
1408
1409 return DC1394_SUCCESS==dc1394_feature_set_power(m_pCamera,(dc1394feature_t)feature,onoff?DC1394_ON:DC1394_OFF);
1410}
1411
1412// 05
1414{
1415 if (!m_pCamera) return false;
1416 feature+=DC1394_FEATURE_MIN;
1417 dc1394switch_t pwr;
1418 dc1394_feature_get_power(m_pCamera,(dc1394feature_t)feature,&pwr);
1419 return pwr;
1420}
1421
1422// 06
1424{
1425 if (!m_pCamera) return false;
1426 feature+=DC1394_FEATURE_MIN;
1427 dc1394feature_modes_t modes;
1428 if (DC1394_SUCCESS!=dc1394_feature_get_modes(m_pCamera,(dc1394feature_t)feature,&modes)) return false;
1429 for (uint32_t num=0; num<modes.num; ++num)
1430 {
1431 if (modes.modes[num]==DC1394_FEATURE_MODE_MANUAL)
1432 {
1433 return true;
1434 }
1435 }
1436 return false;
1437}
1438
1439// 07
1441{
1442 if (!m_pCamera) return false;
1443 feature+=DC1394_FEATURE_MIN;
1444 dc1394feature_modes_t modes;
1445 if (DC1394_SUCCESS!=dc1394_feature_get_modes(m_pCamera,(dc1394feature_t)feature,&modes)) return false;
1446 for (uint32_t num=0; num<modes.num; ++num)
1447 {
1448 if (modes.modes[num]==DC1394_FEATURE_MODE_AUTO)
1449 {
1450 return true;
1451 }
1452 }
1453 return false;
1454}
1455
1456// 08
1458{
1459 if (!m_pCamera) return false;
1460 feature+=DC1394_FEATURE_MIN;
1461 dc1394feature_modes_t modes;
1462 if (DC1394_SUCCESS!=dc1394_feature_get_modes(m_pCamera,(dc1394feature_t)feature,&modes)) return false;
1463 for (uint32_t num=0; num<modes.num; ++num)
1464 {
1465 if (modes.modes[num]==DC1394_FEATURE_MODE_ONE_PUSH_AUTO)
1466 {
1467 return true;
1468 }
1469 }
1470 return false;
1471}
1472
1473// 09
1474bool CFWCamera_DR2_2::setModeDC1394(int feature, bool auto_onoff)
1475{
1476 if (!m_pCamera) return false;
1477 feature+=DC1394_FEATURE_MIN;
1478
1479 return DC1394_SUCCESS==dc1394_feature_set_mode(m_pCamera,(dc1394feature_t)feature,auto_onoff?DC1394_FEATURE_MODE_AUTO:DC1394_FEATURE_MODE_MANUAL);
1480}
1481
1482// 10
1484{
1485 if (!m_pCamera) return false;
1486 feature+=DC1394_FEATURE_MIN;
1487 dc1394feature_mode_t mode;
1488 dc1394_feature_get_mode(m_pCamera,(dc1394feature_t)feature,&mode);
1489 return mode==DC1394_FEATURE_MODE_AUTO;
1490}
1491
1492// 11
1494{
1495 if (!m_pCamera) return false;
1496 feature+=DC1394_FEATURE_MIN;
1497 return DC1394_SUCCESS==dc1394_feature_set_mode(m_pCamera,(dc1394feature_t)feature,DC1394_FEATURE_MODE_ONE_PUSH_AUTO);
1498}
1499
1500// 23
1502{
1503 if (b<0.0 || b>1.0 || r<0.0 || r>1.0 || !m_pCamera)
1504 {
1505 return false;
1506 }
1507
1508 return DC1394_SUCCESS==dc1394_feature_whitebalance_set_value(m_pCamera,
1509 NormToValue(b,DC1394_FEATURE_WHITE_BALANCE),
1510 NormToValue(r,DC1394_FEATURE_WHITE_BALANCE));
1511}
1512
1513// 24
1515{
1516 unsigned int iB,iR;
1517 bool ok=DC1394_SUCCESS==dc1394_feature_whitebalance_get_value(m_pCamera,&iB,&iR);
1518 b=ValueToNorm(iB,DC1394_FEATURE_WHITE_BALANCE);
1519 r=ValueToNorm(iR,DC1394_FEATURE_WHITE_BALANCE);
1520 return ok;
1521}
1522
1524// end feature functions
1526
1527// 12
1529{
1530 if (mRawDriver)
1531 {
1532 return 1<<(DC1394_VIDEO_MODE_FORMAT7_0-DC1394_VIDEO_MODE_MIN);
1533 }
1534
1535 dc1394video_modes_t modes;
1536 dc1394_video_get_supported_modes(m_pCamera,&modes);
1537
1538 unsigned int mask=0;
1539 for (unsigned int m=0; m<modes.num; ++m)
1540 {
1541 mask|=1<<(modes.modes[m]-DC1394_VIDEO_MODE_MIN);
1542 }
1543 yInfo("video mode mask: %x\n",mask);
1544 fflush(stdout);
1545
1546 return mask;
1547}
1548
1549// 13
1551{
1552 if (mRawDriver) return false;
1553
1554 yInfo("SET VIDEO MODE %d\n",newVideoMode);
1555
1556 std::lock_guard<std::mutex> lck(m_AcqMutex);
1557
1558 if (!m_pCamera)
1559 {
1560 return false;
1561 }
1562
1564
1565 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
1566 dc1394_capture_stop(m_pCamera);
1567
1568 dc1394video_mode_t videoModeToSet=(dc1394video_mode_t)((int)DC1394_VIDEO_MODE_MIN+newVideoMode);
1569
1570 if (videoModeToSet<DC1394_VIDEO_MODE_FORMAT7_MIN)
1571 {
1572 yError("Attempting to set NON format 7\n");
1573 SetVideoMode(videoModeToSet);
1574 }
1575 else
1576 {
1577 yError("Attempting to set format 7\n");
1578 SetF7(videoModeToSet,SKIP,SKIP,SKIP,SKIP,SKIP,SKIP);
1579 }
1580
1581 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
1582 {
1583 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
1584 dc1394_camera_free(m_pCamera);
1585 m_pCamera=NULL;
1586 return false;
1587 }
1588
1589 if (dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
1590 {
1591 yError("Can't set DC1394_ON\n");
1592 dc1394_camera_free(m_pCamera);
1593 m_pCamera=NULL;
1594 return false;
1595 }
1596
1597 return true;
1598}
1599
1600// 14
1602{
1603 dc1394video_mode_t videoMode;
1604 dc1394_video_get_mode(m_pCamera,&videoMode);
1605 return videoMode-DC1394_VIDEO_MODE_MIN;
1606}
1607
1608// 15
1610{
1611 if (!m_pCamera) return 0;
1612
1613 dc1394video_mode_t videoMode;
1614 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1615 if (manage(error) || videoMode>=DC1394_VIDEO_MODE_FORMAT7_MIN)
1616 {
1617 yError("LINE: %d\n",__LINE__);
1618 return 0;
1619 }
1620
1621 dc1394framerates_t fps;
1622 dc1394_video_get_supported_framerates(m_pCamera,videoMode,&fps);
1623
1624 unsigned int mask=0;
1625 for (unsigned int f=0; f<fps.num; ++f)
1626 {
1627 mask|=1<<(fps.framerates[f]-DC1394_FRAMERATE_MIN);
1628 }
1629
1630 return mask;
1631}
1632
1633// 16
1635{
1636 if (!m_pCamera) return 0;
1637
1638 dc1394video_mode_t videoMode;
1639 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1640 if (manage(error) || videoMode>=DC1394_VIDEO_MODE_FORMAT7_MIN)
1641 {
1642 yError("LINE: %d\n",__LINE__);
1643 return 0;
1644 }
1645
1646 dc1394framerate_t fps;
1647 dc1394_video_get_framerate(m_pCamera,&fps);
1648
1649 return fps-DC1394_FRAMERATE_MIN;
1650}
1651
1652// 17
1654{
1655 if (!m_pCamera) return false;
1656
1657 dc1394video_mode_t videoMode;
1658 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1659 if (manage(error) || videoMode>=DC1394_VIDEO_MODE_FORMAT7_MIN)
1660 {
1661 yError("LINE: %d\n",__LINE__);
1662 return false;
1663 }
1664
1665 return DC1394_SUCCESS==dc1394_video_set_framerate(m_pCamera,(dc1394framerate_t)((int)fps+DC1394_FRAMERATE_MIN));
1666}
1667
1668// 18
1670{
1671 if (!m_pCamera) return false;
1672 dc1394speed_t speed;
1673 dc1394_video_get_iso_speed(m_pCamera,&speed);
1674 return speed-DC1394_ISO_SPEED_MIN;
1675}
1676
1677// 19
1679{
1680 if (!m_pCamera) return false;
1681 return DC1394_SUCCESS==dc1394_video_set_iso_speed(m_pCamera,(dc1394speed_t)(speed+DC1394_ISO_SPEED_MIN));
1682}
1683
1684// 20
1685unsigned int CFWCamera_DR2_2::getColorCodingMaskDC1394(unsigned int videoMode)
1686{
1687 if (!m_pCamera) return 0;
1688
1689 if (mRawDriver) return 1<<(DC1394_COLOR_CODING_RAW8-DC1394_COLOR_CODING_MIN);
1690
1691 dc1394video_mode_t vm=(dc1394video_mode_t)(videoMode+DC1394_VIDEO_MODE_MIN);
1692
1693 if (vm<DC1394_VIDEO_MODE_FORMAT7_MIN) return 0;
1694
1695 dc1394color_codings_t codings;
1696 dc1394_format7_get_color_codings(m_pCamera,vm,&codings);
1697
1698 unsigned int mask=0;
1699 for (unsigned int m=0; m<codings.num; ++m)
1700 {
1701 mask|=1<<(codings.codings[m]-DC1394_COLOR_CODING_MIN);
1702 }
1703
1704 yInfo("color coding mask for video mode %d is %x\n",videoMode,mask);
1705
1706 return mask;
1707}
1709{
1710 if (!m_pCamera) return false;
1711
1712 if (mRawDriver) return 1<<(DC1394_COLOR_CODING_RAW8-DC1394_COLOR_CODING_MIN);
1713
1714 dc1394video_mode_t videoMode;
1715 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1716 if (manage(error) || videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
1717 {
1718 yError("LINE: %d\n",__LINE__);
1719 return 0;
1720 }
1721
1722 dc1394color_codings_t codings;
1723 dc1394_format7_get_color_codings(m_pCamera,videoMode,&codings);
1724
1725 unsigned int mask=0;
1726 for (unsigned int m=0; m<codings.num; ++m)
1727 {
1728 mask|=1<<(codings.codings[m]-DC1394_COLOR_CODING_MIN);
1729 }
1730
1731 yInfo("actual color coding mask %x\n",mask);
1732
1733 return mask;
1734}
1735
1736// 21
1738{
1739 if (!m_pCamera) return false;
1740
1741 dc1394video_mode_t videoMode;
1742 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1743 if (manage(error) || videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
1744 {
1745 yError("LINE: %d\n",__LINE__);
1746 return 0;
1747 }
1748
1749 dc1394color_coding_t coding;
1750 dc1394_format7_get_color_coding(m_pCamera,videoMode,&coding);
1751 return coding-DC1394_COLOR_CODING_MIN;
1752}
1753
1754// 22
1756{
1757 if (mRawDriver) return false;
1758
1759 std::lock_guard<std::mutex> lck(m_AcqMutex);
1760
1761 if (!m_pCamera)
1762 {
1763 return false;
1764 }
1765
1766 dc1394video_mode_t videoMode;
1767 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1768 if (manage(error) || videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
1769 {
1770 yError("LINE: %d\n",__LINE__);
1771 return false;
1772 }
1773
1775
1776 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
1777 dc1394_capture_stop(m_pCamera);
1778
1779 dc1394color_coding_t cc=(dc1394color_coding_t)((int)coding+DC1394_COLOR_CODING_MIN);
1781
1782 bool bRetVal=true;
1783
1784 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
1785 {
1786 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
1787 dc1394_camera_free(m_pCamera);
1788 m_pCamera=NULL;
1789 bRetVal=false;
1790 }
1791
1792 if (bRetVal && dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
1793 {
1794 yError("Can't set DC1394_ON\n");
1795 dc1394_camera_free(m_pCamera);
1796 m_pCamera=NULL;
1797 bRetVal=false;
1798 }
1799
1800 return bRetVal;
1801}
1802
1803//experimental cleanup function, Lorenzo
1804
1805// 25
1806bool CFWCamera_DR2_2::getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep)
1807{
1808 if (!m_pCamera) return false;
1809
1810 dc1394video_mode_t videoMode;
1811 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1812 if (manage(error))
1813 {
1814 yError("LINE: %d\n",__LINE__);
1815 xdim=ydim=0;
1816 xstep=ystep=2;
1817 xoffstep=yoffstep=2;
1818 return false;
1819 }
1820
1821 if (videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
1822 {
1823 xdim=m_XDim;
1824 ydim=m_YDim;
1825 xoffstep=yoffstep=2;
1826 return true;
1827 }
1828
1829 error=dc1394_format7_get_unit_size(m_pCamera,videoMode,&xstep,&ystep);
1830 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1831 error=dc1394_format7_get_max_image_size(m_pCamera,videoMode,&xdim,&ydim);
1832 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1833 error=dc1394_format7_get_unit_position(m_pCamera,videoMode,&xoffstep,&yoffstep);
1834 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1835
1836 return true;
1837}
1838
1839// 26
1840bool CFWCamera_DR2_2::setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0)
1841{
1842 std::lock_guard<std::mutex> lck(m_AcqMutex);
1843
1844 if (!m_pCamera)
1845 {
1846 return false;
1847 }
1848
1849 dc1394video_mode_t videoMode;
1850 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
1851 if (manage(error) || videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
1852 {
1853 yError("LINE: %d\n",__LINE__);
1854 return false;
1855 }
1856
1858 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
1859 dc1394_capture_stop(m_pCamera);
1860
1861 SetF7(SKIP,xdim,ydim,SKIP,SKIP,x0,y0);
1862
1863 bool bRetVal=true;
1864
1865 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
1866 {
1867 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
1868 dc1394_camera_free(m_pCamera);
1869 m_pCamera=NULL;
1870 bRetVal=false;
1871 }
1872
1873 if (bRetVal && dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
1874 {
1875 yError("Can't set DC1394_ON\n");
1876 dc1394_camera_free(m_pCamera);
1877 m_pCamera=NULL;
1878 bRetVal=false;
1879 }
1880
1881 return bRetVal;
1882}
1883
1884// 27
1885bool CFWCamera_DR2_2::getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0)
1886{
1887 if (!m_pCamera) return false;
1888
1889 //xdim=m_XDim;
1890 //ydim=m_YDim;
1891
1892 dc1394video_mode_t actVideoMode;
1893 dc1394error_t error;
1894
1895 error=dc1394_video_get_mode(m_pCamera,&actVideoMode);
1896 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1897
1898 if (actVideoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
1899 {
1900 xdim=m_XDim;
1901 ydim=m_YDim;
1902 x0=y0=0;
1903 return true;
1904 }
1905
1906 unsigned int xmaxdim,ymaxdim;
1907 error=dc1394_format7_get_max_image_size(m_pCamera,actVideoMode,&xmaxdim,&ymaxdim);
1908 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1909
1910 unsigned int xoff,yoff;
1911 error=dc1394_format7_get_image_position(m_pCamera,actVideoMode,&xoff,&yoff);
1912 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1913
1914 error=dc1394_format7_get_image_size(m_pCamera,actVideoMode,&xdim,&ydim);
1915 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
1916
1917 x0=(int)xoff-(xmaxdim-xdim)/2;
1918 y0=(int)yoff-(ymaxdim-ydim)/2;
1919
1920 return true;
1921}
1922
1923// 28
1925{
1926 std::lock_guard<std::mutex> lck(m_AcqMutex);
1927
1928 if (!m_pCamera)
1929 {
1930 return false;
1931 }
1932
1934
1935 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
1936 dc1394_capture_stop(m_pCamera);
1937 dc1394_video_set_operation_mode(m_pCamera,b1394b?DC1394_OPERATION_MODE_1394B:DC1394_OPERATION_MODE_LEGACY);
1938 dc1394_video_set_iso_speed(m_pCamera,DC1394_ISO_SPEED_400);
1939
1940 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
1941 {
1942 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
1943 dc1394_camera_free(m_pCamera);
1944 m_pCamera=NULL;
1945 return false;
1946 }
1947
1948 if (dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
1949 {
1950 yError("Can't set DC1394_ON\n");
1951 dc1394_camera_free(m_pCamera);
1952 m_pCamera=NULL;
1953 return false;
1954 }
1955
1956 return true;
1957}
1958
1959// 29
1961{
1962 if (!m_pCamera) return false;
1963 dc1394operation_mode_t b1394b;
1964 dc1394_video_get_operation_mode(m_pCamera,&b1394b);
1965 return b1394b==DC1394_OPERATION_MODE_1394B;
1966}
1967
1968// 30
1970{
1971 if (!m_pCamera) return false;
1972 return DC1394_SUCCESS==dc1394_video_set_transmission(m_pCamera,(dc1394switch_t)bTxON);
1973}
1974
1975// 31
1977{
1978 if (!m_pCamera) return false;
1979 dc1394switch_t bTxON;
1980 dc1394_video_get_transmission(m_pCamera,&bTxON);
1981 return bTxON;
1982}
1983
1984// 32 setBayer
1985// 33 getBayer
1986
1987// 34
1989{
1990 if (!m_pCamera) return false;
1991 return DC1394_SUCCESS==dc1394_camera_set_broadcast(m_pCamera,(dc1394bool_t)onoff);
1992}
1993
1994// 35
1996{
1997 std::lock_guard<std::mutex> lck(m_AcqMutex);
1998
1999 if (!m_pCamera)
2000 {
2001 return false;
2002 }
2003
2005
2006 bool bRetVal=DC1394_SUCCESS==dc1394_memory_load(m_pCamera,0);
2007
2008 dc1394video_mode_t videoMode;
2009 dc1394_video_get_mode(m_pCamera,&videoMode);
2010
2011 SetVideoMode(videoMode);
2012
2013 return bRetVal;
2014}
2015
2016// 36
2018{
2019 std::lock_guard<std::mutex> lck(m_AcqMutex);
2020
2021 if (!m_pCamera)
2022 {
2023 return false;
2024 }
2025
2026 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
2027 dc1394_capture_stop(m_pCamera);
2028
2029 dc1394_camera_reset(m_pCamera);
2030
2031 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
2032 {
2033 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
2034 dc1394_camera_free(m_pCamera);
2035 m_pCamera=NULL;
2036 return false;
2037 }
2038
2039 if (dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
2040 {
2041 yError("Can't set DC1394_ON\n");
2042 dc1394_camera_free(m_pCamera);
2043 m_pCamera=NULL;
2044 return false;
2045 }
2046
2047 return true;
2048}
2049
2050// 37
2052{
2053 std::lock_guard<std::mutex> lck(m_AcqMutex);
2054
2055 if (!m_pCamera)
2056 {
2057 return false;
2058 }
2059
2060 if (onoff)
2061 {
2062 dc1394_camera_set_power(m_pCamera,(dc1394switch_t)onoff);
2063
2064 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
2065 {
2066 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
2067 dc1394_camera_free(m_pCamera);
2068 m_pCamera=NULL;
2069 return false;
2070 }
2071
2072 if (dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
2073 {
2074 yError("Can't set DC1394_ON\n");
2075 dc1394_camera_free(m_pCamera);
2076 m_pCamera=NULL;
2077 return false;
2078 }
2079
2080 m_bCameraOn=true;
2081 }
2082 else
2083 {
2084 m_bCameraOn=false;
2085 dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
2086 dc1394_capture_stop(m_pCamera);
2087 dc1394_camera_set_power(m_pCamera,(dc1394switch_t)onoff);
2088 }
2089
2090 return true;
2091}
2092
2093// 38
2095{
2096 if (!m_pCamera) return false;
2097
2098 if (bON)
2099 return DC1394_SUCCESS==dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT);
2100 else
2101 return DC1394_SUCCESS==dc1394_capture_stop(m_pCamera);
2102}
2103
2104// 39
2106{
2107 if (!m_pCamera) return 0;
2108
2109 dc1394video_mode_t videoMode;
2110 dc1394error_t error=dc1394_video_get_mode(m_pCamera,&videoMode);
2111 if (manage(error) || videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
2112 {
2113 yError("LINE: %d\n",__LINE__);
2114 return 0;
2115 }
2116
2117 dc1394speed_t isoSpeed;
2118 error=dc1394_video_get_iso_speed(m_pCamera,&isoSpeed);
2119 if (manage(error)) { yError("LINE: %d\n",__LINE__); return 0; }
2120
2121 // get ISO bandwidth
2122 int busBand=10000000<<(isoSpeed-DC1394_ISO_SPEED_MIN);
2123
2124 dc1394color_coding_t colorCoding;
2125 unsigned int dummy,bytesPerPacket,xDim,yDim;
2126 error=dc1394_format7_get_roi(m_pCamera,videoMode,&colorCoding,&bytesPerPacket,&dummy,&dummy,&xDim,&yDim);
2127 if (manage(error)) { yError("LINE: %d\n",__LINE__); return 0; }
2128
2129 unsigned int maxBytesPerPacket,unitBytesPerPacket;
2130 error=dc1394_format7_get_packet_parameters(m_pCamera,videoMode,&unitBytesPerPacket,&maxBytesPerPacket);
2131 if (manage(error)) { yError("LINE: %d\n",__LINE__); return 0; }
2132
2133 int fps=maxFPS(videoMode,colorCoding);
2134 double bpp=bytesPerPixel(colorCoding);
2135 double maxBandOcc=double(fps*xDim*yDim)*bpp;
2136 double margin=double(busBand)/maxBandOcc;
2137
2138 int bandPercent=(int)(100.0*double(bytesPerPacket)/(double(maxBytesPerPacket)*margin));
2139
2140 if (bandPercent<0) bandPercent=0; else if (bandPercent>100) bandPercent=100;
2141
2142 return (unsigned)bandPercent;
2143}
2144
2145// 40
2146bool CFWCamera_DR2_2::setBytesPerPacketDC1394(unsigned int newBandPercent)
2147{
2148 std::lock_guard<std::mutex> lck(m_AcqMutex);
2149
2150 if (!m_pCamera)
2151 {
2152 return false;
2153 }
2154
2155 dc1394error_t error;
2156
2157 error=dc1394_video_set_transmission(m_pCamera,DC1394_OFF);
2158 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2159
2160 error=dc1394_capture_stop(m_pCamera);
2161 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2162
2163 //
2164
2165 dc1394video_mode_t videoMode;
2166 error=dc1394_video_get_mode(m_pCamera,&videoMode);
2167 if (manage(error) || videoMode<DC1394_VIDEO_MODE_FORMAT7_MIN)
2168 {
2169 yError("LINE: %d\n",__LINE__);
2170 return false;
2171 }
2172
2173 if (newBandPercent<0)
2174 {
2175 newBandPercent=0;
2176 }
2177 else if (newBandPercent>100)
2178 {
2179 newBandPercent=100;
2180 }
2181
2182 dc1394speed_t isoSpeed;
2183 error=dc1394_video_get_iso_speed(m_pCamera,&isoSpeed);
2184 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2185
2186 // get ISO bandwidth
2187 int busBand=10000000<<(isoSpeed-DC1394_ISO_SPEED_MIN);
2188
2189 dc1394color_coding_t colorCoding;
2190 unsigned int dummy,xDim,yDim;
2191 error=dc1394_format7_get_roi(m_pCamera,videoMode,&colorCoding,&dummy,&dummy,&dummy,&xDim,&yDim);
2192 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2193
2194 unsigned int maxBytesPerPacket,unitBytesPerPacket;
2195 error=dc1394_format7_get_packet_parameters(m_pCamera,videoMode,&unitBytesPerPacket,&maxBytesPerPacket);
2196 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2197
2198 int fps=maxFPS(videoMode,colorCoding);
2199 double bpp=bytesPerPixel(colorCoding);
2200 double newBandOcc=double(fps*xDim*yDim)*bpp;
2201
2202 unsigned int bytesPerPacket=(unsigned int)(0.01*double(newBandPercent)*double(busBand)*double(maxBytesPerPacket)/newBandOcc);
2203 bytesPerPacket=(bytesPerPacket/unitBytesPerPacket)*unitBytesPerPacket;
2204 if (bytesPerPacket>maxBytesPerPacket)
2205 {
2206 bytesPerPacket=maxBytesPerPacket;
2207 }
2208 else if (bytesPerPacket<unitBytesPerPacket)
2209 {
2210 bytesPerPacket=unitBytesPerPacket;
2211 }
2212
2213 printf("videoMode %d band percnet %d bytesPerPacket %d\n",videoMode,newBandPercent,bytesPerPacket);
2214
2215 error=dc1394_format7_set_packet_size(m_pCamera,videoMode,bytesPerPacket);
2216 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2217
2218 error=dc1394_format7_get_packet_size(m_pCamera,videoMode,&bytesPerPacket);
2219 if (manage(error)) { yError("LINE: %d\n",__LINE__); return false; }
2220
2221 if (dc1394_capture_setup(m_pCamera,NUM_DMA_BUFFERS,DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS)
2222 {
2223 yError("Can't set DC1394_CAPTURE_FLAGS_DEFAULT\n");
2224 dc1394_camera_free(m_pCamera);
2225 m_pCamera=NULL;
2226 return false;
2227 }
2228
2229 if (dc1394_video_set_transmission(m_pCamera,DC1394_ON)!=DC1394_SUCCESS)
2230 {
2231 yError("Can't set DC1394_ON\n");
2232 dc1394_camera_free(m_pCamera);
2233 m_pCamera=NULL;
2234 return false;
2235 }
2236
2237 printf("bytesPerPacket %d\n",bytesPerPacket);
2238
2239 return true;
2240}
2241
2242// base class implementation
2243
2244#define NOT_PRESENT -1
2246{
2247 switch (feature)
2248 {
2249 case YARP_FEATURE_BRIGHTNESS: return DC1394_FEATURE_BRIGHTNESS;
2250 case YARP_FEATURE_EXPOSURE: return DC1394_FEATURE_EXPOSURE;
2251 case YARP_FEATURE_SHARPNESS: return DC1394_FEATURE_SHARPNESS;
2252 case YARP_FEATURE_WHITE_BALANCE: return DC1394_FEATURE_WHITE_BALANCE;
2253 case YARP_FEATURE_HUE: return DC1394_FEATURE_HUE;
2254 case YARP_FEATURE_SATURATION: return DC1394_FEATURE_SATURATION;
2255 case YARP_FEATURE_GAMMA: return DC1394_FEATURE_GAMMA;
2256 case YARP_FEATURE_SHUTTER: return DC1394_FEATURE_SHUTTER;
2257 case YARP_FEATURE_GAIN: return DC1394_FEATURE_GAIN;
2258 case YARP_FEATURE_IRIS: return DC1394_FEATURE_IRIS;
2259 case YARP_FEATURE_FOCUS: return DC1394_FEATURE_FOCUS;
2260 case YARP_FEATURE_TEMPERATURE: return DC1394_FEATURE_TEMPERATURE;
2261 case YARP_FEATURE_TRIGGER: return DC1394_FEATURE_TRIGGER;
2262 case YARP_FEATURE_TRIGGER_DELAY: return DC1394_FEATURE_TRIGGER_DELAY;
2263 case YARP_FEATURE_FRAME_RATE: return DC1394_FEATURE_FRAME_RATE;
2264 case YARP_FEATURE_ZOOM: return DC1394_FEATURE_ZOOM;
2265 case YARP_FEATURE_PAN: return DC1394_FEATURE_PAN;
2266 case YARP_FEATURE_TILT: return DC1394_FEATURE_TILT;
2267 }
2268
2269 return NOT_PRESENT;
2270}
2271
2273{
2274 if (error!=DC1394_SUCCESS)
2275 {
2276 yError("%d\n",error);
2277 return true;
2278 }
2279 return false;
2280}
2281
2282int CFWCamera_DR2_2::checkInt(yarp::os::Searchable& config,const char* key)
2283{
2284 if (config.check(key))
2285 {
2286 return config.find(key).asInt32();
2287 }
2288
2289 return 0;
2290}
2291
2292double CFWCamera_DR2_2::checkDouble(yarp::os::Searchable& config,const char* key)
2293{
2294 if (config.check(key))
2295 {
2296 return config.find(key).asFloat64();
2297 }
2298
2299 return -1.0;
2300}
2301
2303{
2304 if (v<0.0 || v>1.0) return false;
2305 int feature=YARP_FEATURE_BRIGHTNESS;
2306 setActiveDC1394(feature,true);
2307 setModeDC1394(feature,false);
2308 return setFeatureDC1394(feature,v);
2309}
2311{
2312 if (v<0.0 || v>1.0) return false;
2313 int feature=YARP_FEATURE_EXPOSURE;
2314 setActiveDC1394(feature,true);
2315 setModeDC1394(feature,false);
2316 return setFeatureDC1394(feature,v);
2317}
2319{
2320 if (v<0.0 || v>1.0) return false;
2321 int feature=YARP_FEATURE_SHARPNESS;
2322 setActiveDC1394(feature,true);
2323 setModeDC1394(feature,false);
2324 return setFeatureDC1394(feature,v);
2325}
2326bool CFWCamera_DR2_2::setWhiteBalance(double blue, double red)
2327{
2328 if (blue<0.0 || blue>1.0 || red<0.0 || red>1.0) return false;
2329 int feature=YARP_FEATURE_WHITE_BALANCE;
2330 setActiveDC1394(feature,true);
2331 setModeDC1394(feature,false);
2332 return setWhiteBalanceDC1394(blue,red);
2333}
2335{
2336 if (v<0.0 || v>1.0) return false;
2337 int feature=YARP_FEATURE_HUE;
2338 setActiveDC1394(feature,true);
2339 setModeDC1394(feature,false);
2340 return setFeatureDC1394(feature,v);
2341}
2343{
2344 if (v<0.0 || v>1.0) return false;
2345 int feature=YARP_FEATURE_SATURATION;
2346 setActiveDC1394(feature,true);
2347 setModeDC1394(feature,false);
2348 return setFeatureDC1394(feature,v);
2349}
2351{
2352 if (v<0.0 || v>1.0) return false;
2353 int feature=YARP_FEATURE_GAMMA;
2354 setActiveDC1394(feature,true);
2355 setModeDC1394(feature,false);
2356 return setFeatureDC1394(feature,v);
2357}
2359{
2360 if (v<0.0 || v>1.0) return false;
2361 int feature=YARP_FEATURE_SHUTTER;
2362 setActiveDC1394(feature,true);
2363 setModeDC1394(feature,false);
2364 return setFeatureDC1394(feature,v);
2365}
2367{
2368 if (v<0.0 || v>1.0) return false;
2369 int feature=YARP_FEATURE_GAIN;
2370 setActiveDC1394(feature,true);
2371 setModeDC1394(feature,false);
2372 return setFeatureDC1394(feature,v);
2373}
2375{
2376 if (v<0.0 || v>1.0) return false;
2377 int feature=YARP_FEATURE_IRIS;
2378 setActiveDC1394(feature,true);
2379 setModeDC1394(feature,false);
2380 return setFeatureDC1394(feature,v);
2381}
2382
2383// GET
2384
2386{
2387 return getFeatureDC1394(TRANSL(YARP_FEATURE_BRIGHTNESS));
2388}
2390{
2391 return getFeatureDC1394(TRANSL(YARP_FEATURE_EXPOSURE));
2392}
2394{
2395 return getFeatureDC1394(TRANSL(YARP_FEATURE_SHARPNESS));
2396}
2397bool CFWCamera_DR2_2::getWhiteBalance(double &blue, double &red)
2398{
2399 return getWhiteBalance(blue,red);
2400}
2401double CFWCamera_DR2_2::CFWCamera_DR2_2::getHue()
2402{
2403 return getFeatureDC1394(TRANSL(YARP_FEATURE_HUE));
2404}
2406{
2407 return CFWCamera_DR2_2::getFeatureDC1394(TRANSL(YARP_FEATURE_SATURATION));
2408}
2410{
2411 return getFeatureDC1394(TRANSL(YARP_FEATURE_GAMMA));
2412}
2414{
2415 return getFeatureDC1394(TRANSL(YARP_FEATURE_SHUTTER));
2416}
2418{
2419 return getFeatureDC1394(TRANSL(YARP_FEATURE_GAIN));
2420}
2422{
2423 return getFeatureDC1394(TRANSL(YARP_FEATURE_IRIS));
2424}
2425
2426//IVisualParams
2427
2429 return height();
2430}
2431
2433 return width();
2434}
2435
2436bool CFWCamera_DR2_2::getRgbSupportedConfigurations(yarp::sig::VectorOf<yarp::dev::CameraConfig> &configurations)
2437{
2438 yError()<<"CFWCamera_DR2_2: getRgbSupportedConfigurations not supported yet";
2439 return false;
2440}
2441bool CFWCamera_DR2_2::getRgbResolution(int &width, int &height)
2442{
2443 width = this->width();
2444 height = this->height();
2445 return true;
2446}
2447
2448bool CFWCamera_DR2_2::setRgbResolution(int width, int height){
2449
2450 yError()<<"CFWCamera_DR2_2: setRgbResolution not supported use setVideoModeDC1394 instead";
2451 return false;
2452}
2453
2454bool CFWCamera_DR2_2::getRgbFOV(double &horizontalFov, double &verticalFov){
2456 verticalFov=this->verticalFov;
2457 return configFx && configFy;
2458}
2459
2460bool CFWCamera_DR2_2::setRgbFOV(double horizontalFov, double verticalFov){
2461 this->horizontalFov=horizontalFov;
2462 this->verticalFov=verticalFov;
2463 return true;
2464}
2465
2466bool CFWCamera_DR2_2::getRgbIntrinsicParam(yarp::os::Property &intrinsic){
2467 intrinsic=this->intrinsic;
2468 return configIntrins;
2469}
2470
2472 yWarning()<<"CFWCamera_DR2_2: mirroring not supported";
2473 return false;
2474}
2475
2477 yWarning()<<"CFWCamera_DR2_2: mirroring not supported";
2478 return false;
2479}
virtual bool setModeDC1394(int feature, bool auto_onoff)
virtual bool setTransmissionDC1394(bool bTxON)
virtual unsigned int getISOSpeedDC1394()
bool Capture(yarp::sig::ImageOf< yarp::sig::PixelRgb > *pImage, unsigned char *pBuffer=0, bool bRaw=false)
bool CaptureRaw(unsigned char *pBuffer)
virtual unsigned int getFPSDC1394()
virtual unsigned int getColorCodingDC1394()
bool SetVideoMode(dc1394video_mode_t videoMode)
uint32_t m_iMax[DC1394_FEATURE_NUM]
dc1394video_frame_t m_ConvFrame_tmp
double checkDouble(yarp::os::Searchable &config, const char *key)
const yarp::os::Stamp & getLastInputStamp()
uint32_t NormToValue(double &dVal, int feature)
dc1394video_frame_t m_ConvFrame
virtual bool hasFeatureDC1394(int feature)
virtual bool getWhiteBalanceDC1394(double &b, double &r)
bool SetF7(int newVideoMode, int newXdim, int newYdim, int newColorCoding, int newSpeed, int x0, int y0)
virtual unsigned int getVideoModeMaskDC1394()
virtual bool setPowerDC1394(bool onoff)
virtual bool setHue(double v)
virtual bool setShutter(double v)
virtual unsigned int getBytesPerPacketDC1394()
virtual bool setWhiteBalanceDC1394(double b, double r)
virtual unsigned int getVideoModeDC1394()
virtual bool setCaptureDC1394(bool bON)
virtual bool setBrightness(double v)
bool manage(dc1394error_t error)
bool CaptureImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
virtual bool setFeatureDC1394(int feature, double value)
virtual bool getWhiteBalance(double &blue, double &red)
yarp::os::Property intrinsic
virtual bool hasOnePushDC1394(int feature)
double ValueToNorm(uint32_t iVal, int feature)
virtual bool setRgbFOV(double horizontalFov, double verticalFov)
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)
virtual bool setOperationModeDC1394(bool b1394b)
virtual bool setBytesPerPacketDC1394(unsigned int bpp)
virtual unsigned int getFPSMaskDC1394()
virtual bool setRgbMirroring(bool mirror)
virtual bool hasAutoDC1394(int feature)
dc1394feature_mode_t m_ShutterSaveModeAuto
virtual bool getRgbFOV(double &horizontalFov, double &verticalFov)
virtual bool setBroadcastDC1394(bool onoff)
virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations)
dc1394feature_mode_t m_GainSaveModeAuto
virtual bool getRgbResolution(int &width, int &height)
double bytesPerPixel(dc1394color_coding_t pixelFormat)
virtual bool setExposure(double v)
virtual bool setRgbResolution(int width, int height)
dc1394video_frame_t * m_pFramePoll
virtual bool setSharpness(double v)
uint32_t m_iMin[DC1394_FEATURE_NUM]
int checkInt(yarp::os::Searchable &config, const char *key)
virtual bool hasManualDC1394(int feature)
virtual double getFeatureDC1394(int feature)
virtual unsigned int getActualColorCodingMaskDC1394()
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)
dc1394video_frame_t * m_pFrame
bool CaptureRgb(unsigned char *pBuffer)
dc1394camera_list_t * m_pCameraList
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)
virtual bool setGamma(double v)
virtual bool setActiveDC1394(int feature, bool onoff)
virtual bool setIris(double v)
virtual bool setFPSDC1394(int fps)
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)
virtual bool hasOnOffDC1394(int feature)
virtual bool getActiveDC1394(int feature)
virtual bool setISOSpeedDC1394(int speed)
virtual bool setColorCodingDC1394(int coding)
virtual bool getModeDC1394(int feature)
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)
virtual bool setWhiteBalance(double blue, double red)
virtual bool getRgbMirroring(bool &mirror)
virtual bool setVideoModeDC1394(int video_mode)
int maxFPS(dc1394video_mode_t mode, dc1394color_coding_t pixelFormat)
virtual bool setOnePushDC1394(int feature)
virtual bool setSaturation(double v)
bool Create(yarp::os::Searchable &config)
virtual bool setGain(double v)
bool error
static dc1394error_t set_embedded_timestamp(dc1394camera_t *camera, bool enable)
#define POINTGREY_REGISTER_TIMESTAMP
#define DR_RGB_1024x768
#define DR_BAYER16_640x480
#define DR_BAYER_640x480
#define DR_RGB_800x600
#define DR_RGB_512x384
#define DR_YUV_1024x768
#define DR_BAYER_1024x768
#define DR_RGB_320x240
#define DR_RGB_640x480
#define DR_YUV_640x480
#define DR_YUV_800x600
#define NUM_DMA_BUFFERS
#define DR_UNINIT