From 281f4eb3a0f17633125c981cbc9b12e2e69a0451 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sat, 13 Nov 2021 19:25:07 +0300 Subject: [PATCH] replaced MEMSET_ZERO to initializers --- src/dump/main.c | 6 ++---- src/ustreamer/device.c | 40 +++++++++++++-------------------------- src/ustreamer/encoder.c | 3 +-- src/ustreamer/http/unix.c | 3 +-- src/ustreamer/main.c | 3 +-- 5 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/dump/main.c b/src/dump/main.c index 7548561..f427356 100644 --- a/src/dump/main.c +++ b/src/dump/main.c @@ -175,8 +175,7 @@ int main(int argc, char *argv[]) { return 1; } - _output_context_s ctx; - MEMSET_ZERO(ctx); + _output_context_s ctx = {0}; if (output_path && output_path[0] != '\0') { if ((ctx.v_output = (void *)output_file_init(output_path, output_json)) == NULL) { @@ -206,8 +205,7 @@ static void _signal_handler(int signum) { } static void _install_signal_handlers(void) { - struct sigaction sig_act; - MEMSET_ZERO(sig_act); + struct sigaction sig_act = {0}; assert(!sigemptyset(&sig_act.sa_mask)); sig_act.sa_handler = _signal_handler; diff --git a/src/ustreamer/device.c b/src/ustreamer/device.c index bfce3fb..79f87f8 100644 --- a/src/ustreamer/device.c +++ b/src/ustreamer/device.c @@ -226,8 +226,7 @@ int device_export_to_vcsm(device_s *dev) { # define VCSM_HANDLE RUN(hw_bufs[index].vcsm_handle) for (unsigned index = 0; index < RUN(n_bufs); ++index) { - struct v4l2_exportbuffer exp; - MEMSET_ZERO(exp); + struct v4l2_exportbuffer exp = {0}; exp.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; exp.index = index; @@ -334,8 +333,7 @@ int device_select(device_s *dev, bool *has_read, bool *has_write, bool *has_erro int device_grab_buffer(device_s *dev, hw_buffer_s **hw) { *hw = NULL; - struct v4l2_buffer buf; - MEMSET_ZERO(buf); + struct v4l2_buffer buf = {0}; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = dev->io_method; @@ -430,8 +428,7 @@ int device_consume_event(device_s *dev) { } static int _device_open_check_cap(device_s *dev) { - struct v4l2_capability cap; - MEMSET_ZERO(cap); + struct v4l2_capability cap = {0}; LOG_DEBUG("Calling ioctl(VIDIOC_QUERYCAP) ..."); if (xioctl(RUN(fd), VIDIOC_QUERYCAP, &cap) < 0) { @@ -477,9 +474,7 @@ static int _device_open_dv_timings(device_s *dev) { return -1; } - struct v4l2_event_subscription sub; - - MEMSET_ZERO(sub); + struct v4l2_event_subscription sub = {0}; sub.type = V4L2_EVENT_SOURCE_CHANGE; LOG_DEBUG("Calling ioctl(VIDIOC_SUBSCRIBE_EVENT) ..."); @@ -492,8 +487,7 @@ static int _device_open_dv_timings(device_s *dev) { } static int _device_apply_dv_timings(device_s *dev) { - struct v4l2_dv_timings dv; - MEMSET_ZERO(dv); + struct v4l2_dv_timings dv = {0}; LOG_DEBUG("Calling ioctl(VIDIOC_QUERY_DV_TIMINGS) ..."); if (xioctl(RUN(fd), VIDIOC_QUERY_DV_TIMINGS, &dv) == 0) { @@ -540,8 +534,7 @@ static int _device_apply_dv_timings(device_s *dev) { static int _device_open_format(device_s *dev, bool first) { const unsigned stride = align_size(RUN(width), 32) << 1; - struct v4l2_format fmt; - MEMSET_ZERO(fmt); + struct v4l2_format fmt = {0}; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = RUN(width); fmt.fmt.pix.height = RUN(height); @@ -599,8 +592,7 @@ static int _device_open_format(device_s *dev, bool first) { static void _device_open_hw_fps(device_s *dev) { RUN(hw_fps) = 0; - struct v4l2_streamparm setfps; - MEMSET_ZERO(setfps); + struct v4l2_streamparm setfps = {0}; setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; LOG_DEBUG("Calling ioctl(VIDIOC_G_PARM) ..."); @@ -654,8 +646,7 @@ static void _device_open_jpeg_quality(device_s *dev) { unsigned quality = 0; if (is_jpeg(RUN(format))) { - struct v4l2_jpegcompression comp; - MEMSET_ZERO(comp); + struct v4l2_jpegcompression comp = {0}; if (xioctl(RUN(fd), VIDIOC_G_JPEGCOMP, &comp) < 0) { LOG_ERROR("Device does not support setting of HW encoding quality parameters"); @@ -683,8 +674,7 @@ static int _device_open_io_method(device_s *dev) { } static int _device_open_io_method_mmap(device_s *dev) { - struct v4l2_requestbuffers req; - MEMSET_ZERO(req); + struct v4l2_requestbuffers req = {0}; req.count = dev->n_bufs; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; @@ -706,8 +696,7 @@ static int _device_open_io_method_mmap(device_s *dev) { A_CALLOC(RUN(hw_bufs), req.count); for (RUN(n_bufs) = 0; RUN(n_bufs) < req.count; ++RUN(n_bufs)) { - struct v4l2_buffer buf; - MEMSET_ZERO(buf); + struct v4l2_buffer buf = {0}; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = RUN(n_bufs); @@ -747,8 +736,7 @@ static int _device_open_io_method_mmap(device_s *dev) { } static int _device_open_io_method_userptr(device_s *dev) { - struct v4l2_requestbuffers req; - MEMSET_ZERO(req); + struct v4l2_requestbuffers req = {0}; req.count = dev->n_bufs; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_USERPTR; @@ -785,8 +773,7 @@ static int _device_open_io_method_userptr(device_s *dev) { static int _device_open_queue_buffers(device_s *dev) { for (unsigned index = 0; index < RUN(n_bufs); ++index) { - struct v4l2_buffer buf; - MEMSET_ZERO(buf); + struct v4l2_buffer buf = {0}; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = dev->io_method; buf.index = index; @@ -905,8 +892,7 @@ static void _device_set_control( return; } - struct v4l2_control ctl; - MEMSET_ZERO(ctl); + struct v4l2_control ctl = {0}; ctl.id = cid; ctl.value = value; diff --git a/src/ustreamer/encoder.c b/src/ustreamer/encoder.c index a46c303..e9ed973 100644 --- a/src/ustreamer/encoder.c +++ b/src/ustreamer/encoder.c @@ -140,8 +140,7 @@ workers_pool_s *encoder_workers_pool_init(encoder_s *enc, device_s *dev) { } } - frame_s frame; - MEMSET_ZERO(frame); + frame_s frame = {0}; frame.width = DR(width); frame.height = DR(height); frame.format = DR(format); diff --git a/src/ustreamer/http/unix.c b/src/ustreamer/http/unix.c index 44c8c18..75ed319 100644 --- a/src/ustreamer/http/unix.c +++ b/src/ustreamer/http/unix.c @@ -24,7 +24,7 @@ evutil_socket_t evhttp_my_bind_unix(struct evhttp *http, const char *path, bool rm, mode_t mode) { - struct sockaddr_un addr; + struct sockaddr_un addr = {0}; # define MAX_SUN_PATH (sizeof(addr.sun_path) - 1) @@ -33,7 +33,6 @@ evutil_socket_t evhttp_my_bind_unix(struct evhttp *http, const char *path, bool return -1; } - MEMSET_ZERO(addr); strncpy(addr.sun_path, path, MAX_SUN_PATH); addr.sun_family = AF_UNIX; diff --git a/src/ustreamer/main.c b/src/ustreamer/main.c index e027110..575b5a6 100644 --- a/src/ustreamer/main.c +++ b/src/ustreamer/main.c @@ -94,8 +94,7 @@ static void _signal_handler(int signum) { } static void _install_signal_handlers(void) { - struct sigaction sig_act; - MEMSET_ZERO(sig_act); + struct sigaction sig_act = {0}; assert(!sigemptyset(&sig_act.sa_mask)); sig_act.sa_handler = _signal_handler;