summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cameras/dummy.c9
-rw-r--r--src/uca-cam.h10
-rw-r--r--test/grab-async.c8
3 files changed, 18 insertions, 9 deletions
diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c
index 53351f8..60dea7f 100644
--- a/src/cameras/dummy.c
+++ b/src/cameras/dummy.c
@@ -130,7 +130,7 @@ static void *uca_dummy_grab_thread(void *arg)
while (dc->thread_running) {
uca_dummy_memcpy(cam, dc->buffer);
- cam->callback(cam->current_frame, dc->buffer);
+ cam->callback(cam->current_frame, dc->buffer, cam->user_callback);
cam->current_frame++;
usleep(sleep_time);
}
@@ -233,10 +233,12 @@ uint32_t uca_dummy_stop_recording(struct uca_camera *cam)
return UCA_NO_ERROR;
}
-uint32_t uca_dummy_register_callback(struct uca_camera *cam, uca_cam_grab_callback cb)
+uint32_t uca_dummy_register_callback(struct uca_camera *cam, uca_cam_grab_callback cb, void *user)
{
- if (cam->callback == NULL)
+ if (cam->callback == NULL) {
cam->callback = cb;
+ cam->user_callback = user;
+ }
else
return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED;
@@ -277,6 +279,7 @@ uint32_t uca_dummy_init(struct uca_camera **cam, struct uca_grabber *grabber)
uca->current_frame = 0;
uca->grabber = NULL;
uca->callback = NULL;
+ uca->user_callback = NULL;
struct dummy_cam *dummy_cam = (struct dummy_cam *) malloc(sizeof(struct dummy_cam));
dummy_cam->bitdepth = 8;
diff --git a/src/uca-cam.h b/src/uca-cam.h
index ca80ec9..4ccb07e 100644
--- a/src/uca-cam.h
+++ b/src/uca-cam.h
@@ -137,8 +137,10 @@ typedef uint32_t (*uca_cam_stop_recording) (struct uca_camera *cam);
* \param[in] image_number Current frame number
*
* \param[in] buffer Image data
+ *
+ * \param[in] user User data registered in uca_cam_register_callback()
*/
-typedef void (*uca_cam_grab_callback) (uint32_t image_number, void *buffer);
+typedef void (*uca_cam_grab_callback) (uint32_t image_number, void *buffer, void *user);
/**
* Register callback for given frame grabber. To actually start receiving
@@ -147,8 +149,10 @@ typedef void (*uca_cam_grab_callback) (uint32_t image_number, void *buffer);
* \param[in] grabber The grabber for which the callback should be installed
*
* \param[in] cb Callback function for when a frame arrived
+ *
+ * \param[in] user User data that is passed to the callback function
*/
-typedef uint32_t (*uca_cam_register_callback) (struct uca_camera *cam, uca_cam_grab_callback cb);
+typedef uint32_t (*uca_cam_register_callback) (struct uca_camera *cam, uca_cam_grab_callback cb, void *user);
/**
* \brief Grab one image from the camera
@@ -224,7 +228,9 @@ typedef struct uca_camera {
uint32_t frame_width; /**< current frame width */
uint32_t frame_height; /**< current frame height */
uint32_t current_frame; /**< last grabbed frame number */
+
uca_cam_grab_callback callback;
+ void *user_callback; /**< user data for callback */
void *user; /**< private user data to be used by the camera driver */
} uca_camera_t;
diff --git a/test/grab-async.c b/test/grab-async.c
index 8086d92..ba3ae85 100644
--- a/test/grab-async.c
+++ b/test/grab-async.c
@@ -5,7 +5,7 @@
#include "uca.h"
#include "uca-cam.h"
-void grab_callback(uint32_t image_number, void *buffer)
+void grab_callback(uint32_t image_number, void *buffer, void *user)
{
printf("got picture number %i\n", image_number);
}
@@ -35,10 +35,10 @@ int main(int argc, char *argv[])
uca_cam_alloc(cam, 10);
- cam->register_callback(cam, &grab_callback);
+ cam->register_callback(cam, &grab_callback, NULL);
cam->start_recording(cam);
- printf("waiting for 10 seconds\n");
- sleep(10);
+ printf("waiting for 5 seconds\n");
+ sleep(5);
cam->stop_recording(cam);
uca_destroy(u);