summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2011-07-25 15:29:43 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2011-07-25 15:29:43 +0200
commita928623c86b19025f0bc63720e45d4ca4b3ad98c (patch)
treeb85d63ebc2d7f0bc14f19fffdb9a2284497940b8 /src
parentbfb2f3a1a05b8d41a2047f86972ea35137f55381 (diff)
downloadlibuca-a928623c86b19025f0bc63720e45d4ca4b3ad98c.tar.gz
libuca-a928623c86b19025f0bc63720e45d4ca4b3ad98c.tar.bz2
libuca-a928623c86b19025f0bc63720e45d4ca4b3ad98c.tar.xz
libuca-a928623c86b19025f0bc63720e45d4ca4b3ad98c.zip
Add simple grabber only accessed using framegrabber
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/cameras/simple.c150
-rw-r--r--src/cameras/simple.h6
-rw-r--r--src/config.h.in1
-rw-r--r--src/uca.c7
5 files changed, 169 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1a22c1e..dc7ebbe 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -72,7 +72,6 @@ endif()
if (CLSERME4_FOUND AND FGLIB5_FOUND)
option(HAVE_ME4 "Grabber: Silicon Software microEnable IV" ON)
-
if (HAVE_ME4)
set(uca_SRCS ${uca_SRCS} grabbers/me4.c)
set(uca_LIBS ${uca_LIBS}
@@ -83,6 +82,11 @@ if (CLSERME4_FOUND AND FGLIB5_FOUND)
${CLSERME4_INCLUDE_DIR}
${FGLIB5_INCLUDE_DIR})
endif()
+
+ option(HAVE_SIMPLE_CAMERA "Camera: Just grabber based" ON)
+ if (HAVE_SIMPLE_CAMERA)
+ set(uca_SRCS ${uca_SRCS} cameras/simple.c)
+ endif()
endif()
if (HAVE_DUMMY_CAMERA)
diff --git a/src/cameras/simple.c b/src/cameras/simple.c
new file mode 100644
index 0000000..e6cc233
--- /dev/null
+++ b/src/cameras/simple.c
@@ -0,0 +1,150 @@
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include "uca.h"
+#include "uca-cam.h"
+#include "uca-grabber.h"
+
+
+static uint32_t uca_simple_set_property(struct uca_camera_priv *cam, enum uca_property_ids property, void *data)
+{
+ struct uca_grabber_priv *grabber = cam->grabber;
+ int err = UCA_NO_ERROR;
+
+ /* We try to set the property on the grabber. If it returns "invalid", we
+ * also try it via the PF SDK. Else, there was a more serious error.
+ *
+ * FIXME: This is actually not that good for cases where only the grabber
+ * should set a certain property and the camera itself is not able to do so. */
+ err = grabber->set_property(grabber, property, data);
+ if (((err & UCA_ERR_MASK_CODE) == UCA_ERR_INVALID) || (err == UCA_NO_ERROR))
+ err = UCA_ERR_CAMERA | UCA_ERR_PROP;
+ else
+ return err;
+
+ return UCA_NO_ERROR;
+}
+
+
+static uint32_t uca_simple_get_property(struct uca_camera_priv *cam, enum uca_property_ids property, void *data, size_t num)
+{
+ struct uca_grabber_priv *grabber = cam->grabber;
+ uint32_t value32 = 0;
+
+ /* Handle all special cases */
+ switch (property) {
+ case UCA_PROP_NAME:
+ strncpy((char *) data, "Simple Framegrabber Access", num);
+ break;
+
+ case UCA_PROP_WIDTH:
+ grabber->get_property(grabber, UCA_PROP_WIDTH, &value32);
+ uca_set_void(data, uint32_t, value32);
+ break;
+
+ case UCA_PROP_HEIGHT:
+ grabber->get_property(grabber, UCA_PROP_HEIGHT, &value32);
+ uca_set_void(data, uint32_t, value32);
+ break;
+
+ case UCA_PROP_X_OFFSET:
+ grabber->get_property(grabber, UCA_PROP_X_OFFSET, &value32);
+ uca_set_void(data, uint32_t, value32);
+ break;
+
+ case UCA_PROP_Y_OFFSET:
+ grabber->get_property(grabber, UCA_PROP_Y_OFFSET, &value32);
+ uca_set_void(data, uint32_t, value32);
+ break;
+
+ case UCA_PROP_BITDEPTH:
+ uca_set_void(data, uint32_t, 8);
+ return UCA_NO_ERROR;
+
+ default:
+ break;
+ }
+
+ /* Try to get the property via frame grabber */
+ return cam->grabber->get_property(cam->grabber, property, data);
+}
+
+static uint32_t uca_simple_start_recording(struct uca_camera_priv *cam)
+{
+ return cam->grabber->acquire(cam->grabber, -1);
+}
+
+static uint32_t uca_simple_stop_recording(struct uca_camera_priv *cam)
+{
+ return cam->grabber->stop_acquire(cam->grabber);
+}
+
+static uint32_t uca_simple_trigger(struct uca_camera_priv *cam)
+{
+ return cam->grabber->trigger(cam->grabber);
+}
+
+static uint32_t uca_simple_grab(struct uca_camera_priv *cam, char *buffer, void *metadata)
+{
+ uint16_t *frame;
+ uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, &cam->current_frame);
+ if (err != UCA_NO_ERROR)
+ return err;
+
+ memcpy(buffer, frame, cam->frame_width*cam->frame_height);
+ return UCA_NO_ERROR;
+}
+
+static uint32_t uca_simple_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback callback, void *user)
+{
+ if (cam->callback == NULL) {
+ cam->callback = callback;
+ cam->callback_user = user;
+ return cam->grabber->register_callback(cam->grabber, callback, NULL, user);
+ }
+ return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED;
+}
+
+static uint32_t uca_simple_destroy(struct uca_camera_priv *cam)
+{
+ return UCA_NO_ERROR;
+}
+
+uint32_t uca_simple_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber)
+{
+ if (grabber == NULL)
+ return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_NOT_FOUND;
+
+ struct uca_camera_priv *uca = uca_cam_new();
+ uca->grabber = grabber;
+ uca->grabber->synchronous = false;
+
+ /* Camera found, set function pointers... */
+ uca->destroy = &uca_simple_destroy;
+ uca->set_property = &uca_simple_set_property;
+ uca->get_property = &uca_simple_get_property;
+ uca->start_recording = &uca_simple_start_recording;
+ uca->stop_recording = &uca_simple_stop_recording;
+ uca->trigger = &uca_simple_trigger;
+ uca->grab = &uca_simple_grab;
+ uca->register_callback = &uca_simple_register_callback;
+
+ /* Prepare frame grabber for recording */
+ int val = UCA_CL_8BIT_FULL_8;
+ grabber->set_property(grabber, UCA_GRABBER_CAMERALINK_TYPE, &val);
+
+ val = UCA_FORMAT_GRAY8;
+ grabber->set_property(grabber, UCA_GRABBER_FORMAT, &val);
+
+ val = UCA_TRIGGER_AUTO;
+ grabber->set_property(grabber, UCA_GRABBER_TRIGGER_MODE, &val);
+
+ grabber->get_property(grabber, UCA_PROP_WIDTH, &uca->frame_width);
+ grabber->get_property(grabber, UCA_PROP_HEIGHT, &uca->frame_height);
+
+ uca->state = UCA_CAM_CONFIGURABLE;
+ *cam = uca;
+
+ return UCA_NO_ERROR;
+}
diff --git a/src/cameras/simple.h b/src/cameras/simple.h
new file mode 100644
index 0000000..22fa15e
--- /dev/null
+++ b/src/cameras/simple.h
@@ -0,0 +1,6 @@
+#ifndef __UNIFIED_CAMERA_ACCESS_PHOTON_H
+#define __UNIFIED_CAMERA_ACCESS_PHOTON_H
+
+uint32_t uca_simple_init(struct uca_camera_priv **uca, struct uca_grabber_priv *grabber);
+
+#endif
diff --git a/src/config.h.in b/src/config.h.in
index 43736b4..554efc5 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -7,5 +7,6 @@
#cmakedefine HAVE_IPE_CAMERA
#cmakedefine HAVE_DUMMY_CAMERA
+#cmakedefine HAVE_SIMPLE_CAMERA
#cmakedefine HAVE_PTHREADS
diff --git a/src/uca.c b/src/uca.c
index 7a9d628..ec8ad07 100644
--- a/src/uca.c
+++ b/src/uca.c
@@ -30,6 +30,10 @@
#include "cameras/ipe.h"
#endif
+#ifdef HAVE_SIMPLE_CAMERA
+#include "cameras/simple.h"
+#endif
+
const char *uca_unit_map[] = {
"px",
"bits",
@@ -134,6 +138,9 @@ struct uca *uca_init(const char *config_filename)
#ifdef HAVE_DUMMY_CAMERA
uca_dummy_init,
#endif
+#ifdef HAVE_SIMPLE_CAMERA
+ uca_simple_init,
+#endif
NULL
};