]> git.sesse.net Git - ffmpeg/blob - libavutil/internal.h
mpegenc: use avctx->slices as number of slices
[ffmpeg] / libavutil / internal.h
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 #include <limits.h>
34 #include <stdint.h>
35 #include <stddef.h>
36 #include <assert.h>
37 #include "config.h"
38 #include "attributes.h"
39 #include "timer.h"
40 #include "dict.h"
41
42 struct AVDictionary {
43     int count;
44     AVDictionaryEntry *elems;
45 };
46
47 #ifndef attribute_align_arg
48 #if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2)
49 #    define attribute_align_arg __attribute__((force_align_arg_pointer))
50 #else
51 #    define attribute_align_arg
52 #endif
53 #endif
54
55 #ifndef INT16_MIN
56 #define INT16_MIN       (-0x7fff - 1)
57 #endif
58
59 #ifndef INT16_MAX
60 #define INT16_MAX       0x7fff
61 #endif
62
63 #ifndef INT32_MIN
64 #define INT32_MIN       (-0x7fffffff - 1)
65 #endif
66
67 #ifndef INT32_MAX
68 #define INT32_MAX       0x7fffffff
69 #endif
70
71 #ifndef UINT32_MAX
72 #define UINT32_MAX      0xffffffff
73 #endif
74
75 #ifndef INT64_MIN
76 #define INT64_MIN       (-0x7fffffffffffffffLL - 1)
77 #endif
78
79 #ifndef INT64_MAX
80 #define INT64_MAX INT64_C(9223372036854775807)
81 #endif
82
83 #ifndef UINT64_MAX
84 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
85 #endif
86
87 #ifndef INT_BIT
88 #    define INT_BIT (CHAR_BIT * sizeof(int))
89 #endif
90
91 #ifndef offsetof
92 #    define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
93 #endif
94
95 /* Use to export labels from asm. */
96 #define LABEL_MANGLE(a) EXTERN_PREFIX #a
97
98 // Use rip-relative addressing if compiling PIC code on x86-64.
99 #if ARCH_X86_64 && defined(PIC)
100 #    define LOCAL_MANGLE(a) #a "(%%rip)"
101 #else
102 #    define LOCAL_MANGLE(a) #a
103 #endif
104
105 #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
106
107 /* debug stuff */
108
109 #define av_abort()      do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
110
111 /* math */
112
113 #if ARCH_X86
114 #define MASK_ABS(mask, level)\
115             __asm__ volatile(\
116                 "cltd                   \n\t"\
117                 "xorl %1, %0            \n\t"\
118                 "subl %1, %0            \n\t"\
119                 : "+a" (level), "=&d" (mask)\
120             );
121 #else
122 #define MASK_ABS(mask, level)\
123             mask  = level >> 31;\
124             level = (level ^ mask) - mask;
125 #endif
126
127 /* avoid usage of dangerous/inappropriate system functions */
128 #undef  malloc
129 #define malloc please_use_av_malloc
130 #undef  free
131 #define free please_use_av_free
132 #undef  realloc
133 #define realloc please_use_av_realloc
134 #undef  time
135 #define time time_is_forbidden_due_to_security_issues
136 #undef  rand
137 #define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
138 #undef  srand
139 #define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
140 #undef  random
141 #define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
142 #undef  sprintf
143 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
144 #undef  strcat
145 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
146 #undef  strncpy
147 #define strncpy strncpy_is_forbidden_due_to_security_issues_use_av_strlcpy
148 #undef  exit
149 #define exit exit_is_forbidden
150 #undef  printf
151 #define printf please_use_av_log_instead_of_printf
152 #undef  fprintf
153 #define fprintf please_use_av_log_instead_of_fprintf
154 #undef  puts
155 #define puts please_use_av_log_instead_of_puts
156 #undef  perror
157 #define perror please_use_av_log_instead_of_perror
158 #undef strcasecmp
159 #define strcasecmp please_use_av_strcasecmp
160 #undef strncasecmp
161 #define strncasecmp please_use_av_strncasecmp
162
163 #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
164 {\
165     p = av_malloc(size);\
166     if (p == NULL && (size) != 0) {\
167         av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
168         goto label;\
169     }\
170 }
171
172 #define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
173 {\
174     p = av_mallocz(size);\
175     if (p == NULL && (size) != 0) {\
176         av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
177         goto label;\
178     }\
179 }
180
181 #include "libm.h"
182
183 /**
184  * Return NULL if CONFIG_SMALL is true, otherwise the argument
185  * without modification. Used to disable the definition of strings
186  * (for example AVCodec long_names).
187  */
188 #if CONFIG_SMALL
189 #   define NULL_IF_CONFIG_SMALL(x) NULL
190 #else
191 #   define NULL_IF_CONFIG_SMALL(x) x
192 #endif
193
194
195 /**
196  * Define a function with only the non-default version specified.
197  *
198  * On systems with ELF shared libraries, all symbols exported from
199  * Libav libraries are tagged with the name and major version of the
200  * library to which they belong.  If a function is moved from one
201  * library to another, a wrapper must be retained in the original
202  * location to preserve binary compatibility.
203  *
204  * Functions defined with this macro will never be used to resolve
205  * symbols by the build-time linker.
206  *
207  * @param type return type of function
208  * @param name name of function
209  * @param args argument list of function
210  * @param ver  version tag to assign function
211  */
212 #if HAVE_SYMVER_ASM_LABEL
213 #   define FF_SYMVER(type, name, args, ver)                     \
214     type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver);  \
215     type ff_##name args
216 #elif HAVE_SYMVER_GNU_ASM
217 #   define FF_SYMVER(type, name, args, ver)                             \
218     __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver);      \
219     type ff_##name args;                                                \
220     type ff_##name args
221 #endif
222
223 /**
224  * Return NULL if a threading library has not been enabled.
225  * Used to disable threading functions in AVCodec definitions
226  * when not needed.
227  */
228 #if HAVE_THREADS
229 #   define ONLY_IF_THREADS_ENABLED(x) x
230 #else
231 #   define ONLY_IF_THREADS_ENABLED(x) NULL
232 #endif
233
234 #if HAVE_MMX
235 /**
236  * Empty mmx state.
237  * this must be called between any dsp function and float/double code.
238  * for example sin(); dsp->idct_put(); emms_c(); cos()
239  */
240 static av_always_inline void emms_c(void)
241 {
242     __asm__ volatile ("emms" ::: "memory");
243 }
244 #else /* HAVE_MMX */
245 #define emms_c()
246 #endif /* HAVE_MMX */
247
248 #endif /* AVUTIL_INTERNAL_H */