diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-04-27 09:00:22 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-04-27 09:00:22 +0200 |
commit | c1b6c87c62f544fa6353bdb45bd9a21139eb1fa9 (patch) | |
tree | eec71dc5dc39c57e132db637f8a616a1588b16b1 /src | |
parent | 45cd588f12f485d4b3a44b425dcbbcdec5f833db (diff) | |
download | uca-c1b6c87c62f544fa6353bdb45bd9a21139eb1fa9.tar.gz uca-c1b6c87c62f544fa6353bdb45bd9a21139eb1fa9.tar.bz2 uca-c1b6c87c62f544fa6353bdb45bd9a21139eb1fa9.tar.xz uca-c1b6c87c62f544fa6353bdb45bd9a21139eb1fa9.zip |
Do state handling only once in uca.c instead of all camera implementations
Diffstat (limited to 'src')
-rw-r--r-- | src/cameras/dummy.c | 4 | ||||
-rw-r--r-- | src/cameras/pco.c | 13 | ||||
-rw-r--r-- | src/uca-cam.h | 10 | ||||
-rw-r--r-- | src/uca.c | 20 | ||||
-rw-r--r-- | src/uca.h | 1 |
5 files changed, 22 insertions, 26 deletions
diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c index 0283989..f0e8545 100644 --- a/src/cameras/dummy.c +++ b/src/cameras/dummy.c @@ -159,8 +159,6 @@ static void *uca_dummy_grab_thread(void *arg) static uint32_t uca_dummy_set_property(struct uca_camera_priv *cam, enum uca_property_ids property, void *data) { uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; - if (cam->state == UCA_CAM_RECORDING) - return err | UCA_ERR_IS_RECORDING; switch (property) { case UCA_PROP_WIDTH: @@ -235,7 +233,6 @@ static uint32_t uca_dummy_start_recording(struct uca_camera_priv *cam) #endif } cam->current_frame = 0; - cam->state = UCA_CAM_RECORDING; return UCA_NO_ERROR; } @@ -247,7 +244,6 @@ static uint32_t uca_dummy_stop_recording(struct uca_camera_priv *cam) free(dc->buffer); dc->buffer = NULL; } - cam->state = UCA_CAM_ARMED; return UCA_NO_ERROR; } diff --git a/src/cameras/pco.c b/src/cameras/pco.c index 9de6467..c11ba24 100644 --- a/src/cameras/pco.c +++ b/src/cameras/pco.c @@ -228,8 +228,6 @@ static uint32_t uca_pco_get_property(struct uca_camera_priv *cam, enum uca_prope static uint32_t uca_pco_start_recording(struct uca_camera_priv *cam) { uint32_t err = UCA_ERR_CAMERA | UCA_ERR_INIT; - if (cam->state == UCA_CAM_RECORDING) - return err | UCA_ERR_IS_RECORDING; struct pco_edge *pco = GET_PCO(cam); if (pco_arm_camera(pco) != PCO_NOERROR) @@ -237,32 +235,23 @@ static uint32_t uca_pco_start_recording(struct uca_camera_priv *cam) if (pco_set_rec_state(pco, 1) != PCO_NOERROR) return err | UCA_ERR_UNCLASSIFIED; - cam->state = UCA_CAM_RECORDING; return cam->grabber->acquire(cam->grabber, -1); } static uint32_t uca_pco_stop_recording(struct uca_camera_priv *cam) { - if ((cam->state == UCA_CAM_RECORDING) && (pco_set_rec_state(GET_PCO(cam), 0) != PCO_NOERROR)) + if (pco_set_rec_state(GET_PCO(cam), 0) != PCO_NOERROR) return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_UNCLASSIFIED; - - cam->state = UCA_CAM_CONFIGURABLE; return UCA_NO_ERROR; } static uint32_t uca_pco_trigger(struct uca_camera_priv *cam) { - if (cam->state != UCA_CAM_RECORDING) - return UCA_ERR_CAMERA | UCA_ERR_TRIGGER | UCA_ERR_NOT_RECORDING; - return cam->grabber->trigger(cam->grabber); } static uint32_t uca_pco_grab(struct uca_camera_priv *cam, char *buffer, void *meta_data) { - if (cam->state != UCA_CAM_RECORDING) - return UCA_ERR_CAMERA | UCA_ERR_NOT_RECORDING; - uint16_t *frame; uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, &cam->current_frame); if (err != UCA_NO_ERROR) diff --git a/src/uca-cam.h b/src/uca-cam.h index cd97ea9..a194054 100644 --- a/src/uca-cam.h +++ b/src/uca-cam.h @@ -47,13 +47,7 @@ struct uca_camera_priv *uca_cam_new(void); * Represents a camera abstraction, that concrete cameras must implement. */ typedef struct uca_camera_priv { - /** - * Points to the next available camera in a linked-list fashion. - * - * End of list is specified with next == NULL. - */ - struct uca_camera_priv *next; - + /* virtual methods to be overridden by concrete cameras */ uint32_t (*destroy) (struct uca_camera_priv *cam); uint32_t (*set_property) (struct uca_camera_priv *cam, enum uca_property_ids property, void *data); uint32_t (*get_property) (struct uca_camera_priv *cam, enum uca_property_ids property, void *data, size_t num); @@ -64,7 +58,7 @@ typedef struct uca_camera_priv { uint32_t (*grab) (struct uca_camera_priv *cam, char *buffer, void *meta_data); struct uca_grabber_priv *grabber; /**< grabber associated with this camera */ - enum uca_cam_state state; /**< camera state */ + enum uca_cam_state state; /**< camera state handled in uca.c */ uint32_t frame_width; /**< current frame width */ uint32_t frame_height; /**< current frame height */ uint64_t current_frame; /**< last grabbed frame number */ @@ -278,18 +278,32 @@ uint32_t uca_cam_get_property(struct uca_camera *cam, enum uca_property_ids prop uint32_t uca_cam_start_recording(struct uca_camera *cam) { struct uca_camera_priv *priv = cam->priv; - return priv->start_recording(priv); + if (priv->state == UCA_CAM_RECORDING) + return UCA_ERR_CAMERA | UCA_ERR_CONFIGURATION | UCA_ERR_IS_RECORDING; + + uint32_t err = priv->start_recording(priv); + if (err == UCA_NO_ERROR) + priv->state = UCA_CAM_RECORDING; + return err; } uint32_t uca_cam_stop_recording(struct uca_camera *cam) { struct uca_camera_priv *priv = cam->priv; - return priv->stop_recording(priv); + if (priv->state != UCA_CAM_RECORDING) + return UCA_ERR_CAMERA | UCA_ERR_CONFIGURATION | UCA_ERR_NOT_RECORDING; + + uint32_t err = priv->stop_recording(priv); + if (err == UCA_NO_ERROR) + priv->state = UCA_CAM_CONFIGURABLE; + return err; } uint32_t uca_cam_trigger(struct uca_camera *cam) { struct uca_camera_priv *priv = cam->priv; + if (priv->state != UCA_CAM_RECORDING) + return UCA_ERR_CAMERA | UCA_ERR_TRIGGER | UCA_ERR_NOT_RECORDING; return priv->trigger(priv); } @@ -302,6 +316,8 @@ uint32_t uca_cam_register_callback(struct uca_camera *cam, uca_cam_grab_callback uint32_t uca_cam_grab(struct uca_camera *cam, char *buffer, void *meta_data) { struct uca_camera_priv *priv = cam->priv; + if (priv->state != UCA_CAM_RECORDING) + return UCA_ERR_CAMERA | UCA_ERR_NOT_RECORDING; return priv->grab(priv, buffer, meta_data); } @@ -265,6 +265,7 @@ extern const char *uca_unit_map[]; /**< maps unit numbers to corresponding #define UCA_ERR_PROP 0x00200000 /**< error while setting/getting property */ #define UCA_ERR_CALLBACK 0x00300000 /**< callback-related errors */ #define UCA_ERR_TRIGGER 0x00400000 /**< errors concerning trigger */ +#define UCA_ERR_CONFIGURATION 0x00500000 /**< errors related to configuration steps */ #define UCA_ERR_FAILURE 0x10000000 #define UCA_ERR_WARNING 0x20000000 |