summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-16 10:15:15 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-16 10:15:15 +0100
commit2de85655bd50cfcd2a21267ecf4e5f91b0800a9c (patch)
tree0abf914efecdd76edc48043feb15aa4e96806464 /src
parent3d037dbe86665b59c6bb5d71f3d58558a5848d38 (diff)
downloaduca-2de85655bd50cfcd2a21267ecf4e5f91b0800a9c.tar.gz
uca-2de85655bd50cfcd2a21267ecf4e5f91b0800a9c.tar.bz2
uca-2de85655bd50cfcd2a21267ecf4e5f91b0800a9c.tar.xz
uca-2de85655bd50cfcd2a21267ecf4e5f91b0800a9c.zip
Implement grab callback for Silicon Software me4
Diffstat (limited to 'src')
-rw-r--r--src/grabbers/me4.c39
-rw-r--r--src/uca-grabber.h3
-rw-r--r--src/uca.h4
3 files changed, 36 insertions, 10 deletions
diff --git a/src/grabbers/me4.c b/src/grabbers/me4.c
index d6419e0..7bb687b 100644
--- a/src/grabbers/me4.c
+++ b/src/grabbers/me4.c
@@ -8,9 +8,10 @@
#include "uca.h"
#include "uca-grabber.h"
-struct uca_me4_grabber_t {
+struct fg_apc_data {
Fg_Struct *fg;
dma_mem *mem;
+ uca_grabber_grab_callback cb;
};
struct uca_sisofg_map_t {
@@ -39,8 +40,8 @@ static struct uca_sisofg_map_t uca_to_fg[] = {
{ UCA_GRABBER_INVALID, 0, false }
};
-#define GET_FG(grabber) (((struct uca_me4_grabber_t *) grabber->user)->fg)
-#define GET_MEM(grabber) (((struct uca_me4_grabber_t *) grabber->user)->mem)
+#define GET_FG(grabber) (((struct fg_apc_data *) grabber->user)->fg)
+#define GET_MEM(grabber) (((struct fg_apc_data *) grabber->user)->mem)
uint32_t uca_me4_destroy(struct uca_grabber_t *grabber)
{
@@ -103,7 +104,7 @@ uint32_t uca_me4_alloc(struct uca_grabber_t *grabber, uint32_t pixel_size, uint3
dma_mem *mem = Fg_AllocMemEx(GET_FG(grabber), n_buffers*width*height*pixel_size, n_buffers);
if (mem != NULL) {
- ((struct uca_me4_grabber_t *) grabber->user)->mem = mem;
+ ((struct fg_apc_data *) grabber->user)->mem = mem;
return UCA_NO_ERROR;
}
return UCA_ERR_PROP_GENERAL;
@@ -145,11 +146,31 @@ uint32_t uca_me4_grab(struct uca_grabber_t *grabber, void **buffer)
return UCA_NO_ERROR;
}
+static int uca_me4_callback(frameindex_t frame, struct fg_apc_data *apc)
+{
+ apc->cb(frame, Fg_getImagePtr(apc->fg, frame, PORT_A));
+ return 0;
+}
+
uint32_t uca_me4_register_callback(struct uca_grabber_t *grabber, uca_grabber_grab_callback cb)
{
- grabber->callback = cb;
+ if (grabber->callback == NULL) {
+ grabber->callback = cb;
+ ((struct fg_apc_data *) grabber->user)->cb = cb;
+
+ struct FgApcControl ctrl;
+ ctrl.version = 0;
+ ctrl.data = (struct fg_apc_data *) grabber->user;
+ ctrl.func = &uca_me4_callback;
+ ctrl.flags = FG_APC_DEFAULTS;
+ ctrl.timeout = 1;
+
+ if (Fg_registerApcHandler(GET_FG(grabber), PORT_A, &ctrl, FG_APC_CONTROL_BASIC) != FG_OK)
+ return UCA_ERR_GRABBER_CALLBACK_REGISTRATION_FAILED;
+ }
+ else
+ return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED;
- /* TODO: add me4 registerApc stuff */
return UCA_NO_ERROR;
}
@@ -160,10 +181,12 @@ uint32_t uca_me4_init(struct uca_grabber_t **grabber)
return UCA_ERR_GRABBER_NOT_FOUND;
struct uca_grabber_t *uca = (struct uca_grabber_t *) malloc(sizeof(struct uca_grabber_t));
- struct uca_me4_grabber_t *me4 = (struct uca_me4_grabber_t *) malloc(sizeof(struct uca_me4_grabber_t));
+ struct fg_apc_data *me4 = (struct fg_apc_data *) malloc(sizeof(struct fg_apc_data));
- me4->fg = fg;
+ me4->fg = fg;
me4->mem = NULL;
+ me4->cb = NULL;
+
uca->user = me4;
uca->destroy = &uca_me4_destroy;
uca->set_property = &uca_me4_set_property;
diff --git a/src/uca-grabber.h b/src/uca-grabber.h
index f29b950..a10d463 100644
--- a/src/uca-grabber.h
+++ b/src/uca-grabber.h
@@ -110,7 +110,8 @@ typedef uint32_t (*uca_grabber_grab) (struct uca_grabber_t *grabber, void **buff
typedef void (*uca_grabber_grab_callback) (uint32_t image_number, void *buffer);
/**
- * Register callback for given frame grabber.
+ * Register callback for given frame grabber. To actually start receiving
+ * frames, call uca_grabber_acquire().
*
* \param[in] grabber The grabber for which the callback should be installed
*
diff --git a/src/uca.h b/src/uca.h
index 06904bc..1ae371a 100644
--- a/src/uca.h
+++ b/src/uca.h
@@ -245,7 +245,9 @@ enum uca_errors {
UCA_ERR_CAM_RECORD, /**< could not record */
UCA_ERR_GRABBER_ACQUIRE, /**< grabber couldn't acquire a frame */
- UCA_ERR_GRABBER_NOMEM /**< no memory was allocated using uca_grabber->alloc() */
+ UCA_ERR_GRABBER_NOMEM, /**< no memory was allocated using uca_grabber->alloc() */
+ UCA_ERR_GRABBER_CALLBACK_REGISTRATION_FAILED,
+ UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED
};
/**