[aravis/wip/emmanuel/usb3vision: 1/7] usb: start work on usb3vision support



commit 01b26744f13b722696e63356ee73b422816bb82d
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Thu Mar 31 09:37:09 2016 +0200

    usb: start work on usb3vision support

 configure.ac         |   24 +++++++++++
 src/Makefile.am      |    8 ++++
 src/arv.h            |    3 +
 src/arvsystem.c      |   10 ++++
 src/arvtypes.h       |    7 +++-
 src/arvuvinterface.c |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/arvuvinterface.h |   58 +++++++++++++++++++++++++
 7 files changed, 222 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f9e892a..5873edc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,6 +31,11 @@ IT_PROG_INTLTOOL([0.31.2])
 
 LT_INIT()
 
+AC_ARG_ENABLE(usb,
+             [AS_HELP_STRING([--enable-usb],
+                             [build with USB support [default=auto]])],
+             [enable_usb=$enableval],
+             [enable_usb=auto])
 AC_ARG_ENABLE(viewer,
              [AS_HELP_STRING([--enable-viewer],
                              [build viewer [default=auto]])],
@@ -60,6 +65,7 @@ AC_ARG_ENABLE(zlib_pc,
 PKG_PROG_PKG_CONFIG([0.14])
 
 ARAVIS_REQUIREMENTS="glib-2.0 >= 2.26 gobject-2.0 gio-2.0 libxml-2.0 gthread-2.0"
+ARAVIS_USB_REQUIREMENTS="libusb-1.0"
 ARAVIS_GSTREAMER_REQUIREMENTS="gstreamer-base-1.0 gstreamer-app-1.0"
 ARAVIS_GSTREAMER_0_10_REQUIREMENTS="gstreamer-base-0.10 gstreamer-app-0.10"
 ARAVIS_VIEWER_REQUIREMENTS="$ARAVIS_GSTREAMER_REQUIREMENTS gstreamer-video-1.0 gtk+-3.0 libnotify"
@@ -73,9 +79,26 @@ else
        ARAVIS_ADDITIONAL_LIBS="-lm -lz"
 fi
 
+# USB support
+# ===========
+
+build_usb=no
+if test "x$enable_usb" = "xyes" || test "x$enable_usb" = "xauto"; then
+       PKG_CHECK_MODULES([ARAVIS_USB], [$ARAVIS_USB_REQUIREMENTS],
+                         [AC_DEFINE([ARAVIS_BUILD_USB], [1], [Build USB support]) build_usb=yes],
+                         [AS_IF([test "x$enable_usb" = "xyes"],
+                                AC_MSG_ERROR([${ARAVIS_USB_PKG_ERRORS} - Can not build USB support]))]);
+fi
+AM_CONDITIONAL(ARAVIS_BUILD_USB, test "x$build_usb" = "xyes")
+
+if test "x$build_usb" = "xyes"; then
+       ARAVIS_REQUIREMENTS="${ARAVIS_REQUIREMENTS} ${ARAVIS_USB_REQUIREMENTS}"
+fi
+
 PKG_CHECK_MODULES(ARAVIS, [$ARAVIS_REQUIREMENTS])
 
 # Standard math library doesn't come with a pkgconfig file.
+
 ARAVIS_LIBS="${ARAVIS_ADDITIONAL_LIBS} ${ARAVIS_LIBS}"
 
 AC_SUBST(ARAVIS_CFLAGS)
@@ -200,6 +223,7 @@ echo "  Compiler:                    ${CC}"
 echo "  Compiler flags:              ${ARAVIS_CFLAGS}"
 echo "  Linker flags:                ${ARAVIS_LIBS}"
 echo ""
+echo "  Build USB support:           $build_usb"
 echo "  Build viewer:                $build_viewer"
 echo "  Build gstreamer plugin:      $build_gst_plugin"
 echo "  Build gstreamer-0.10 plugin: $build_gst_0_10_plugin"
diff --git a/src/Makefile.am b/src/Makefile.am
index c6626a9..f930c2c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -156,6 +156,14 @@ noinst_HEADERS =                           \
        arvstreamprivate.h                      \
        arvrealtimeprivate.h
 
+if ARAVIS_BUILD_USB
+ARAVIS_SRCS +=                                 \
+       arvuvinterface.c
+
+ARAVIS_HDRS +=                                 \
+       arvuvinterface.h
+endif
+
 arv_fake_cameradir = $(aravis_datadir)
 arv_fake_camera_DATA = arv-fake-camera.xml
 
diff --git a/src/arv.h b/src/arv.h
index fe8475e..e3dbc76 100644
--- a/src/arv.h
+++ b/src/arv.h
@@ -68,6 +68,9 @@
 #include <arvgvinterface.h>
 #include <arvgvdevice.h>
 #include <arvgvstream.h>
+#ifdef ARAVIS_BUILD_USB
+#include <arvuvinterface.h>
+#endif
 #include <arvfakeinterface.h>
 #include <arvfakedevice.h>
 #include <arvfakestream.h>
diff --git a/src/arvsystem.c b/src/arvsystem.c
index 2a59e21..4799155 100644
--- a/src/arvsystem.c
+++ b/src/arvsystem.c
@@ -22,6 +22,9 @@
 
 #include <arvsystem.h>
 #include <arvgvinterface.h>
+#ifdef ARAVIS_BUILD_USB
+#include <arvuvinterface.h>
+#endif
 #include <arvfakeinterface.h>
 #include <arvdevice.h>
 #include <arvdebug.h>
@@ -45,7 +48,14 @@ ArvInterfaceInfos interfaces[] = {
                .is_available = TRUE,
                .get_interface_instance = arv_gv_interface_get_instance,
                .destroy_interface_instance = arv_gv_interface_destroy_instance
+       },
+#ifdef ARAVIS_BUILD_USB
+       {       .interface_id = "USB3Vision",
+               .is_available = TRUE,
+               .get_interface_instance = arv_uv_interface_get_instance,
+               .destroy_interface_instance = arv_uv_interface_destroy_instance
        }
+#endif
 };
 
 unsigned int
diff --git a/src/arvtypes.h b/src/arvtypes.h
index 1b2721b..4e4b96e 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -1,6 +1,6 @@
 /* Aravis - Digital camera library
  *
- * Copyright © 2009-2010 Emmanuel Pacaud
+ * Copyright © 2009-2016 Emmanuel Pacaud
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -24,6 +24,7 @@
 #define ARV_TYPES_H
 
 #include <arvenums.h>
+#include <arvconfig.h>
 
 G_BEGIN_DECLS
 
@@ -78,6 +79,10 @@ typedef struct _ArvGvInterface               ArvGvInterface;
 typedef struct _ArvGvDevice            ArvGvDevice;
 typedef struct _ArvGvStream            ArvGvStream;
 
+#ifdef ARAVIS_BUILD_USB
+typedef struct _ArvUvInterface                 ArvUvInterface;
+#endif
+
 typedef struct _ArvFakeInterface       ArvFakeInterface;
 typedef struct _ArvFakeDevice          ArvFakeDevice;
 typedef struct _ArvFakeStream          ArvFakeStream;
diff --git a/src/arvuvinterface.c b/src/arvuvinterface.c
new file mode 100644
index 0000000..1359008
--- /dev/null
+++ b/src/arvuvinterface.c
@@ -0,0 +1,113 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+/**
+ * SECTION: arvuvinterface
+ * @short_description: USB3 camera interface
+ */
+
+#include <arvuvinterface.h>
+#include <arvdebug.h>
+#include <arvmisc.h>
+
+/* ArvUvInterface implementation */
+
+static GObjectClass *parent_class = NULL;
+
+struct _ArvUvInterfacePrivate {
+       GHashTable *devices;
+};
+
+static void
+arv_uv_interface_update_device_list (ArvInterface *interface, GArray *device_ids)
+{
+}
+
+static ArvDevice *
+arv_uv_interface_open_device (ArvInterface *interface, const char *device_id)
+{
+       return NULL;
+}
+
+static ArvInterface *uv_interface = NULL;
+ARV_DEFINE_STATIC_MUTEX (uv_interface_mutex);
+
+/**
+ * arv_uv_interface_get_instance:
+ *
+ * Gets the unique instance of the GV interface.
+ *
+ * Returns: (transfer none): a #ArvInterface singleton.
+ */
+
+ArvInterface *
+arv_uv_interface_get_instance (void)
+{
+       arv_g_mutex_lock (&uv_interface_mutex);
+
+       if (uv_interface == NULL)
+               uv_interface = g_object_new (ARV_TYPE_UV_INTERFACE, NULL);
+
+       arv_g_mutex_unlock (&uv_interface_mutex);
+
+       return ARV_INTERFACE (uv_interface);
+}
+
+void
+arv_uv_interface_destroy_instance (void)
+{
+       arv_g_mutex_lock (&uv_interface_mutex);
+
+       g_clear_object (&uv_interface);
+
+       arv_g_mutex_unlock (&uv_interface_mutex);
+}
+
+static void
+arv_uv_interface_init (ArvUvInterface *uv_interface)
+{
+       uv_interface->priv = G_TYPE_INSTANCE_GET_PRIVATE (uv_interface, ARV_TYPE_UV_INTERFACE, 
ArvUvInterfacePrivate);
+}
+
+static void
+arv_uv_interface_finalize (GObject *object)
+{
+       parent_class->finalize (object);
+}
+
+static void
+arv_uv_interface_class_init (ArvUvInterfaceClass *uv_interface_class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (uv_interface_class);
+       ArvInterfaceClass *interface_class = ARV_INTERFACE_CLASS (uv_interface_class);
+
+       g_type_class_add_private (uv_interface_class, sizeof (ArvUvInterfacePrivate));
+
+       parent_class = g_type_class_peek_parent (uv_interface_class);
+
+       object_class->finalize = arv_uv_interface_finalize;
+
+       interface_class->update_device_list = arv_uv_interface_update_device_list;
+       interface_class->open_device = arv_uv_interface_open_device;
+}
+
+G_DEFINE_TYPE (ArvUvInterface, arv_uv_interface, ARV_TYPE_INTERFACE)
diff --git a/src/arvuvinterface.h b/src/arvuvinterface.h
new file mode 100644
index 0000000..05d5661
--- /dev/null
+++ b/src/arvuvinterface.h
@@ -0,0 +1,58 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2016 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef ARV_UV_INTERFACE_H
+#define ARV_UV_INTERFACE_H
+
+#include <arvtypes.h>
+#include <arvinterface.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_UV_INTERFACE             (arv_uv_interface_get_type ())
+#define ARV_UV_INTERFACE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_UV_INTERFACE, 
ArvUvInterface))
+#define ARV_UV_INTERFACE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_UV_INTERFACE, 
ArvUvInterfaceClass))
+#define ARV_IS_UV_INTERFACE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_UV_INTERFACE))
+#define ARV_IS_UV_INTERFACE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_UV_INTERFACE))
+#define ARV_UV_INTERFACE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_UV_INTERFACE, 
ArvUvInterfaceClass))
+
+typedef struct _ArvUvInterfacePrivate ArvUvInterfacePrivate;
+typedef struct _ArvUvInterfaceClass ArvUvInterfaceClass;
+
+struct _ArvUvInterface {
+       ArvInterface    interface;
+
+       ArvUvInterfacePrivate *priv;
+};
+
+struct _ArvUvInterfaceClass {
+       ArvInterfaceClass parent_class;
+};
+
+GType arv_uv_interface_get_type (void);
+
+ArvInterface *                 arv_uv_interface_get_instance           (void);
+void                   arv_uv_interface_destroy_instance       (void);
+
+G_END_DECLS
+
+#endif


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