From 34ff200ceb27e3743fb8338ca70aa6a7b3c4acb3 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 24 Feb 2023 20:02:42 +0100 Subject: [PATCH] camera: add `force_active` option to make camera always hot --- cmd/camera-streamer/opts.c | 1 + device/camera/camera.c | 2 +- device/camera/camera.h | 1 + device/links.c | 14 +++++++++----- device/links.h | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/camera-streamer/opts.c b/cmd/camera-streamer/opts.c index 1049a91..584bbc9 100644 --- a/cmd/camera-streamer/opts.c +++ b/cmd/camera-streamer/opts.c @@ -99,6 +99,7 @@ option_t all_options[] = { DEFINE_OPTION_PTR(camera, options, list, "Set the camera options. List all available options with `-camera-list_options`."), DEFINE_OPTION(camera, auto_reconnect, uint, "Set the camera auto-reconnect delay in seconds."), DEFINE_OPTION_DEFAULT(camera, auto_focus, bool, "1", "Do auto-focus on start-up (does not work with all camera)."), + DEFINE_OPTION_DEFAULT(camera, force_active, bool, "1", "Force camera to be always active."), DEFINE_OPTION_DEFAULT(camera, vflip, bool, "1", "Do vertical image flip (does not work with all camera)."), DEFINE_OPTION_DEFAULT(camera, hflip, bool, "1", "Do horizontal image flip (does not work with all camera)."), diff --git a/device/camera/camera.c b/device/camera/camera.c index 805cab2..4c47982 100644 --- a/device/camera/camera.c +++ b/device/camera/camera.c @@ -117,5 +117,5 @@ int camera_set_params(camera_t *camera) int camera_run(camera_t *camera) { bool running = false; - return links_loop(camera->links, &running); + return links_loop(camera->links, camera->options.force_active, &running); } diff --git a/device/camera/camera.h b/device/camera/camera.h index a10faeb..af2a9c0 100644 --- a/device/camera/camera.h +++ b/device/camera/camera.h @@ -32,6 +32,7 @@ typedef struct camera_options_s { float low_res_factor; bool auto_focus; unsigned auto_reconnect; + bool force_active; union { bool vflip; unsigned vflip_align; diff --git a/device/links.c b/device/links.c index a4a071d..31a784d 100644 --- a/device/links.c +++ b/device/links.c @@ -58,7 +58,7 @@ static int links_count(link_t *all_links) return n; } -static void links_process_paused(link_t *all_links) +static void links_process_paused(link_t *all_links, bool force_active) { // This traverses in reverse order as it requires to first fix outputs // and go back into captures @@ -69,6 +69,10 @@ static void links_process_paused(link_t *all_links) bool paused = true; + if (force_active) { + paused = false; + } + if (link_needs_buffer_by_callbacks(link)) { paused = false; } @@ -280,7 +284,7 @@ static void print_pollfds(struct pollfd *fds, int n) printf("pollfds = %d\n", n); } -static int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_ms) +static int links_step(link_t *all_links, bool force_active, int timeout_now_ms, int *timeout_next_ms) { link_pool_t pool = { .fds = {{0}}, @@ -289,7 +293,7 @@ static int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_m .output_lists = {0} }; - links_process_paused(all_links); + links_process_paused(all_links, force_active); links_process_capture_buffers(all_links, timeout_next_ms); int n = links_build_fds(all_links, &pool); @@ -413,7 +417,7 @@ static void links_refresh_stats(link_t *all_links, uint64_t *last_refresh_us) } } -int links_loop(link_t *all_links, bool *running) +int links_loop(link_t *all_links, bool force_active, bool *running) { *running = true; @@ -429,7 +433,7 @@ int links_loop(link_t *all_links, bool *running) int timeout_now_ms = timeout_ms; timeout_ms = LINKS_LOOP_INTERVAL; - ret = links_step(all_links, timeout_now_ms, &timeout_ms); + ret = links_step(all_links, force_active, timeout_now_ms, &timeout_ms); links_refresh_stats(all_links, &last_refresh_us); } diff --git a/device/links.h b/device/links.h index bfa66c0..8f8865f 100644 --- a/device/links.h +++ b/device/links.h @@ -30,5 +30,5 @@ typedef struct link_s { int n_callbacks; } link_t; -int links_loop(link_t *all_links, bool *running); +int links_loop(link_t *all_links, bool force_active, bool *running); void links_dump(link_t *all_links);