1 #include <unicap.h>
    2 #include <unicapgtk.h>
    3 #include <string.h>
    4 
    5 struct widgets
    6 {
    7   GtkWidget *video_display;
    8   GtkWidget *format_selection;
    9 };
   10 
   11 static void
   12 format_change_cb (GtkWidget * ugtk, unicap_format_t * format,
   13                   struct widgets *widgets)
   14 {
   15   unicapgtk_video_display_set_format (UNICAPGTK_VIDEO_DISPLAY   // (3)
   16                                       (widgets->video_display), format);
   17 }
   18 
   19 static void
   20 device_change_cb (UnicapgtkDeviceSelection * selection, gchar * device_id,
   21                   struct widgets *widgets)
   22 {
   23   unicap_device_t device;
   24   unicap_handle_t handle;
   25 
   26   unicap_void_device (&device);
   27   strcpy (device.identifier, device_id);
   28 
   29   if (!SUCCESS (unicap_enumerate_devices (&device, &device, 0)) ||
   30       !SUCCESS (unicap_open (&handle, &device)))
   31     {
   32       // device is not available anymore
   33       g_printerr ("device '%s' not available!\n", device_id);
   34       return;
   35     }
   36 
   37   unicapgtk_video_format_selection_set_handle
   38     (UNICAPGTK_VIDEO_FORMAT_SELECTION (widgets->format_selection), handle);
   39 
   40   unicapgtk_video_display_stop (UNICAPGTK_VIDEO_DISPLAY
   41                                 (widgets->video_display));
   42   unicapgtk_video_display_set_handle (UNICAPGTK_VIDEO_DISPLAY
   43                                       (widgets->video_display), handle);
   44   unicapgtk_video_display_start (UNICAPGTK_VIDEO_DISPLAY
   45                                  (widgets->video_display));
   46 }
   47 
   48 
   49 int
   50 main (int argc, char **argv)
   51 {
   52   GtkWidget *window;
   53   GtkWidget *vbox;
   54   GtkWidget *hbox;
   55   GtkWidget *device_selection;
   56   struct widgets widgets;
   57 
   58   gtk_init (&argc, &argv);
   59 
   60   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   61   g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit),
   62                     NULL);
   63 
   64   vbox = gtk_vbox_new (FALSE, 10);
   65   gtk_container_add (GTK_CONTAINER (window), vbox);
   66 
   67   hbox = gtk_hbox_new (FALSE, 10);
   68   gtk_box_pack_start_defaults (GTK_BOX (vbox), hbox);
   69 
   70   widgets.video_display = unicapgtk_video_display_new ();
   71   widgets.format_selection = unicapgtk_video_format_selection_new ();   // (1)
   72 
   73   device_selection = unicapgtk_device_selection_new (TRUE);
   74   gtk_box_pack_start_defaults (GTK_BOX (hbox), device_selection);
   75   gtk_box_pack_start_defaults (GTK_BOX (hbox), widgets.format_selection);
   76   unicapgtk_device_selection_rescan (UNICAPGTK_DEVICE_SELECTION
   77                                      (device_selection));
   78   g_signal_connect (G_OBJECT (device_selection),
   79                     "unicapgtk_device_selection_changed",
   80                     G_CALLBACK (device_change_cb), &widgets);
   81   gtk_combo_box_set_active (GTK_COMBO_BOX (device_selection), 0);
   82 
   83   g_signal_connect (G_OBJECT (widgets.format_selection),        // (2)
   84                     "unicapgtk_video_format_changed",
   85                     G_CALLBACK (format_change_cb), &widgets);
   86 
   87   gtk_box_pack_start_defaults (GTK_BOX (vbox), widgets.video_display);
   88 
   89   gtk_widget_show_all (window);
   90   gtk_main ();
   91 
   92   return 0;
   93 }