Beispiel #1
0
static PyObject *
unicap_getshutter(PyObject *self, PyObject *args)
{
  unicap_handle_t handle = getHandle();
  double dur = getduration(handle);
  unicap_close(handle);
  return  PyFloat_FromDouble(dur);
}
Beispiel #2
0
/*
  device_change_cb: 
  callback called when the user selected a video capture device
*/
static 
void device_change_cb( UnicapgtkDeviceSelection *selection, gchar *device_id, GtkWidget *ugtk_display )
{
   unicap_device_t device;
   unicap_handle_t handle;
   GtkWidget *property_dialog;
   GtkWidget *format_selection;
   GtkWidget *_window;

   property_dialog = g_object_get_data( G_OBJECT( ugtk_display ), "property_dialog" );
   g_assert( property_dialog );

   format_selection = g_object_get_data( G_OBJECT( ugtk_display ), "format_selection" );
   g_assert( format_selection );

   _window = g_object_get_data( G_OBJECT( ugtk_display ), "app-window" );
   g_assert( _window );

   unicap_void_device( &device );
   strcpy( device.identifier, device_id );
   
   if( !SUCCESS( unicap_enumerate_devices( &device, &device, 0 ) ) ||
       !SUCCESS( unicap_open( &handle, &device ) ) )
   {
      // device is not available anymore
      g_printerr( "*** TODO: device rescan*** device not available!\n" );
      return;
   }
   
   if( unicap_is_stream_locked( &device ) )
   {
      // could not acquire lock
      unicap_close( handle );
      g_printerr( "*** TODO: device rescan*** device is locked\n" );
      return;
   }
		
   unicapgtk_video_display_set_handle( UNICAPGTK_VIDEO_DISPLAY( ugtk_display ), handle );
   unicapgtk_property_dialog_set_handle( UNICAPGTK_PROPERTY_DIALOG( property_dialog ), handle );
   unicapgtk_video_format_selection_set_handle( UNICAPGTK_VIDEO_FORMAT_SELECTION( format_selection ), handle );
   unicap_close( handle );
   gtk_window_set_title( GTK_WINDOW( _window ), device.identifier );
}
Beispiel #3
0
void print

int main (int argc, char **argv)
{
  unicap_handle_t handle;
  handle = open_imagingsource_camera();
  print_formats(handle);
  unicap_close (handle);
  return 0;
}
static void unicapgtk_video_format_selection_destroy             ( GtkObject     *object )
{
   UnicapgtkVideoFormatSelection *ugtk = UNICAPGTK_VIDEO_FORMAT_SELECTION( object );
	
   if( ugtk->unicap_handle )
   {
      unicap_close( ugtk->unicap_handle );
      ugtk->unicap_handle = NULL;
   }
}
Beispiel #5
0
static PyObject *
unicap_setshutter(PyObject *self, PyObject *args)
{
  unicap_handle_t handle = getHandle();
  double shutter;
  if(!PyArg_ParseTuple(args, "d", &shutter))
    {
      return NULL;
    }
  printf("arg was: %f\n", shutter);
  setshutter(handle, shutter);
  unicap_close(handle);
  return PyLong_FromLong(1);
}
int UnicapCamera::Close(void)
{
	if( !SUCCESS( unicap_stop_capture( *m_Handle ) ) )
	{
		printf( "Failed to stop capture on device: %s\n", m_Device->identifier );
	}
	
	if( !SUCCESS( unicap_close( *m_Handle ) ) )
	{
		printf("Failed to close the device: %s\n", m_Device->identifier );
		return UNSPECIFIED_ERROR;
	}
	else
	{
		printf("UnicapCamera: %s closed\n",m_Device->identifier);
		return 0;
	}
}
Beispiel #7
0
static PyObject *
unicap_capture(PyObject *self, PyObject *args)
{
  unicap_handle_t handle = getHandle();
  
  capture(handle);
  unicap_close(handle);

  PyObject* imgarray = PyList_New(nrOfPixel);
  int i;
  for(i = 0; i < nrOfPixel; i++)
    {
      long l = buf[i];
      PyObject* intensity = PyLong_FromLong(l);
      PyList_SetItem(imgarray, i, intensity);
    }
  free(buf);
  buf = NULL;
  return imgarray;
}
static void unicapgtk_video_display_destroy( GtkObject *object )
{
   UnicapgtkVideoDisplay *ugtk = UNICAPGTK_VIDEO_DISPLAY( object );

/*    g_object_unref( ugtk->gc ); */
   if( ugtk->capture_running )
   {
      unicapgtk_video_display_stop( ugtk );
   }

   if( ugtk->unicap_handle )
   {
      unicap_close( ugtk->unicap_handle );
      ugtk->unicap_handle = NULL;
   }

   if( ugtk->backend )
   {
      ugtk->backend_destroy( ugtk->backend_data );
      ugtk->backend = NULL;
   }

   GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
int main( int argc, char **argv )
{
   unicap_handle_t handle;
   unicap_device_t device;
   unicap_device_t device_spec;
   unicap_property_t property;
   unicap_property_t property_spec;

   int list_only = 0;
   int get_property = 0;
   int value_set = 0;
	
   int i;
   int c = 0;

   unicap_void_device( &device_spec );
   unicap_void_property( &property );
	
   while( c != -1 )
   {
      c = getopt( argc, argv, "gp:M:v:m:l" );
      switch( c )
      {
	 case 'p':
	    if( optarg )
	    {
	       strcpy( property.identifier, optarg );
	    }
	    break;
		      
	 case 'M':
	    if( optarg )
	    {
	       printf( "Model: %s\n", optarg );
	       strcpy( device_spec.model_name, optarg );
	    }
	    else
	    {
	       print_usage( argv[0] );
	       exit( 1 );
	    }
	    break;
				
	 case 'v':
	    if( optarg )
	    {
	       sscanf( optarg, "%f", &property_spec.value );
	       value_set = 1;
	    }
	    else
	    {
	       print_usage( argv[0] );
	       exit( 1 );
	    }
	    break;
				
	 case 'm':
	    if( optarg )
	    {
	       strcpy( property.menu_item, optarg );
	    }
	    else
	    {
	       print_usage( argv[0] );
	       exit( 1 );
	    }
	    break;
				
	 case 'l':
	    list_only = 1;
	    break;
	 case 'g':
	    get_property = 1;
	    break;
				
	 case -1:
	    printf( "optind: %d\n", optind );
	    break;
				
	 default:
	    print_usage( argv[0] );
	    exit( 1 );
	    break;
      }
   }
	
	

   //
   // Enumerate all video capture devices; if more than 1 device present, ask for which device to open
   //
   for( i = 0; SUCCESS( unicap_enumerate_devices( &device_spec, &device, i ) ); i++ )
   {
      printf( "%i: %s\n", i, device.identifier );
   }
   if( --i > 0 )
   {
      printf( "Select video capture device: " );
      scanf( "%d", &i );
   }

   if( !SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ) )
   {
      fprintf( stderr, "Failed to get info for device '%s'\n", device.identifier );
      exit( 1 );
   }

   /*
     Acquire a handle to this device
   */
   if( !SUCCESS( unicap_open( &handle, &device ) ) )
   {
      fprintf( stderr, "Failed to open device: %s\n", device.identifier );
      exit( 1 );
   }

   printf( "Opened video capture device: %s\n", device.identifier );

	
   // Initialize a property specifier structure
   unicap_void_property( &property_spec );
   strcpy( property_spec.identifier, property.identifier );

   printf( "Supported properties: \n" );
   printf( "\tName\t\tValue\n" );

   //
   // Print a list of all properties matching the specifier. For a "void" specifier, this matches all 
   //   properties supported by the device
   // If more than 1 property is supported, ask for which property to modify
   for( i = 0; SUCCESS( unicap_enumerate_properties( handle, &property_spec, &property, i ) ); i++ )
   {
      unicap_get_property( handle, &property );
      printf( "%i: \t%s\t\t", i, property.identifier );
      switch( property.type )
      {
	 case UNICAP_PROPERTY_TYPE_RANGE:
	 case UNICAP_PROPERTY_TYPE_VALUE_LIST:
	    printf( "%f", property.value );
	    break;
		      
	 case UNICAP_PROPERTY_TYPE_MENU:
	    printf( "%s", property.menu_item );
	    break;
		      
	 case UNICAP_PROPERTY_TYPE_FLAGS:
	 {
	    int j;
	    const char *flags[] =
	       { "MANUAL", 
		 "AUTO", 
		 "ONE_PUSH", 
		 "READ_OUT", 
		 "ON_OFF", 
		 "READ_ONLY", 
		 "FORMAT_CHANGE" 
	       };
		      
		      
	    for( j = 0; j < ( sizeof( flags ) / sizeof( char* ) ); j++ )
	    {
	       if( ( property.flags & ( 1<<j ) ) == ( 1<<j ) )
	       {
		  printf( "%s ",flags[j] );
	       }
	    }
	 }
	 break;
		   
	 default:
	    break;
      }
		
      printf( "\n" );
   }
   if( --i > 1 )
   {
      printf( "Select a property to edit: " );
      scanf( "%d", &i );
   }

   // Now get the description of the requested property. unicap_enumerate_property gives the 
   // property structure initialized to the default values. So just change the value of the 
   // returned property to the new one and set it using 'unicap_set_property'
   if( !SUCCESS( unicap_enumerate_properties( handle, &property_spec, &property, i ) ) )
   {
      printf( "Failed to enumerate property\n" );
      exit( -1 );
   }

   
   switch( property.type )
   {
      case UNICAP_PROPERTY_TYPE_RANGE:
      case UNICAP_PROPERTY_TYPE_VALUE_LIST:
      {
	 if( !value_set )
	 {
	    double new_value;
	    printf( "Enter new value for property '%s' ( floating point value ): ", property.identifier );
	    scanf( "%lf", &new_value );
	    property.value = new_value;
	    property.flags = UNICAP_FLAGS_MANUAL;
	 }
	 else
	 {
	    property.value = property_spec.value;
	 }
      }
      break;
	   
      case UNICAP_PROPERTY_TYPE_MENU:
      {
	 printf( "Enter new value for property '%s' ( string ): ", property.identifier );
	 scanf( "%128s", property.menu_item );
      }
      break;

      case UNICAP_PROPERTY_TYPE_FLAGS:
      {
	 int i;
	 char buf[128];
	 char *str;
	 printf( "Enter new flags for property '%s' ( out of ", property.identifier );

	 for( i = 0; i < ( sizeof( property_flag_strings ) / sizeof( struct flag_string ) ); i++ )
	 {
	    if( property.flags_mask & property_flag_strings[i].flag )
	    {
	       printf( "%s ", property_flag_strings[i].name );
	    }
	 }
	 printf( "): " );
	 scanf( "%128s", buf );
	 str = strtok( buf, " " );
	 property.flags = 0;
	 while( str )
	 {
	    for( i = 0; i < ( sizeof( property_flag_strings ) / sizeof( struct flag_string ) ); i++ )
	    {
	       if( !strcmp( str, property_flag_strings[i].name ) )
	       {
		  property.flags |= property_flag_strings[i].flag;
		  break;
	       }
	    }
		 
	    if( i == ( sizeof( property_flag_strings ) / sizeof( struct flag_string ) ) )
	    {
	       printf( "Unknown flag: %s\n", str );
	       break;
	    }
	    str = strtok( NULL, " " );
	 }
      }   
   }
	

   if( !get_property )
   {
      if( !SUCCESS( unicap_set_property( handle, &property ) ) )
      {
	 printf( "Failed to set property!\n" );
      }
   }
   else
   {
      char buffer[512];
      int s = sizeof( buffer );
      if( !SUCCESS( unicap_get_property( handle, &property ) ) )
      {
	 printf( "Failed to set property!\n" );
      }

      unicap_describe_property( &property, buffer, &s );
	   
      printf( "%s\n", buffer );
   }
	

   unicap_close( handle );
	
	
   return 0;
}
int main( int argc, char **argv )
{
   unicap_handle_t handle;
   unicap_device_t device;
   unicap_format_t format_spec;
   unicap_format_t format;
   unicap_data_buffer_t buffer;
   unicap_data_buffer_t *returned_buffer;
	
   int i;

   SDL_Surface *screen;
   SDL_Overlay *overlay;

   int quit=0;

   /*
     Enumerate available video capture devices
    */
   printf( "select video device\n" );
   for( i = 0; SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ); i++ )
   {
      printf( "%i: %s\n", i, device.identifier );
   }
   if( --i > 0 )
   {
      printf( "Select video capture device: " );
      scanf( "%d", &i );
   }

   if( !SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ) )
   {
      fprintf( stderr, "Failed to get info for device '%s'\n", device.identifier );
      exit( 1 );
   }

   /*
     Acquire a handle to selected device
   */
   if( !SUCCESS( unicap_open( &handle, &device ) ) )
   {
      fprintf( stderr, "Failed to open device: %s\n", device.identifier );
      exit( 1 );
   }

   printf( "Opened video capture device: %s\n", device.identifier );

   unicap_void_format( &format_spec );
	
   /*
     Get the list of video formats
   */
   for( i = 0; SUCCESS( unicap_enumerate_formats( handle, 
						  NULL, 
						  &format, i ) ); 
	i++ )
   {
      printf( "%d: %s\n", 
	      i,
	      format.identifier );
   }
   if( --i > 0 )
   {
      printf( "Select video format: " );
      scanf( "%d", &i );
   }
   if( !SUCCESS( unicap_enumerate_formats( handle, &format_spec, &format, i ) ) )
   {
      fprintf( stderr, "Failed to get video format %d\n", i );
      exit( 1 );
   }
	
   /*
     If a video format has more than one size, ask for which size to use
   */
   if( format.size_count )
   {
      for( i = 0; i < format.size_count; i++ )
      {
	 printf( "%d: %dx%d\n", i, format.sizes[i].width, format.sizes[i].height );
      }
      do
      {
	 printf( "Select video format size: " );
	 scanf( "%d", &i );
      }while( ( i < 0 ) && ( i > format.size_count ) );
      format.size.width = format.sizes[i].width;
      format.size.height = format.sizes[i].height;
   }

   /*
     Set this video format
   */
   if( !SUCCESS( unicap_set_format( handle, &format ) ) )
   {
      fprintf( stderr, "Failed to set video format\n" );
      exit( 1 );
   }

   /*
     Initialize the image buffer
   */
   memset( &buffer, 0x0, sizeof( unicap_data_buffer_t ) );

   /**
      Init SDL & SDL_Overlay
   **/
   if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
   {
      fprintf(stderr, "Failed to initialize SDL:  %s\n", SDL_GetError());
      exit(1);
   }
	
   atexit(SDL_Quit);

   screen = SDL_SetVideoMode( format.size.width, format.size.height, 32, SDL_HWSURFACE);
   if ( screen == NULL ) {
      fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
      exit(1);
   }
   
   

   overlay = SDL_CreateYUVOverlay( format.size.width, 
				   format.size.height, 
				   format.fourcc, 
				   screen );
   if( overlay == NULL )
   {
      fprintf( stderr, "Unable to create overlay: %s\n", SDL_GetError() );
      exit( 1 );
   }

   /*
     Pass the pointer to the overlay to the unicap data buffer. 
   */
   buffer.data = overlay->pixels[0];	
   buffer.buffer_size = format.size.width * format.size.height * format.bpp / 8;

   /*
     Start the capture process on the device
   */
   if( !SUCCESS( unicap_start_capture( handle ) ) )
   {
      fprintf( stderr, "Failed to start capture on device: %s\n", device.identifier );
      exit( 1 );
   }
	

   while( !quit )
   {
      SDL_Rect rect;
      SDL_Event event;

      rect.x = rect.y = 0;
      rect.w = format.size.width;
      rect.h = format.size.height;
      /*
	Queue the buffer
		  
	The buffer now gets filled with image data by the capture device
      */
      if( !SUCCESS( unicap_queue_buffer( handle, &buffer ) ) )
      {
	 fprintf( stderr, "Failed to queue a buffer on device: %s\n", device.identifier );
	 exit( 1 );
      }
		
      /*
	Wait until the image buffer is ready
      */
      if( !SUCCESS( unicap_wait_buffer( handle, &returned_buffer ) ) )
      {
	 fprintf( stderr, "Failed to wait for buffer on device: %s\n", device.identifier );
      }

      /*
	Display the video data
      */
      SDL_UnlockYUVOverlay( overlay );
      SDL_DisplayYUVOverlay( overlay, &rect );
      SDL_LockYUVOverlay(overlay);

      while( SDL_PollEvent( &event ) )
      {
	 if( event.type == SDL_QUIT )
	 {
	    printf( "Quit\n" );
	    quit=1;
	 }
      }
   }
	
   /*
     Stop the device
   */
   if( !SUCCESS( unicap_stop_capture( handle ) ) )
   {
      fprintf( stderr, "Failed to stop capture on device: %s\n", device.identifier );
   }

   /*
     Close the device 

     This invalidates the handle
   */
   if( !SUCCESS( unicap_close( handle ) ) )
   {
      fprintf( stderr, "Failed to close the device: %s\n", device.identifier );
   }

   SDL_Quit();
	
   return 0;
}
int main( int argc, char **argv )
{
	unicap_handle_t handle;
	unicap_device_t device;
	unicap_format_t format_spec;
	unicap_format_t format;
	unicap_data_buffer_t buffer;
	unicap_data_buffer_t *returned_buffer;
	int width, height;
	
	int i;

	SDL_Surface *screen;
	SDL_Overlay *overlay;

	int quit=0;
	int imgcnt = 0;

	printf( "select video device\n" );
	for( i = 0; SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ); i++ )
	{
		printf( "%i: %s\n", i, device.identifier );
	}
	if( --i > 0 )
	{
		printf( "Select video capture device: " );
		scanf( "%d", &i );
	}

	if( !SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ) )
	{
		fprintf( stderr, "Failed to get info for device '%s'\n", device.identifier );
		exit( 1 );
	}

	/*
	  Acquire a handle to this device
	 */
	if( !SUCCESS( unicap_open( &handle, &device ) ) )
	{
		fprintf( stderr, "Failed to open device: %s\n", device.identifier );
		exit( 1 );
	}

	printf( "Opened video capture device: %s\n", device.identifier );

	/*
	  Create a format specification to limit the list of formats returned by 
	  unicap_enumerate_formats to the ones with the color format 'UYVY'
	 */
	unicap_void_format( &format_spec );
	format_spec.fourcc = FOURCC('U','Y','V','Y');
	
	/*
	  Get the list of video formats of the colorformat UYVY
	 */
	for( i = 0; SUCCESS( unicap_enumerate_formats( handle, &format_spec, &format, i ) ); i++ )
	{
		printf( "%d: %s [%dx%d]\n", 
				i,
				format.identifier, 
				format.size.width, 
				format.size.height );
	}
	if( --i > 0 )
	{
		printf( "Select video format: " );
		scanf( "%d", &i );
	}
	if( !SUCCESS( unicap_enumerate_formats( handle, &format_spec, &format, i ) ) )
	{
		fprintf( stderr, "Failed to get video format\n" );
		exit( 1 );
	}
	
   /*
     If a video format has more than one size, ask for which size to use
   */
   if( format.size_count )
   {
      for( i = 0; i < format.size_count; i++ )
      {
	 printf( "%d: %dx%d\n", i, format.sizes[i].width, format.sizes[i].height );
      }
      do
      {
	 printf( "Select video format size: " );
	 scanf( "%d", &i );
      }while( ( i < 0 ) && ( i > format.size_count ) );
      format.size.width = format.sizes[i].width;
      format.size.height = format.sizes[i].height;
   }

	/*
	  Set this video format
	 */
	if( !SUCCESS( unicap_set_format( handle, &format ) ) )
	{
		fprintf( stderr, "Failed to set video format\n" );
		exit( 1 );
	}

	/*
	  Initialize the image buffer
	 */
	memset( &buffer, 0x0, sizeof( unicap_data_buffer_t ) );

	/**
	   Init SDL & SDL_Overlay
	 **/
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
	{
	   fprintf(stderr, "Failed to initialize SDL:  %s\n", SDL_GetError());
	   exit(1);
	}
	
	atexit(SDL_Quit);

	/*
	  Make sure the video window does not get too big. 
	 */
	width = MIN( format.size.width, 800 );
	height = MIN( format.size.height, 600 );

	screen = SDL_SetVideoMode( width, height, 32, SDL_HWSURFACE);
	if ( screen == NULL ) {
	   fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
	   exit(1);
	}
	
	overlay = SDL_CreateYUVOverlay( format.size.width, 
									format.size.height, SDL_UYVY_OVERLAY, screen );
	if( overlay == NULL )
	{
	   fprintf( stderr, "Unable to create overlay: %s\n", SDL_GetError() );
	   exit( 1 );
	}

	/*
	  Pass the pointer to the overlay to the unicap data buffer. 
	 */
	buffer.data = overlay->pixels[0];	
   buffer.buffer_size = format.size.width * format.size.height * format.bpp / 8;
	
	/*
	  Start the capture process on the device
	 */
	if( !SUCCESS( unicap_start_capture( handle ) ) )
	{
		fprintf( stderr, "Failed to start capture on device: %s\n", device.identifier );
		exit( 1 );
	}
	

	while( !quit )
	{
		SDL_Rect rect;
		SDL_Event event;

		rect.x = 0;
		rect.y = 0;
		rect.w = width;
		rect.h = height;
		/*
		  Queue the buffer
		  
		  The buffer now gets filled with image data by the capture device
		*/
		if( !SUCCESS( unicap_queue_buffer( handle, &buffer ) ) )
		{
			fprintf( stderr, "Failed to queue a buffer on device: %s\n", device.identifier );
			exit( 1 );
		}
		
		/*
		  Wait until the image buffer is ready
		*/
		if( !SUCCESS( unicap_wait_buffer( handle, &returned_buffer ) ) )
		{
			fprintf( stderr, "Failed to wait for buffer on device: %s\n", device.identifier );
		}

		/*
		  Display the video data
		 */
		SDL_UnlockYUVOverlay( overlay );
		SDL_DisplayYUVOverlay( overlay, &rect );

		while( SDL_PollEvent( &event ) )
		{
			switch( event.type )
			{
				case SDL_QUIT:
					quit = 1;
					break;
					
				case SDL_MOUSEBUTTONDOWN:
				{
					unsigned char *pixels;
					struct jpeg_compress_struct cinfo;
					struct jpeg_error_mgr jerr;
					FILE *outfile;
					JSAMPROW row_pointer[1];
					int row_stride;
					char filename[128];

					struct timeval t1, t2;
					unsigned long long usecs;
					
					sprintf( filename, "%04d.jpg", imgcnt++ );
					
					cinfo.err = jpeg_std_error(&jerr);
					/* Now we can initialize the JPEG compression object. */
					jpeg_create_compress(&cinfo);
					if ((outfile = fopen( filename, "wb" ) ) == NULL ) 
					{
						fprintf(stderr, "can't open %s\n", "file");
						exit(1);
					}
					jpeg_stdio_dest(&cinfo, outfile);
					
					cinfo.image_width = format.size.width; 	/* image width and height, in pixels */
					cinfo.image_height = format.size.height;
					cinfo.input_components = 3;		/* # of color components per pixel */
					cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
					
					jpeg_set_defaults(&cinfo);
					pixels = malloc( format.size.width * format.size.height * 3 );
					uyvy2rgb24( pixels, returned_buffer->data,
						    format.size.width * format.size.height * 3,
						    format.size.width * format.size.height * 2 );

					gettimeofday( &t1, NULL );
					jpeg_start_compress(&cinfo, TRUE);
					while( cinfo.next_scanline < cinfo.image_height )
					{
						row_pointer[0] = &pixels[cinfo.next_scanline * format.size.width * 3 ];
						(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
					}
					jpeg_finish_compress(&cinfo);
					gettimeofday( &t2, NULL );

					usecs = t2.tv_sec * 1000000LL + t2.tv_usec;
					usecs -= ( t1.tv_sec * 1000000LL + t1.tv_usec );
					
					printf( "Compression took: %lld usec\n", usecs );

					/* After finish_compress, we can close the output file. */
					fclose(outfile);
					jpeg_destroy_compress(&cinfo);
					
					free( pixels );
				}
				
				break;
				
				
				default: 
					break;
			}
		}
		SDL_LockYUVOverlay(overlay);
	}
	
	/*
	  Stop the device
	 */
	if( !SUCCESS( unicap_stop_capture( handle ) ) )
	{
		fprintf( stderr, "Failed to stop capture on device: %s\n", device.identifier );
	}

	/*
	  Close the device 

	  This invalidates the handle
	 */
	if( !SUCCESS( unicap_close( handle ) ) )
	{
		fprintf( stderr, "Failed to close the device: %s\n", device.identifier );
	}

	SDL_Quit();
	
	return 0;
}