[ekiga] Added a new component to monitor video input devices using GUDev



commit 31baf08517d5c8cd1e0c04f7a64f5399069528b5
Author: Julien Puydt <jpuydt free fr>
Date:   Mon Mar 3 18:29:45 2014 +0100

    Added a new component to monitor video input devices using GUDev

 lib/Makefile.am                                    |   15 +++
 lib/engine/components/hal-gudev/hal-gudev-main.cpp |   81 ++++++++++++++
 lib/engine/components/hal-gudev/hal-gudev-main.h   |   45 ++++++++
 .../components/hal-gudev/hal-gudev-monitor.cpp     |  117 ++++++++++++++++++++
 .../components/hal-gudev/hal-gudev-monitor.h       |   81 ++++++++++++++
 lib/engine/engine.cpp                              |    8 ++
 6 files changed, 347 insertions(+), 0 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 48bb0d0..a117138 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -36,6 +36,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/engine/components/echo \
        -I$(top_srcdir)/lib/engine/components/gmconf-personal-details \
        -I$(top_srcdir)/lib/engine/components/hal-dbus \
+       -I$(top_srcdir)/lib/engine/components/hal-gudev \
        -I$(top_srcdir)/lib/engine/components/local-roster \
        -I$(top_srcdir)/lib/engine/components/mlogo-videoinput \
        -I$(top_srcdir)/lib/engine/components/null-audioinput \
@@ -517,6 +518,20 @@ libekiga_la_SOURCES += \
        engine/components/null-audiooutput/audiooutput-main-null.cpp
 
 ##
+# Sources of the GUDev component
+##
+if HAVE_GUDEV
+libekiga_la_SOURCES += \
+       engine/components/hal-gudev/hal-gudev-monitor.h \
+       engine/components/hal-gudev/hal-gudev-monitor.cpp \
+       engine/components/hal-gudev/hal-gudev-main.h \
+       engine/components/hal-gudev/hal-gudev-main.cpp
+
+AM_CPPFLAGS += $(GUDEV_CFLAGS)
+libekiga_la_LDFLAGS += $(GUDEV_LIBS)
+endif
+
+##
 # Sources of the hal dbus component
 ##
 if HAVE_DBUS
diff --git a/lib/engine/components/hal-gudev/hal-gudev-main.cpp 
b/lib/engine/components/hal-gudev/hal-gudev-main.cpp
new file mode 100644
index 0000000..69583e2
--- /dev/null
+++ b/lib/engine/components/hal-gudev/hal-gudev-main.cpp
@@ -0,0 +1,81 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         hal-gudev-main.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (c) 2014 Julien Puydt
+ *   description          : implementation of the hook for the GUDev device monitor
+ *
+ */
+
+#include "hal-gudev-main.h"
+#include "hal-core.h"
+
+#include "hal-gudev-monitor.h"
+
+struct GUDevSpark: public Ekiga::Spark
+{
+  GUDevSpark (): result(false)
+  {}
+
+  bool try_initialize_more (Ekiga::ServiceCore& core,
+                           int* /*argc*/,
+                           char** /*argv*/[])
+  {
+    boost::shared_ptr<Ekiga::HalCore> hal_core = core.get<Ekiga::HalCore> ("hal-core");
+    boost::shared_ptr<GUDevMonitor> monitor = core.get<GUDevMonitor> ("gudev");
+
+    if (hal_core && !monitor) {
+
+      monitor = boost::shared_ptr<GUDevMonitor> (new GUDevMonitor);
+
+      core.add (Ekiga::ServicePtr (monitor));
+      hal_core->add_manager (*monitor);
+      result = true;
+    }
+
+    return result;
+  }
+
+  Ekiga::Spark::state get_state () const
+  { return result?FULL:BLANK; }
+
+  const std::string get_name () const
+  { return "GUDEV"; }
+
+  bool result;
+};
+
+void
+hal_gudev_init (Ekiga::KickStart& kickstart)
+{
+  boost::shared_ptr<Ekiga::Spark> spark(new GUDevSpark);
+  kickstart.add_spark (spark);
+}
diff --git a/lib/engine/components/hal-gudev/hal-gudev-main.h 
b/lib/engine/components/hal-gudev/hal-gudev-main.h
new file mode 100644
index 0000000..b6792b2
--- /dev/null
+++ b/lib/engine/components/hal-gudev/hal-gudev-main.h
@@ -0,0 +1,45 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         hal-gudev-main.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (c) 2014 Julien Puydt
+ *   description          : api to hook the GUDev device monitor to the HAL core
+ *
+ */
+
+#ifndef __HAL_GUDEV_MAIN_H__
+#define __HAL_GUDEV_MAIN_H__
+
+#include "kickstart.h"
+
+void hal_gudev_init (Ekiga::KickStart& kickstart);
+
+#endif
diff --git a/lib/engine/components/hal-gudev/hal-gudev-monitor.cpp 
b/lib/engine/components/hal-gudev/hal-gudev-monitor.cpp
new file mode 100644
index 0000000..084e670
--- /dev/null
+++ b/lib/engine/components/hal-gudev/hal-gudev-monitor.cpp
@@ -0,0 +1,117 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         hal-gudev-monitor.cpp  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (c) 2014 Julien Puydt
+ *   description          : implementation of the GUDev device monitor
+ *
+ */
+
+#include "hal-gudev-monitor.h"
+
+void
+videoinput_uevent_handler_cb (G_GNUC_UNUSED GUdevClient* client,
+                             const gchar* action,
+                             GUdevDevice* device,
+                             GUDevMonitor* monitor)
+{
+  if (g_str_equal ("remove", action)) {
+
+    monitor->videoinput_remove (device);
+  }
+  if (g_str_equal ("add", action)) {
+
+    monitor->videoinput_added (device);
+  }
+}
+
+GUDevMonitor::GUDevMonitor ()
+{
+  const gchar* videoinput_subsystems[] = {"video4linux", NULL};
+  videoinput = g_udev_client_new (videoinput_subsystems);
+  g_signal_connect (G_OBJECT (videoinput), "uevent",
+                   G_CALLBACK (videoinput_uevent_handler_cb), this);
+}
+
+GUDevMonitor::~GUDevMonitor ()
+{
+  g_object_unref (videoinput);
+}
+
+void
+GUDevMonitor::videoinput_added (GUdevDevice* device)
+{
+  gint v4l_version = 0;
+
+  // first check the api version
+  v4l_version = g_udev_device_get_property_as_int (device, "ID_V4L_VERSION");
+
+  if (v4l_version == 1 || v4l_version == 2) {
+
+    // then check it can actually capture video
+    const char* caps = g_udev_device_get_property (device, "ID_V4L_CAPABILITIES");
+    if (caps != NULL && g_strstr_len (caps, -1, ":capture:") != NULL) {
+
+      // we're almost good!
+      const gchar* file = g_udev_device_get_device_file (device);
+
+      if (file != NULL) {
+       VideoInputDevice vdevice = {"video4linux", file, v4l_version};
+       videoinput_devices.push_back(vdevice);
+       videoinput_device_added ("video4linux", file, v4l_version);
+      }
+    }
+  }
+}
+
+void
+GUDevMonitor::videoinput_remove (GUdevDevice* device)
+{
+  const gchar* file = g_udev_device_get_device_file (device);
+  bool found = false;
+  std::vector<VideoInputDevice>::iterator iter;
+
+  for (iter = videoinput_devices.begin ();
+       iter != videoinput_devices.end ();
+       ++iter) {
+
+    if (iter->name == file) {
+
+      found = true;
+      break;
+    }
+  }
+  if (found) {
+
+    videoinput_device_removed (iter->framework, iter->name, iter->caps);
+    videoinput_devices.erase (iter);
+  }
+}
diff --git a/lib/engine/components/hal-gudev/hal-gudev-monitor.h 
b/lib/engine/components/hal-gudev/hal-gudev-monitor.h
new file mode 100644
index 0000000..72b8723
--- /dev/null
+++ b/lib/engine/components/hal-gudev/hal-gudev-monitor.h
@@ -0,0 +1,81 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         hal-gudev-monitor.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (c) 2014 Julien Puydt
+ *   description          : declaration of the GUDev device monitor
+ *
+ */
+
+#ifndef __HAL_GUDEV_MONITOR_H__
+#define __HAL_GUDEV_MONITOR_H__
+
+#include "services.h"
+#include "hal-manager.h"
+
+#include <gudev/gudev.h>
+
+class GUDevMonitor:
+  public Ekiga::Service,
+  public Ekiga::HalManager
+{
+public:
+  GUDevMonitor();
+
+  ~GUDevMonitor();
+
+  const std::string get_name () const
+  { return "gudev"; }
+
+  const std::string get_description () const
+  { return "\tComponent monitoring devices using GUDev"; }
+
+private:
+
+  // video input part of the api
+
+  friend void videoinput_uevent_handler_cb (GUdevClient* client,
+                                           const gchar* action,
+                                           GUdevDevice* device,
+                                           GUDevMonitor* monitor);
+  void videoinput_added (GUdevDevice* device);
+  void videoinput_remove (GUdevDevice* device);
+  typedef struct VideoInputDevice {
+    std::string framework;
+    std::string name;
+    int caps;
+  } VideoInputDevice;
+  std::vector<VideoInputDevice> videoinput_devices;
+  GUdevClient* videoinput;
+  
+};
+
+#endif
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index d03cc19..75a2cb6 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -72,6 +72,10 @@
 #include "audioinput-main-ptlib.h"
 #include "audiooutput-main-ptlib.h"
 
+#ifdef HAVE_GUDEV
+#include "hal-gudev-main.h"
+#endif
+
 #ifdef HAVE_DBUS
 #include "hal-main-dbus.h"
 #endif
@@ -141,6 +145,10 @@ engine_init (Ekiga::ServiceCorePtr service_core,
   audioinput_ptlib_init (kickstart);
   audiooutput_ptlib_init (kickstart);
 
+#ifdef HAVE_GUDEV
+  hal_gudev_init (kickstart);
+#endif
+
 #ifdef HAVE_DBUS
   hal_dbus_init (kickstart);
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]