diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/cameras/dummy.c | 201 | ||||
-rw-r--r-- | src/cameras/dummy.h | 9 | ||||
-rw-r--r-- | src/cameras/pco.c | 1 | ||||
-rw-r--r-- | src/uca-cam.c | 3 | ||||
-rw-r--r-- | src/uca.c | 7 |
6 files changed, 219 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a11833b..3ae6394 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,12 +9,14 @@ set(uca_SRCS uca.c uca-cam.c uca-grabber.c + cameras/dummy.c ) set(uca_HDRS uca.h uca-cam.h uca-grabber.h + cameras/dummy.h ) set(uca_LIBS "") @@ -117,6 +119,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) # --- Build target ------------------------------------------------------------ +add_definitions("-std=c99 -Wall") add_library(uca SHARED ${uca_SRCS}) target_link_libraries(uca ${uca_LIBS}) diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c new file mode 100644 index 0000000..93952a9 --- /dev/null +++ b/src/cameras/dummy.c @@ -0,0 +1,201 @@ + +#include <stdlib.h> +#include <string.h> +#include "uca.h" +#include "uca-cam.h" +#include "uca-grabber.h" + +struct dummy_cam_t { + uint32_t width; + uint32_t height; + uint32_t bitdepth; + uint32_t framerate; + uint32_t current_frame; + char* buffer; +}; + +#define GET_DUMMY(uca) ((struct dummy_cam_t *)(uca->user)) +#define set_void(p, type, value) { *((type *) p) = value; } + +static uint32_t uca_dummy_set_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data) +{ + return UCA_NO_ERROR; +} + +static uint32_t uca_dummy_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data) +{ + struct dummy_cam_t *dummy_cam = (struct dummy_cam_t *) cam->user; + + switch (property) { + case UCA_PROP_NAME: + strcpy((char *) data, "dummy"); + break; + + case UCA_PROP_WIDTH: + set_void(data, uint32_t, dummy_cam->width); + break; + + case UCA_PROP_WIDTH_MIN: + set_void(data, uint32_t, 1); + break; + + case UCA_PROP_WIDTH_MAX: + set_void(data, uint32_t, 4096); + break; + + case UCA_PROP_HEIGHT: + set_void(data, uint32_t, dummy_cam->height); + break; + + case UCA_PROP_HEIGHT_MIN: + set_void(data, uint32_t, 1); + break; + + case UCA_PROP_HEIGHT_MAX: + set_void(data, uint32_t, 4096); + break; + + case UCA_PROP_BITDEPTH: + set_void(data, uint32_t, 8); + break; + + default: + return UCA_ERR_PROP_INVALID; + } + return UCA_NO_ERROR; +} + +uint32_t uca_dummy_start_recording(struct uca_camera_t *cam) +{ + GET_DUMMY(cam)->current_frame = 0; + return UCA_NO_ERROR; +} + +uint32_t uca_dummy_stop_recording(struct uca_camera_t *cam) +{ + return UCA_NO_ERROR; +} + +static const char digits[10][20] = { + /* 0 */ + { 0x00, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0xff, 0x00, 0x00, 0xff, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0xff, 0x00 }, + /* 1 */ + { 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, + 0x00, 0x00, 0xff, 0x00, + 0x00, 0x00, 0xff, 0x00, + 0x00, 0x00, 0xff, 0x00 }, + /* 2 */ + { 0x00, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff }, + /* 3 */ + { 0x00, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0x00, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0xff, 0x00 }, + /* 4 */ + { 0xff, 0x00, 0x00, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0xff, + 0x00, 0x00, 0x00, 0xff }, + /* 5 */ + { 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x00 }, + /* 6 */ + { 0x00, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0xff, 0x00 }, + /* 7 */ + { 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0xff, + 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, + 0xff, 0x00, 0x00, 0x00 }, + /* 8 */ + { 0x00, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0xff, 0x00 }, + /* 9 */ + { 0x00, 0xff, 0xff, 0x00, + 0xff, 0x00, 0x00, 0xff, + 0x00, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x00 } +}; + +static void uca_dummy_print_number(struct dummy_cam_t *dummy, int number, int x, int y) +{ + const int digit_width = 4; + const int digit_height = 5; + char *buffer = dummy->buffer; + for (int i = 0; i < digit_width; i++) { + for (int j = 0; j < digit_height; j++) { + buffer[(y+j)*dummy->width + (x+i)] = digits[number][j*digit_width+i]; + } + } +} + +uint32_t uca_dummy_grab(struct uca_camera_t *cam, char *buffer) +{ + struct dummy_cam_t *dummy = GET_DUMMY(cam); + dummy->buffer = buffer; + + /* print current frame number */ + unsigned int number = dummy->current_frame; + unsigned int divisor = 100000000; + int x = 10; + while (divisor > 1) { + uca_dummy_print_number(dummy, number / divisor, x, 10); + number = number % divisor; + divisor = divisor / 10; + x += 5; + } + dummy->current_frame++; + return UCA_NO_ERROR; +} + +static uint32_t uca_dummy_destroy(struct uca_camera_t *cam) +{ + return UCA_NO_ERROR; +} + +uint32_t uca_dummy_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber) +{ + struct uca_camera_t *uca = (struct uca_camera_t *) malloc(sizeof(struct uca_camera_t)); + + uca->destroy = &uca_dummy_destroy; + uca->set_property = &uca_dummy_set_property; + uca->get_property = &uca_dummy_get_property; + uca->start_recording = &uca_dummy_start_recording; + uca->stop_recording = &uca_dummy_stop_recording; + uca->grab = &uca_dummy_grab; + uca->state = UCA_CAM_CONFIGURABLE; + + struct dummy_cam_t *dummy_cam = (struct dummy_cam_t *) malloc(sizeof(struct dummy_cam_t)); + dummy_cam->width = 320; + dummy_cam->height = 240; + dummy_cam->bitdepth = 8; + dummy_cam->framerate = 100; + dummy_cam->buffer = NULL; + uca->user = dummy_cam; + + *cam = uca; + + return UCA_NO_ERROR; +} diff --git a/src/cameras/dummy.h b/src/cameras/dummy.h new file mode 100644 index 0000000..143bbd1 --- /dev/null +++ b/src/cameras/dummy.h @@ -0,0 +1,9 @@ +#ifndef __UNIFIED_CAMERA_ACCESS_DUMMY_H +#define __UNIFIED_CAMERA_ACCESS_DUMMY_H + +struct uca_camera_t; +struct uca_grabber_t; + +uint32_t uca_dummy_init(struct uca_camera_t **uca, struct uca_grabber_t *grabber); + +#endif diff --git a/src/cameras/pco.c b/src/cameras/pco.c index cb286e8..565fd62 100644 --- a/src/cameras/pco.c +++ b/src/cameras/pco.c @@ -243,7 +243,6 @@ uint32_t uca_pco_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber) return UCA_ERR_CAM_NOT_FOUND; struct pco_edge_t *pco = pco_init(); - if (pco == NULL) { return UCA_ERR_CAM_NOT_FOUND; } diff --git a/src/uca-cam.c b/src/uca-cam.c index 31ad416..7e033fd 100644 --- a/src/uca-cam.c +++ b/src/uca-cam.c @@ -9,7 +9,8 @@ uint32_t uca_cam_alloc(struct uca_camera_t *cam, uint32_t n_buffers) uint32_t bitdepth; cam->get_property(cam, UCA_PROP_BITDEPTH, &bitdepth); const int pixel_size = bitdepth == 8 ? 1 : 2; - cam->grabber->alloc(cam->grabber, pixel_size, n_buffers); + if (cam->grabber != NULL) + cam->grabber->alloc(cam->grabber, pixel_size, n_buffers); } enum uca_cam_state uca_cam_get_state(struct uca_camera_t *cam) @@ -4,6 +4,7 @@ #include "uca.h" #include "uca-cam.h" #include "uca-grabber.h" +#include "cameras/dummy.h" #ifdef HAVE_ME4 #include "grabbers/me4.h" @@ -98,13 +99,12 @@ struct uca_t *uca_init(void) #ifdef HAVE_PH uca_photron_init, #endif + uca_dummy_init, NULL }; - int i = 0; - struct uca_camera_t *current = NULL; - /* Probe each frame grabber that is configured */ + int i = 0; struct uca_grabber_t *grabber = NULL; while (grabber_inits[i] != NULL) { uca_grabber_init init = grabber_inits[i]; @@ -125,6 +125,7 @@ struct uca_t *uca_init(void) /* Probe each camera that is configured */ i = 0; + struct uca_camera_t *current = NULL; while (cam_inits[i] != NULL) { struct uca_camera_t *cam = NULL; uca_cam_init init = cam_inits[i]; |