[aravis/wip/emmanuel/usb3vision: 4/7] usb: device and stream boilerplate
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis/wip/emmanuel/usb3vision: 4/7] usb: device and stream boilerplate
- Date: Tue, 17 May 2016 15:45:01 +0000 (UTC)
commit ef1d87cd20b0c09fa6437cf9f390d68371515e8c
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sat Apr 9 12:39:26 2016 +0200
usb: device and stream boilerplate
docs/reference/aravis/aravis-docs.xml | 7 +
docs/reference/aravis/aravis-sections.txt | 55 +++++++++
src/Makefile.am | 8 +-
src/arvtypes.h | 2 +
src/arvuvdevice.c | 151 ++++++++++++++++++++++++
src/arvuvdevice.h | 57 +++++++++
src/arvuvstream.c | 178 +++++++++++++++++++++++++++++
src/arvuvstream.h | 57 +++++++++
8 files changed, 513 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-docs.xml b/docs/reference/aravis/aravis-docs.xml
index 829cfda..14074c0 100644
--- a/docs/reference/aravis/aravis-docs.xml
+++ b/docs/reference/aravis/aravis-docs.xml
@@ -85,6 +85,13 @@
</chapter>
<chapter>
+ <title>USB camera</title>
+ <xi:include href="xml/arvuvinterface.xml"/>
+ <xi:include href="xml/arvuvdevice.xml"/>
+ <xi:include href="xml/arvuvstream.xml"/>
+ </chapter>
+
+ <chapter>
<title>Fake camera</title>
<xi:include href="xml/arvfakeinterface.xml"/>
<xi:include href="xml/arvfakedevice.xml"/>
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 91683fd..0d2b810 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -230,6 +230,61 @@ ARV_FAKE_INTERFACE_SOCKET_BUFFER_SIZE
</SECTION>
<SECTION>
+<FILE>arvuvinterface</FILE>
+<TITLE>ArvUvInterface</TITLE>
+arv_uv_interface_destroy_instance
+arv_uv_interface_get_instance
+<SUBSECTION Standard>
+ArvUvInterface
+ARV_IS_UV_INTERFACE
+ARV_IS_UV_INTERFACE_CLASS
+ARV_TYPE_UV_INTERFACE
+ARV_UV_INTERFACE
+ARV_UV_INTERFACE_CLASS
+ARV_UV_INTERFACE_GET_CLASS
+ArvUvInterfaceClass
+ArvUvInterfacePrivate
+arv_uv_interface_get_type
+<SUBSECTION Private>
+</SECTION>
+
+<SECTION>
+<FILE>arvuvdevice</FILE>
+<TITLE>ArvUvDevice</TITLE>
+arv_uv_device_new
+<SUBSECTION Standard>
+ArvUvDevice
+ARV_IS_UV_DEVICE
+ARV_IS_UV_DEVICE_CLASS
+ARV_TYPE_UV_DEVICE
+ARV_UV_DEVICE
+ARV_UV_DEVICE_CLASS
+ARV_UV_DEVICE_GET_CLASS
+ArvUvDeviceClass
+ArvUvDevicePrivate
+arv_uv_device_get_type
+<SUBSECTION Private>
+</SECTION>
+
+<SECTION>
+<FILE>arvuvstream</FILE>
+<TITLE>ArvUvStream</TITLE>
+arv_uv_stream_new
+<SUBSECTION Standard>
+ArvUvStream
+ARV_IS_UV_STREAM
+ARV_IS_UV_STREAM_CLASS
+ARV_TYPE_UV_STREAM
+ARV_UV_STREAM
+ARV_UV_STREAM_CLASS
+ARV_UV_STREAM_GET_CLASS
+ArvUvStreamClass
+ArvUvStreamPrivate
+arv_uv_stream_get_type
+<SUBSECTION Private>
+</SECTION>
+
+<SECTION>
<FILE>arvgcport</FILE>
<TITLE>ArvGcPort</TITLE>
ArvGcPort
diff --git a/src/Makefile.am b/src/Makefile.am
index f930c2c..26e2bf5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -158,10 +158,14 @@ noinst_HEADERS = \
if ARAVIS_BUILD_USB
ARAVIS_SRCS += \
- arvuvinterface.c
+ arvuvinterface.c \
+ arvuvdevice.c \
+ arvuvstream.c
ARAVIS_HDRS += \
- arvuvinterface.h
+ arvuvinterface.h \
+ arvuvdevice.h \
+ arvuvstream.h
endif
arv_fake_cameradir = $(aravis_datadir)
diff --git a/src/arvtypes.h b/src/arvtypes.h
index 4e4b96e..5343283 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -81,6 +81,8 @@ typedef struct _ArvGvStream ArvGvStream;
#ifdef ARAVIS_BUILD_USB
typedef struct _ArvUvInterface ArvUvInterface;
+typedef struct _ArvUvDevice ArvUvDevice;
+typedef struct _ArvUvStream ArvUvStream;
#endif
typedef struct _ArvFakeInterface ArvFakeInterface;
diff --git a/src/arvuvdevice.c b/src/arvuvdevice.c
new file mode 100644
index 0000000..1e23ad7
--- /dev/null
+++ b/src/arvuvdevice.c
@@ -0,0 +1,151 @@
+/* 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>
+ */
+
+/**
+ * SECTION: arvuvdevice
+ * @short_description: Uv camera device
+ */
+
+#include <arvuvdevice.h>
+#include <arvuvstream.h>
+#include <arvgc.h>
+#include <arvdebug.h>
+
+static GObjectClass *parent_class = NULL;
+
+struct _ArvUvDevicePrivate {
+ ArvGc *genicam;
+
+ const char *genicam_xml;
+ size_t genicam_xml_size;
+};
+
+/* ArvUvDevice implemenation */
+
+/* ArvDevice implemenation */
+
+static ArvStream *
+arv_uv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void *user_data)
+{
+ ArvStream *stream;
+
+ stream = arv_uv_stream_new (callback, user_data);
+
+ return stream;
+}
+
+static const char *
+arv_uv_device_get_genicam_xml (ArvDevice *device, size_t *size)
+{
+ ArvUvDevice *uv_device = ARV_UV_DEVICE (device);
+
+ *size = uv_device->priv->genicam_xml_size;
+
+ return uv_device->priv->genicam_xml;
+}
+
+static ArvGc *
+arv_uv_device_get_genicam (ArvDevice *device)
+{
+ ArvUvDevice *uv_device = ARV_UV_DEVICE (device);
+
+ return uv_device->priv->genicam;
+}
+
+static gboolean
+arv_uv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
+{
+ g_assert_not_reached ();
+ return FALSE;
+}
+
+static gboolean
+arv_uv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
+{
+ g_assert_not_reached ();
+ return FALSE;
+}
+
+static gboolean
+arv_uv_device_read_register (ArvDevice *device, guint32 address, guint32 *value, GError **error)
+{
+ g_assert_not_reached ();
+ return FALSE;
+}
+
+static gboolean
+arv_uv_device_write_register (ArvDevice *device, guint32 address, guint32 value, GError **error)
+{
+ g_assert_not_reached ();
+ return FALSE;
+}
+
+ArvDevice *
+arv_uv_device_new (const char *serial_number)
+{
+ ArvUvDevice *uv_device;
+
+ g_return_val_if_fail (serial_number != NULL, NULL);
+
+ uv_device = g_object_new (ARV_TYPE_UV_DEVICE, NULL);
+
+ return ARV_DEVICE (uv_device);
+}
+
+static void
+arv_uv_device_init (ArvUvDevice *uv_device)
+{
+ uv_device->priv = G_TYPE_INSTANCE_GET_PRIVATE (uv_device, ARV_TYPE_UV_DEVICE, ArvUvDevicePrivate);
+}
+
+static void
+arv_uv_device_finalize (GObject *object)
+{
+ ArvUvDevice *uv_device = ARV_UV_DEVICE (object);
+
+ g_object_unref (uv_device->priv->genicam);
+
+ parent_class->finalize (object);
+}
+
+static void
+arv_uv_device_class_init (ArvUvDeviceClass *uv_device_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (uv_device_class);
+ ArvDeviceClass *device_class = ARV_DEVICE_CLASS (uv_device_class);
+
+ g_type_class_add_private (uv_device_class, sizeof (ArvUvDevicePrivate));
+
+ parent_class = g_type_class_peek_parent (uv_device_class);
+
+ object_class->finalize = arv_uv_device_finalize;
+
+ device_class->create_stream = arv_uv_device_create_stream;
+ device_class->get_genicam_xml = arv_uv_device_get_genicam_xml;
+ device_class->get_genicam = arv_uv_device_get_genicam;
+ device_class->read_memory = arv_uv_device_read_memory;
+ device_class->write_memory = arv_uv_device_write_memory;
+ device_class->read_register = arv_uv_device_read_register;
+ device_class->write_register = arv_uv_device_write_register;
+}
+
+G_DEFINE_TYPE (ArvUvDevice, arv_uv_device, ARV_TYPE_DEVICE)
diff --git a/src/arvuvdevice.h b/src/arvuvdevice.h
new file mode 100644
index 0000000..922adaf
--- /dev/null
+++ b/src/arvuvdevice.h
@@ -0,0 +1,57 @@
+/* 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_DEVICE_H
+#define ARV_UV_DEVICE_H
+
+#include <arvtypes.h>
+#include <arvdevice.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_UV_DEVICE (arv_uv_device_get_type ())
+#define ARV_UV_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_UV_DEVICE, ArvUvDevice))
+#define ARV_UV_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_UV_DEVICE,
ArvUvDeviceClass))
+#define ARV_IS_UV_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_UV_DEVICE))
+#define ARV_IS_UV_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_UV_DEVICE))
+#define ARV_UV_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_UV_DEVICE,
ArvUvDeviceClass))
+
+typedef struct _ArvUvDeviceClass ArvUvDeviceClass;
+typedef struct _ArvUvDevicePrivate ArvUvDevicePrivate;
+
+struct _ArvUvDevice {
+ ArvDevice device;
+
+ ArvUvDevicePrivate *priv;
+};
+
+struct _ArvUvDeviceClass {
+ ArvDeviceClass parent_class;
+};
+
+GType arv_uv_device_get_type (void);
+
+ArvDevice * arv_uv_device_new (const char *serial_number);
+
+G_END_DECLS
+
+#endif
diff --git a/src/arvuvstream.c b/src/arvuvstream.c
new file mode 100644
index 0000000..67c4269
--- /dev/null
+++ b/src/arvuvstream.c
@@ -0,0 +1,178 @@
+/* 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>
+ */
+
+/**
+ * SECTION: arvuvstream
+ * @short_description: USB3Vision camera stream
+ */
+
+#include <arvuvstream.h>
+#include <arvstreamprivate.h>
+#include <arvbufferprivate.h>
+#include <arvdebug.h>
+#include <arvmisc.h>
+
+static GObjectClass *parent_class = NULL;
+
+struct _ArvUvStreamPrivate {
+ GThread *thread;
+ void *thread_data;
+};
+
+/* Acquisition thread */
+
+typedef struct {
+ ArvStream *stream;
+
+ ArvStreamCallback callback;
+ void *user_data;
+
+ gboolean cancel;
+
+ /* Statistics */
+
+ guint n_completed_buffers;
+ guint n_failures;
+ guint n_underruns;
+} ArvUvStreamThreadData;
+
+static void *
+arv_uv_stream_thread (void *data)
+{
+ ArvUvStreamThreadData *thread_data = data;
+
+ arv_log_stream_thread ("[UvStream::thread] Start");
+
+ if (thread_data->callback != NULL)
+ thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_INIT, NULL);
+
+ while (!thread_data->cancel) {
+ g_usleep (1000000);
+ }
+
+ if (thread_data->callback != NULL)
+ thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_EXIT, NULL);
+
+ arv_log_stream_thread ("[UvStream::thread] Stop");
+
+ return NULL;
+}
+
+/* ArvUvStream implemenation */
+
+
+/**
+ * arv_uv_stream_new: (skip)
+ * @callback: (scope call): image processing callback
+ * @user_data: (closure): user data for @callback
+ *
+ * Return Value: (transfer full): a new #ArvStream.
+ */
+
+ArvStream *
+arv_uv_stream_new (ArvStreamCallback callback, void *user_data)
+{
+ ArvUvStream *uv_stream;
+ ArvUvStreamThreadData *thread_data;
+ ArvStream *stream;
+
+ uv_stream = g_object_new (ARV_TYPE_UV_STREAM, NULL);
+
+ stream = ARV_STREAM (uv_stream);
+
+ thread_data = g_new (ArvUvStreamThreadData, 1);
+ thread_data->stream = stream;
+ thread_data->callback = callback;
+ thread_data->user_data = user_data;
+ thread_data->cancel = FALSE;
+
+ thread_data->n_completed_buffers = 0;
+ thread_data->n_failures = 0;
+ thread_data->n_underruns = 0;
+
+ uv_stream->priv->thread_data = thread_data;
+ uv_stream->priv->thread = arv_g_thread_new ("arv_uv_stream", arv_uv_stream_thread,
uv_stream->priv->thread_data);
+
+ return ARV_STREAM (uv_stream);
+}
+
+/* ArvStream implementation */
+
+static void
+arv_uv_stream_get_statistics (ArvStream *stream,
+ guint64 *n_completed_buffers,
+ guint64 *n_failures,
+ guint64 *n_underruns)
+{
+ ArvUvStream *uv_stream = ARV_UV_STREAM (stream);
+ ArvUvStreamThreadData *thread_data;
+
+ thread_data = uv_stream->priv->thread_data;
+
+ *n_completed_buffers = thread_data->n_completed_buffers;
+ *n_failures = thread_data->n_failures;
+ *n_underruns = thread_data->n_underruns;
+}
+
+static void
+arv_uv_stream_init (ArvUvStream *uv_stream)
+{
+ uv_stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (uv_stream, ARV_TYPE_UV_STREAM, ArvUvStreamPrivate);
+}
+
+static void
+arv_uv_stream_finalize (GObject *object)
+{
+ ArvUvStream *uv_stream = ARV_UV_STREAM (object);
+
+ if (uv_stream->priv->thread != NULL) {
+ ArvUvStreamThreadData *thread_data;
+
+ thread_data = uv_stream->priv->thread_data;
+
+ thread_data->cancel = TRUE;
+ g_thread_join (uv_stream->priv->thread);
+ g_free (thread_data);
+
+ uv_stream->priv->thread_data = NULL;
+ uv_stream->priv->thread = NULL;
+ }
+
+ parent_class->finalize (object);
+}
+
+static void
+arv_uv_stream_class_init (ArvUvStreamClass *uv_stream_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (uv_stream_class);
+ ArvStreamClass *stream_class = ARV_STREAM_CLASS (uv_stream_class);
+
+ g_type_class_add_private (uv_stream_class, sizeof (ArvUvStreamPrivate));
+
+ parent_class = g_type_class_peek_parent (uv_stream_class);
+
+ object_class->finalize = arv_uv_stream_finalize;
+
+ stream_class->get_statistics = arv_uv_stream_get_statistics;
+}
+
+G_DEFINE_TYPE (ArvUvStream, arv_uv_stream, ARV_TYPE_STREAM)
diff --git a/src/arvuvstream.h b/src/arvuvstream.h
new file mode 100644
index 0000000..a88572c
--- /dev/null
+++ b/src/arvuvstream.h
@@ -0,0 +1,57 @@
+/* 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_STREAM_H
+#define ARV_UV_STREAM_H
+
+#include <arvtypes.h>
+#include <arvstream.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_UV_STREAM (arv_uv_stream_get_type ())
+#define ARV_UV_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_UV_STREAM, ArvUvStream))
+#define ARV_UV_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_UV_STREAM,
ArvUvStreamClass))
+#define ARV_IS_UV_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_UV_STREAM))
+#define ARV_IS_UV_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_UV_STREAM))
+#define ARV_UV_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_UV_STREAM,
ArvUvStreamClass))
+
+typedef struct _ArvUvStreamPrivate ArvUvStreamPrivate;
+typedef struct _ArvUvStreamClass ArvUvStreamClass;
+
+struct _ArvUvStream {
+ ArvStream stream;
+
+ ArvUvStreamPrivate *priv;
+};
+
+struct _ArvUvStreamClass {
+ ArvStreamClass parent_class;
+};
+
+GType arv_uv_stream_get_type (void);
+
+ArvStream * arv_uv_stream_new (ArvStreamCallback callback, void *user_data);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]