Fixed DevStudio 2003 build with memory check code.
[pwlib.git] / plugins / vidinput_dc / video4dc1394.cxx
blobd470b5b974025da190516a7ecd5b436a6b411035
1 /*
2 * README for IEEE 1394 digital camera support routine in PWLib
3 * ------------------------------------------------------------
4 *
5 * PWLib now contains preliminary support for the IEEE 1394 digital
6 * cameras under Linux.
7 *
8 *
9 * Supported cameras:
11 * There are two kind of the specifications of IEEE 1394 digital video
12 * cameras, one is called "digital camera" and another is "AV/C camera".
13 * A digital camera sends uncompressed video data while an AV/C camera
14 * sends compressed data. Currently PWLib only supports digital
15 * cameras. We can find a list of supported digital cameras by the Linux
16 * device driver at:
17 * http://www.tele.ucl.ac.be/PEOPLE/DOUXCHAMPS/ieee1394/cameras/
19 * AV/C cameras seem able to be used for video phone. You are welcome to
20 * write supporting codes for AV/C cameras!
23 * Installation and Use:
25 * To enable 1394 camera support, you have to define the "TRY_1394DC"
26 * shell environment variable at compilation time of PWLib, OpenH323, and
27 * ohphone. To select your 1394 camera for video input device instead of
28 * usual Video4Linux devices, specify "/dev/raw1394" or "/dev/video1394"
29 * as the filename of video input device. For example "ohphone
30 * --videoinput /dev/raw1394" should use your 1394 camera as video input.
32 * "/dev/video1394" uses faster DMA transfer for video input.
34 * If you use DEVFS, the filename for DMA transfer may be /dev/video1394/0.
36 * Requirements for Installation:
38 * You needs the following softwares to compile the 1394 camera support
39 * module in PWLib.
41 * - libdc1394 0.9.0 or later.
42 * - Linux 2.4.19 or later, which is required by the above version of
43 * libdc1394
44 * - libraw1394 0.9.0 or later
46 * You cannot compile it with older versions of libdc1394.
48 * Troubleshooting:
50 * If this module does not work for you, please verify the following
51 * items before sending email:
53 * 1) Can you view image of your camera by other programs? A sample
54 * program called "grab_gray_image" is included in the example
55 * directory of libdc1394. Please run grab_gray_image and see what
56 * happens. You can also use Coriander instead.
57 * (http://www.tele.ucl.ac.be/PEOPLE/DOUXCHAMPS/ieee1394/coriander/).
58 * 2) If you have make sure other programs can use the camera, but
59 * this module still does not work, please run the debbuging version
60 * of ohphone with option "-tttt -o log.txt". Examine the file "log.txt"
61 * and you may see what is wrong.
64 * Problem Reports:
65 * They should be send to Ryutaroh Matsumoto <ryutaroh@rmatsumoto.org>.
68 * Acknowledgment:
69 * R. Matsumoto thanks Dr. Derek Smithies for his kind support for making
70 * this module.
73 * Technical Notes for Programmers
74 * ------------------------------------------------------------
76 * Test Environment:
77 * This module was tested against:
79 * Pentium III
80 * Linux 2.4.19
81 * libraw1394 0.9.0
82 * libdc1394 0.9.0
84 * Irez StealthFire Camera (http://www.irez.com)
85 * OrangeMicro iBot Camera (http://www.orangemicro.com)
88 * Internal Structure:
89 * This module has been tested against the ohphone and GnomeMeeting
90 * video phone programs. They use 352x288 and 176x144 resolutions in
91 * YUV420P color format. So this module only supports these
92 * resolutions and YUV420P.
94 * 1394 Digital Cameras has many resolutions and color formats. Among
95 * them, this module uses:
96 * 160x120 YUV(4:4:4) for 176x144 PTlib resolution, and
97 * 320x240 YUV(4:2:2) for 352x288 PTlib resolution.
98 * The bus speed is always set to P_DC1394_DEFAULT_SPEED (400 Mbps).
99 * If transfer at P_DC1394_DEFAULT_SPEED is not supported by your
100 * camera, this module does not capture images from yours. In such
101 * a case please set P_DC1394_DEFAULT_SPEED to appropriate value.
103 * Conversion routines from above formats to YUV420P were added to
104 * src/ptlib/common/vconvert.cxx
106 * ToDo or Bugs:
107 * This module does not implement GetBrightness() etc. 1394 cameras
108 * can do both automatic control and manual control of brightness
109 * etc., and they are usually set to automatic
110 * control. Get/SetBrightness() etc. cannot access manual/automatic
111 * selection. So we cannot implement an interface that can fully
112 * control all of 1394 camera features. I decided not to implement
113 * controlling interface at all. Those features can be controlled by
114 * Coriander program even when ohphone or GnomeMeeting is being used.
115 * Please use Coriander.
117 * PVideoInputDevice_1394DC does not allow creation of two or more instances.
119 * The bus speed is always set to P_DC1394_DEFAULT_SPEED (400 Mbps).
120 * If transfer at P_DC1394_DEFAULT_SPEED is not supported by your
121 * camera, this module does not capture images from yours. In such
122 * a case please set P_DC1394_DEFAULT_SPEED to appropriate value.
124 * Copyright:
125 * Copyright (c) 2002 Ryutaroh Matsumoto <ryutaroh@rmatsumoto.org>
127 * The contents of this file are subject to the Mozilla Public License
128 * Version 1.0 (the "License"); you may not use this file except in
129 * compliance with the License. You may obtain a copy of the License at
130 * http://www.mozilla.org/MPL/
132 * Software distributed under the License is distributed on an "AS IS"
133 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
134 * the License for the specific language governing rights and limitations
135 * under the License.
139 * $Log$
140 * Revision 1.12 2007/04/27 17:34:45 dsandras
141 * Applied patch from Luc Saillard to fix things after the latest change
142 * which broke all drivers. Thanks Luc <luc saillard org>.
144 * Revision 1.11 2007/04/19 09:44:24 csoutheren
145 * Fix compilation of avc driver
147 * Revision 1.10 2007/04/14 07:08:55 rjongbloed
148 * Major update of video subsystem:
149 * Abstracted video frame info (width, height etc) into separate class.
150 * Changed devices, converter and video file to use above.
151 * Enhanced video file hint detection for frame rate and more
152 * flexible formats.
153 * Fixed issue if need to convert both colour format and size, had to do
154 * colour format first or it didn't convert size.
155 * Win32 video output device can be selected by "MSWIN" alone.
157 * Revision 1.9 2006/04/30 21:25:20 dsandras
158 * Fixed resolution detection thanks to Luc Saillard <luc saillard org>.
159 * Thanks a lot!
161 * Revision 1.8 2005/12/01 00:43:45 csoutheren
162 * Fixed typo
164 * Revision 1.7 2005/11/30 12:47:39 csoutheren
165 * Removed tabs, reformatted some code, and changed tags for Doxygen
167 * Revision 1.6 2005/08/09 09:08:10 rjongbloed
168 * Merged new video code from branch back to the trunk.
170 * Revision 1.5.6.2 2005/07/24 09:01:48 rjongbloed
171 * Major revisions of the PWLib video subsystem including:
172 * removal of F suffix on colour formats for vertical flipping, all done with existing bool
173 * working through use of RGB and BGR formats so now consistent
174 * cleaning up the plug in system to use virtuals instead of pointers to functions.
175 * rewrite of SDL to be a plug in compatible video output device.
176 * extensive enhancement of video test program
178 * Revision 1.5.6.1 2005/07/17 09:27:07 rjongbloed
179 * Major revisions of the PWLib video subsystem including:
180 * removal of F suffix on colour formats for vertical flipping, all done with existing bool
181 * working through use of RGB and BGR formats so now consistent
182 * cleaning up the plug in system to use virtuals instead of pointers to functions.
183 * rewrite of SDL to be a plug in compatible video output device.
184 * extensive enhancement of video test program
186 * Revision 1.5 2004/06/15 23:55:50 csoutheren
187 * Added check for different versions of dc1394 API
189 * Revision 1.4 2004/06/15 15:38:29 dsandras
190 * Fixed bug with latest API of libdc1394.
192 * Revision 1.3 2004/06/14 20:43:33 dsandras
193 * Try to fix compilation.
195 * Revision 1.2 2004/05/10 10:09:19 csoutheren
196 * Removed printf that was interpreted as a trigraph
198 * Revision 1.1 2003/12/17 15:40:56 dominance
199 * Added DC Plugin as provided by Julien Puydt <julien.puydt@laposte.net>. Needs manual patching of plugins/configure for now though. (i.e. disabled by default, run autoconf in plugins/)
201 * Revision 1.9 2003/03/17 07:53:04 robertj
202 * Removed canCaptureVideo variable as this is really a virtual function to
203 * distinguish PVideoOutputDevice from PVideoInputDevice, it is not dynamic.
205 * Revision 1.8 2002/08/21 00:00:31 dereks
206 * Patches from Ryutaroh, to improve firewire (linux only) support. Many thanks.
208 * Revision 1.7 2002/05/30 22:49:35 dereks
209 * correct implementation of GetInputDeviceNames().
211 * Revision 1.6 2002/03/04 01:21:31 dereks
212 * Add frame rate support to Firewire camera. Thanks Ryutaroh Matsumoto.
214 * Revision 1.5 2002/02/28 19:44:03 dereks
215 * Add complete readme on Firewire usage. Thanks to Ryutaroh Matsumoto.
217 * Revision 1.4 2002/02/21 20:00:21 dereks
218 * Fix memory leak. Thanks Ryutaroh Matsumoto.
220 * Revision 1.3 2002/02/21 19:49:57 dereks
221 * Fix spelling mistake. Thanks Ryutaroh
223 * Revision 1.2 2002/02/20 20:27:28 dereks
224 * updates to previous checkin.
226 * Revision 1.1 2002/02/20 02:37:26 dereks
227 * Initial release of Firewire camera support for linux.
228 * Many thanks to Ryutaroh Matsumoto <ryutaroh@rmatsumoto.org>.
235 #pragma implementation "videoio1394dc.h"
237 #include <ptlib.h>
238 #include <ptlib/videoio.h>
239 #include <ptlib/vconvert.h>
240 #include <ptlib/file.h>
241 #include "videoio1394dc.h"
242 #include <sys/utsname.h>
244 PCREATE_VIDINPUT_PLUGIN(1394DC);
246 #ifndef P_DC1394_DEFAULT_SPEED
247 #define P_DC1394_DEFAULT_SPEED SPEED_400
248 #endif
250 //#define ESTIMATE_CAPTURE_PERFORMANCE
252 #ifdef ESTIMATE_CAPTURE_PERFORMANCE
253 // for debugging
254 static PInt64 start_time;
255 static int num_captured;
256 #endif
259 ///////////////////////////////////////////////////////////////////////////////
260 // PVideoInput1394DC
262 PVideoInputDevice_1394DC::PVideoInputDevice_1394DC()
264 handle = NULL;
265 is_capturing = FALSE;
266 capturing_duration = 10000; // arbitrary large value suffices
269 PVideoInputDevice_1394DC::~PVideoInputDevice_1394DC()
271 Close();
274 #define OK 1
275 #define NG 0
276 static int kernel_version_ok(void)
278 struct utsname utsbuf;
279 unsigned major_ver, minor_ver, minorminor_ver;
281 if (uname(&utsbuf) == -1)
282 return NG;
284 /* utsbuf.release looks like "2.4.19-pre8". */
285 if (sscanf(utsbuf.release, "%u.%u.%u", &major_ver, &minor_ver,
286 &minorminor_ver) < 3)
287 return NG; /* Should we return OK? */
289 if (major_ver >= 3)
290 return OK;
291 else if (major_ver <= 1)
292 return NG;
294 if (minor_ver >= 6)
295 return OK;
296 else if (minor_ver <= 3)
297 return NG;
298 else if (minor_ver == 4)
299 return minorminor_ver >= 19;
300 else /* if (minor_ver == 5) */
301 return minorminor_ver >= 9;
304 BOOL PVideoInputDevice_1394DC::Open(const PString & devName, BOOL startImmediate)
306 if (!kernel_version_ok()) {
307 PTRACE(0, "The Linux kernel version is too old.");
308 return FALSE;
311 if (IsOpen()) {
312 PTRACE(0, "You cannot open PVideoInputDevice_1394DC twice.");
313 return FALSE;
316 if (devName == "/dev/raw1394")
317 UseDMA = FALSE;
318 // Don't forget /dev/video1394/0
319 else if (strncmp(devName, "/dev/video1394", 14) == 0)
320 UseDMA = TRUE;
321 else {
322 PTRACE(0, "devName must be /dev/raw1394 or /dev/video1394");
323 return FALSE;
326 // See if devName is accessible.
327 if (!PFile::Exists(devName)) {
328 PTRACE(1, devName << " is not accessible.");
329 return FALSE;
332 /*-----------------------------------------------------------------------
333 * Open ohci and asign handle to it
334 *-----------------------------------------------------------------------*/
335 handle = dc1394_create_handle(0);
336 if (handle==NULL)
338 PTRACE(0, "Unable to aquire a raw1394 handle\ndid you insmod the drivers?\n");
339 return FALSE;
342 /*-----------------------------------------------------------------------
343 * get the camera nodes and describe them as we find them
344 *-----------------------------------------------------------------------*/
345 int numNodes = raw1394_get_nodecount(handle);
346 camera_nodes = dc1394_get_camera_nodes(handle,&numCameras,0);
347 if (numCameras<1)
349 PTRACE(0, "no cameras found :(\n");
350 dc1394_destroy_handle(handle);
351 handle = NULL;
352 return FALSE;
355 /*-----------------------------------------------------------------------
356 * to prevent the iso-transfer bug from raw1394 system, check if
357 * camera is highest node. For details see
358 * http://linux1394.sourceforge.net/faq.html#DCbusmgmt
359 * and
360 * http://sourceforge.net/tracker/index.php?func=detail&aid=435107&group_id=8157&atid=108157
361 *-----------------------------------------------------------------------*/
362 for (int i=0; i<numCameras; i++) {
363 if( camera_nodes[i] == numNodes-1) {
364 PTRACE(0,"Sorry, your camera is the highest numbered node\n"
365 "of the bus, and has therefore become the root node.\n"
366 "The root node is responsible for maintaining \n"
367 "the timing of isochronous transactions on the IEEE \n"
368 "1394 bus. However, if the root node is not cycle master \n"
369 "capable (it doesn't have to be), then isochronous \n"
370 "transactions will not work. The host controller card is \n"
371 "cycle master capable, however, most cameras are not.\n"
372 "\n"
373 "The quick solution is to add the parameter \n"
374 "attempt_root=1 when loading the OHCI driver as a \n"
375 "module. So please do (as root):\n"
376 "\n"
377 " rmmod ohci1394\n"
378 " insmod ohci1394 attempt_root=1\n"
379 "\n"
380 "for more information see the FAQ at \n"
381 "http://linux1394.sourceforge.net/faq.html#DCbusmgmt\n"
382 "\n");
383 dc1394_destroy_handle(handle);
384 handle = NULL;
385 return FALSE;
389 frameHeight = 240;
390 frameWidth = 320;
391 colourFormat = "UYVY422";
392 capturing_duration = 10000; // arbitrary large value suffices
393 deviceName = devName;
395 // select the specified input and video format
396 if (!SetChannel(channelNumber) ||
397 !SetVideoFormat(videoFormat)) {
398 PTRACE(1, "SetChannel() or SetVideoFormat() failed");
399 Close();
400 return FALSE;
403 if (startImmediate && !Start()) {
404 Close();
405 return FALSE;
408 // Verify the format that the card accept
409 quadlet_t supported_framerates;
410 supportedFormat = 0;
411 if (dc1394_query_supported_framerates(handle, camera_nodes[channelNumber],
412 FORMAT_VGA_NONCOMPRESSED, MODE_320x240_YUV422,
413 &supported_framerates) == DC1394_SUCCESS) {
414 supportedFormat |= DC1394_FORMAT_320x240;
417 if (dc1394_query_supported_framerates(handle, camera_nodes[channelNumber],
418 FORMAT_VGA_NONCOMPRESSED, MODE_160x120_YUV444,
419 &supported_framerates) == DC1394_SUCCESS) {
420 supportedFormat |= DC1394_FORMAT_160x120;
423 PTRACE(3, "Successfully opended\n");
424 return TRUE;
428 BOOL PVideoInputDevice_1394DC::IsOpen()
430 return handle != NULL;
434 BOOL PVideoInputDevice_1394DC::Close()
436 if (IsOpen()) {
437 if (IsCapturing())
438 Stop();
439 dc1394_destroy_handle(handle);
440 handle = NULL;
441 return TRUE;
442 } else
443 return FALSE;
446 BOOL PVideoInputDevice_1394DC::Start()
448 int dc1394_mode;
449 if (!IsOpen()) return FALSE;
450 if (is_capturing) return TRUE;
451 if (frameWidth == 320 && frameHeight == 240)
452 dc1394_mode = MODE_320x240_YUV422;
453 else if (frameWidth == 160 && frameHeight == 120)
454 dc1394_mode = MODE_160x120_YUV444;
455 else {
456 PTRACE(1, "Frame size is neither 320x240 or 160x120" << frameWidth << "x" << frameHeight);
457 return FALSE;
459 PTRACE(1, deviceName << " " << channelNumber);
461 quadlet_t supported_framerates;
462 if (dc1394_query_supported_framerates(handle, camera_nodes[channelNumber],
463 FORMAT_VGA_NONCOMPRESSED, dc1394_mode,
464 &supported_framerates) != DC1394_SUCCESS) {
465 PTRACE(1, "dc1394_query_supported_framerates() failed.");
466 return FALSE;
469 int framerate;
471 // supported_framerates seems always in the network byte order.
472 if (supported_framerates & (1U << (31-5)))
473 framerate = FRAMERATE_60;
474 else if (supported_framerates & (1U << (31-4)))
475 framerate = FRAMERATE_30;
476 else if (supported_framerates & (1U << (31-3)))
477 framerate = FRAMERATE_15;
478 else if (supported_framerates & (1U << (31-2)))
479 framerate = FRAMERATE_7_5;
480 else if (supported_framerates & (1U << (31-1)))
481 framerate = FRAMERATE_3_75;
482 else if (supported_framerates & (1U << (31-0)))
483 framerate = FRAMERATE_1_875;
484 else {
485 PTRACE(1, "Frame rate " << supported_framerates << " is not supported");
486 return FALSE;
489 // In order to compile the following line, you need libdc1394 0.9.0 or later.
490 if ((UseDMA &&dc1394_dma_setup_capture(handle,camera_nodes[channelNumber],
491 0, /* channel of IEEE 1394 */
492 FORMAT_VGA_NONCOMPRESSED,
493 dc1394_mode,
494 P_DC1394_DEFAULT_SPEED,
495 framerate, 4, 1,
496 #ifdef NEW_DC_API
498 #endif
499 deviceName,
500 &camera)!=DC1394_SUCCESS) ||
501 (!UseDMA && dc1394_setup_capture(handle,camera_nodes[channelNumber],
502 0, /* channel of IEEE 1394 */
503 FORMAT_VGA_NONCOMPRESSED,
504 dc1394_mode,
505 P_DC1394_DEFAULT_SPEED,
506 framerate,
507 &camera)!=DC1394_SUCCESS))
509 PTRACE(0,"unable to setup camera-\n"
510 "check " __FILE__ " to make sure\n"
511 "that the video mode,framerate and format are\n"
512 "supported by your camera\n");
513 return FALSE;
516 /*-----------------------------------------------------------------------
517 * have the camera start sending us data
518 *-----------------------------------------------------------------------*/
519 if (dc1394_start_iso_transmission(handle,camera.node)
520 !=DC1394_SUCCESS)
522 PTRACE(0, "unable to start camera iso transmission\n");
523 if (UseDMA)
524 dc1394_dma_release_camera(handle,&camera);
525 else
526 dc1394_release_camera(handle,&camera);
527 return FALSE;
529 is_capturing = TRUE;
530 #ifdef ESTIMATE_CAPTURE_PERFORMANCE
531 PTime now;
532 start_time = now.GetTimestamp();
533 num_captured = 0;
534 #endif
535 return TRUE;
539 BOOL PVideoInputDevice_1394DC::Stop()
541 if (IsCapturing()) {
542 dc1394_stop_iso_transmission(handle,camera.node);
543 if (UseDMA) {
544 dc1394_dma_unlisten(handle, &camera);
545 dc1394_dma_release_camera(handle,&camera);
546 } else
547 dc1394_release_camera(handle,&camera);
548 is_capturing = FALSE;
549 return TRUE;
550 } else
551 return FALSE;
555 BOOL PVideoInputDevice_1394DC::IsCapturing()
557 return is_capturing;
560 PStringList PVideoInputDevice_1394DC::GetInputDeviceNames()
562 PStringList list;
564 if (PFile::Exists("/dev/raw1394"))
565 list.AppendString("/dev/raw1394");
567 if (PFile::Exists("/dev/video1394/0")) {
569 // DEVFS naming scheme
570 for (int i=0; ; i++) {
571 PString devname = PString("/dev/video1394/") + PString(i);
572 if (PFile::Exists(devname))
573 list.AppendString(devname);
574 else
575 break;
578 else if (PFile::Exists("/dev/video1394"))
579 /* traditional naming */
580 list.AppendString("/dev/video1394");
582 return list;
586 BOOL PVideoInputDevice_1394DC::SetVideoFormat(VideoFormat newFormat)
588 if (!PVideoDevice::SetVideoFormat(newFormat)) {
589 PTRACE(3,"PVideoDevice::SetVideoFormat\t failed for format "<<newFormat);
590 return FALSE;
592 return TRUE;
595 int PVideoInputDevice_1394DC::GetBrightness()
597 return -1;
601 BOOL PVideoInputDevice_1394DC::SetBrightness(unsigned newBrightness)
603 return FALSE;
607 int PVideoInputDevice_1394DC::GetHue()
609 return -1;
613 BOOL PVideoInputDevice_1394DC::SetHue(unsigned newHue)
615 return FALSE;
619 int PVideoInputDevice_1394DC::GetContrast()
621 return -1;
625 BOOL PVideoInputDevice_1394DC::SetContrast(unsigned newContrast)
627 return FALSE;
630 BOOL PVideoInputDevice_1394DC::SetColour(unsigned newColour)
632 return -1;
635 int PVideoInputDevice_1394DC::GetColour()
637 return -1;
641 BOOL PVideoInputDevice_1394DC::SetWhiteness(unsigned newWhiteness)
643 return FALSE;
646 int PVideoInputDevice_1394DC::GetWhiteness()
648 return -1;
652 BOOL PVideoInputDevice_1394DC::GetParameters (int *whiteness, int *brightness,
653 int *colour, int *contrast, int *hue)
655 *whiteness = -1;
656 *brightness = -1;
657 *colour = -1;
658 *hue = -1;
659 return FALSE;
663 int PVideoInputDevice_1394DC::GetNumChannels()
665 return numCameras;
669 BOOL PVideoInputDevice_1394DC::SetChannel(int newChannel)
671 if (PVideoDevice::SetChannel(newChannel) == FALSE)
672 return FALSE;
673 if(IsCapturing()) {
674 Stop();
675 Start();
677 return TRUE;
682 BOOL PVideoInputDevice_1394DC::SetFrameRate(unsigned rate)
684 if (!PVideoDevice::SetFrameRate(rate))
685 return FALSE;
687 return TRUE;
691 BOOL PVideoInputDevice_1394DC::GetFrameSizeLimits(unsigned & minWidth,
692 unsigned & minHeight,
693 unsigned & maxWidth,
694 unsigned & maxHeight)
696 minWidth = 160;
697 maxWidth = 320;
698 minHeight = 120;
699 maxHeight = 240;
700 return TRUE;
704 PINDEX PVideoInputDevice_1394DC::GetMaxFrameBytes()
706 return GetMaxFrameBytesConverted(frameBytes);
710 BOOL PVideoInputDevice_1394DC::GetFrameDataNoDelay(BYTE * buffer, PINDEX * bytesReturned)
712 if (!IsCapturing()) return FALSE;
714 PTRACE(3, "We are going to single capture.\n");
715 if ((UseDMA && dc1394_dma_single_capture(&camera)!=DC1394_SUCCESS) ||
716 (!UseDMA && dc1394_single_capture(handle,&camera)!=DC1394_SUCCESS)){
717 PTRACE(1, "dc1394_single_capture() failed.");
718 return FALSE;
721 PTRACE(3, "single captured, try to convert\n");
723 // If converting on the fly do it from frame store to output buffer, otherwise do
724 // straight copy.
725 if (converter != NULL)
726 converter->Convert((const BYTE *)camera.capture_buffer, buffer, bytesReturned);
727 else {
728 PTRACE(1, "Converter must exist. Something goes wrong.");
729 return FALSE;
732 #ifdef ESTIMATE_CAPTURE_PERFORMANCE
733 ++num_captured;
734 PTime now;
735 double capturing_time = (double)((now.GetTimestamp()-start_time))/1000000;
736 ::fprintf(stderr, "time %f, num_captured=%d, fps=%f\n", capturing_time, num_captured, num_captured/capturing_time);
737 #endif
739 if (UseDMA)
740 dc1394_dma_done_with_buffer(&camera);
741 return TRUE;
744 BOOL PVideoInputDevice_1394DC::GetFrameData(BYTE * buffer, PINDEX * bytesReturned)
746 m_pacing.Delay(1000/GetFrameRate());
747 return GetFrameDataNoDelay(buffer,bytesReturned);
751 void PVideoInputDevice_1394DC::ClearMapping()
756 BOOL PVideoInputDevice_1394DC::TestAllFormats()
758 return TRUE;
762 BOOL PVideoInputDevice_1394DC::SetColourFormat(const PString & newFormat)
764 return newFormat == colourFormat;
768 BOOL PVideoInputDevice_1394DC::SetFrameSize(unsigned width, unsigned height)
770 if (width == 320 && height == 240) {
771 if (!(supportedFormat & DC1394_FORMAT_320x240))
772 return FALSE;
773 colourFormat = "UYVY422";
775 else if (width == 160 && height == 120) {
776 if (!(supportedFormat & DC1394_FORMAT_160x120))
777 return FALSE;
778 colourFormat = "UYV444";
780 else
781 return FALSE;
783 frameWidth = width;
784 frameHeight = height;
786 frameBytes = PVideoDevice::CalculateFrameBytes(frameWidth, frameHeight, colourFormat);
788 if (IsCapturing()) {
789 Stop();
790 Start();
793 return TRUE;
798 // End Of File ///////////////////////////////////////////////////////////////