diff options
-rw-r--r-- | src/cameras/pco.c | 1 | ||||
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/benchmark.c | 84 |
3 files changed, 86 insertions, 1 deletions
diff --git a/src/cameras/pco.c b/src/cameras/pco.c index ebde852..ac2e950 100644 --- a/src/cameras/pco.c +++ b/src/cameras/pco.c @@ -90,7 +90,6 @@ static uint32_t uca_pco_get_property(struct uca_camera *cam, enum uca_property_i switch (property) { case UCA_PROP_NAME: { - /* FIXME: how to ensure, that buffer is large enough? */ SC2_Camera_Name_Response name; /* FIXME: This is _not_ a mistake. For some reason (which I diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 287f9ea..1a25ee6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,10 +16,12 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/control.glade add_executable(enum enum.c) add_executable(grab grab.c) add_executable(grab-async grab-async.c) +add_executable(benchmark benchmark.c) target_link_libraries(enum uca) target_link_libraries(grab uca) target_link_libraries(grab-async uca) +target_link_libraries(benchmark uca) if (GTK2_FOUND) include_directories(${GTK2_INCLUDE_DIRS}) diff --git a/test/benchmark.c b/test/benchmark.c new file mode 100644 index 0000000..900b66a --- /dev/null +++ b/test/benchmark.c @@ -0,0 +1,84 @@ + +#define __USE_BSD +#include <unistd.h> +#undef __USE_BSD +#include <sys/time.h> +#include <stdio.h> +#include <stdlib.h> +#include "uca.h" +#include "uca-cam.h" + + +static __suseconds_t time_diff(struct timeval *start, struct timeval *stop) +{ + return (stop->tv_sec - start->tv_sec)*1000000 + (stop->tv_usec - start->tv_usec); +} + +void grab_callback_raw(uint32_t image_number, void *buffer, void *meta_data, void *user) +{ + uint32_t *count = (uint32_t *) user; + *count = image_number; +} + +void benchmark_cam(struct uca_camera *cam) +{ + char name[256]; + cam->get_property(cam, UCA_PROP_NAME, name, 256); + + uint32_t val = 5000; + cam->set_property(cam, UCA_PROP_EXPOSURE, &val); + val = 0; + cam->set_property(cam, UCA_PROP_DELAY, &val); + + uint32_t width, height, bits; + cam->get_property(cam, UCA_PROP_WIDTH, &width, 0); + cam->get_property(cam, UCA_PROP_HEIGHT, &height, 0); + cam->get_property(cam, UCA_PROP_BITDEPTH, &bits, 0); + int pixel_size = bits == 8 ? 1 : 2; + + struct timeval start, stop; + + for (int i = 0; i < 2; i++) { + char *buffer = (char *) malloc(width*height*pixel_size); + cam->set_property(cam, UCA_PROP_HEIGHT, &height); + uca_cam_alloc(cam, 20); + + /* + * Experiment 1: Grab n frames manually + */ + gettimeofday(&start, NULL); + cam->start_recording(cam); + for (int i = 0; i < 1000; i++) + cam->grab(cam, (char *) buffer, NULL); + + cam->stop_recording(cam); + gettimeofday(&stop, NULL); + + float seconds = time_diff(&start, &stop) / 1000000.0; + printf("%f,%s;%i;%i;1;%.2f;%.2f\n", seconds,name, width, height, 1000.0 / seconds, width*height*pixel_size*1000.0/ (1024*1024*seconds)); + + height /= 2; + free(buffer); + } +} + +int main(int argc, char *argv[]) +{ + struct uca *u = uca_init(NULL); + if (u == NULL) { + printf("Couldn't find a camera\n"); + return 1; + } + + printf("# camera;width;height;experiment;frames-per-second;throughput in MB/s\n"); + + /* take first camera */ + struct uca_camera *cam = u->cameras; + while (cam != NULL) { + benchmark_cam(cam); + cam = cam->next; + } + + uca_destroy(u); + return 0; +} |