vcap/import: IWYU + aligned_malloc compat

This commit is contained in:
Martin Pulec
2025-03-25 08:20:05 +01:00
parent 70903661f9
commit e8cd71b259
7 changed files with 159 additions and 34 deletions

View File

@@ -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 \

View File

@@ -0,0 +1,59 @@
/**
* @file compat/aligned_malloc.c
* @author Martin Pulec <pulec@cesnet.cz>
*/
/*
* 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 <errno.h>
#include <stdlib.h>
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

View File

@@ -0,0 +1,70 @@
/**
* @file compat/aligned_malloc.h
* @author Martin Pulec <pulec@cesnet.cz>
*
* 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 <malloc.h>
#define aligned_malloc _aligned_malloc
#define aligned_free _aligned_free
#else
#ifdef __cplusplus
#include <cstddef>
#include <cstdlib>
#else
#include <stddef.h>
#include <stdlib.h>
#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

View File

@@ -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

View File

@@ -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 <assert.h> // for assert
#include <errno.h> // for ENOENT, errno
#include <fcntl.h> // for SEEK_SET, open, O_DIRECT, O_RDONLY
#include <limits.h> // for LONG_MIN, INT_MAX, LONG_MAX
#include <math.h> // for HUGE_VAL
#include <pthread.h> // for pthread_mutex_unlock, pthread_mute...
#include <stdbool.h> // for bool, false, true
#include <stdint.h> // for uint32_t
#include <stdio.h> // for NULL, perror, snprintf, fprintf
#include <stdlib.h> // for free, malloc, abort, atof, atoi
#include <string.h> // for strlen, strncmp, strcmp, memcpy
#include <sys/stat.h> // for stat, fstat
#include <sys/time.h> // for gettimeofday, timeval
#include <sys/types.h> // for ssize_t
#include <time.h> // for timespec_get, TIME_UTC, timespec
#ifdef _WIN32
#include <io.h> // for close, read
#include <fcntl.h> // for O_RDONLY
#else
#include <unistd.h> // 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 <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#define BUFFER_LEN_MAX 40
#define MAX_CLIENTS 16

View File

@@ -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"

View File

@@ -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