From 9c7f5fed1264452c6ca201536e4b900d99a85345 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 14 Apr 2022 10:13:18 +0200 Subject: [PATCH] Enable `-Wall` --- .vscode/settings.json | 4 +++- Makefile | 2 +- cmd/camera-streamer.c | 1 - device/buffer_lock.c | 1 - device/buffer_queue.c | 6 ++---- device/camera/camera.h | 2 +- device/device.c | 3 +-- device/libcamera/buffer.cc | 8 ++++---- device/libcamera/device.cc | 3 +++ device/links.c | 4 +--- device/v4l2/buffer.c | 5 ++--- device/v4l2/buffer_list.c | 2 +- device/v4l2/device.c | 2 +- device/v4l2/device_media.c | 5 ++--- device/v4l2/device_options.c | 3 +-- device/v4l2/v4l2.h | 1 + ffmpeg/remuxer.c | 9 ++++----- http/http.c | 6 +++--- http/http.h | 7 ++++--- http/http_ffmpeg.c | 2 +- http/http_h264.c | 2 -- http/http_jpeg.c | 10 +--------- opts/fourcc.h | 1 + opts/opts.c | 5 +---- opts/opts.h | 4 ++-- 25 files changed, 41 insertions(+), 57 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0d0d3b3..c156a0c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -68,6 +68,8 @@ "fourcc.h": "c", "device.h": "c", "log.h": "c", - "buffer_list.h": "c" + "buffer_list.h": "c", + "buffer.h": "c", + "stdbool.h": "c" } } diff --git a/Makefile b/Makefile index 63323fe..36adb8e 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SRC := $(wildcard **/*.c **/*/*.c **/*.cc **/*/*.cc) HEADERS := $(wildcard **/*.h **/*/*.h **/*.hh **/*/*.hh) HTML := $(wildcard html/*.js html/*.html) -CFLAGS := -Werror -g -I$(PWD) +CFLAGS := -Werror -Wall -g -I$(PWD) LDLIBS := -lpthread -lstdc++ ifneq (x,x$(shell which ccache)) diff --git a/cmd/camera-streamer.c b/cmd/camera-streamer.c index 7063a2f..b16925d 100644 --- a/cmd/camera-streamer.c +++ b/cmd/camera-streamer.c @@ -119,7 +119,6 @@ int main(int argc, char *argv[]) { int http_fd = -1; int ret = -1; - const char *env; if (parse_opts(all_options, argc, argv) < 0) { return -1; diff --git a/device/buffer_lock.c b/device/buffer_lock.c index 0d8b051..80d4536 100644 --- a/device/buffer_lock.c +++ b/device/buffer_lock.c @@ -128,7 +128,6 @@ int buffer_lock_write_loop(buffer_lock_t *buf_lock, int nframes, buffer_write_fn } } -ok: buffer_lock_use(buf_lock, -1); return frames; diff --git a/device/buffer_queue.c b/device/buffer_queue.c index a4a8ded..e379130 100644 --- a/device/buffer_queue.c +++ b/device/buffer_queue.c @@ -127,7 +127,7 @@ int buffer_list_enqueue(buffer_list_t *buf_list, buffer_t *dma_buf) memcpy(buf->start, dma_buf->start, dma_buf->used); uint64_t after = get_monotonic_time_us(NULL, NULL); - LOG_DEBUG(buf, "mmap copy: dest=%p, src=%p (%s), size=%zu, space=%zu, time=%dllus", + LOG_DEBUG(buf, "mmap copy: dest=%p, src=%p (%s), size=%zu, space=%zu, time=%luus", buf->start, dma_buf->start, dma_buf->name, dma_buf->used, buf->length, after-before); } else { LOG_DEBUG(buf, "dmabuf copy: dest=%p, src=%p (%s, dma_fd=%d), size=%zu", @@ -141,8 +141,6 @@ int buffer_list_enqueue(buffer_list_t *buf_list, buffer_t *dma_buf) buf->used = dma_buf->used; buffer_consumed(buf, "copy-data"); return 1; -error: - return -1; } buffer_t *buffer_list_dequeue(buffer_list_t *buf_list) @@ -162,7 +160,7 @@ buffer_t *buffer_list_dequeue(buffer_list_t *buf_list) buf->enqueued = false; buf->mmap_reflinks = 1; - LOG_DEBUG(buf_list, "Grabbed mmap buffer=%u, bytes=%d, used=%d, frame=%d, linked=%s", + LOG_DEBUG(buf_list, "Grabbed mmap buffer=%u, bytes=%zu, used=%zu, frame=%d, linked=%s", buf->index, buf->length, buf->used, diff --git a/device/camera/camera.h b/device/camera/camera.h index 5804b93..d1ab85c 100644 --- a/device/camera/camera.h +++ b/device/camera/camera.h @@ -22,7 +22,7 @@ typedef struct camera_options_s { bool allow_dma; float high_res_factor; float low_res_factor; - int auto_reconnect; + unsigned auto_reconnect; char options[CAMERA_OPTIONS_LENGTH]; diff --git a/device/device.c b/device/device.c index feb0640..60f9fad 100644 --- a/device/device.c +++ b/device/device.c @@ -54,7 +54,6 @@ buffer_list_t *device_open_buffer_list(device_t *dev, bool do_capture, unsigned buffer_list_t *device_open_buffer_list2(device_t *dev, const char *path, bool do_capture, unsigned width, unsigned height, unsigned format, unsigned bytesperline, int nbufs, bool do_mmap) { - unsigned type; char name[64]; int index = 0; buffer_list_t *buf_list; @@ -239,7 +238,7 @@ void device_set_option_list(device_t *dev, const char *option_list) char *string = start; char *option; - while (option = strsep(&string, OPTION_VALUE_LIST_SEP)) { + while ((option = strsep(&string, OPTION_VALUE_LIST_SEP)) != NULL) { char *value = option; char *key = strsep(&value, "="); diff --git a/device/libcamera/buffer.cc b/device/libcamera/buffer.cc index eb4481c..bf23b93 100644 --- a/device/libcamera/buffer.cc +++ b/device/libcamera/buffer.cc @@ -37,7 +37,7 @@ int libcamera_buffer_open(buffer_t *buf) } if (offset + length != plane.offset) { - LOG_ERROR(buf, "Plane is not continuous: offset=%lld, expected=%lld", plane.offset, offset + length); + LOG_ERROR(buf, "Plane is not continuous: offset=%u, expected=%lu", plane.offset, offset + length); } length += plane.length; @@ -51,7 +51,7 @@ int libcamera_buffer_open(buffer_t *buf) buf->dma_fd = dma_fd.get(); buf->length = length; - LOG_DEBUG(buf, "Mapped buffer: start=%p, length=%d, fd=%d, planes=%d", + LOG_DEBUG(buf, "Mapped buffer: start=%p, length=%zu, fd=%d, planes=%lu", buf->start, buf->length, buf->dma_fd, buffer->planes().size()); } @@ -76,7 +76,7 @@ int libcamera_buffer_enqueue(buffer_t *buf, const char *who) request->reuse(libcamera::Request::ReuseBuffers); - if (buf->buf_list->dev->libcamera->camera->queueRequest(buf->libcamera->request.get()) < 0) { + if (camera->queueRequest(buf->libcamera->request.get()) < 0) { LOG_ERROR(buf, "Can't queue buffer."); } return 0; @@ -107,7 +107,7 @@ int libcamera_buffer_list_dequeue(buffer_list_t *buf_list, buffer_t **bufp) return -1; } - if (index >= buf_list->nbufs) { + if (index >= (unsigned)buf_list->nbufs) { LOG_INFO(buf_list, "Received invalid index from `read`: %d >= %d", index, buf_list->nbufs); return -1; } diff --git a/device/libcamera/device.cc b/device/libcamera/device.cc index c285824..0d6acea 100644 --- a/device/libcamera/device.cc +++ b/device/libcamera/device.cc @@ -86,6 +86,9 @@ int libcamera_device_set_option(device_t *dev, const char *keyp, const char *val libcamera::ControlValue control_value; switch (control_id->type()) { + case libcamera::ControlTypeNone: + break; + case libcamera::ControlTypeBool: control_value.set(atoi(value)); break; diff --git a/device/links.c b/device/links.c index 0a90018..99a7471 100644 --- a/device/links.c +++ b/device/links.c @@ -11,7 +11,6 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_list_t **buf_lists, int max_n, int *max_timeout_ms) { int n = 0, nlinks = 0; - uint64_t now_us = get_monotonic_time_us(NULL, NULL); for (nlinks = 0; all_links[nlinks].source; nlinks++); @@ -143,7 +142,6 @@ int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_ms) struct pollfd fds[N_FDS] = {0}; link_t *links[N_FDS]; buffer_list_t *buf_lists[N_FDS]; - buffer_t *buf; int n = _build_fds(all_links, fds, links, buf_lists, N_FDS, &timeout_now_ms); print_pollfds(fds, n); @@ -220,7 +218,7 @@ int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_ms) continue; #endif - if (buf = buffer_list_find_slot(buf_list)) { + if ((buf = buffer_list_find_slot(buf_list)) != NULL) { buffer_consumed(buf, "enqueued"); } } diff --git a/device/v4l2/buffer.c b/device/v4l2/buffer.c index f331c34..2af5f78 100644 --- a/device/v4l2/buffer.c +++ b/device/v4l2/buffer.c @@ -10,7 +10,6 @@ int v4l2_buffer_open(buffer_t *buf) struct v4l2_plane v4l2_plane = {0}; buffer_list_t *buf_list = buf->buf_list; - device_t *dev = buf_list->dev; buf->v4l2 = calloc(1, sizeof(buffer_v4l2_t)); @@ -29,7 +28,7 @@ int v4l2_buffer_open(buffer_t *buf) v4l2_buf.memory = V4L2_MEMORY_DMABUF; } - ERR_IOCTL(buf_list, buf_list->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Cannot query buffer %d", index); + ERR_IOCTL(buf_list, buf_list->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Cannot query buffer %d", buf->index); uint64_t mem_offset = 0; @@ -51,7 +50,7 @@ int v4l2_buffer_open(buffer_t *buf) v4l2_exp.type = v4l2_buf.type; v4l2_exp.index = buf->index; v4l2_exp.plane = 0; - ERR_IOCTL(buf_list, buf_list->v4l2->dev_fd, VIDIOC_EXPBUF, &v4l2_exp, "Can't export queue buffer=%u to DMA", index); + ERR_IOCTL(buf_list, buf_list->v4l2->dev_fd, VIDIOC_EXPBUF, &v4l2_exp, "Can't export queue buffer=%u to DMA", buf->index); buf->dma_fd = v4l2_exp.fd; } diff --git a/device/v4l2/buffer_list.c b/device/v4l2/buffer_list.c index fcc5cd5..28dcc8f 100644 --- a/device/v4l2/buffer_list.c +++ b/device/v4l2/buffer_list.c @@ -62,7 +62,7 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list) // JPEG is in 16x16 blocks (shrink image to fit) (but adapt to 32x32) // And ISP output - if (strstr(buf_list->name, "JPEG") || strstr(buf_list->name, "H264") || buf_list->do_capture && strstr(buf_list->name, "ISP")) { + if (strstr(buf_list->name, "JPEG") || strstr(buf_list->name, "H264") || (buf_list->do_capture && strstr(buf_list->name, "ISP"))) { buffer_format_t org_fmt = buf_list->fmt; fmt.width = shrink_to_block(fmt.width, 32); fmt.height = shrink_to_block(fmt.height, 32); diff --git a/device/v4l2/device.c b/device/v4l2/device.c index 5f282ae..321b381 100644 --- a/device/v4l2/device.c +++ b/device/v4l2/device.c @@ -24,7 +24,7 @@ int v4l2_device_open(device_t *dev) LOG_ERROR(dev, "Device doesn't support streaming IO"); } - strcpy(dev->bus_info, v4l2_cap.bus_info); + strcpy(dev->bus_info, (char *)v4l2_cap.bus_info); dev->v4l2->subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0); v4l2_device_query_controls(dev, dev->v4l2->dev_fd); diff --git a/device/v4l2/device_media.c b/device/v4l2/device_media.c index 5373034..d39ef5a 100644 --- a/device/v4l2/device_media.c +++ b/device/v4l2/device_media.c @@ -22,7 +22,7 @@ int v4l2_device_open_media_device(device_t *dev) return -1; } - char path[256]; + char path[300]; sprintf(path, "/sys/dev/char/%d:%d/device", major(st.st_rdev), minor(st.st_rdev)); struct dirent **namelist; @@ -47,7 +47,6 @@ int v4l2_device_open_media_device(device_t *dev) } free(namelist); -error: return ret; } @@ -94,7 +93,7 @@ int v4l2_device_open_v4l2_subdev(device_t *dev, int subdev) } if (strstr(last, "/v4l-subdev") != last) { - LOG_VERBOSE(dev, "Link '%s' does not contain '/v4l-subdev'", link, path); + LOG_VERBOSE(dev, "Link '%s' does not contain '/v4l-subdev'", link); goto error; } diff --git a/device/v4l2/device_options.c b/device/v4l2/device_options.c index c1636d4..ec509c2 100644 --- a/device/v4l2/device_options.c +++ b/device/v4l2/device_options.c @@ -23,7 +23,6 @@ error: static int v4l2_device_query_control_iter_id(device_t *dev, int fd, uint32_t *id) { struct v4l2_query_ext_ctrl qctrl = { .id = *id }; - void *data = NULL; if (0 != ioctl (fd, VIDIOC_QUERY_EXT_CTRL, &qctrl)) { return -1; @@ -120,7 +119,7 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value) char *token; int tokens = 0; - for ( ; token = strsep(&string, ","); tokens++) { + for ( ; (token = strsep(&string, ",")) != NULL; tokens++) { if (tokens >= control->control.elems) continue; diff --git a/device/v4l2/v4l2.h b/device/v4l2/v4l2.h index 275572e..f6c366f 100644 --- a/device/v4l2/v4l2.h +++ b/device/v4l2/v4l2.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include diff --git a/ffmpeg/remuxer.c b/ffmpeg/remuxer.c index cf6320d..75ce04d 100644 --- a/ffmpeg/remuxer.c +++ b/ffmpeg/remuxer.c @@ -140,10 +140,10 @@ int ffmpeg_remuxer_feed(ffmpeg_remuxer_t *remuxer, int nframes) ret = av_read_frame(remuxer->input_context, remuxer->packet); if (ret == AVERROR_EOF) { ret = 0; - LOG_DEBUG(remuxer, "av_read_frame: EOF", ret); + LOG_DEBUG(remuxer, "av_read_frame: EOF"); break; } else if (ret < 0) { - LOG_DEBUG(remuxer, "av_read_frame: %08x, pts: %d", ret, remuxer->packet->pts); + LOG_DEBUG(remuxer, "av_read_frame: %08x, pts: %ld", ret, remuxer->packet->pts); break; } @@ -155,7 +155,6 @@ int ffmpeg_remuxer_feed(ffmpeg_remuxer_t *remuxer, int nframes) remuxer->frames++; frames++; - AVStream *in_stream = remuxer->input_context->streams[remuxer->packet->stream_index]; remuxer->packet->stream_index = 0; AVStream *out_stream = remuxer->output_context->streams[remuxer->packet->stream_index]; @@ -173,7 +172,7 @@ int ffmpeg_remuxer_feed(ffmpeg_remuxer_t *remuxer, int nframes) av_packet_unref(remuxer->packet); if (ret == AVERROR_EOF) { - LOG_DEBUG(remuxer, "av_interleaved_write_frame: EOF, pts: %d, since_start: %d", ret, pts, since_start); + LOG_DEBUG(remuxer, "av_interleaved_write_frame: EOF, pts: %d, since_start: %d", pts, since_start); } else { LOG_DEBUG(remuxer, "av_interleaved_write_frame: %08x, pts: %d, since_start: %d", ret, pts, since_start); } @@ -190,7 +189,7 @@ int ffmpeg_remuxer_flush(ffmpeg_remuxer_t *remuxer) { int ret = av_write_frame(remuxer->output_context, NULL); if (ret == AVERROR_EOF) { - LOG_DEBUG(remuxer, "av_write_frame (flush): EOF", ret); + LOG_DEBUG(remuxer, "av_write_frame (flush): EOF"); } else { LOG_DEBUG(remuxer, "av_write_frame (flush): %08x", ret); } diff --git a/http/http.c b/http/http.c index f6f54c3..6990166 100644 --- a/http/http.c +++ b/http/http.c @@ -84,7 +84,7 @@ static void http_process(http_worker_t *worker, FILE *stream) continue; // allow last character to match `?` or ` ` - if (worker->client_method[nlen-1] == name[nlen-1] || name[nlen-1] == '?' && worker->client_method[nlen-1] == ' ') { + if (worker->client_method[nlen-1] == name[nlen-1] || (name[nlen-1] == '?' && worker->client_method[nlen-1] == ' ')) { worker->current_method = &worker->methods[i]; break; } @@ -130,7 +130,7 @@ static void http_client(http_worker_t *worker) static int http_worker(http_worker_t *worker) { while (1) { - int addrlen = sizeof(worker->client_addr); + unsigned addrlen = sizeof(worker->client_addr); worker->client_fd = accept(worker->listen_fd, (struct sockaddr *)&worker->client_addr, &addrlen); if (worker->client_fd < 0) { goto error; @@ -152,7 +152,7 @@ int http_server(http_server_options_t *options, http_method_t *methods) return -1; } - sigaction(SIGPIPE, &(struct sigaction){ SIG_IGN }, NULL); + sigaction(SIGPIPE, &(struct sigaction){{ SIG_IGN }}, NULL); for (int worker = 0; worker < options->maxcons; worker++) { char name[20]; diff --git a/http/http.h b/http/http.h index fa77189..f4a0b76 100644 --- a/http/http.h +++ b/http/http.h @@ -4,6 +4,7 @@ #include #include #include +#include #include typedef struct buffer_s buffer_t; @@ -17,7 +18,7 @@ typedef struct http_method_s { const char *name; http_method_fn func; const char *content_type; - const char *content_body; + const void *content_body; unsigned content_length; unsigned *content_lengthp; } http_method_t; @@ -38,8 +39,8 @@ typedef struct http_worker_s { } http_worker_t; typedef struct http_server_options_s { - int port; - int maxcons; + unsigned port; + unsigned maxcons; } http_server_options_t; int http_server(http_server_options_t *options, http_method_t *methods); diff --git a/http/http_ffmpeg.c b/http/http_ffmpeg.c index 42770d2..855df41 100644 --- a/http/http_ffmpeg.c +++ b/http/http_ffmpeg.c @@ -64,7 +64,7 @@ static int http_ffmpeg_write_to_stream(void *opaque, uint8_t *buf, int buf_size) size_t n = fwrite(buf, 1, buf_size, status->stream); fflush(status->stream); - LOG_DEBUG(status, "http_ffmpeg_write_to_stream: offset=%d, n=%d, buf_size=%d, error=%d", + LOG_DEBUG(status, "http_ffmpeg_write_to_stream: offset=%d, n=%zu, buf_size=%d, error=%d", status->stream_offset, n, buf_size, ferror(status->stream)); status->stream_offset += n; if (ferror(status->stream)) diff --git a/http/http_h264.c b/http/http_h264.c index f1f8668..cff44d5 100644 --- a/http/http_h264.c +++ b/http/http_h264.c @@ -65,8 +65,6 @@ bool h264_is_key_frame(buffer_t *buf) int http_video_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, http_video_status_t *status) { - unsigned char *data = buf->start; - if (!status->had_key_frame) { status->had_key_frame = h264_is_key_frame(buf); } diff --git a/http/http_jpeg.c b/http/http_jpeg.c index 1aa9511..51c2777 100644 --- a/http/http_jpeg.c +++ b/http/http_jpeg.c @@ -18,14 +18,6 @@ static const char *const STREAM_HEADER = "HTTP/1.0 200 OK\r\n" "Content-Type: multipart/x-mixed-replace;boundary=" PART_BOUNDARY "\r\n" "\r\n" "--" PART_BOUNDARY "\r\n"; -static const char *const STREAM_ERROR = "Content-Type: text/plain\r\n" - "\r\n" - "Error: %d (%s).\r\n" - "--" PART_BOUNDARY "\r\n"; -static const char *const STREAM_TIMEDOUT = "Content-Type: text/plain\r\n" - "\r\n" - "Timedout.\r\n" - "--" PART_BOUNDARY "\r\n"; static const char *const STREAM_PART = "Content-Type: " CONTENT_TYPE "\r\n" CONTENT_LENGTH ": %u\r\n\r\n"; static const char *const STREAM_BOUNDARY = "\r\n" "--" PART_BOUNDARY "\r\n"; @@ -57,7 +49,7 @@ int http_snapshot_buf_part(buffer_lock_t *buf_lock, buffer_t *buf, int frame, FI { fprintf(stream, "HTTP/1.1 200 OK\r\n"); fprintf(stream, "Content-Type: image/jpeg\r\n"); - fprintf(stream, "Content-Length: %d\r\n", buf->used); + fprintf(stream, "Content-Length: %zu\r\n", buf->used); fprintf(stream, "\r\n"); fwrite(buf->start, buf->used, 1, stream); return 1; diff --git a/opts/fourcc.h b/opts/fourcc.h index 524d109..b46e34d 100644 --- a/opts/fourcc.h +++ b/opts/fourcc.h @@ -1,5 +1,6 @@ #pragma once +#include #include typedef struct { diff --git a/opts/opts.c b/opts/opts.c index 337afcc..7350cb7 100644 --- a/opts/opts.c +++ b/opts/opts.c @@ -5,9 +5,6 @@ #include #include -static int option_handler_print(option_t *option, char *data); -static int option_handler_set(option_t *option, char *data); - static void print_help(option_t *options) { for (int i = 0; options[i].name; i++) { @@ -20,7 +17,7 @@ static void print_help(option_t *options) char *token; int tokens = 0; - while (token = strsep(&string, OPTION_VALUE_LIST_SEP)) { + while ((token = strsep(&string, OPTION_VALUE_LIST_SEP)) != NULL) { if (tokens++ > 0) printf("\n%40s\t", ""); printf("%s", token); diff --git a/opts/opts.h b/opts/opts.h index abb34fc..265ede5 100644 --- a/opts/opts.h +++ b/opts/opts.h @@ -27,12 +27,12 @@ typedef struct options_s { #define OPTION_VALUE_LIST_SEP ";" -#define OPTION_FORMAT_uint "%d" +#define OPTION_FORMAT_uint "%u" #define OPTION_FORMAT_hex "%08x" #define OPTION_FORMAT_bool "%d" #define OPTION_FORMAT_float "%f" #define OPTION_FORMAT_string "%s" -#define OPTION_FORMAT_list "%s" +#define OPTION_FORMAT_list "%s" #define DEFINE_OPTION(_section, _name, _type) \ { \