[aravis] fake: begin implementation of a fake camera.



commit 732c09fc3735051f9fd7a7ffa954c2a522a4a620
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed May 5 17:28:51 2010 +0200

    fake: begin implementation of a fake camera.
    
    It will be used for ArvFakeDevice and for the implementation of
    a fake GigE camera.

 configure.ac            |    2 +
 src/Makefile.am         |   10 +++-
 src/arv-fake-camera.xml |   82 ++++++++++++++++++++++++++++++
 src/arv.h               |    4 ++
 src/arvfakecamera.c     |  129 +++++++++++++++++++++++++++++++++++++++++++++++
 src/arvfakecamera.h     |   61 ++++++++++++++++++++++
 src/arvtypes.h          |    1 +
 src/tests/.gitignore    |    1 +
 src/tests/Makefile.am   |    6 ++-
 src/tests/fake.c        |   31 +++++++++++
 10 files changed, 324 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8efcbe4..508e2af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,6 +68,8 @@ else
 fi
 AC_SUBST(gstplugindir)
 
+AC_SUBST(aravis_datadir, '$(datadir)/aravis')
+
 GST_PLUGIN_LDFLAGS='-module -avoid-version -export-symbols-regex [_]*\(gst_\|Gst\|GST_\).*'
 AC_SUBST(GST_PLUGIN_LDFLAGS)
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 4954220..16afd82 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,7 @@ INCLUDES = \
 	-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
 	-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
 	-DPACKAGE_DATA_DIR=\""$(datadir)"\" $(ARAVIS_CFLAGS) \
+	-DARAVIS_DATA_DIR=\""$(aravis_datadir)"\" \
 	-DG_LOG_DOMAIN=\"Aravis\"
 
 AM_CFLAGS = -Wall
@@ -60,7 +61,8 @@ libaravis_la_SOURCES =				\
 	arvgvstream.c				\
 	arvfakeinterface.c			\
 	arvfakedevice.c				\
-	arvfakestream.c
+	arvfakestream.c				\
+	arvfakecamera.c
 
 ARAVIS_HDRS = 					\
 	arv.h					\
@@ -99,7 +101,11 @@ ARAVIS_HDRS = 					\
 	arvgvstream.h				\
 	arvfakeinterface.h			\
 	arvfakedevice.h				\
-	arvfakestream.h
+	arvfakestream.h				\
+	arvfakecamera.h
+
+arv_fake_cameradir = $(aravis_datadir)
+arv_fake_camera_DATA = arv-fake-camera.xml
 
 libaravis_ladir = $(includedir)/aravis
 libaravis_la_HEADERS = $(ARAVIS_HDRS)
diff --git a/src/arv-fake-camera.xml b/src/arv-fake-camera.xml
new file mode 100644
index 0000000..b7d5daf
--- /dev/null
+++ b/src/arv-fake-camera.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<RegisterDescription
+ ModelName="Model"
+ VendorName="Aravis"
+ StandardNameSpace="None"
+ SchemaMajorVersion="1"
+ SchemaMinorVersion="0"
+ SchemaSubMinorVersion="0"
+ MajorVersion="292"
+ MinorVersion="0"
+ SubMinorVersion="0"
+ ToolTip="TestTooltip"
+ ProductGuid="111-222"
+ VersionGuid="222-333"
+ xmlns="http://www.genicam.org/GenApi/Version_1_0";
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+ xsi:schemaLocation="http://www.genicam.org/GenApi/Version_1_0 GenApiSchema.xsd">
+ <Category Name="Root" NameSpace="Standard">
+  <pFeature>AcquisitionControl</pFeature>
+ </Category>
+
+ <Category Name="AcquisitionControl" NameSpace="Custom">
+  <pFeature>AcquisitionStart</pFeature>
+  <pFeature>AcquisitionStop</pFeature>
+ </Category>
+
+ <Command Name="AcquisitionStart" NameSpace="Standard">
+  <Description>Start acquisition. Before image acquisition can occur, acquisition must be started, either by a hardware trigger or this software command.</Description>
+  <pValue>RegAcquisitionCommand</pValue>
+  <CommandValue>1</CommandValue>
+ </Command>
+
+ <Command Name="AcquisitionStop" NameSpace="Standard">
+  <Description>Stop acquisition. Acquisition will stop after acquisition of the current frame is complete.</Description>
+  <pValue>RegAcquisitionCommand</pValue>
+  <CommandValue>0</CommandValue>
+ </Command>
+
+ <IntReg Name="RegAcquisitionCommand" NameSpace="Custom">
+  <Address>0x130F4</Address>
+  <Length>4</Length>
+  <AccessMode>WO</AccessMode>
+  <pPort>Device</pPort>
+  <Sign>Unsigned</Sign>
+  <Endianess>BigEndian</Endianess>
+ </IntReg>
+
+ <IntReg Name="RegPixelFormat" NameSpace="Custom">
+  <Address>0x12120</Address>
+  <Length>4</Length>
+  <AccessMode>RW</AccessMode>
+  <pPort>Device</pPort>
+  <pInvalidator>BinningHorizontal</pInvalidator>
+  <pInvalidator>BinningVertical</pInvalidator>
+  <Sign>Unsigned</Sign>
+  <Endianess>BigEndian</Endianess>
+ </IntReg>
+
+ <IntReg Name="RegWhitebalValueMax" NameSpace="Custom">
+  <Address>0x1418C</Address>
+  <Length>4</Length>
+  <AccessMode>RW</AccessMode>
+  <pPort>Device</pPort>
+  <Sign>Unsigned</Sign>
+  <Endianess>BigEndian</Endianess>
+ </IntReg>
+
+ <IntSwissKnife Name="IntWidthIncrement" NameSpace="Custom">
+  <pVariable Name="FORMAT">RegPixelFormat</pVariable>
+  <Formula>((FORMAT=35127328) || (FORMAT=34603039) || (FORMAT=34340894)) ? 4 : 1</Formula>
+ </IntSwissKnife>
+
+ <SwissKnife Name="WhitebalValueMin" NameSpace="Custom">
+  <pVariable Name="VALUE">RegWhitebalValueMin</pVariable>
+  <Formula>(VALUE / 100)</Formula>
+ </SwissKnife>
+
+ <Port Name="Device" NameSpace="Standard">
+ </Port>
+
+</RegisterDescription>
diff --git a/src/arv.h b/src/arv.h
index 53b351f..4956320 100644
--- a/src/arv.h
+++ b/src/arv.h
@@ -55,5 +55,9 @@
 #include <arvgvinterface.h>
 #include <arvgvdevice.h>
 #include <arvgvstream.h>
+#include <arvfakeinterface.h>
+#include <arvfakedevice.h>
+#include <arvfakestream.h>
+#include <arvfakecamera.h>
 
 #endif
diff --git a/src/arvfakecamera.c b/src/arvfakecamera.c
new file mode 100644
index 0000000..cf61562
--- /dev/null
+++ b/src/arvfakecamera.c
@@ -0,0 +1,129 @@
+/* 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <arvfakecamera.h>
+#include <arvgvcp.h>
+#include <arvdebug.h>
+#include <string.h>
+
+static GObjectClass *parent_class = NULL;
+
+struct _ArvFakeCameraPrivate {
+	void *memory;
+};
+
+/* ArvFakeCamera implementation */
+
+const char *
+arv_get_fake_camera_genicam_data (size_t *size)
+{
+	static GMappedFile *genicam_file = NULL;
+	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+
+	g_static_mutex_lock (&mutex);
+
+	if (genicam_file == NULL ) {
+		char *filename;
+
+		filename = g_build_filename (ARAVIS_DATA_DIR, "arv-fake-camera.xml", NULL);
+		genicam_file = g_mapped_file_new (filename, FALSE, NULL);
+
+		if (genicam_file != NULL) {
+			arv_debug ("fakegenicam", "[get_fake_camera_genicam_data] %s [size = %d]",
+				   filename,
+				   g_mapped_file_get_length (genicam_file));
+			arv_debug ("fakegenicam", g_mapped_file_get_contents (genicam_file));
+		}
+
+		g_free (filename);
+	}
+
+	g_static_mutex_unlock (&mutex);
+
+	g_return_val_if_fail( genicam_file != NULL, NULL);
+
+	if (size != NULL)
+		*size = g_mapped_file_get_length (genicam_file);
+
+	return g_mapped_file_get_contents (genicam_file);
+}
+
+/* GObject implemenation */
+
+ArvFakeCamera *
+arv_fake_camera_new (void)
+{
+	ArvFakeCamera *fake_camera;
+	void *memory;
+	char *xml_url;
+	size_t size;
+
+	fake_camera = g_object_new (ARV_TYPE_FAKE_CAMERA, NULL);
+
+	memory = g_malloc0 (ARV_FAKE_CAMERA_MEMORY_SIZE);
+
+	strcpy (memory + ARV_GVBS_MANUFACTURER_NAME, "Aravis");
+	strcpy (memory + ARV_GVBS_MODEL_NAME, "Fake");
+	strcpy (memory + ARV_GVBS_DEVICE_VERSION, PACKAGE_VERSION);
+	strcpy (memory + ARV_GVBS_SERIAL_NUMBER, "0");
+
+	arv_get_fake_camera_genicam_data (&size);
+	xml_url = g_strdup_printf ("Local:arv-fake-camera-%s.xml;%x;%x",
+				   PACKAGE_VERSION,
+				   ARV_FAKE_CAMERA_MEMORY_SIZE, size);
+	strcpy (memory + ARV_GVBS_FIRST_XML_URL, xml_url);
+	g_free (xml_url);
+
+	fake_camera->priv->memory = g_malloc0 (ARV_FAKE_CAMERA_MEMORY_SIZE);
+
+	return fake_camera;
+}
+
+static void
+arv_fake_camera_init (ArvFakeCamera *fake_camera)
+{
+	fake_camera->priv = G_TYPE_INSTANCE_GET_PRIVATE (fake_camera, ARV_TYPE_FAKE_CAMERA, ArvFakeCameraPrivate);
+}
+
+static void
+arv_fake_camera_finalize (GObject *object)
+{
+	ArvFakeCamera *fake_camera = ARV_FAKE_CAMERA (object);
+
+	g_free (fake_camera->priv->memory);
+
+	parent_class->finalize (object);
+}
+
+static void
+arv_fake_camera_class_init (ArvFakeCameraClass *fake_camera_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (fake_camera_class);
+
+	g_type_class_add_private (fake_camera_class, sizeof (ArvFakeCameraPrivate));
+
+	parent_class = g_type_class_peek_parent (fake_camera_class);
+
+	object_class->finalize = arv_fake_camera_finalize;
+}
+
+G_DEFINE_TYPE (ArvFakeCamera, arv_fake_camera, G_TYPE_OBJECT)
diff --git a/src/arvfakecamera.h b/src/arvfakecamera.h
new file mode 100644
index 0000000..3a0ea39
--- /dev/null
+++ b/src/arvfakecamera.h
@@ -0,0 +1,61 @@
+/* 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef ARV_FAKE_CAMERA_H
+#define ARV_FAKE_CAMERA_H
+
+#include <arvtypes.h>
+
+G_BEGIN_DECLS
+
+#define ARV_FAKE_CAMERA_MEMORY_SIZE	0x1000
+
+#define ARV_TYPE_FAKE_CAMERA             (arv_fake_camera_get_type ())
+#define ARV_FAKE_CAMERA(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_FAKE_CAMERA, ArvFakeCamera))
+#define ARV_FAKE_CAMERA_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_FAKE_CAMERA, ArvFakeCameraClass))
+#define ARV_IS_FAKE_CAMERA(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_FAKE_CAMERA))
+#define ARV_IS_FAKE_CAMERA_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_FAKE_CAMERA))
+#define ARV_FAKE_CAMERA_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_FAKE_CAMERA, ArvFakeCameraClass))
+
+typedef struct _ArvFakeCameraClass ArvFakeCameraClass;
+typedef struct _ArvFakeCameraPrivate ArvFakeCameraPrivate;
+
+struct _ArvFakeCamera {
+	GObject object;
+
+	ArvFakeCameraPrivate *priv;
+};
+
+struct _ArvFakeCameraClass {
+	GObjectClass parent_class;
+};
+
+GType arv_fake_camera_get_type (void);
+
+ArvFakeCamera * 	arv_fake_camera_new 			(void);
+
+const char *		arv_get_fake_camera_genicam_data	(size_t *size);
+
+G_END_DECLS
+
+#endif
+
diff --git a/src/arvtypes.h b/src/arvtypes.h
index d66632a..63326cf 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -62,6 +62,7 @@ typedef struct _ArvGvStream 		ArvGvStream;
 typedef struct _ArvFakeInterface	ArvFakeInterface;
 typedef struct _ArvFakeDevice		ArvFakeDevice;
 typedef struct _ArvFakeStream		ArvFakeStream;
+typedef struct _ArvFakeCamera		ArvFakeCamera;
 
 typedef struct _ArvZip			ArvZip;
 typedef struct _ArvZipFile 		ArvZipFile;
diff --git a/src/tests/.gitignore b/src/tests/.gitignore
index 022518c..6d77df7 100644
--- a/src/tests/.gitignore
+++ b/src/tests/.gitignore
@@ -1,2 +1,3 @@
 evaluator
 genicam
+fake
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 73ad240..45d8541 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -4,7 +4,7 @@ INCLUDES = -g -I$(top_srcdir)/src/ $(ARAVIS_CFLAGS)
 
 noinst_PROGRAMS = $(TEST_PROGS)
 
-TEST_PROGS        += evaluator genicam
+TEST_PROGS        += evaluator genicam fake
 
 evaluator_SOURCES = evaluator.c
 evaluator_LDADD = $(ARAVIS_LIBS) $(top_builddir)/src/libaravis.la
@@ -12,3 +12,7 @@ evaluator_LDADD = $(ARAVIS_LIBS) $(top_builddir)/src/libaravis.la
 genicam_SOURCES = genicam.c
 genicam_CFLAGS = -DGENICAM_FILENAME="\"$(srcdir)/genicam.xml\""
 genicam_LDADD = $(ARAVIS_LIBS) $(top_builddir)/src/libaravis.la
+
+fake_SOURCES = fake.c
+fake_LDADD = $(ARAVIS_LIBS) $(top_builddir)/src/libaravis.la
+
diff --git a/src/tests/fake.c b/src/tests/fake.c
new file mode 100644
index 0000000..a117d3b
--- /dev/null
+++ b/src/tests/fake.c
@@ -0,0 +1,31 @@
+#include <glib.h>
+#include <arv.h>
+
+static void
+load_fake_camera_genicam_test (void)
+{
+	const char *genicam_data;
+	size_t size;
+
+	genicam_data = arv_get_fake_camera_genicam_data (&size);
+	g_assert (genicam_data != NULL);
+	g_assert (size != 0);
+
+	genicam_data = arv_get_fake_camera_genicam_data (NULL);
+	g_assert (genicam_data != NULL);
+}
+
+int
+main (int argc, char *argv[])
+{
+	int i;
+
+	g_test_init (&argc, &argv, NULL);
+
+	g_type_init ();
+
+	g_test_add_func ("/fake/load-fake-camera-genicam", load_fake_camera_genicam_test);
+
+	return g_test_run();
+}
+



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