static unicap_status_t aravis_enumerate_devices (unicap_device_t *device, int index) { unicap_status_t status = STATUS_NO_MATCH; if (index == 0) arv_update_device_list (); unicap_void_device (device); if (index < arv_get_n_devices ()){ ArvCamera *camera; strncpy (device->identifier, arv_get_device_id (index), sizeof (device->identifier)-1); camera = arv_camera_new (device->identifier); if (arv_camera_get_model_name (camera)) strncpy (device->model_name, arv_camera_get_model_name (camera), sizeof (device->model_name)-1); if (arv_camera_get_vendor_name (camera)) strncpy (device->vendor_name, arv_camera_get_vendor_name (camera), sizeof (device->vendor_name)-1); strcpy (device->cpi_layer, "aravis_cpi"); status = STATUS_SUCCESS; g_object_unref (camera); } return status; }
/* 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 ); }
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; }
unicap_handle_t user_config_try_restore( void ) { GKeyFile *keyfile = NULL; gchar *config_path; gchar *ini_path; unicap_handle_t handle = NULL; config_path = get_config_path(); ini_path = g_build_path( G_DIR_SEPARATOR_S, config_path, "default.ini", NULL ); g_free( config_path ); keyfile = g_key_file_new( ); if( !g_key_file_load_from_file( keyfile, ini_path, G_KEY_FILE_NONE, NULL ) ) { g_free( ini_path ); ini_path = g_build_path( G_DIR_SEPARATOR_S, UCVIEW_GLOBAL_CONFIGDIR, "default.ini", NULL ); if( !g_key_file_load_from_file( keyfile, ini_path, G_KEY_FILE_NONE, NULL ) ) { g_warning( "failed\n" ); g_key_file_free( keyfile ); keyfile = NULL; } } g_free( ini_path ); if( keyfile ) { gchar *devid = NULL; gchar *vendor_name = NULL; gchar *model_name = NULL; unicap_device_t devspec; unicap_device_t device; unicap_void_device( &devspec ); devid = g_key_file_get_string( keyfile, "Device", "Identifier", NULL ); if( devid ) { strcpy( devspec.identifier, devid ); } else { vendor_name = g_key_file_get_string( keyfile, "Device", "Vendor", NULL ); model_name = g_key_file_get_string( keyfile, "Device", "Model", NULL ); if( vendor_name && model_name ) { strncpy( device.vendor_name, vendor_name, sizeof( device.vendor_name ) - 1 ); strncpy( device.model_name, model_name, sizeof( device.model_name ) - 1 ); } } // Only call unicap_open if a matching device was found, // otherwise we would always open any device if( devid || ( vendor_name && model_name ) ) { if( SUCCESS( unicap_enumerate_devices( &devspec, &device, 0 ) ) ) { if( SUCCESS( unicap_open( &handle, &device ) ) ) { unicapgtk_load_device_state( handle, keyfile, UNICAPGTK_DEVICE_STATE_VIDEO_FORMAT | UNICAPGTK_DEVICE_STATE_PROPERTIES ); } } } if( devid ) { g_free( devid ); } if( vendor_name ) { g_free( vendor_name ); } if( model_name ) { g_free( model_name ); } g_key_file_free( keyfile ); } return handle; }