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
50 #define INT16_MIN (-0x7fff - 1)
54 #define INT16_MAX 0x7fff
58 #define INT32_MIN (-0x7fffffff - 1)
62 #define INT32_MAX 0x7fffffff
66 #define UINT32_MAX 0xffffffff
70 #define INT64_MIN (-0x7fffffffffffffffLL - 1)
74 #define INT64_MAX INT64_C(9223372036854775807)
78 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
82 # define INT_BIT (CHAR_BIT * sizeof(int))
86 # define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
89 /* Use to export labels from asm. */
90 #define LABEL_MANGLE(a) EXTERN_PREFIX #a
92 // Use rip-relative addressing if compiling PIC code on x86-64.
93 #if ARCH_X86_64 && defined(PIC)
94 # define LOCAL_MANGLE(a) #a "(%%rip)"
96 # define LOCAL_MANGLE(a) #a
99 #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
103 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
108 #define MASK_ABS(mask, level)\
113 : "+a" (level), "=&d" (mask)\
116 #define MASK_ABS(mask, level)\
118 level = (level ^ mask) - mask;
121 /* avoid usage of dangerous/inappropriate system functions */
123 #define malloc please_use_av_malloc
125 #define free please_use_av_free
127 #define realloc please_use_av_realloc
129 #define time time_is_forbidden_due_to_security_issues
131 #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
133 #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
135 #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
137 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
139 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
141 #define exit exit_is_forbidden
142 #ifndef LIBAVFORMAT_BUILD
144 #define printf please_use_av_log_instead_of_printf
146 #define fprintf please_use_av_log_instead_of_fprintf
148 #define puts please_use_av_log_instead_of_puts
150 #define perror please_use_av_log_instead_of_perror
153 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
155 p = av_malloc(size);\
156 if (p == NULL && (size) != 0) {\
157 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
162 #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
164 p = av_mallocz(size);\
165 if (p == NULL && (size) != 0) {\
166 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
174 * Return NULL if CONFIG_SMALL is true, otherwise the argument
175 * without modification. Used to disable the definition of strings
176 * (for example AVCodec long_names).
179 # define NULL_IF_CONFIG_SMALL(x) NULL
181 # define NULL_IF_CONFIG_SMALL(x) x
186 * Define a function with only the non-default version specified.
188 * On systems with ELF shared libraries, all symbols exported from
189 * FFmpeg libraries are tagged with the name and major version of the
190 * library to which they belong. If a function is moved from one
191 * library to another, a wrapper must be retained in the original
192 * location to preserve binary compatibility.
194 * Functions defined with this macro will never be used to resolve
195 * symbols by the build-time linker.
197 * @param type return type of function
198 * @param name name of function
199 * @param args argument list of function
200 * @param ver version tag to assign function
202 #if HAVE_SYMVER_ASM_LABEL
203 # define FF_SYMVER(type, name, args, ver) \
204 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
206 #elif HAVE_SYMVER_GNU_ASM
207 # define FF_SYMVER(type, name, args, ver) \
208 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
209 type ff_##name args; \
214 * Returns NULL if a threading library has not been enabled.
215 * Used to disable threading functions in AVCodec definitions
219 # define ONLY_IF_THREADS_ENABLED(x) x
221 # define ONLY_IF_THREADS_ENABLED(x) NULL
224 #endif /* AVUTIL_INTERNAL_H */