Ejemplo n.º 1
0
/* check for udev events for v4l2 devices*/
gboolean 
check_v4l2_udev_events(gpointer data)
{
    struct ALL_DATA * all_data = (struct ALL_DATA *) data;
    struct vdIn *videoIn = all_data->videoIn;
    struct GLOBAL *global = all_data->global;
    struct GWIDGET *gwidget = all_data->gwidget;
    
    fd_set fds;
    struct timeval tv;
    int ret;
    
    FD_ZERO(&fds);
    FD_SET(videoIn->udev_fd, &fds);
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    
    ret = select(videoIn->udev_fd+1, &fds, NULL, NULL, &tv);
    
    /* Check if our file descriptor has received data. */
    if (ret > 0 && FD_ISSET(videoIn->udev_fd, &fds)) 
    {
        /* Make the call to receive the device.
            select() ensured that this will not block. */
        struct udev_device *dev = udev_monitor_receive_device(videoIn->udev_mon);
        if (dev) 
        {
            if (global->debug)
            {
                g_print("Got Device event\n");
                g_print("   Node: %s\n", udev_device_get_devnode(dev));
                g_print("   Subsystem: %s\n", udev_device_get_subsystem(dev));
                g_print("   Devtype: %s\n", udev_device_get_devtype(dev));

                g_print("   Action: %s\n",udev_device_get_action(dev));
            }
            
            /*update device list*/
            g_signal_handlers_block_by_func(GTK_COMBO_BOX_TEXT(gwidget->Devices), 
                G_CALLBACK (Devices_changed), all_data);
                
            /* clear out the old device list... */
            if(videoIn->listDevices != NULL) freeDevices(videoIn->listDevices);
            
            GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model (GTK_COMBO_BOX(gwidget->Devices)));
            gtk_list_store_clear(store);
            
            /*create new device list*/
            videoIn->listDevices = enum_devices( videoIn->videodevice, videoIn->udev, global->debug );
            
            if (videoIn->listDevices->num_devices < 1)
            {
                //use current
                gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(gwidget->Devices),
                    videoIn->videodevice);
                gtk_combo_box_set_active(GTK_COMBO_BOX(gwidget->Devices),0);
            }
            else
            {
                int i=0;
                for(i=0;i<(videoIn->listDevices->num_devices);i++)
                {
                    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(gwidget->Devices),
                        videoIn->listDevices->listVidDevices[i].name);
                    if(videoIn->listDevices->listVidDevices[i].current)
                        gtk_combo_box_set_active(GTK_COMBO_BOX(gwidget->Devices),i);
                }
            }
            g_signal_handlers_unblock_by_func(GTK_COMBO_BOX_TEXT(gwidget->Devices), 
                G_CALLBACK (Devices_changed), all_data);
            
            udev_device_unref(dev);
        }
        else 
            g_printerr("No Device from receive_device(). An error occured.\n");

    }

    return(TRUE);
}
JNIEXPORT void JNICALL
Java_org_jitsi_impl_neomedia_CoreAudioDevice_freeDevices
  (JNIEnv *env, jclass clazz)
{
    freeDevices();
}