camera/drv-v4l2.c
V4L2Capture* v4l2CaptureOpen(const char *filename) {
  struct v4l2_capability argp;
  int fd;
  int res;
  V4L2Capture *capture =0;
	
  fd = open(filename,O_RDWR);
	
  if (fd!=-1){
    res = ioctl (fd,VIDIOC_QUERYCAP,&argp);
		
    if (!res) { //It is a V4L2 device
      capture = malloc(sizeof(V4L2Capture));
      memset(capture,0,sizeof(V4L2Capture));
      capture->fd = fd;
      capture->name = strdup((char *)argp.card);
      capture->driver = strdup((char *)argp.driver);
      capture->bus = strdup((char *)argp.bus_info);
      capture->location = strdup((char *)filename);
      capture->capabilities = argp.capabilities;
      capture->iomode = V4L2_CAP_READWRITE;
			
      v4l2CaptureSetLog(capture,1);
			
      capture_query_channel(capture);
      capture_query_norm(capture);
      capture_query_buffer_type(capture);
      capture_query_image_format(capture);
			
      capture_refresh_image_format(capture);
			
      capture->channel = -1;
      if (capture->nChannels)
        capture_refresh_channel(capture);
				
      capture->norm = -1;
      if (capture->nNorms)
        capture_refresh_norm(capture);
				
      int n,d;
			
      capture_query_fps(capture,&n,&d);	
				
    } else {
      close(fd);	
    }
  }
	
  return capture;
}
/**
 *  @param filename - The location of device.
 *  @Return Pointer to a initialized video capturing
 * structure, or NULL if failed to open the camera. 
 * 
 *  The function v4l2CaptureOpen opens and querys the properties
 * of a V4L2 video device. The result will be used to initialize
 * the newly allocated V4L2Capture. 
 * 
 *  Soon the video device is not used anymore , it should 
 *  be released by v4l2CaptureRelease
 * 
 * @see v4l2CaptureRelease. 
 * 
 */
@param filename - The location of device.
@Return Pointer to a initialized video capturing
structure, or NULL if failed to open the camera.

The function v4l2CaptureOpen opens and querys the properties
of a V4L2 video device. The result will be used to initialize
the newly allocated V4L2Capture.

Soon the video device is not used anymore , it should
be released by v4l2CaptureRelease


@param filename - The location of device . @Return Pointer to a initialized video capturing structure or NULL if failed to open the camera . The function v4l2CaptureOpen opens and querys the properties of a V4L2 video device . The result will be used to initialize the newly allocated V4L2Capture . Soon the video device is not used anymore it should be released by v4l2CaptureRelease
V4L2Capture* v4l2CaptureOpen(const char *filename) {
  struct v4l2_capability argp;
  int fd;
  int res;
  V4L2Capture *capture =0;
  fd = open(filename,O_RDWR);
  if (fd!=-1){
    res = ioctl (fd,VIDIOC_QUERYCAP,&argp);
    if (!res) { 
      capture = malloc(sizeof(V4L2Capture));
      memset(capture,0,sizeof(V4L2Capture));
      capture->fd = fd;
      capture->name = strdup((char *)argp.card);
      capture->driver = strdup((char *)argp.driver);
      capture->bus = strdup((char *)argp.bus_info);
      capture->location = strdup((char *)filename);
      capture->capabilities = argp.capabilities;
      capture->iomode = V4L2_CAP_READWRITE;
      v4l2CaptureSetLog(capture,1);
      capture_query_channel(capture);
      capture_query_norm(capture);
      capture_query_buffer_type(capture);
      capture_query_image_format(capture);
      capture_refresh_image_format(capture);
      capture->channel = -1;
      if (capture->nChannels)
        capture_refresh_channel(capture);
      capture->norm = -1;
      if (capture->nNorms)
        capture_refresh_norm(capture);
      int n,d;
      capture_query_fps(capture,&n,&d);	
    } else {
      close(fd);	
    }
  }
  return capture;
}
V4L2Capture * v4l2CaptureOpen ( const char * filename ) { struct v4l2_capability argp ; int fd ; int res ; V4L2Capture * capture = 0 ; fd = open ( filename , O_RDWR ) ; if ( fd != -1 ) { res = ioctl ( fd , VIDIOC_QUERYCAP , & argp ) ; if ( ! res ) { capture = malloc ( sizeof ( V4L2Capture ) ) ; memset ( capture , 0 , sizeof ( V4L2Capture ) ) ; capture -> fd = fd ; capture -> name = strdup ( ( char * ) argp . card ) ; capture -> driver = strdup ( ( char * ) argp . driver ) ; capture -> bus = strdup ( ( char * ) argp . bus_info ) ; capture -> location = strdup ( ( char * ) filename ) ; capture -> capabilities = argp . capabilities ; capture -> iomode = V4L2_CAP_READWRITE ; v4l2CaptureSetLog ( capture , 1 ) ; capture_query_channel ( capture ) ; capture_query_norm ( capture ) ; capture_query_buffer_type ( capture ) ; capture_query_image_format ( capture ) ; capture_refresh_image_format ( capture ) ; capture -> channel = -1 ; if ( capture -> nChannels ) capture_refresh_channel ( capture ) ; capture -> norm = -1 ; if ( capture -> nNorms ) capture_refresh_norm ( capture ) ; int n , d ; capture_query_fps ( capture , & n , & d ) ; } else { close ( fd ) ; } } return capture ; }
@param filename - The location of device.
@param filename - The location of device .
//It is a V4L2 device