FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/internal.h
Date: 2026-09-15 15:24:09
Exec Total Coverage
Lines: 7 8 87.5%
Functions: 1 1 100.0%
Branches: 5 6 83.3%

Line Branch Exec Source
1 /*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * common internal API header
24 */
25
26 #ifndef AVUTIL_INTERNAL_H
27 #define AVUTIL_INTERNAL_H
28
29 #if !defined(DEBUG) && !defined(NDEBUG)
30 # define NDEBUG
31 #endif
32
33 // This can be enabled to allow detection of additional integer overflows with ubsan
34 //#define CHECKED
35
36 #include <limits.h>
37 #include <math.h>
38 #include <stdint.h>
39 #include <stddef.h>
40 #include <assert.h>
41 #include <stdio.h>
42 #include "config.h"
43 #include "attributes.h"
44 #include "mathematics.h"
45 #include "macros.h"
46
47 #ifndef attribute_align_arg
48 #if ARCH_X86_32 && defined(__GNUC__)
49 # define attribute_align_arg __attribute__((force_align_arg_pointer))
50 #else
51 # define attribute_align_arg
52 #endif
53 #endif
54
55 #if HAVE_MIPSFPU && HAVE_INLINE_ASM
56 # include "mips/libm_mips.h"
57 #endif
58
59 #if HAVE_PRAGMA_DEPRECATED
60 # if defined(__ICL) || defined (__INTEL_COMPILER)
61 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
62 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
63 # elif defined(_MSC_VER)
64 # define FF_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
65 # define FF_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
66 # else
67 # define FF_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
68 # define FF_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
69 # endif
70 #else
71 # define FF_DISABLE_DEPRECATION_WARNINGS
72 # define FF_ENABLE_DEPRECATION_WARNINGS
73 #endif
74
75
76 #ifdef __ANDROID__
77 # include "compat/android/math.h"
78 #endif
79
80 #define FF_ALLOC_TYPED_ARRAY(p, nelem) (p = av_malloc_array(nelem, sizeof(*p)))
81 #define FF_ALLOCZ_TYPED_ARRAY(p, nelem) (p = av_calloc(nelem, sizeof(*p)))
82
83 #define FF_PTR_ADD(ptr, off) ((off) ? (ptr) + (off) : (ptr))
84
85 /**
86 * Access a field in a structure by its offset.
87 */
88 #define FF_FIELD_AT(type, off, obj) (*(type *)((char *)&(obj) + (off)))
89
90 /**
91 * Return NULL if CONFIG_SMALL is true, otherwise the argument
92 * without modification. Used to disable the definition of strings.
93 */
94 #if CONFIG_SMALL
95 # define NULL_IF_CONFIG_SMALL(x) NULL
96 #else
97 # define NULL_IF_CONFIG_SMALL(x) x
98 #endif
99
100 /**
101 * Log a generic warning message about a missing feature.
102 *
103 * @param[in] avc a pointer to an arbitrary struct of which the first
104 * field is a pointer to an AVClass struct
105 * @param[in] msg string containing the name of the missing feature
106 */
107 void avpriv_report_missing_feature(void *avc,
108 const char *msg, ...) av_printf_format(2, 3);
109
110 /**
111 * Log a generic warning message about a missing feature.
112 * Additionally request that a sample showcasing the feature be uploaded.
113 *
114 * @param[in] avc a pointer to an arbitrary struct of which the first field is
115 * a pointer to an AVClass struct
116 * @param[in] msg string containing the name of the missing feature
117 */
118 void avpriv_request_sample(void *avc,
119 const char *msg, ...) av_printf_format(2, 3);
120
121 #ifdef DEBUG
122 # define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__)
123 #else
124 # define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
125 #endif
126
127 #ifdef TRACE
128 # define ff_tlog(ctx, ...) av_log(ctx, AV_LOG_TRACE, __VA_ARGS__)
129 #else
130 # define ff_tlog(ctx, ...) do { } while(0)
131 #endif
132
133 // For debugging we use signed operations so overflows can be detected (by ubsan)
134 // For production we use unsigned so there are no undefined operations
135 #ifdef CHECKED
136 #define SUINT int
137 #define SUINT32 int32_t
138 #else
139 #define SUINT unsigned
140 #define SUINT32 uint32_t
141 #endif
142
143 113853554 static av_always_inline av_const int avpriv_mirror(int x, int w)
144 {
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113853554 times.
113853554 if (!w)
146 return 0;
147
148
2/2
✓ Branch 0 taken 32659291 times.
✓ Branch 1 taken 113853554 times.
260366399 while ((unsigned)x > (unsigned)w) {
149 32659291 x = -x;
150
2/2
✓ Branch 0 taken 17679757 times.
✓ Branch 1 taken 14979534 times.
32659291 if (x < 0)
151 14979534 x += 2 * w;
152 }
153 113853554 return x;
154 }
155
156 #endif /* AVUTIL_INTERNAL_H */
157