diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-05 11:29:35 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-05 11:29:35 +0100 |
commit | 881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3 (patch) | |
tree | 0ccdb1c14551a1bc37025dc09c10a2f4f4bf020c /src/cameras/dummy.c | |
parent | 0010c60ac578e8d463b5948f5b2f137dde54abd9 (diff) | |
download | uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.tar.gz uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.tar.bz2 uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.tar.xz uca-881abcb70c5ac2f8e65b2d892b7bde3f5311e8b3.zip |
Remove cruft
Diffstat (limited to 'src/cameras/dummy.c')
-rw-r--r-- | src/cameras/dummy.c | 327 |
1 files changed, 0 insertions, 327 deletions
diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c deleted file mode 100644 index 255a54b..0000000 --- a/src/cameras/dummy.c +++ /dev/null @@ -1,327 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> - (Karlsruhe Institute of Technology) - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by the - Free Software Foundation; either version 2.1 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License along - with this library; if not, write to the Free Software Foundation, Inc., 51 - Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <stdlib.h> -#include <string.h> -#define __USE_BSD -#include <unistd.h> -#undef __USE_BSD -#include <sys/time.h> -#include <assert.h> - -#include "config.h" -#include "uca.h" -#include "uca-cam.h" -#include "uca-grabber.h" - -#ifdef HAVE_PTHREADS -#include <pthread.h> -#endif - -/** - * User structure for the dummy camera. - */ -typedef struct dummy_cam { - uint32_t bitdepth; - uint32_t frame_rate; -#ifdef HAVE_PTHREADS - pthread_t grab_thread; - bool thread_running; - char *buffer; -#endif -} dummy_cam_t; - - -static const char g_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 } -}; - -const int DIGIT_WIDTH = 4; -const int DIGIT_HEIGHT = 5; - -#define GET_DUMMY(uca) ((struct dummy_cam *)(uca->user)) - -static void uca_dummy_print_number(char *buffer, int number, int x, int y, int width) -{ - for (int i = 0; i < DIGIT_WIDTH; i++) { - for (int j = 0; j < DIGIT_HEIGHT; j++) { - buffer[(y+j)*width + (x+i)] = g_digits[number][j*DIGIT_WIDTH+i]; - } - } -} - -static void uca_dummy_memcpy(struct uca_camera_priv *cam, char *buffer) -{ - /* print current frame number */ - unsigned int number = cam->current_frame; - unsigned int divisor = 100000000; - int x = 10; - while (divisor > 1) { - uca_dummy_print_number(buffer, number / divisor, x, 10, cam->frame_width); - number = number % divisor; - divisor = divisor / 10; - x += 5; - } -} - -static __suseconds_t uca_dummy_time_diff(struct timeval *start, struct timeval *stop) -{ - return (stop->tv_sec - start->tv_sec)*1000000 + (stop->tv_usec - start->tv_usec); -} - -static void *uca_dummy_grab_thread(void *arg) -{ - struct uca_camera_priv *cam = ((struct uca_camera_priv *) arg); - struct dummy_cam *dc = GET_DUMMY(cam); - - assert(dc->frame_rate > 0); - const __useconds_t sleep_time = (unsigned int) 1000000.0f / dc->frame_rate; - __suseconds_t call_time; - struct timeval start, stop; - - while (dc->thread_running) { - uca_dummy_memcpy(cam, dc->buffer); - gettimeofday(&start, NULL); - cam->callback(cam->current_frame, dc->buffer, NULL, cam->callback_user); - gettimeofday(&stop, NULL); - - call_time = uca_dummy_time_diff(&start, &stop); - if (call_time < sleep_time) { - cam->current_frame++; - usleep(sleep_time - call_time); - } - else - cam->current_frame += call_time / sleep_time; - } - return NULL; -} - - -/* - * --- interface implementations ---------------------------------------------- - */ -static uint32_t uca_dummy_set_property(struct uca_camera_priv *cam, uca_property_ids property, void *data) -{ - uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; - - switch (property) { - case UCA_PROP_WIDTH: - cam->frame_width = *((uint32_t *) data); - break; - - case UCA_PROP_HEIGHT: - cam->frame_height = *((uint32_t *) data); - break; - - case UCA_PROP_FRAMERATE: - GET_DUMMY(cam)->frame_rate = *((uint32_t *) data); - break; - - default: - return err | UCA_ERR_INVALID; - } - - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_get_property(struct uca_camera_priv *cam, uca_property_ids property, void *data, size_t num) -{ - switch (property) { - case UCA_PROP_NAME: - strncpy((char *) data, "dummy", num); - break; - - case UCA_PROP_WIDTH: - uca_set_void(data, uint32_t, cam->frame_width); - break; - - case UCA_PROP_WIDTH_MIN: - uca_set_void(data, uint32_t, 1); - break; - - case UCA_PROP_WIDTH_MAX: - uca_set_void(data, uint32_t, 4096); - break; - - case UCA_PROP_HEIGHT: - uca_set_void(data, uint32_t, cam->frame_height); - break; - - case UCA_PROP_HEIGHT_MIN: - uca_set_void(data, uint32_t, 1); - break; - - case UCA_PROP_HEIGHT_MAX: - uca_set_void(data, uint32_t, 4096); - break; - - case UCA_PROP_BITDEPTH: - uca_set_void(data, uint32_t, 8); - break; - - default: - return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_start_recording(struct uca_camera_priv *cam) -{ - if (cam->callback != NULL) { -#ifdef HAVE_PTHREADS - struct dummy_cam *dc = GET_DUMMY(cam); - /* FIXME: handle return value */ - dc->thread_running = true; - dc->buffer = (char *) malloc(cam->frame_width * cam->frame_height); - pthread_create(&dc->grab_thread, NULL, &uca_dummy_grab_thread, cam); -#endif - } - cam->current_frame = 0; - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_stop_recording(struct uca_camera_priv *cam) -{ - struct dummy_cam *dc = GET_DUMMY(cam); - if (cam->callback != NULL) { - dc->thread_running = false; - free(dc->buffer); - dc->buffer = NULL; - } - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_register_callback(struct uca_camera_priv *cam, uca_cam_grab_callback cb, void *user) -{ - if (cam->callback == NULL) { - cam->callback = cb; - cam->callback_user = user; - } - else - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; - - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_grab(struct uca_camera_priv *cam, char *buffer, void *meta_data) -{ - if (cam->callback != NULL) - return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; - - uca_dummy_memcpy(cam, buffer); - cam->current_frame++; - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_destroy(struct uca_camera_priv *cam) -{ - struct dummy_cam *dc = GET_DUMMY(cam); - free(dc->buffer); - free(dc); - return UCA_NO_ERROR; -} - -static uint32_t uca_dummy_ignore(struct uca_camera_priv *cam) -{ - return UCA_NO_ERROR; -} - -uint32_t uca_dummy_init(struct uca_camera_priv **cam, struct uca_grabber_priv *grabber) -{ - struct uca_camera_priv *uca = uca_cam_new(); - - 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->trigger = &uca_dummy_ignore; - uca->grab = &uca_dummy_grab; - uca->register_callback = &uca_dummy_register_callback; - - uca->state = UCA_CAM_CONFIGURABLE; - uca->frame_width = 320; - uca->frame_height = 240; - - struct dummy_cam *dummy_cam = (struct dummy_cam *) malloc(sizeof(struct dummy_cam)); - dummy_cam->bitdepth = 8; - dummy_cam->frame_rate = 100; - uca->user = dummy_cam; - - *cam = uca; - - return UCA_NO_ERROR; -} |