[artoolkit-commits] artoolkit/lib/SRC/VideoLinux1394Cam video.c, 1.16, 1.17
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Wayne P. <ti...@us...> - 2007-03-13 04:53:48
|
Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinux1394Cam In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv31539 Modified Files: video.c Log Message: Previously the error checking was inconsistent, with some exit() calls and some return() calls. I have now made it so that return is used whenever there is some kind of recoverable error, and if the error indicates a fault in the code itself, then we just exit because there is no point continuing. I also added better debugging during the config string parsing. Index: video.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinux1394Cam/video.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** video.c 13 Mar 2007 04:26:43 -0000 1.16 --- video.c 13 Mar 2007 04:53:47 -0000 1.17 *************** *** 266,270 **** 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"); --- 266,270 ---- 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 'iris' or 'gain'.\n"); printf(" (value must be a legal value for this parameter - use coriander to find what they are\n"); printf("\n"); *************** *** 304,324 **** vid->status = 0; ! /* If no config string is supplied, we should use the environment variable, otherwise set a sane default */ ! if (!config_in || !(config_in[0])) { ! /* None suppplied, lets see if the user supplied one from the shell */ ! char *envconf = getenv ("ARTOOLKIT_CONFIG"); ! if (envconf && envconf[0]) { ! config = envconf; ! printf ("Using config string from environment [%s].\n", envconf); ! } else { ! config = NULL; ! printf ("No video config string supplied, using defaults.\n"); ! } ! } else { ! config = config_in; ! printf ("Using supplied video config string [%s].\n", config_in); ! } ! ! a = config; if( a != NULL) { for(;;) { --- 304,324 ---- vid->status = 0; ! /* If no config string is supplied, we should use the environment variable, otherwise set a sane default */ ! if (!config_in || !(config_in[0])) { ! /* None suppplied, lets see if the user supplied one from the shell */ ! char *envconf = getenv ("ARTOOLKIT_CONFIG"); ! if (envconf && envconf[0]) { ! config = envconf; ! printf ("Using config string from environment [%s].\n", envconf); ! } else { ! config = NULL; ! printf ("No video config string supplied, using default 640x480 RGB at 15 Hz.\n"); ! } ! } else { ! config = config_in; ! printf ("Using supplied video config string [%s].\n", config_in); ! } ! ! a = config; if( a != NULL) { for(;;) { *************** *** 337,343 **** } else { ar2VideoDispOption(); free( vid ); ! return 0; } } --- 337,344 ---- } else { + fprintf (stderr, "Video mode string supplied [%s] is not parseable", &a[6]); ar2VideoDispOption(); free( vid ); ! return (NULL); } } *************** *** 346,352 **** sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &iris ) == 0 ) { ar2VideoDispOption(); free( vid ); ! return 0; } } --- 347,354 ---- sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &iris ) == 0 ) { + fprintf (stderr, "Video iris value supplied [%s] is not parseable", &line[6]); ar2VideoDispOption(); free( vid ); ! return (NULL); } } *************** *** 354,360 **** sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &gain ) == 0 ) { ar2VideoDispOption(); free( vid ); ! return 0; } } --- 356,363 ---- sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &gain ) == 0 ) { + fprintf (stderr, "Video gain value supplied [%s] is not parseable", &line[6]); ar2VideoDispOption(); free( vid ); ! return (NULL); } } *************** *** 363,369 **** sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &vid->node ) == 0 ) { ar2VideoDispOption(); free( vid ); ! return 0; } } --- 366,373 ---- sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &vid->node ) == 0 ) { + fprintf (stderr, "Firewire node value supplied [%s] is not parseable", &line[6]); ar2VideoDispOption(); free( vid ); ! return (NULL); } } *************** *** 371,377 **** sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &vid->card ) == 0 ) { ar2VideoDispOption(); free( vid ); ! return 0; } } --- 375,382 ---- sscanf( a, "%s", line ); if( sscanf( &line[6], "%d", &vid->card ) == 0 ) { + fprintf (stderr, "Firewire card value supplied [%s] is not parseable", &line[6]); ar2VideoDispOption(); free( vid ); ! return (NULL); } } *************** *** 396,402 **** } else { ar2VideoDispOption(); free( vid ); ! return 0; } } --- 401,408 ---- } else { + fprintf (stderr, "Frame rate value supplied [%s] is not parseable", &a[6]); ar2VideoDispOption(); free( vid ); ! return (NULL); } } *************** *** 405,414 **** } else if( strncmp( a, "-adjust", 7 ) == 0 ) { ! /* Do nothing - this is for V4L compatibility */ } else { ar2VideoDispOption(); free( vid ); ! return 0; } --- 411,421 ---- } else if( strncmp( a, "-adjust", 7 ) == 0 ) { ! /* Do nothing - this is for VideoLinuxV4L compatibility */ } else { + fprintf (stderr, "Unknown config option supplied [%s]", a); ar2VideoDispOption(); free( vid ); ! return (NULL); } *************** *** 423,427 **** { fprintf (stderr, "Could not initialise 1394 bus with card=%d and node=%d\n", vid->card, vid->node); ! exit(1); } initFlag = 1; --- 430,434 ---- { fprintf (stderr, "Could not initialise 1394 bus with card=%d and node=%d\n", vid->card, vid->node); ! return (NULL); } initFlag = 1; *************** *** 436,439 **** --- 443,447 ---- &(vid->features)) != DC1394_SUCCESS ) { fprintf( stderr, "Unable to get feature set from device\n"); + return (NULL); } else if( vid->debug ) { *************** *** 464,468 **** /*-----------------------------------------------------------------------*/ if( dc1394_query_supported_formats(arV1394.handle, vid->node, &value) != DC1394_SUCCESS ) { ! fprintf( stderr, "unable to query_supported_formats\n"); } i = 31 - (FORMAT_VGA_NONCOMPRESSED - FORMAT_MIN); --- 472,477 ---- /*-----------------------------------------------------------------------*/ if( dc1394_query_supported_formats(arV1394.handle, vid->node, &value) != DC1394_SUCCESS ) { ! fprintf( stderr, "Unable to perform a query_supported_formats call\n"); ! return (NULL); } i = 31 - (FORMAT_VGA_NONCOMPRESSED - FORMAT_MIN); *************** *** 470,475 **** p2 = value & p1; if( p2 == 0 ) { ! fprintf( stderr, "unable to use this camera on VGA_NONCOMPRESSED format.\n"); ! exit(0); } --- 479,484 ---- p2 = value & p1; if( p2 == 0 ) { ! fprintf( stderr, "Unable to use this camera on VGA_NONCOMPRESSED format.\n"); ! return (NULL); } *************** *** 489,493 **** fprintf( stderr, "Unsupported Mode for the specified camera.\n"); ar2VideoDispOption(); ! exit(0); } else --- 498,502 ---- fprintf( stderr, "Unsupported Mode for the specified camera.\n"); ar2VideoDispOption(); ! return (NULL); } else *************** *** 504,510 **** p2 = value & p1; if( p2 == 0 ) { ! fprintf( stderr, "Unsupported Framerate for the specified mode.\n"); ar2VideoDispOption(); ! exit(0); } --- 513,519 ---- p2 = value & p1; if( p2 == 0 ) { ! fprintf( stderr, "Unsupported framerate for the specified mode.\n"); ar2VideoDispOption(); ! return (NULL); } *************** *** 541,556 **** #endif &(vid->camera)) != DC1394_SUCCESS ) { ! fprintf( stderr,"unable to setup camera-\n" ! "check if you did 'insmod video1394' or,\n" ! "check line %d of %s to make sure\n" ! "that the video mode,framerate and format are\n" ! "supported by your camera\n", ! __LINE__,__FILE__); ! exit(1); } /* set trigger mode */ if( dc1394_set_trigger_mode(arV1394.handle, vid->node, TRIGGER_MODE_0) != DC1394_SUCCESS ) { ! fprintf( stderr, "unable to set camera trigger mode (ignored)\n"); } --- 550,560 ---- #endif &(vid->camera)) != DC1394_SUCCESS ) { ! fprintf (stderr, "Unable to setup initial camera DMA transfer, check that the video1394 module is loaded, and that the video mode, frame rate, and format are supported by your camera"); ! return (NULL); } /* set trigger mode */ if( dc1394_set_trigger_mode(arV1394.handle, vid->node, TRIGGER_MODE_0) != DC1394_SUCCESS ) { ! fprintf( stderr, "unable to set camera trigger mode (ignored)\n"); } *************** *** 616,629 **** #endif &(vid->camera)) != DC1394_SUCCESS ) { ! fprintf( stderr,"unable to setup camera-\n" ! "check if you did 'insmod video1394' or,\n" ! "check line %d of %s to make sure\n" ! "that the video mode,framerate and format are\n" ! "supported by your camera\n", ! __LINE__,__FILE__); ! exit(1); } } ! if( dc1394_start_iso_transmission(arV1394.handle, vid->node) != DC1394_SUCCESS ) { fprintf( stderr, "unable to start camera iso transmission\n"); --- 620,629 ---- #endif &(vid->camera)) != DC1394_SUCCESS ) { ! ! fprintf (stderr, "Unable to setup initial camera DMA transfer, check that the video1394 module is loaded, and that the video mode, frame rate, and format are supported by your camera"); ! return (-1); } } ! if( dc1394_start_iso_transmission(arV1394.handle, vid->node) != DC1394_SUCCESS ) { fprintf( stderr, "unable to start camera iso transmission\n"); *************** *** 714,718 **** if (ar2Video_dragonfly < 0) { ! fprintf (stderr, "It is not possible to be in mono mode without the dragonfly flag being set previously\n"); exit (1); } --- 714,718 ---- if (ar2Video_dragonfly < 0) { ! fprintf (stderr, "It is not possible to be in mono mode without the dragonfly flag being set previously - internal error\n"); exit (1); } *************** *** 744,753 **** break; case 0x59595959: /* YYYY = BW */ ! fprintf (stderr, "Camera is black and white, Bayer conversion is not possible\n"); exit (1); default: if (prev_pattern == -1) { ! fprintf (stderr, "Camera BAYER_TILE_MAPPING register has an unexpected value 0x%x on initial startup, which should not occur\n", qValue); exit (1); } --- 744,753 ---- break; case 0x59595959: /* YYYY = BW */ ! fprintf (stderr, "Camera is black and white, Bayer conversion is not possible - internal error\n"); exit (1); default: if (prev_pattern == -1) { ! fprintf (stderr, "Camera BAYER_TILE_MAPPING register has an unexpected value 0x%x on initial startup, which should not occur - internal error\n", qValue); exit (1); } *************** *** 755,759 **** { /* This is a wierd bug where occasionally you get an invalid register value and I have no idea why this is */ ! fprintf (stderr, "WARNING! The BAYER_TILE_MAPPING register has an unexpected value 0x%x, but I was able to use the previous stored result\n", qValue); pattern = prev_pattern; } --- 755,759 ---- { /* This is a wierd bug where occasionally you get an invalid register value and I have no idea why this is */ ! fprintf (stderr, "WARNING! The BAYER_TILE_MAPPING register has an unexpected value 0x%x, but I was able to use the previous stored result - this might be a bug\n", qValue); pattern = prev_pattern; } *************** *** 910,914 **** { fprintf (stderr, "Card value is %d and node value is %d, you must either auto-detect both or specify both\n", *card, *node); ! exit (1); } --- 910,914 ---- { fprintf (stderr, "Card value is %d and node value is %d, you must either auto-detect both or specify both\n", *card, *node); ! return (-1); } *************** *** 924,928 **** { fprintf (stderr, "Could not acquire a raw1394 handle - driver not installed?\n"); ! exit (1); } numPorts = raw1394_get_port_info (raw_handle, ports, numPorts); --- 924,928 ---- { fprintf (stderr, "Could not acquire a raw1394 handle - driver not installed?\n"); ! return (-1); } numPorts = raw1394_get_port_info (raw_handle, ports, numPorts); *************** *** 976,980 **** { 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); --- 976,980 ---- { fprintf (stderr, "Could not auto detect any cameras on the %d firewire cards available\n", numPorts); ! return (-1); } printf ("Using the firewire camera on card %d and node %d\n", *card, *node); *************** *** 987,991 **** { fprintf (stderr, "Could not acquire a raw1394 handle, did you insmod the drivers?\n"); ! exit(1); } --- 987,991 ---- { fprintf (stderr, "Could not acquire a raw1394 handle, did you insmod the drivers?\n"); ! return (-1); } |