[artoolkit-commits] artoolkit/lib/SRC/VideoLinux1394Cam video.c,1.1.1.1,1.2
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2004-11-22 02:33:08
|
Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinux1394Cam In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13718 Modified Files: video.c Log Message: Linux video driver updates and patches. Index: video.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinux1394Cam/video.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** video.c 4 Nov 2004 08:51:47 -0000 1.1.1.1 --- video.c 22 Nov 2004 02:32:48 -0000 1.2 *************** *** 1,9 **** /* * Video capture subrutine for Linux/libdc1394 devices * author: Kiyoshi Kiyokawa ( ki...@cr... ) ! Hirokazu Kato ( ka...@sy... ) * - * Revision: 1.0 Date: 2002/01/01 */ #include <sys/ioctl.h> #include <sys/types.h> --- 1,18 ---- /* + * Revision: 1.0 Date: 2002/01/01 * Video capture subrutine for Linux/libdc1394 devices * author: Kiyoshi Kiyokawa ( ki...@cr... ) ! * Hirokazu Kato ( ka...@sy... ) ! * ! * ! * Revision: 1.1 Date: 2004/09/30 ! * Modifications by Wayne Piekarski ( wa...@cs... ) ! * - #ifdef macros added to support the many different versions of libdc1394 ! * - Initialisation code rewritten to support multiple 1394 busses ! * - Either autodetect of cameras or specifying the exact camera is now possible ! * - Support for changing of various 1394 camera properties * */ + #include <sys/ioctl.h> #include <sys/types.h> *************** *** 23,26 **** --- 32,82 ---- + + + /* Do not touch the following macros! */ + #undef LIBDC_8 + #undef LIBDC_9 + #undef LIBDC_10 + #undef LIBDC_DEF + + + /* ----------------------- MAKE ANY #define CHANGES HERE ONLY -------------------------------- */ + /* This define controls if we use the new or old libDC1394 API functions. The new code is much + more stable for multiple cameras and so is recommended */ + // #define LIBDC_8 + // #define LIBDC_9 + #define LIBDC_10 + /* ----------------------- MAKE ANY #define CHANGES HERE ONLY -------------------------------- */ + + + /* These are some extra constants I defined for my modifications */ + #define DEFAULT_VIDEO_CARD -1 + #define MAX_PORTS 4 /* This is the maximum number of Firewire cards we can have installed in the system, it is an arbitrary number */ + + + /* Error checking to ensure we have a proper configuration, and put some debugging out */ + #ifdef LIBDC_8 + #warning Compiling using original 0.8.3 libDC library (single camera only) - debian: libdc1394-8-dev + #warning The 0.8.3 libDC code is dangerous and has a number of bugs which will cause trouble - upgrade to 0.9.1 or later! + #define LIBDC_DEF + #endif + + #ifdef LIBDC_9 + #warning Compiling using the newer and safer 0.9.1 libDC library (multiple camera support) - debian: libdc1394-9-dev + #define LIBDC_DEF + #endif + + #ifdef LIBDC_10 + #warning Compiling using the newer and safer 0.9.5 libDC library (multiple camera support) - debian: libdc1394-10-dev + #define LIBDC_DEF + #endif + + #ifndef LIBDC_DEF + #error One of the LIBDC_[8,9,10] macros must be defined to compile this code properly! + #endif + + + + static AR2VideoParamT *gVid = NULL; *************** *** 94,101 **** { raw1394handle_t handle; - int numNodes; - int numCameras; - nodeid_t *camera_nodes; - int *activeFlag; } ARVideo1394; --- 150,153 ---- *************** *** 103,107 **** static int initFlag = 0; ! static int ar2Video1394Init( int debug ); --- 155,159 ---- static int initFlag = 0; ! static int ar2Video1394Init( int debug, int *card, int *node ); *************** *** 112,122 **** printf(" -node=N\n"); printf(" specifies detected node ID of a FireWire camera (-1: Any).\n"); ! printf(" -mode=[320x240_YUV422|640x480_RGB|640x480_YUV411|\n"); ! printf(" 640x480_YUV411_HALF|640x480_MONO|640x480_MONO_COLOR\n"); ! printf(" 640x480_MONO_COLOR_HALF]\n"); printf(" specifies input image format.\n"); printf(" -rate=N\n"); printf(" specifies desired framerate of a FireWire camera. \n"); printf(" (1.875, 3.75, 7.5, 15, 30, 60)\n"); printf("\n"); --- 164,176 ---- printf(" -node=N\n"); printf(" specifies detected node ID of a FireWire camera (-1: Any).\n"); ! printf(" -card=N\n"); ! printf(" specifies the FireWire adaptor id number (-1: Any).\n"); ! printf(" -mode=[320x240_YUV422|640x480_RGB|640x480_YUV411]\n"); printf(" specifies input image format.\n"); printf(" -rate=N\n"); printf(" specifies desired framerate of a FireWire camera. \n"); printf(" (1.875, 3.75, 7.5, 15, 30, 60)\n"); + printf(" -[name]=N where name is brightness, iris, shutter, gain, saturation, gamma, sharpness\n"); + printf(" (value must be a legal value for this parameter - use coriander to find what they are\n"); printf("\n"); *************** *** 126,129 **** --- 180,184 ---- AR2VideoParamT *ar2VideoOpen( char *config ) { + char video1394devname [128]; AR2VideoParamT *vid; ARUint32 p1,p2; *************** *** 132,140 **** int i; arMalloc( vid, AR2VideoParamT, 1 ); vid->node = DEFAULT_VIDEO_NODE; vid->mode = DEFAULT_VIDEO_MODE; vid->rate = DEFAULT_VIDEO_FRAME_RATE; ! //vid->channel = 0; vid->speed = SPEED_400; vid->format = FORMAT_VGA_NONCOMPRESSED; --- 187,204 ---- int i; + int brightness = -1; + int iris = -1; + int shutter = -1; + int gain = -1; + int saturation = -1; + int gamma = -1; + int sharpness = -1; + arMalloc( vid, AR2VideoParamT, 1 ); vid->node = DEFAULT_VIDEO_NODE; + vid->card = DEFAULT_VIDEO_CARD; vid->mode = DEFAULT_VIDEO_MODE; vid->rate = DEFAULT_VIDEO_FRAME_RATE; ! vid->channel = 0; vid->speed = SPEED_400; vid->format = FORMAT_VGA_NONCOMPRESSED; *************** *** 153,159 **** vid->mode = VIDEO_MODE_320x240_YUV422; } - else if ( strncmp( &a[6], "640x480_YUV411_HALF", 19 ) == 0 ) { - vid->mode = VIDEO_MODE_640x480_YUV411_HALF; - } else if ( strncmp( &a[6], "640x480_YUV411", 14 ) == 0 ) { vid->mode = VIDEO_MODE_640x480_YUV411; --- 217,220 ---- *************** *** 162,175 **** vid->mode = VIDEO_MODE_640x480_RGB; } ! else if ( strncmp( &a[6], "640x480_MONO_COLOR_HALF", 23 ) == 0 ) { ! vid->mode = VIDEO_MODE_640x480_MONO_COLOR_HALF; ! } ! else if ( strncmp( &a[6], "640x480_MONO_COLOR", 18 ) == 0 ) { ! vid->mode = VIDEO_MODE_640x480_MONO_COLOR; } ! else if ( strncmp( &a[6], "640x480_MONO", 12 ) == 0 ) { ! vid->mode = VIDEO_MODE_640x480_MONO; } ! else { ar2VideoDispOption(); free( vid ); --- 223,244 ---- vid->mode = VIDEO_MODE_640x480_RGB; } ! else { ! ar2VideoDispOption(); ! free( vid ); ! return 0; } ! } ! ! else if( strncmp( a, "-iris=", 6 ) == 0 ) { ! sscanf( a, "%s", line ); ! if( sscanf( &line[6], "%d", &iris ) == 0 ) { ! ar2VideoDispOption(); ! free( vid ); ! return 0; } ! } ! else if( strncmp( a, "-gain=", 6 ) == 0 ) { ! sscanf( a, "%s", line ); ! if( sscanf( &line[6], "%d", &gain ) == 0 ) { ar2VideoDispOption(); free( vid ); *************** *** 177,180 **** --- 246,250 ---- } } + else if( strncmp( a, "-node=", 6 ) == 0 ) { sscanf( a, "%s", line ); *************** *** 185,188 **** --- 255,266 ---- } } + else if( strncmp( a, "-card=", 6 ) == 0 ) { + sscanf( a, "%s", line ); + if( sscanf( &line[6], "%d", &vid->card ) == 0 ) { + ar2VideoDispOption(); + free( vid ); + return 0; + } + } else if( strncmp( a, "-rate=", 6 ) == 0 ) { if ( strncmp( &a[6], "1.875", 5 ) == 0 ) { *************** *** 223,247 **** } ! if( initFlag == 0 ) { ! if( ar2Video1394Init(vid->debug) < 0 ) exit(0); initFlag = 1; } - - for( i=0; i<arV1394.numCameras; i++ ) { - if( (vid->node == VIDEO_NODE_ANY && arV1394.activeFlag[i] == 0) || (arV1394.camera_nodes[i] == vid->node) ) { - if( vid->debug ) printf("Using a camera #%d (Node ID = %d)\n", i, arV1394.camera_nodes[i]); - vid->internal_id = i; - if( vid->node == VIDEO_NODE_ANY ) vid->node = arV1394.camera_nodes[i]; - break; - } - } - if( i == arV1394.numCameras ) { - printf("cound not find the specified camera.\n"); - exit(0); - } - - vid->channel = vid->node; - switch( vid->mode ) { case VIDEO_MODE_320x240_YUV422: --- 301,312 ---- } ! ! if( initFlag == 0 ) ! { ! if( ar2Video1394Init(vid->debug, &vid->card, &vid->node) < 0 ) ! exit(0); initFlag = 1; } switch( vid->mode ) { case VIDEO_MODE_320x240_YUV422: *************** *** 249,253 **** break; case VIDEO_MODE_640x480_YUV411: - case VIDEO_MODE_640x480_YUV411_HALF: vid->int_mode = MODE_640x480_YUV411; break; --- 314,317 ---- *************** *** 255,263 **** vid->int_mode = MODE_640x480_RGB; break; - case VIDEO_MODE_640x480_MONO: - case VIDEO_MODE_640x480_MONO_COLOR: - case VIDEO_MODE_640x480_MONO_COLOR_HALF: - vid->int_mode = MODE_640x480_MONO; - break; default: printf("Sorry, Unsupported Video Format for IEEE1394 Camera.\n"); --- 319,322 ---- *************** *** 300,303 **** --- 359,381 ---- } + + /* Change the camera settings if we need to */ + if (iris != -1) + { + fprintf (stderr, "Adjusting IRIS setting to %d\n", iris); + dc1394_set_iris (arV1394.handle, vid->node, (unsigned int)iris); + } + if (gain != -1) + { + fprintf (stderr, "Adjusting GAIN setting to %d\n", gain); + dc1394_set_gain (arV1394.handle, vid->node, (unsigned int)gain); + } + + + /* Dump out the new parameters now */ + if (vid->debug) + dc1394_print_feature_set( &(vid->features) ); + + /*-----------------------------------------------------------------------*/ /* check parameters */ *************** *** 335,341 **** /* setup capture */ /*-----------------------------------------------------------------------*/ if( dc1394_dma_setup_capture(arV1394.handle, vid->node, ! vid->channel, vid->format, vid->int_mode, --- 413,424 ---- /* setup capture */ /*-----------------------------------------------------------------------*/ + sprintf (video1394devname, "/dev/video1394/%d", vid->card); if( dc1394_dma_setup_capture(arV1394.handle, vid->node, ! #ifndef LIBDC_8 ! vid->node, ! #else ! vid->channel, ! #endif vid->format, vid->int_mode, *************** *** 343,346 **** --- 426,435 ---- vid->int_rate, vid->dma_buf_num, + #ifdef LIBDC_10 + 0, /* do_extra_buffering */ + #endif + #ifndef LIBDC_8 + 1, video1394devname, /* drop_frames, dma_device_file */ + #endif &(vid->camera)) != DC1394_SUCCESS ) { fprintf( stderr,"unable to setup camera-\n" *************** *** 360,365 **** arMalloc( vid->image, ARUint8, (vid->camera.frame_width * vid->camera.frame_height * AR_PIX_SIZE) ); - arV1394.activeFlag[vid->internal_id] = 1; - return vid; } --- 449,452 ---- *************** *** 374,389 **** dc1394_dma_release_camera(arV1394.handle, &(vid->camera)); #endif - arV1394.activeFlag[vid->internal_id] = 0; free( vid->image ); free( vid ); ! ! for( i=0; i<arV1394.numCameras; i++ ) { ! if( arV1394.activeFlag[i] ) break; ! } ! if( i == arV1394.numCameras ) { ! raw1394_destroy_handle(arV1394.handle); ! free (arV1394.activeFlag); initFlag = 0; - } return 0; --- 461,469 ---- dc1394_dma_release_camera(arV1394.handle, &(vid->camera)); #endif free( vid->image ); free( vid ); ! ! raw1394_destroy_handle(arV1394.handle); initFlag = 0; return 0; *************** *** 392,395 **** --- 472,478 ---- int ar2VideoCapStart( AR2VideoParamT *vid ) { + char video1394devname [128]; + + if(vid->status != 0 && vid->status != 3){ printf("arVideoCapStart has already been called.\n"); *************** *** 400,407 **** /* setup capture */ /*-----------------------------------------------------------------------*/ if( vid->status == 3 ) { if( dc1394_dma_setup_capture(arV1394.handle, vid->node, ! vid->channel, vid->format, vid->int_mode, --- 483,495 ---- /* setup capture */ /*-----------------------------------------------------------------------*/ + sprintf (video1394devname, "/dev/video1394/%d", vid->card); if( vid->status == 3 ) { if( dc1394_dma_setup_capture(arV1394.handle, vid->node, ! #ifndef LIBDC_8 ! vid->node, ! #else ! vid->channel, ! #endif vid->format, vid->int_mode, *************** *** 409,412 **** --- 497,506 ---- vid->int_rate, vid->dma_buf_num, + #ifdef LIBDC_10 + 0, /* do_extra_buffering */ + #endif + #ifndef LIBDC_8 + 1, video1394devname, /* drop_frames, dma_device_file */ + #endif &(vid->camera)) != DC1394_SUCCESS ) { fprintf( stderr,"unable to setup camera-\n" *************** *** 477,481 **** { register ARUint8 *buf, *buf2; - register ARUint8 *p1, *p2, *p3; register int i, j; register int U, V, R, G, B, V2, U5, UV; --- 571,574 ---- *************** *** 499,507 **** ! switch( vid->mode ) { ! case VIDEO_MODE_640x480_RGB: return (ARUint8 *)vid->camera.capture_buffer; ! case VIDEO_MODE_640x480_YUV411: buf = vid->image; buf2 = (ARUint8 *)vid->camera.capture_buffer; --- 592,600 ---- ! switch( vid->int_mode ) { ! case MODE_640x480_RGB: return (ARUint8 *)vid->camera.capture_buffer; ! case MODE_640x480_YUV411: buf = vid->image; buf2 = (ARUint8 *)vid->camera.capture_buffer; *************** *** 578,661 **** return vid->image; ! case VIDEO_MODE_640x480_YUV411_HALF: ! buf = vid->image; ! buf2 = (ARUint8 *)vid->camera.capture_buffer; ! for( j = 0; j < vid->camera.frame_height / 2; j++ ) { ! for( i = 0; i < vid->camera.frame_width / 4; i++ ) { ! U = ((ARUint8)*buf2++ - 128) * 0.354; ! U5 = 5*U; ! Y0 = (ARUint8)*buf2++; ! Y1 = (ARUint8)*buf2++; ! V = ((ARUint8)*buf2++ - 128) * 0.707; ! V2 = 2*V; ! Y2 = (ARUint8)*buf2++; ! Y3 = (ARUint8)*buf2++; ! UV = - U - V; ! ! // Original equations ! // R = Y + 1.402 V ! // G = Y - 0.344 U - 0.714 V ! // B = Y + 1.772 U ! R = Y0 + V2; ! if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0; ! ! G = Y0 + UV; ! if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0; ! ! B = Y0 + U5; ! if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0; ! ! *buf++ = (ARUint8)R; ! *buf++ = (ARUint8)G; ! *buf++ = (ARUint8)B; ! ! //--- ! R = Y1 + V2; ! if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0; ! ! G = Y1 + UV; ! if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0; ! ! B = Y1 + U5; ! if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0; ! ! *buf++ = (ARUint8)R; ! *buf++ = (ARUint8)G; ! *buf++ = (ARUint8)B; ! ! //--- ! R = Y2 + V2; ! if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0; ! ! G = Y2 + UV; ! if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0; ! ! B = Y2 + U5; ! if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0; ! ! *buf++ = (ARUint8)R; ! *buf++ = (ARUint8)G; ! *buf++ = (ARUint8)B; ! ! //--- ! R = Y3 + V2; ! if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0; ! ! G = Y3 + UV; ! if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0; ! ! B = Y3 + U5; ! if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0; ! ! *buf++ = (ARUint8)R; ! *buf++ = (ARUint8)G; ! *buf++ = (ARUint8)B; ! } ! buf2 += (vid->camera.frame_width / 4) * 6; ! buf += vid->camera.frame_width * 3; ! } ! return vid->image; ! ! case VIDEO_MODE_320x240_YUV422: buf = vid->image; buf2 = (ARUint8 *)vid->camera.capture_buffer; --- 671,675 ---- return vid->image; ! case MODE_320x240_YUV422: buf = vid->image; buf2 = (ARUint8 *)vid->camera.capture_buffer; *************** *** 698,884 **** } return vid->image; - - case VIDEO_MODE_640x480_MONO: - buf = vid->image; - buf2 = (ARUint8 *)vid->camera.capture_buffer; - for( i = vid->camera.frame_height * vid->camera.frame_width; i; i--) { - *buf++ = *buf2; - *buf++ = *buf2; - *buf++ = *buf2++; - } - return vid->image; - - case VIDEO_MODE_640x480_MONO_COLOR: - buf = vid->image; - p2 = (ARUint8 *)vid->camera.capture_buffer; - p3 = p2 + vid->camera.frame_width; - - *buf++ = *p2; - *buf++ = *(p2+1); - *buf++ = *(p3+1); - p2++; - p3++; - for( i = vid->camera.frame_width/2-1; i; i-- ) { - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = *p2; - *buf++ = *p3; - p2++; - p3++; - *buf++ = *p2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = ((int)*(p3-1) + (int)*(p3+1))/2; - p2++; - p3++; - } - *buf++ = *(p2-1); - *buf++ = *p2; - *buf++ = *p3; - p2++; - p3++; - p1 = (ARUint8 *)vid->camera.capture_buffer; - - for( j = vid->camera.frame_height/2-1; j; j-- ) { - *buf++ = ((int)*p1 + (int)*p3)/2; - *buf++ = *p2; - *buf++ = *(p2+1); - p1++; - p2++; - p3++; - for( i = vid->camera.frame_width/2-1; i; i-- ) { - *buf++ = ((int)*(p1-1) + (int)*(p1+1) + (int)*(p3-1) + (int)*(p3+1))/4; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = *p2; - p1++; - p2++; - p3++; - *buf++ = ((int)*p1 + (int)*p3)/2; - *buf++ = *p2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - p1++; - p2++; - p3++; - } - *buf++ = ((int)*(p1-1) + (int)*(p3-1))/2; - *buf++ = ((int)*p1 + (int)*p3)/2; - *buf++ = *p2; - p1++; - p2++; - p3++; - - *buf++ = *p2; - *buf++ = ((int)*p1 + (int)*p3)/2; - *buf++ = ((int)*(p1+1) + (int)*(p3+1))/2; - p1++; - p2++; - p3++; - for( i = vid->camera.frame_width/2-1; i; i-- ) { - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = *p2; - *buf++ = ((int)*p1 + (int)*p3)/2; - p1++; - p2++; - p3++; - *buf++ = *p2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = ((int)*(p1-1) + (int)*(p1+1) + (int)*(p3-1) + (int)*(p3+1))/4; - p1++; - p2++; - p3++; - } - *buf++ = *(p2-1); - *buf++ = *p2; - *buf++ = ((int)*p1 + (int)*p3)/2; - p1++; - p2++; - p3++; - } - - *buf++ = *p1; - *buf++ = *p2; - *buf++ = *(p2+1); - p1++; - p2++; - for( i = vid->camera.frame_width/2; i; i-- ) { - *buf++ = ((int)*(p1-1) + (int)*(p1+1))/2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = *p2; - p1++; - p2++; - *buf++ = *p1; - *buf++ = *p2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - p1++; - p2++; - } - *buf++ = *(p1-1); - *buf++ = *(p2-1); - *buf++ = *p2; - - return vid->image; - - case VIDEO_MODE_640x480_MONO_COLOR_HALF: - buf = vid->image; - p2 = (ARUint8 *)vid->camera.capture_buffer; - p3 = p2 + vid->camera.frame_width; - - *buf++ = *p2; - *buf++ = *(p2+1); - *buf++ = *(p3+1); - p2++; - p3++; - for( i = vid->camera.frame_width/2-1; i; i-- ) { - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = *p2; - *buf++ = *p3; - p2++; - p3++; - *buf++ = *p2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = ((int)*(p3-1) + (int)*(p3+1))/2; - p2++; - p3++; - } - *buf++ = *(p2-1); - *buf++ = *p2; - *buf++ = *p3; - p2++; - p3++; - p1 = (ARUint8 *)vid->camera.capture_buffer; - - for( j = vid->camera.frame_height/2-1; j; j-- ) { - p1 += vid->camera.frame_width; - p2 += vid->camera.frame_width; - p3 += vid->camera.frame_width; - buf += vid->camera.frame_width * 3; - - *buf++ = *p2; - *buf++ = ((int)*p1 + (int)*p3)/2; - *buf++ = ((int)*(p1+1) + (int)*(p3+1))/2; - p1++; - p2++; - p3++; - for( i = vid->camera.frame_width/2-1; i; i-- ) { - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = *p2; - *buf++ = ((int)*p1 + (int)*p3)/2; - p1++; - p2++; - p3++; - *buf++ = *p2; - *buf++ = ((int)*(p2-1) + (int)*(p2+1))/2; - *buf++ = ((int)*(p1-1) + (int)*(p1+1) + (int)*(p3-1) + (int)*(p3+1))/4; - p1++; - p2++; - p3++; - } - *buf++ = *(p2-1); - *buf++ = *p2; - *buf++ = ((int)*p1 + (int)*p3)/2; - p1++; - p2++; - p3++; - } - - return vid->image; } --- 712,715 ---- *************** *** 889,943 **** ! static int ar2Video1394Init( int debug ) { int i; ! ! /*-----------------------------------------------------------------------*/ ! /* Open ohci and asign handle to it */ ! /*-----------------------------------------------------------------------*/ ! arV1394.handle = dc1394_create_handle(0); ! if (arV1394.handle==NULL) { ! fprintf( stderr, "Unable to aquire a raw1394 handle\n" ! "did you insmod the drivers?\n"); ! exit(0); ! } ! ! /*-----------------------------------------------------------------------*/ ! /* get the camera nodes and describe them as we find them */ ! /*-----------------------------------------------------------------------*/ ! arV1394.numNodes = raw1394_get_nodecount(arV1394.handle); ! arV1394.camera_nodes = dc1394_get_camera_nodes(arV1394.handle,&arV1394.numCameras,((debug)? 1: 0)); ! fflush(stdout); ! if (arV1394.numCameras<1) { ! fprintf( stderr, "no cameras found :(\n"); ! raw1394_destroy_handle(arV1394.handle); ! exit(0); ! } ! if( debug ) { ! printf("%d camera(s) found on the bus\n", arV1394.numCameras); ! printf("Node IDs are: "); ! for (i=0; i<arV1394.numCameras; i++) { ! printf("%d, ", arV1394.camera_nodes[i]); ! } ! printf("\n"); ! } ! ! arMalloc( arV1394.activeFlag, int, arV1394.numCameras ); ! for( i=0; i<arV1394.numCameras; i++ ) { ! if( arV1394.camera_nodes[i] == arV1394.numNodes-1) { ! fprintf( stderr, "\n" ! "If ohci1394 is not working as root, please do:\n" ! "\n" ! " rmmod ohci1394\n" ! " insmod ohci1394 attempt_root=1\n" ! "\n" ! "Otherwise, try to change FireWire connections so that\n" ! "the highest number is not given to any camera.\n"); ! exit(0); ! } ! ! arV1394.activeFlag[i] = 0; ! } ! return 0; } --- 720,814 ---- ! static int ar2Video1394Init( int debug, int *card, int *node ) { int i; ! ! /* The user must either specify both card and node, or neither of them */ ! if (((*card == -1) && (*node != -1)) || ! ((*card != -1) && (*node == -1))) ! { ! fprintf (stderr, "Card value is %d and node value is %d, you must either auto-detect both or specify both\n"); ! exit (1); ! } ! ! /* If the user has specified so, we will autodetect for the camera and grab the first one we can find */ ! if ((*card == -1) && (*node == -1)) ! { ! /* Find the total number of firewire cards in the system */ ! int numPorts = MAX_PORTS; ! int p; ! struct raw1394_portinfo ports[MAX_PORTS]; ! raw1394handle_t raw_handle = raw1394_new_handle (); ! if (raw_handle == NULL) ! { ! fprintf (stderr, "Could not acquire a raw1394 handle - driver not installed?\n"); ! exit (1); ! } ! numPorts = raw1394_get_port_info (raw_handle, ports, numPorts); ! raw1394_destroy_handle (raw_handle); ! ! /* Perform autodetection */ ! printf ("Auto-detecting firewire camera because card and node is not specified\n"); ! ! /* We need to traverse all available cards and process each one */ ! for (p = 0; p < numPorts; p++) ! { ! /* Open up OHCI and assign a handle */ ! int numnodes, c; ! raw1394handle_t handle; ! handle = dc1394_create_handle (p); ! if (handle == NULL) ! continue; ! ! /* Get the camera nodes */ ! numnodes = raw1394_get_nodecount (handle); ! if (numnodes <= 1) ! continue; ! ! /* Get info for each camera node */ ! for (c = 0; c < numnodes; c++) ! { ! dc1394_camerainfo info; ! if (dc1394_get_camera_info (handle, c, &info) < 0) ! { ! printf ("1394 card %d node %d is not a camera [INVALID]\n", p, c); ! } ! else ! { ! printf ("1394 card %d node %d is a [%s - %s] --> ", p, c, info.vendor, info.model); ! ! /* Store the node numbers */ ! if (*card == -1) ! { ! printf ("auto detected\n"); ! *card = p; ! *node = c; ! } ! else ! printf ("not used\n"); ! } ! } ! } ! ! /* If we still haven't found a camera then we are in trouble */ ! if ((*card == -1) && (*node == -1)) ! { ! fprintf (stderr, "Could not auto detect any cameras on the %d firewire cards available\n", numPorts); ! exit (1); ! } ! printf ("Using the firewire camera on card %d and node %d\n", *card, *node); ! } ! ! ! /* Lets create a handle so it can be used later on */ ! arV1394.handle = dc1394_create_handle(*card); ! if (arV1394.handle==NULL) ! { ! fprintf (stderr, "Could not acquire a raw1394 handle, did you insmod the drivers?\n"); ! exit(1); ! } ! ! ! /* Success */ return 0; } |