summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cameras/dummy.c6
-rw-r--r--src/cameras/ipe.c5
-rw-r--r--src/cameras/pco.c2
-rw-r--r--src/cameras/pf.c2
-rw-r--r--src/uca-cam.c28
-rw-r--r--src/uca-cam.h11
6 files changed, 43 insertions, 11 deletions
diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c
index 2ad2ec9..0d6c9d1 100644
--- a/src/cameras/dummy.c
+++ b/src/cameras/dummy.c
@@ -283,7 +283,7 @@ static uint32_t uca_dummy_destroy(struct uca_camera *cam)
uint32_t uca_dummy_init(struct uca_camera **cam, struct uca_grabber *grabber)
{
- struct uca_camera *uca = (struct uca_camera *) malloc(sizeof(struct uca_camera));
+ struct uca_camera *uca = uca_cam_new();
uca->destroy = &uca_dummy_destroy;
uca->set_property = &uca_dummy_set_property;
@@ -296,10 +296,6 @@ uint32_t uca_dummy_init(struct uca_camera **cam, struct uca_grabber *grabber)
uca->state = UCA_CAM_CONFIGURABLE;
uca->frame_width = 320;
uca->frame_height = 240;
- uca->current_frame = 0;
- uca->grabber = NULL;
- uca->callback = NULL;
- uca->callback_user = NULL;
struct dummy_cam *dummy_cam = (struct dummy_cam *) malloc(sizeof(struct dummy_cam));
dummy_cam->bitdepth = 8;
diff --git a/src/cameras/ipe.c b/src/cameras/ipe.c
index a9f1ff2..45a619c 100644
--- a/src/cameras/ipe.c
+++ b/src/cameras/ipe.c
@@ -119,7 +119,7 @@ uint32_t uca_ipe_init(struct uca_camera **cam, struct uca_grabber *grabber)
pcilib_set_error_handler(&uca_ipe_handle_error, &uca_ipe_handle_error);
model = pcilib_get_model(handle);
- struct uca_camera *uca = (struct uca_camera *) malloc(sizeof(struct uca_camera));
+ struct uca_camera *uca = uca_cam_new();
/* Camera found, set function pointers... */
uca->destroy = &uca_ipe_destroy;
@@ -130,9 +130,6 @@ uint32_t uca_ipe_init(struct uca_camera **cam, struct uca_grabber *grabber)
uca->grab = &uca_ipe_grab;
uca->register_callback = &uca_ipe_register_callback;
- uca->callback = NULL;
- uca_>callback_user = NULL;
- uca->state = UCA_CAM_CONFIGURABLE;
uca->user = handle;
*cam = uca;
diff --git a/src/cameras/pco.c b/src/cameras/pco.c
index 59c689d..3801157 100644
--- a/src/cameras/pco.c
+++ b/src/cameras/pco.c
@@ -250,7 +250,7 @@ uint32_t uca_pco_init(struct uca_camera **cam, struct uca_grabber *grabber)
return UCA_ERR_CAM_NOT_FOUND;
}
- struct uca_camera *uca = (struct uca_camera *) malloc(sizeof(struct uca_camera));
+ struct uca_camera *uca = uca_cam_new();
uca->user = pco;
uca->grabber = grabber;
uca->grabber->asynchronous = true;
diff --git a/src/cameras/pf.c b/src/cameras/pf.c
index ab6a490..5ae35ab 100644
--- a/src/cameras/pf.c
+++ b/src/cameras/pf.c
@@ -208,7 +208,7 @@ uint32_t uca_pf_init(struct uca_camera **cam, struct uca_grabber *grabber)
/* We could check if a higher baud rate is supported, but... forget about
* it. We don't need high speed configuration. */
- struct uca_camera *uca = (struct uca_camera *) malloc(sizeof(struct uca_camera));
+ struct uca_camera *uca = uca_cam_new();
uca->grabber = grabber;
uca->grabber->asynchronous = true;
diff --git a/src/uca-cam.c b/src/uca-cam.c
index eb76fad..b26b826 100644
--- a/src/uca-cam.c
+++ b/src/uca-cam.c
@@ -19,3 +19,31 @@ enum uca_cam_state uca_cam_get_state(struct uca_camera *cam)
return cam->state;
}
+struct uca_camera *uca_cam_new(void)
+{
+ struct uca_camera *cam = (struct uca_camera *) malloc(sizeof(struct uca_camera));
+
+ cam->next = NULL;
+
+ /* Set all function pointers to NULL so we know early on, if something has
+ * not been implemented. */
+ cam->set_property = NULL;
+ cam->get_property = NULL;
+ cam->start_recording = NULL;
+ cam->stop_recording = NULL;
+ cam->grab = NULL;
+ cam->register_callback = NULL;
+ cam->destroy = NULL;
+
+ cam->user = NULL;
+
+ cam->grabber = NULL;
+ cam->state = UCA_CAM_CONFIGURABLE;
+ cam->current_frame = 0;
+
+ /* No callbacks and user data associated yet */
+ cam->callback = NULL;
+ cam->callback_user = NULL;
+
+ return cam;
+}
diff --git a/src/uca-cam.h b/src/uca-cam.h
index ec84c27..d52f390 100644
--- a/src/uca-cam.h
+++ b/src/uca-cam.h
@@ -43,8 +43,10 @@ enum uca_cam_state {
*
* \param[in] n_buffers Number of sub-buffers with size frame_width*frame_height.
*/
+/* FIXME: put this into vtable?! */
uint32_t uca_cam_alloc(struct uca_camera *cam, uint32_t n_buffers);
+
/**
* Retrieve current state of the camera.
*
@@ -55,6 +57,15 @@ uint32_t uca_cam_alloc(struct uca_camera *cam, uint32_t n_buffers);
*/
enum uca_cam_state uca_cam_get_state(struct uca_camera *cam);
+/**
+ * Allocates memory for a new uca_camera structure and initializes all fields to
+ * sane values.
+ *
+ * \return Pointer to block of memory for a uca_camera structure
+ *
+ * \note This is is a utility function used internally by drivers
+ */
+struct uca_camera *uca_cam_new(void);
/*
* --- virtual methods --------------------------------------------------------