2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
23 * common internal API header
26 #ifndef AVUTIL_INTERNAL_H
27 #define AVUTIL_INTERNAL_H
29 #if !defined(DEBUG) && !defined(NDEBUG)
38 #include "attributes.h"
41 #ifndef attribute_align_arg
42 #if ARCH_X86_32 && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,2)
43 # define attribute_align_arg __attribute__((force_align_arg_pointer))
45 # define attribute_align_arg
51 * Mark a variable as used and prevent the compiler from optimizing it away.
52 * This is useful for asm that accesses varibles in ways that the compiler does not
55 #ifndef attribute_used
56 #if AV_GCC_VERSION_AT_LEAST(3,1)
57 # define attribute_used __attribute__((used))
59 # define attribute_used
64 #define INT16_MIN (-0x7fff - 1)
68 #define INT16_MAX 0x7fff
72 #define INT32_MIN (-0x7fffffff - 1)
76 #define INT32_MAX 0x7fffffff
80 #define UINT32_MAX 0xffffffff
84 #define INT64_MIN (-0x7fffffffffffffffLL - 1)
88 #define INT64_MAX INT64_C(9223372036854775807)
92 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
96 # define INT_BIT (CHAR_BIT * sizeof(int))
100 # define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
103 /* Use to export labels from asm. */
104 #define LABEL_MANGLE(a) EXTERN_PREFIX #a
106 // Use rip-relative addressing if compiling PIC code on x86-64.
107 #if ARCH_X86_64 && defined(PIC)
108 # define LOCAL_MANGLE(a) #a "(%%rip)"
110 # define LOCAL_MANGLE(a) #a
113 #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
119 # define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
121 # define dprintf(pctx, ...)
124 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
129 #define MASK_ABS(mask, level)\
134 : "+a" (level), "=&d" (mask)\
137 #define MASK_ABS(mask, level)\
139 level = (level ^ mask) - mask;
142 /* avoid usage of dangerous/inappropriate system functions */
144 #define malloc please_use_av_malloc
146 #define free please_use_av_free
148 #define realloc please_use_av_realloc
150 #define time time_is_forbidden_due_to_security_issues
152 #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
154 #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
156 #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
158 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
160 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
162 #define exit exit_is_forbidden
163 #ifndef LIBAVFORMAT_BUILD
165 #define printf please_use_av_log_instead_of_printf
167 #define fprintf please_use_av_log_instead_of_fprintf
169 #define puts please_use_av_log_instead_of_puts
171 #define perror please_use_av_log_instead_of_perror
174 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
176 p = av_malloc(size);\
177 if (p == NULL && (size) != 0) {\
178 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
183 #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
185 p = av_mallocz(size);\
186 if (p == NULL && (size) != 0) {\
187 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
195 * Return NULL if CONFIG_SMALL is true, otherwise the argument
196 * without modification. Used to disable the definition of strings
197 * (for example AVCodec long_names).
200 # define NULL_IF_CONFIG_SMALL(x) NULL
202 # define NULL_IF_CONFIG_SMALL(x) x
207 * Define a function with only the non-default version specified.
209 * On systems with ELF shared libraries, all symbols exported from
210 * FFmpeg libraries are tagged with the name and major version of the
211 * library to which they belong. If a function is moved from one
212 * library to another, a wrapper must be retained in the original
213 * location to preserve binary compatibility.
215 * Functions defined with this macro will never be used to resolve
216 * symbols by the build-time linker.
218 * @param type return type of function
219 * @param name name of function
220 * @param args argument list of function
221 * @param ver version tag to assign function
223 #if HAVE_SYMVER_ASM_LABEL
224 # define FF_SYMVER(type, name, args, ver) \
225 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
227 #elif HAVE_SYMVER_GNU_ASM
228 # define FF_SYMVER(type, name, args, ver) \
229 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
230 type ff_##name args; \
234 #endif /* AVUTIL_INTERNAL_H */