Skip to content

Commit e8cd71b

Browse files
committed
vcap/import: IWYU + aligned_malloc compat
1 parent 7090366 commit e8cd71b

File tree

7 files changed

+159
-34
lines changed

7 files changed

+159
-34
lines changed

Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ COMMON_OBJS = \
124124
src/capture_filter.o \
125125
src/color.o \
126126
src/compat/alarm.o \
127+
src/compat/aligned_malloc.o \
127128
src/compat/dlfunc.o \
128129
src/compat/platform_pipe.o \
129130
src/compat/platform_semaphore.o \

src/compat/aligned_malloc.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @file compat/aligned_malloc.c
3+
* @author Martin Pulec <[email protected]>
4+
*/
5+
/*
6+
* Copyright (c) 2025 CESNET
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, is permitted provided that the following conditions
11+
* are met:
12+
*
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
*
16+
* 2. Redistributions in binary form must reproduce the above copyright
17+
* notice, this list of conditions and the following disclaimer in the
18+
* documentation and/or other materials provided with the distribution.
19+
*
20+
* 3. Neither the name of CESNET nor the names of its contributors may be
21+
* used to endorse or promote products derived from this software without
22+
* specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26+
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28+
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
*/
37+
38+
39+
#ifndef _WIN32
40+
41+
#include "aligned_malloc.h"
42+
43+
#include <errno.h>
44+
#include <stdlib.h>
45+
46+
void *
47+
aligned_malloc(size_t size, size_t alignment)
48+
{
49+
void *ptr = NULL;
50+
const int ret = posix_memalign(&ptr, alignment, size);
51+
if (ret != 0) {
52+
errno = ret;
53+
return NULL;
54+
}
55+
56+
return ptr;
57+
}
58+
59+
#endif

src/compat/aligned_malloc.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @file compat/aligned_malloc.h
3+
* @author Martin Pulec <[email protected]>
4+
*
5+
* Define aligned_malloc/aligned_free as defined for MSW. The reason
6+
* why selected over C11 aligned_alloc/free API is that the standard
7+
* API cannot be used in MSW, because of the requirement of aligned_malloc
8+
* to use aligned_free and not just ordinary free.
9+
*/
10+
/*
11+
* Copyright (c) 2025 CESNET
12+
* All rights reserved.
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, is permitted provided that the following conditions
16+
* are met:
17+
*
18+
* 1. Redistributions of source code must retain the above copyright
19+
* notice, this list of conditions and the following disclaimer.
20+
*
21+
* 2. Redistributions in binary form must reproduce the above copyright
22+
* notice, this list of conditions and the following disclaimer in the
23+
* documentation and/or other materials provided with the distribution.
24+
*
25+
* 3. Neither the name of CESNET nor the names of its contributors may be
26+
* used to endorse or promote products derived from this software without
27+
* specific prior written permission.
28+
*
29+
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
30+
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
31+
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
32+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
33+
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
34+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41+
*/
42+
43+
#ifdef _WIN32
44+
45+
#include <malloc.h>
46+
#define aligned_malloc _aligned_malloc
47+
#define aligned_free _aligned_free
48+
49+
#else
50+
51+
#ifdef __cplusplus
52+
#include <cstddef>
53+
#include <cstdlib>
54+
#else
55+
#include <stddef.h>
56+
#include <stdlib.h>
57+
#endif
58+
59+
#ifdef __cplusplus
60+
extern "C" {
61+
#endif
62+
63+
void *aligned_malloc(size_t size, size_t alignment);
64+
#define aligned_free free
65+
66+
#ifdef __cplusplus
67+
} // extern "C"
68+
#endif
69+
70+
#endif

src/config_unix.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,7 @@ typedef int fd_t;
165165

166166
#define USERNAMELEN 8
167167

168-
static inline void *aligned_malloc(size_t size, size_t alignment) __attribute__((unused));
169-
static inline void *aligned_malloc(size_t size, size_t alignment)
170-
{
171-
void *ptr = NULL;
172-
int ret;
173-
ret = posix_memalign(&ptr, alignment, size);
174-
if(ret) {
175-
errno = ret;
176-
}
177-
178-
if(ret == 0) {
179-
return ptr;
180-
} else {
181-
return NULL;
182-
}
183-
}
184-
#define aligned_free free
168+
#include "compat/aligned_malloc.h"
185169

186170
#define INVALID_SOCKET (-1)
187171
#define CLOSESOCKET close

src/video_capture/import.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,51 @@
4444
* most 1 frame AV-desync.
4545
*/
4646

47-
#ifdef HAVE_CONFIG_H
48-
#include "config.h"
49-
#include "config_unix.h"
50-
#include "config_win32.h"
51-
#endif // HAVE_CONFIG_H
47+
#include <assert.h> // for assert
48+
#include <errno.h> // for ENOENT, errno
49+
#include <fcntl.h> // for SEEK_SET, open, O_DIRECT, O_RDONLY
50+
#include <limits.h> // for LONG_MIN, INT_MAX, LONG_MAX
51+
#include <math.h> // for HUGE_VAL
52+
#include <pthread.h> // for pthread_mutex_unlock, pthread_mute...
53+
#include <stdbool.h> // for bool, false, true
54+
#include <stdint.h> // for uint32_t
55+
#include <stdio.h> // for NULL, perror, snprintf, fprintf
56+
#include <stdlib.h> // for free, malloc, abort, atof, atoi
57+
#include <string.h> // for strlen, strncmp, strcmp, memcpy
58+
#include <sys/stat.h> // for stat, fstat
59+
#include <sys/time.h> // for gettimeofday, timeval
60+
#include <sys/types.h> // for ssize_t
61+
#include <time.h> // for timespec_get, TIME_UTC, timespec
5262

63+
#ifdef _WIN32
64+
#include <io.h> // for close, read
65+
#include <fcntl.h> // for O_RDONLY
66+
#else
67+
#include <unistd.h> // for close, read
68+
#endif
69+
5370
#include "audio/types.h"
5471
#include "audio/wav_reader.h"
72+
#include "compat/aligned_malloc.h" // for aligned_free, aligned_malloc
73+
#include "compat/strings.h" // for strcasecmp, strncasecmp
5574
#include "debug.h"
5675
#include "host.h"
5776
#include "lib_common.h"
58-
#include "keyboard_control.h"
5977
#include "messaging.h"
6078
#include "module.h"
6179
#include "playback.h"
6280
#include "tv.h"
81+
#include "types.h" // for video_desc, video_frame, tile
6382
#include "utils/color_out.h"
6483
#include "utils/fs.h"
6584
#include "utils/macros.h"
6685
#include "utils/ring_buffer.h"
6786
#include "utils/worker.h"
6887
#include "video.h"
6988
#include "video_capture.h"
89+
#include "video_capture_params.h" // for vidcap_params_get_flags, vidcap_p...
7090
#include "video_export.h"
7191

72-
#include <pthread.h>
73-
#include <stdio.h>
74-
#include <stdlib.h>
75-
#include <fcntl.h>
76-
#include <stdbool.h>
77-
#include <string.h>
78-
#include <sys/stat.h>
79-
#include <sys/time.h>
80-
#include <sys/types.h>
81-
#include <unistd.h>
82-
8392
#define BUFFER_LEN_MAX 40
8493
#define MAX_CLIENTS 16
8594

src/video_capture/rtsp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
#include "audio/types.h"
6262
#include "config.h" // for PACKAGE_BUGREPORT
63+
#include "compat/aligned_malloc.h" // for alignde_free, aligned_alloc
6364
#include "compat/strings.h" // for strncasecmp
6465
#include "debug.h"
6566
#include "host.h"

tools/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ TARGETS=astat_lib astat_test benchmark_ff_convs convert decklink_temperature \
1515
thumbnailgen uyvy2yuv422p
1616

1717
COMMON_OBJS = src/color.o src/debug.o src/video_codec.o src/pixfmt_conv.o \
18+
src/compat/aligned_malloc.o \
1819
src/utils/color_out.o src/utils/misc.o src/video_frame.o \
1920
src/utils/pam.o src/utils/y4m.o \
2021
ug_stub.o

0 commit comments

Comments
 (0)