From aa007c676ff638080f139915bc8702aaed7122b4 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 16 Mar 2019 13:21:44 +0300 Subject: [PATCH] limited default workers and buffers number --- src/device.c | 2 +- src/main.c | 4 ++-- src/tools.h | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/device.c b/src/device.c index 466cc16..a28667e 100644 --- a/src/device.c +++ b/src/device.c @@ -95,7 +95,7 @@ struct device_t *device_init() { dev->height = 480; dev->format = V4L2_PIX_FMT_YUYV; dev->standard = V4L2_STD_UNKNOWN; - dev->n_buffers = max_u(sysconf(_SC_NPROCESSORS_ONLN), 1) + 1; + dev->n_buffers = max_u(min_u(sysconf(_SC_NPROCESSORS_ONLN), 4), 1) + 1; dev->n_workers = dev->n_buffers; dev->timeout = 1; dev->error_delay = 1; diff --git a/src/main.c b/src/main.c index 9ce4d8f..fda9087 100644 --- a/src/main.c +++ b/src/main.c @@ -129,8 +129,8 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s printf(" Supports automatic resolution changing. Default: disabled.\n\n"); printf(" -b|--buffers -- The number of buffers to receive data from the device.\n"); printf(" Each buffer may processed using an intermediate thread.\n"); - printf(" Default: %u (number of CPU cores + 1)\n\n", dev->n_buffers); - printf(" -w|--workers -- The number of compressing threads. Default: %u (== --buffers).\n\n", dev->n_workers); + printf(" Default: %u (the number of CPU cores (but not more 4) + 1)\n\n", dev->n_buffers); + printf(" -w|--workers -- The number of worker threads. Default: %u (== --buffers).\n\n", dev->n_workers); printf(" -q|--quality -- Set quality of JPEG encoding from 1 to 100 (best). Default: %u.\n\n", encoder->quality); printf(" -c|--encoder -- Use specified encoder. It may affects to workers number.\n"); printf(" -- Available: %s; default: CPU.\n\n", ENCODER_TYPES_STR); diff --git a/src/tools.h b/src/tools.h index bdb2835..642a3a9 100644 --- a/src/tools.h +++ b/src/tools.h @@ -63,6 +63,10 @@ INLINE char *bool_to_string(bool flag) { return (flag ? "true" : "false"); } +INLINE unsigned min_u(unsigned a, unsigned b) { + return (a < b ? a : b); +} + INLINE unsigned max_u(unsigned a, unsigned b) { return (a > b ? a : b); }