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 > 1200) && 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)
117 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
122 #define MASK_ABS(mask, level)\
127 : "+a" (level), "=&d" (mask)\
130 #define MASK_ABS(mask, level)\
132 level = (level ^ mask) - mask;
135 /* avoid usage of dangerous/inappropriate system functions */
137 #define malloc please_use_av_malloc
139 #define free please_use_av_free
141 #define realloc please_use_av_realloc
143 #define time time_is_forbidden_due_to_security_issues
145 #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
147 #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
149 #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
151 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
153 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
155 #define exit exit_is_forbidden
156 #ifndef LIBAVFORMAT_BUILD
158 #define printf please_use_av_log_instead_of_printf
160 #define fprintf please_use_av_log_instead_of_fprintf
162 #define puts please_use_av_log_instead_of_puts
164 #define perror please_use_av_log_instead_of_perror
167 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
169 p = av_malloc(size);\
170 if (p == NULL && (size) != 0) {\
171 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
176 #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
178 p = av_mallocz(size);\
179 if (p == NULL && (size) != 0) {\
180 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
188 * Return NULL if CONFIG_SMALL is true, otherwise the argument
189 * without modification. Used to disable the definition of strings
190 * (for example AVCodec long_names).
193 # define NULL_IF_CONFIG_SMALL(x) NULL
195 # define NULL_IF_CONFIG_SMALL(x) x
200 * Define a function with only the non-default version specified.
202 * On systems with ELF shared libraries, all symbols exported from
203 * FFmpeg libraries are tagged with the name and major version of the
204 * library to which they belong. If a function is moved from one
205 * library to another, a wrapper must be retained in the original
206 * location to preserve binary compatibility.
208 * Functions defined with this macro will never be used to resolve
209 * symbols by the build-time linker.
211 * @param type return type of function
212 * @param name name of function
213 * @param args argument list of function
214 * @param ver version tag to assign function
216 #if HAVE_SYMVER_ASM_LABEL
217 # define FF_SYMVER(type, name, args, ver) \
218 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
220 #elif HAVE_SYMVER_GNU_ASM
221 # define FF_SYMVER(type, name, args, ver) \
222 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
223 type ff_##name args; \
227 #endif /* AVUTIL_INTERNAL_H */