From 4d3e8835ab5d071da72915e526b1b60a3a6fbd00 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 5 Apr 2022 16:13:21 +0200 Subject: [PATCH] Add `http_server_options` --- cmd/main.c | 18 +++++++++++++++++- http/http.c | 8 ++++---- http/http.h | 7 ++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cmd/main.c b/cmd/main.c index 415ee63..6a6109f 100644 --- a/cmd/main.c +++ b/cmd/main.c @@ -20,6 +20,21 @@ http_method_t http_methods[] = { { NULL, NULL } }; +camera_options_t camera_options = { + .path = "/dev/video0", + .width = 1920, + .height = 720, + .format = 0, + .nbufs = 4, + .fps = 30, + .allow_dma = true +}; + +http_server_options_t http_server_options = { + .listen_port = 9092, + .maxcons = 10 +}; + int main(int argc, char *argv[]) { camera_t camera; @@ -32,6 +47,7 @@ int main(int argc, char *argv[]) } camera_init(&camera); + camera.options = camera_options; //camera.width = 1920; camera.height = 1080; strcpy(camera.options.path, "/dev/video2"); camera.options.width = 2328; camera.options.height = 1748; camera.options.format = V4L2_PIX_FMT_SRGGB10P; // 1164x874 @@ -49,7 +65,7 @@ int main(int argc, char *argv[]) goto error; } - http_fd = http_server(9092, 5, http_methods); + http_fd = http_server(&http_server_options, http_methods); if (http_fd < 0) { goto error; } diff --git a/http/http.c b/http/http.c index be9a4fc..7a1fabe 100644 --- a/http/http.c +++ b/http/http.c @@ -122,18 +122,18 @@ error: return -1; } -int http_server(int listen_port, int maxcons, http_method_t *methods) +int http_server(http_server_options_t *options, http_method_t *methods) { - int listen_fd = http_listen(9092, maxcons); + int listen_fd = http_listen(options->listen_port, options->maxcons); if (listen_fd < 0) { return -1; } sigaction(SIGPIPE, &(struct sigaction){ SIG_IGN }, NULL); - while (maxcons-- > 0) { + for (int worker = 0; worker < options->maxcons; worker++) { char name[20]; - sprintf(name, "HTTP%d/%d", listen_port, maxcons); + sprintf(name, "HTTP%d/%d", options->listen_port, worker); http_worker_t *worker = calloc(1, sizeof(http_worker_t)); worker->name = strdup(name); diff --git a/http/http.h b/http/http.h index a59012d..bd2d58f 100644 --- a/http/http.h +++ b/http/http.h @@ -28,7 +28,12 @@ typedef struct http_worker_s { char client_method[256]; } http_worker_t; -int http_server(int listen_port, int maxcons, http_method_t *methods); +typedef struct http_server_options_s { + int listen_port; + int maxcons; +} http_server_options_t; + +int http_server(http_server_options_t *options, http_method_t *methods); void http_index(http_worker_t *worker, FILE *stream); void http_video_html(http_worker_t *worker, FILE *stream);