From e8cd71b2594fb2264bc50c83a80779f5df339df2 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 25 Mar 2025 08:20:05 +0100 Subject: [PATCH] vcap/import: IWYU + aligned_malloc compat --- Makefile.in | 1 + src/compat/aligned_malloc.c | 59 +++++++++++++++++++++++++++++++ src/compat/aligned_malloc.h | 70 +++++++++++++++++++++++++++++++++++++ src/config_unix.h | 18 +--------- src/video_capture/import.c | 43 ++++++++++++++--------- src/video_capture/rtsp.c | 1 + tools/Makefile | 1 + 7 files changed, 159 insertions(+), 34 deletions(-) create mode 100644 src/compat/aligned_malloc.c create mode 100644 src/compat/aligned_malloc.h diff --git a/Makefile.in b/Makefile.in index a06e774f6..317d0efb4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -124,6 +124,7 @@ COMMON_OBJS = \ src/capture_filter.o \ src/color.o \ src/compat/alarm.o \ + src/compat/aligned_malloc.o \ src/compat/dlfunc.o \ src/compat/platform_pipe.o \ src/compat/platform_semaphore.o \ diff --git a/src/compat/aligned_malloc.c b/src/compat/aligned_malloc.c new file mode 100644 index 000000000..618a215e4 --- /dev/null +++ b/src/compat/aligned_malloc.c @@ -0,0 +1,59 @@ +/** + * @file compat/aligned_malloc.c + * @author Martin Pulec + */ +/* + * Copyright (c) 2025 CESNET + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of CESNET nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef _WIN32 + +#include "aligned_malloc.h" + +#include +#include + +void * +aligned_malloc(size_t size, size_t alignment) +{ + void *ptr = NULL; + const int ret = posix_memalign(&ptr, alignment, size); + if (ret != 0) { + errno = ret; + return NULL; + } + + return ptr; +} + +#endif diff --git a/src/compat/aligned_malloc.h b/src/compat/aligned_malloc.h new file mode 100644 index 000000000..3c4ea83ee --- /dev/null +++ b/src/compat/aligned_malloc.h @@ -0,0 +1,70 @@ +/** + * @file compat/aligned_malloc.h + * @author Martin Pulec + * + * Define aligned_malloc/aligned_free as defined for MSW. The reason + * why selected over C11 aligned_alloc/free API is that the standard + * API cannot be used in MSW, because of the requirement of aligned_malloc + * to use aligned_free and not just ordinary free. + */ +/* + * Copyright (c) 2025 CESNET + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, is permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of CESNET nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 + +#include +#define aligned_malloc _aligned_malloc +#define aligned_free _aligned_free + +#else + +#ifdef __cplusplus +#include +#include +#else +#include +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +void *aligned_malloc(size_t size, size_t alignment); +#define aligned_free free + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif diff --git a/src/config_unix.h b/src/config_unix.h index d9d9d76d3..4e068808d 100644 --- a/src/config_unix.h +++ b/src/config_unix.h @@ -165,23 +165,7 @@ typedef int fd_t; #define USERNAMELEN 8 -static inline void *aligned_malloc(size_t size, size_t alignment) __attribute__((unused)); -static inline void *aligned_malloc(size_t size, size_t alignment) -{ - void *ptr = NULL; - int ret; - ret = posix_memalign(&ptr, alignment, size); - if(ret) { - errno = ret; - } - - if(ret == 0) { - return ptr; - } else { - return NULL; - } -} -#define aligned_free free +#include "compat/aligned_malloc.h" #define INVALID_SOCKET (-1) #define CLOSESOCKET close diff --git a/src/video_capture/import.c b/src/video_capture/import.c index 516490c41..0057b5f55 100644 --- a/src/video_capture/import.c +++ b/src/video_capture/import.c @@ -44,22 +44,41 @@ * most 1 frame AV-desync. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "config_unix.h" -#include "config_win32.h" -#endif // HAVE_CONFIG_H +#include // for assert +#include // for ENOENT, errno +#include // for SEEK_SET, open, O_DIRECT, O_RDONLY +#include // for LONG_MIN, INT_MAX, LONG_MAX +#include // for HUGE_VAL +#include // for pthread_mutex_unlock, pthread_mute... +#include // for bool, false, true +#include // for uint32_t +#include // for NULL, perror, snprintf, fprintf +#include // for free, malloc, abort, atof, atoi +#include // for strlen, strncmp, strcmp, memcpy +#include // for stat, fstat +#include // for gettimeofday, timeval +#include // for ssize_t +#include // for timespec_get, TIME_UTC, timespec +#ifdef _WIN32 +#include // for close, read +#include // for O_RDONLY +#else +#include // for close, read +#endif + #include "audio/types.h" #include "audio/wav_reader.h" +#include "compat/aligned_malloc.h" // for aligned_free, aligned_malloc +#include "compat/strings.h" // for strcasecmp, strncasecmp #include "debug.h" #include "host.h" #include "lib_common.h" -#include "keyboard_control.h" #include "messaging.h" #include "module.h" #include "playback.h" #include "tv.h" +#include "types.h" // for video_desc, video_frame, tile #include "utils/color_out.h" #include "utils/fs.h" #include "utils/macros.h" @@ -67,19 +86,9 @@ #include "utils/worker.h" #include "video.h" #include "video_capture.h" +#include "video_capture_params.h" // for vidcap_params_get_flags, vidcap_p... #include "video_export.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #define BUFFER_LEN_MAX 40 #define MAX_CLIENTS 16 diff --git a/src/video_capture/rtsp.c b/src/video_capture/rtsp.c index 941b3897d..b10b8ca3d 100644 --- a/src/video_capture/rtsp.c +++ b/src/video_capture/rtsp.c @@ -60,6 +60,7 @@ #include "audio/types.h" #include "config.h" // for PACKAGE_BUGREPORT +#include "compat/aligned_malloc.h" // for alignde_free, aligned_alloc #include "compat/strings.h" // for strncasecmp #include "debug.h" #include "host.h" diff --git a/tools/Makefile b/tools/Makefile index ff7249e8c..25df0b42a 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -15,6 +15,7 @@ TARGETS=astat_lib astat_test benchmark_ff_convs convert decklink_temperature \ thumbnailgen uyvy2yuv422p COMMON_OBJS = src/color.o src/debug.o src/video_codec.o src/pixfmt_conv.o \ + src/compat/aligned_malloc.o \ src/utils/color_out.o src/utils/misc.o src/video_frame.o \ src/utils/pam.o src/utils/y4m.o \ ug_stub.o