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"
42 #ifndef attribute_align_arg
43 #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
44 # define attribute_align_arg __attribute__((force_align_arg_pointer))
46 # define attribute_align_arg
51 #define INT16_MIN (-0x7fff - 1)
55 #define INT16_MAX 0x7fff
59 #define INT32_MIN (-0x7fffffff - 1)
63 #define INT32_MAX 0x7fffffff
67 #define UINT32_MAX 0xffffffff
71 #define INT64_MIN (-0x7fffffffffffffffLL - 1)
75 #define INT64_MAX INT64_C(9223372036854775807)
79 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
83 # define INT_BIT (CHAR_BIT * sizeof(int))
87 # define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
90 /* Use to export labels from asm. */
91 #define LABEL_MANGLE(a) EXTERN_PREFIX #a
93 // Use rip-relative addressing if compiling PIC code on x86-64.
94 #if ARCH_X86_64 && defined(PIC)
95 # define LOCAL_MANGLE(a) #a "(%%rip)"
97 # define LOCAL_MANGLE(a) #a
100 #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
104 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
109 #define MASK_ABS(mask, level)\
114 : "+a" (level), "=&d" (mask)\
117 #define MASK_ABS(mask, level)\
119 level = (level ^ mask) - mask;
122 /* avoid usage of dangerous/inappropriate system functions */
124 #define malloc please_use_av_malloc
126 #define free please_use_av_free
128 #define realloc please_use_av_realloc
130 #define time time_is_forbidden_due_to_security_issues
132 #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
134 #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
136 #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
138 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
140 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
142 #define strncpy strncpy_is_forbidden_due_to_security_issues_use_av_strlcpy
144 #define exit exit_is_forbidden
145 #ifndef LIBAVFORMAT_BUILD
147 #define printf please_use_av_log_instead_of_printf
149 #define fprintf please_use_av_log_instead_of_fprintf
151 #define puts please_use_av_log_instead_of_puts
153 #define perror please_use_av_log_instead_of_perror
156 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
158 p = av_malloc(size);\
159 if (p == NULL && (size) != 0) {\
160 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
165 #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
167 p = av_mallocz(size);\
168 if (p == NULL && (size) != 0) {\
169 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
177 * Return NULL if CONFIG_SMALL is true, otherwise the argument
178 * without modification. Used to disable the definition of strings
179 * (for example AVCodec long_names).
182 # define NULL_IF_CONFIG_SMALL(x) NULL
184 # define NULL_IF_CONFIG_SMALL(x) x
188 * Define a function with only the non-default version specified.
190 * On systems with ELF shared libraries, all symbols exported from
191 * FFmpeg libraries are tagged with the name and major version of the
192 * library to which they belong. If a function is moved from one
193 * library to another, a wrapper must be retained in the original
194 * location to preserve binary compatibility.
196 * Functions defined with this macro will never be used to resolve
197 * symbols by the build-time linker.
199 * @param type return type of function
200 * @param name name of function
201 * @param args argument list of function
202 * @param ver version tag to assign function
204 #if HAVE_SYMVER_ASM_LABEL
205 # define FF_SYMVER(type, name, args, ver) \
206 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
208 #elif HAVE_SYMVER_GNU_ASM
209 # define FF_SYMVER(type, name, args, ver) \
210 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
211 type ff_##name args; \
216 * Returns NULL if a threading library has not been enabled.
217 * Used to disable threading functions in AVCodec definitions
221 # define ONLY_IF_THREADS_ENABLED(x) x
223 # define ONLY_IF_THREADS_ENABLED(x) NULL
229 * this must be called between any dsp function and float/double code.
230 * for example sin(); dsp->idct_put(); emms_c(); cos()
232 static av_always_inline void emms_c(void)
234 if(av_get_cpu_flags() & AV_CPU_FLAG_MMX)
235 __asm__ volatile ("emms" ::: "memory");
239 #endif /* HAVE_MMX */
241 #endif /* AVUTIL_INTERNAL_H */