Add http_server_options

This commit is contained in:
Kamil Trzcinski 2022-04-05 16:13:21 +02:00
parent 9cf4cc359a
commit 4d3e8835ab
3 changed files with 27 additions and 6 deletions

View File

@ -20,6 +20,21 @@ http_method_t http_methods[] = {
{ NULL, NULL } { 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[]) int main(int argc, char *argv[])
{ {
camera_t camera; camera_t camera;
@ -32,6 +47,7 @@ int main(int argc, char *argv[])
} }
camera_init(&camera); camera_init(&camera);
camera.options = camera_options;
//camera.width = 1920; camera.height = 1080; //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 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; goto error;
} }
http_fd = http_server(9092, 5, http_methods); http_fd = http_server(&http_server_options, http_methods);
if (http_fd < 0) { if (http_fd < 0) {
goto error; goto error;
} }

View File

@ -122,18 +122,18 @@ error:
return -1; 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) { if (listen_fd < 0) {
return -1; return -1;
} }
sigaction(SIGPIPE, &(struct sigaction){ SIG_IGN }, NULL); sigaction(SIGPIPE, &(struct sigaction){ SIG_IGN }, NULL);
while (maxcons-- > 0) { for (int worker = 0; worker < options->maxcons; worker++) {
char name[20]; 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)); http_worker_t *worker = calloc(1, sizeof(http_worker_t));
worker->name = strdup(name); worker->name = strdup(name);

View File

@ -28,7 +28,12 @@ typedef struct http_worker_s {
char client_method[256]; char client_method[256];
} http_worker_t; } 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_index(http_worker_t *worker, FILE *stream);
void http_video_html(http_worker_t *worker, FILE *stream); void http_video_html(http_worker_t *worker, FILE *stream);