/* 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 ); }
/** * unicapgtk_device_selection_rescan: * @combo: an #UnicapgtkDeviceSelection * * Tiggers rescan of available video capture devices and updates the * combo box. * * Returns: number of available devices */ gint unicapgtk_device_selection_rescan( UnicapgtkDeviceSelection *combo ) { unicap_device_t device; GtkListStore *store; GtkTreeIter iter; gint i; g_return_val_if_fail( UNICAPGTK_IS_DEVICE_SELECTION( combo ), 0 ); store = GTK_LIST_STORE( gtk_combo_box_get_model( GTK_COMBO_BOX( combo ) ) ); g_return_val_if_fail( GTK_IS_LIST_STORE( store ), 0 ); if( GTK_WIDGET_REALIZED( combo ) ) { gdk_window_set_cursor( GTK_WIDGET( combo )->window, combo->busy_cursor ); gdk_display_sync( gtk_widget_get_display( GTK_WIDGET( combo ) ) ); } gtk_list_store_clear( store ); gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), -1 ); unicap_reenumerate_devices( NULL ); for( i = 0; SUCCESS( unicap_enumerate_devices( NULL, &device, i ) ); i++ ) { gchar *label; gboolean available = !unicap_is_stream_locked( &device ); label = format_device_label( combo->label_fmt_string, &device ); gtk_list_store_append( store, &iter); gtk_list_store_set( store, &iter, UNICAPGTK_DEVICE_ID, device.identifier, UNICAPGTK_DEVICE_MODEL, device.model_name, UNICAPGTK_DEVICE_VENDOR, device.vendor_name, LABEL, label, SENSITIVE, available, -1); g_free( label ); } if( i == 0 ) { device_combo_box_add_none_entry( store ); } if( combo->include_rescan_entry ) { device_combo_box_add_rescan_entry( store ); } if( combo->active_device ) { unicapgtk_device_selection_set_by_id( combo, combo->active_device ); } if( GTK_WIDGET_REALIZED( combo ) ) { gdk_window_set_cursor( GTK_WIDGET( combo )->window, NULL ); } return i; }