From 19302b93d1157843013acc1007c61f33e2cf3cf6 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 24 Feb 2023 20:01:07 +0100 Subject: [PATCH] links: to avoid overrun limit amount of buffers enqueued on v4l2 --- device/links.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/device/links.c b/device/links.c index 1162855..cc8052b 100644 --- a/device/links.c +++ b/device/links.c @@ -11,6 +11,9 @@ #define CAPTURE_TIMEOUT_US (1000*1000) #define N_FDS 50 +#define MAX_CAPTURED_ON_CAMERA 2 +#define MAX_CAPTURED_ON_M2M 2 + typedef struct link_pool_s { struct pollfd fds[N_FDS]; @@ -119,12 +122,22 @@ static bool links_enqueue_capture_buffers(buffer_list_t *capture_list, int *time // no output, just give back capture_buf if (!output_list) { + // limit amount of buffers enqueued by camera + if (buffer_list_count_enqueued(capture_list) >= MAX_CAPTURED_ON_CAMERA) { + return false; + } + buffer_consumed(capture_buf, "enqueued"); if (capture_list->fmt.interval_us > 0) return false; return true; } + // limit amount of buffers enqueued by m2m + if (buffer_list_count_enqueued(output_list) >= MAX_CAPTURED_ON_M2M) { + return false; + } + // try to find matching output slot, ignore if not present if (!buffer_list_find_slot(output_list)) { return false;