ffmpeg / libavutil / common.h @ 94d85eaf
History | View | Annotate | Download (14.1 KB)
1 | 983e3246 | Michael Niedermayer | /**
|
---|---|---|---|
2 | * @file common.h
|
||
3 | * common internal api header.
|
||
4 | */
|
||
5 | |||
6 | de6d9b64 | Fabrice Bellard | #ifndef COMMON_H
|
7 | #define COMMON_H
|
||
8 | |||
9 | 4bdd9157 | Nick Kurshev | #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
10 | 9b59c92f | Michael Niedermayer | # define CONFIG_WIN32
|
11 | 1a565432 | Fabrice Bellard | #endif
|
12 | |||
13 | 765c3440 | Fredrik Orderud | #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(EMULATE_INTTYPES)
|
14 | # define EMULATE_INTTYPES
|
||
15 | #endif
|
||
16 | |||
17 | e0c53ac8 | Alex Beregszaszi | #ifndef M_PI
|
18 | #define M_PI 3.14159265358979323846 |
||
19 | #endif
|
||
20 | |||
21 | 420b073b | Fabrice Bellard | #ifdef HAVE_AV_CONFIG_H
|
22 | 1a565432 | Fabrice Bellard | /* only include the following when compiling package */
|
23 | 9b59c92f | Michael Niedermayer | # include "config.h" |
24 | |||
25 | # include <stdlib.h> |
||
26 | # include <stdio.h> |
||
27 | # include <string.h> |
||
28 | 56c4a184 | Fabrice Bellard | # include <ctype.h> |
29 | 9ff18a70 | Michael Niedermayer | # include <limits.h> |
30 | 9b59c92f | Michael Niedermayer | # ifndef __BEOS__
|
31 | # include <errno.h> |
||
32 | # else
|
||
33 | # include "berrno.h" |
||
34 | # endif
|
||
35 | # include <math.h> |
||
36 | |||
37 | # ifndef ENODATA
|
||
38 | # define ENODATA 61 |
||
39 | # endif
|
||
40 | 1a565432 | Fabrice Bellard | |
41 | fe1b62fb | Zdenek Kabelac | #include <stddef.h> |
42 | #ifndef offsetof
|
||
43 | # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) |
||
44 | #endif
|
||
45 | |||
46 | #define AVOPTION_CODEC_BOOL(name, help, field) \
|
||
47 | { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL } |
||
48 | 5d4ce457 | Zdenek Kabelac | #define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
|
49 | { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval } |
||
50 | fe1b62fb | Zdenek Kabelac | #define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
|
51 | { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
|
||
52 | #define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
|
||
53 | { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval } |
||
54 | #define AVOPTION_CODEC_STRING(name, help, field, str, val) \
|
||
55 | { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str } |
||
56 | #define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
|
||
57 | { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL } |
||
58 | bec89a84 | Zdenek Kabelac | #define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr } |
59 | fe1b62fb | Zdenek Kabelac | #define AVOPTION_END() AVOPTION_SUB(NULL) |
60 | |||
61 | 44f27b3a | Fabrice Bellard | #endif /* HAVE_AV_CONFIG_H */ |
62 | 1a565432 | Fabrice Bellard | |
63 | 02da51ec | Falk Hüffner | /* Suppress restrict if it was not defined in config.h. */
|
64 | #ifndef restrict |
||
65 | 9b59c92f | Michael Niedermayer | # define restrict |
66 | 02da51ec | Falk Hüffner | #endif
|
67 | |||
68 | f4ae934a | Alex Beregszaszi | #ifndef always_inline
|
69 | d200cab6 | Falk Hüffner | #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
70 | 9b59c92f | Michael Niedermayer | # define always_inline __attribute__((always_inline)) inline |
71 | d200cab6 | Falk Hüffner | #else
|
72 | 9b59c92f | Michael Niedermayer | # define always_inline inline |
73 | d200cab6 | Falk Hüffner | #endif
|
74 | f4ae934a | Alex Beregszaszi | #endif
|
75 | d200cab6 | Falk Hüffner | |
76 | f4ae934a | Alex Beregszaszi | #ifndef attribute_used
|
77 | 5c0513bd | Dmitry Baryshkov | #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
78 | # define attribute_used __attribute__((used))
|
||
79 | #else
|
||
80 | # define attribute_used
|
||
81 | #endif
|
||
82 | f4ae934a | Alex Beregszaszi | #endif
|
83 | 5c0513bd | Dmitry Baryshkov | |
84 | 88730be6 | Måns Rullgård | #ifndef attribute_unused
|
85 | #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) |
||
86 | # define attribute_unused __attribute__((unused))
|
||
87 | #else
|
||
88 | # define attribute_unused
|
||
89 | #endif
|
||
90 | #endif
|
||
91 | |||
92 | d2a9bddd | Michael Niedermayer | #ifndef EMULATE_INTTYPES
|
93 | 7f965c1c | Chris Flerackers | # include <inttypes.h> |
94 | #else
|
||
95 | typedef signed char int8_t; |
||
96 | typedef signed short int16_t; |
||
97 | typedef signed int int32_t; |
||
98 | typedef unsigned char uint8_t; |
||
99 | typedef unsigned short uint16_t; |
||
100 | typedef unsigned int uint32_t; |
||
101 | |||
102 | # ifdef CONFIG_WIN32
|
||
103 | typedef signed __int64 int64_t; |
||
104 | typedef unsigned __int64 uint64_t; |
||
105 | # else /* other OS */ |
||
106 | typedef signed long long int64_t; |
||
107 | typedef unsigned long long uint64_t; |
||
108 | # endif /* other OS */ |
||
109 | 978844cc | Diego Biurrun | #endif /* EMULATE_INTTYPES */ |
110 | 7f965c1c | Chris Flerackers | |
111 | 86f77a49 | François Revol | #ifndef PRId64
|
112 | #define PRId64 "lld" |
||
113 | #endif
|
||
114 | |||
115 | e684b35d | François Revol | #ifndef PRIu64
|
116 | 86f77a49 | François Revol | #define PRIu64 "llu" |
117 | #endif
|
||
118 | |||
119 | #ifndef PRIx64
|
||
120 | #define PRIx64 "llx" |
||
121 | #endif
|
||
122 | |||
123 | #ifndef PRId32
|
||
124 | #define PRId32 "d" |
||
125 | #endif
|
||
126 | |||
127 | #ifndef PRIdFAST16
|
||
128 | #define PRIdFAST16 PRId32
|
||
129 | #endif
|
||
130 | |||
131 | #ifndef PRIdFAST32
|
||
132 | #define PRIdFAST32 PRId32
|
||
133 | e684b35d | François Revol | #endif
|
134 | |||
135 | cc044c1c | Bohdan Horst | #ifndef INT16_MIN
|
136 | #define INT16_MIN (-0x7fff-1) |
||
137 | #endif
|
||
138 | |||
139 | #ifndef INT16_MAX
|
||
140 | #define INT16_MAX 0x7fff |
||
141 | #endif
|
||
142 | |||
143 | d2fbcb3b | Måns Rullgård | #ifndef INT32_MIN
|
144 | #define INT32_MIN (-0x7fffffff-1) |
||
145 | #endif
|
||
146 | |||
147 | #ifndef INT32_MAX
|
||
148 | #define INT32_MAX 0x7fffffff |
||
149 | #endif
|
||
150 | |||
151 | #ifndef UINT32_MAX
|
||
152 | #define UINT32_MAX 0xffffffff |
||
153 | #endif
|
||
154 | |||
155 | cc044c1c | Bohdan Horst | #ifndef INT64_MIN
|
156 | #define INT64_MIN (-0x7fffffffffffffffLL-1) |
||
157 | #endif
|
||
158 | |||
159 | 9ff5f175 | Michael Niedermayer | #ifndef INT64_MAX
|
160 | 2a24fe4c | Gael Chardon | #define INT64_MAX int64_t_C(9223372036854775807) |
161 | 9ff5f175 | Michael Niedermayer | #endif
|
162 | |||
163 | caa50878 | Michael Niedermayer | #ifndef UINT64_MAX
|
164 | #define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF) |
||
165 | #endif
|
||
166 | |||
167 | 19d053c5 | Roman Shaposhnik | #ifdef EMULATE_FAST_INT
|
168 | typedef signed char int_fast8_t; |
||
169 | typedef signed int int_fast16_t; |
||
170 | typedef signed int int_fast32_t; |
||
171 | typedef unsigned char uint_fast8_t; |
||
172 | typedef unsigned int uint_fast16_t; |
||
173 | typedef unsigned int uint_fast32_t; |
||
174 | 59d8efb3 | Michael Niedermayer | typedef uint64_t uint_fast64_t;
|
175 | 19d053c5 | Roman Shaposhnik | #endif
|
176 | |||
177 | 0ff93477 | Michael Niedermayer | #ifndef INT_BIT
|
178 | 9ff18a70 | Michael Niedermayer | # if INT_MAX != 2147483647 |
179 | 0ff93477 | Michael Niedermayer | # define INT_BIT 64 |
180 | # else
|
||
181 | # define INT_BIT 32 |
||
182 | # endif
|
||
183 | #endif
|
||
184 | |||
185 | 19d053c5 | Roman Shaposhnik | #if defined(CONFIG_OS2) || defined(CONFIG_SUNOS)
|
186 | 115329f1 | Diego Biurrun | static inline float floorf(float f) { |
187 | return floor(f);
|
||
188 | 19d053c5 | Roman Shaposhnik | } |
189 | #endif
|
||
190 | |||
191 | 1a565432 | Fabrice Bellard | #ifdef CONFIG_WIN32
|
192 | |||
193 | /* windows */
|
||
194 | |||
195 | 5c668f46 | Sascha Sommer | # if !defined(__MINGW32__) && !defined(__CYGWIN__)
|
196 | 0c1a9eda | Zdenek Kabelac | # define int64_t_C(c) (c ## i64) |
197 | # define uint64_t_C(c) (c ## i64) |
||
198 | 1a565432 | Fabrice Bellard | |
199 | 49e17f84 | Michael Niedermayer | # ifdef HAVE_AV_CONFIG_H
|
200 | # define inline __inline |
||
201 | # endif
|
||
202 | 1a565432 | Fabrice Bellard | |
203 | 9b59c92f | Michael Niedermayer | # else
|
204 | 0c1a9eda | Zdenek Kabelac | # define int64_t_C(c) (c ## LL) |
205 | # define uint64_t_C(c) (c ## ULL) |
||
206 | 9b59c92f | Michael Niedermayer | # endif /* __MINGW32__ */ |
207 | a74127c0 | Fabrice Bellard | |
208 | 49e17f84 | Michael Niedermayer | # ifdef HAVE_AV_CONFIG_H
|
209 | # ifdef _DEBUG
|
||
210 | # define DEBUG
|
||
211 | # endif
|
||
212 | de6d9b64 | Fabrice Bellard | |
213 | 49e17f84 | Michael Niedermayer | # define snprintf _snprintf
|
214 | # define vsnprintf _vsnprintf
|
||
215 | ac44871c | Gildas Bazin | |
216 | # ifdef CONFIG_WINCE
|
||
217 | # define perror(a)
|
||
218 | # endif
|
||
219 | |||
220 | 49e17f84 | Michael Niedermayer | # endif
|
221 | 1a565432 | Fabrice Bellard | |
222 | f3ec2d46 | Slavik Gnatenko | /* CONFIG_WIN32 end */
|
223 | #elif defined (CONFIG_OS2)
|
||
224 | /* OS/2 EMX */
|
||
225 | |||
226 | 0c1a9eda | Zdenek Kabelac | #ifndef int64_t_C
|
227 | #define int64_t_C(c) (c ## LL) |
||
228 | #define uint64_t_C(c) (c ## ULL) |
||
229 | f3ec2d46 | Slavik Gnatenko | #endif
|
230 | |||
231 | f5fe9d5f | Fabrice Bellard | #ifdef HAVE_AV_CONFIG_H
|
232 | |||
233 | f3ec2d46 | Slavik Gnatenko | #ifdef USE_FASTMEMCPY
|
234 | #include "fastmemcpy.h" |
||
235 | #endif
|
||
236 | |||
237 | #include <float.h> |
||
238 | |||
239 | #endif /* HAVE_AV_CONFIG_H */ |
||
240 | |||
241 | /* CONFIG_OS2 end */
|
||
242 | #else
|
||
243 | 1a565432 | Fabrice Bellard | |
244 | /* unix */
|
||
245 | |||
246 | f5fe9d5f | Fabrice Bellard | #ifndef int64_t_C
|
247 | #define int64_t_C(c) (c ## LL) |
||
248 | #define uint64_t_C(c) (c ## ULL) |
||
249 | #endif
|
||
250 | |||
251 | #ifdef HAVE_AV_CONFIG_H
|
||
252 | 1a565432 | Fabrice Bellard | |
253 | 9b59c92f | Michael Niedermayer | # ifdef USE_FASTMEMCPY
|
254 | # include "fastmemcpy.h" |
||
255 | # endif
|
||
256 | # endif /* HAVE_AV_CONFIG_H */ |
||
257 | a74127c0 | Fabrice Bellard | |
258 | f3ec2d46 | Slavik Gnatenko | #endif /* !CONFIG_WIN32 && !CONFIG_OS2 */ |
259 | a74127c0 | Fabrice Bellard | |
260 | #ifdef HAVE_AV_CONFIG_H
|
||
261 | |||
262 | 320d060a | Diego Biurrun | #if defined(__MINGW32__) && !defined(BUILD_AVUTIL) && defined(BUILD_SHARED_AV)
|
263 | # define FF_IMPORT_ATTR __declspec(dllimport)
|
||
264 | #else
|
||
265 | # define FF_IMPORT_ATTR
|
||
266 | #endif
|
||
267 | |||
268 | |||
269 | 9b59c92f | Michael Niedermayer | # include "bswap.h" |
270 | 96707bb7 | Fabrice Bellard | |
271 | a2c3bf82 | Drew Hess | // Use rip-relative addressing if compiling PIC code on x86-64.
|
272 | 9b59c92f | Michael Niedermayer | # if defined(__MINGW32__) || defined(__CYGWIN__) || \
|
273 | 814b648c | Michael Niedermayer | defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) |
274 | a2c3bf82 | Drew Hess | # if defined(ARCH_X86_64) && defined(PIC)
|
275 | # define MANGLE(a) "_" #a"(%%rip)" |
||
276 | # else
|
||
277 | # define MANGLE(a) "_" #a |
||
278 | # endif
|
||
279 | 9b59c92f | Michael Niedermayer | # else
|
280 | a2c3bf82 | Drew Hess | # if defined(ARCH_X86_64) && defined(PIC)
|
281 | # define MANGLE(a) #a"(%%rip)" |
||
282 | 5f112e1f | Sam Hocevar | # elif defined(CONFIG_DARWIN)
|
283 | # define MANGLE(a) "_" #a |
||
284 | a2c3bf82 | Drew Hess | # else
|
285 | # define MANGLE(a) #a |
||
286 | # endif
|
||
287 | 9b59c92f | Michael Niedermayer | # endif
|
288 | 6a3d7e36 | Fabrice Bellard | |
289 | d503f970 | Fabrice Bellard | /* debug stuff */
|
290 | |||
291 | 72468a03 | Diego Pettenò | # if !defined(DEBUG) && !defined(NDEBUG)
|
292 | 9b59c92f | Michael Niedermayer | # define NDEBUG
|
293 | # endif
|
||
294 | # include <assert.h> |
||
295 | 1a565432 | Fabrice Bellard | |
296 | a74127c0 | Fabrice Bellard | /* dprintf macros */
|
297 | 2a86d50b | Sascha Sommer | # if defined(CONFIG_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
298 | a74127c0 | Fabrice Bellard | |
299 | inline void dprintf(const char* fmt,...) {} |
||
300 | |||
301 | 9b59c92f | Michael Niedermayer | # else
|
302 | a74127c0 | Fabrice Bellard | |
303 | 9b59c92f | Michael Niedermayer | # ifdef DEBUG
|
304 | 365e75f8 | Michael Niedermayer | # define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__) |
305 | 9b59c92f | Michael Niedermayer | # else
|
306 | dc7cb06a | Dan Christiansen | # define dprintf(fmt,...)
|
307 | 9b59c92f | Michael Niedermayer | # endif
|
308 | 1a565432 | Fabrice Bellard | |
309 | 9b59c92f | Michael Niedermayer | # endif /* !CONFIG_WIN32 */ |
310 | ac44871c | Gildas Bazin | # ifdef CONFIG_WINCE
|
311 | # define abort()
|
||
312 | # endif
|
||
313 | 1a565432 | Fabrice Bellard | |
314 | 9b879566 | Michel Bardiaux | # define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) |
315 | 935cdf09 | Philip Gladstone | |
316 | 073b013d | Michael Niedermayer | //rounded divison & shift
|
317 | 10f3005f | Michael Niedermayer | #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) |
318 | d7e9533a | Michael Niedermayer | /* assume b>0 */
|
319 | #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) |
||
320 | 32cd20de | Michael Niedermayer | #define ABS(a) ((a) >= 0 ? (a) : (-(a))) |
321 | 75460b0c | Michael Niedermayer | |
322 | b8a78f41 | Michael Niedermayer | #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
|
323 | #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
|
||
324 | d7e9533a | Michael Niedermayer | |
325 | d4961b35 | BERO | extern const uint32_t inverse[256]; |
326 | |||
327 | 053dea12 | Aurelien Jacobs | #if defined(ARCH_X86) || defined(ARCH_X86_64)
|
328 | d4961b35 | BERO | # define FASTDIV(a,b) \
|
329 | ({\ |
||
330 | int ret,dmy;\
|
||
331 | asm volatile(\ |
||
332 | "mull %3"\
|
||
333 | :"=d"(ret),"=a"(dmy)\ |
||
334 | :"1"(a),"g"(inverse[b])\ |
||
335 | );\ |
||
336 | ret;\ |
||
337 | }) |
||
338 | #elif defined(CONFIG_FASTDIV)
|
||
339 | # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32)) |
||
340 | #else
|
||
341 | # define FASTDIV(a,b) ((a)/(b))
|
||
342 | #endif
|
||
343 | 115329f1 | Diego Biurrun | |
344 | de6d9b64 | Fabrice Bellard | /* define it to include statistics code (useful only for optimizing
|
345 | codec efficiency */
|
||
346 | //#define STATS
|
||
347 | |||
348 | #ifdef STATS
|
||
349 | |||
350 | enum {
|
||
351 | ST_UNKNOWN, |
||
352 | ST_DC, |
||
353 | ST_INTRA_AC, |
||
354 | ST_INTER_AC, |
||
355 | ST_INTRA_MB, |
||
356 | ST_INTER_MB, |
||
357 | ST_MV, |
||
358 | ST_NB, |
||
359 | }; |
||
360 | |||
361 | extern int st_current_index; |
||
362 | extern unsigned int st_bit_counts[ST_NB]; |
||
363 | extern unsigned int st_out_bit_counts[ST_NB]; |
||
364 | |||
365 | void print_stats(void); |
||
366 | #endif
|
||
367 | |||
368 | /* misc math functions */
|
||
369 | 320d060a | Diego Biurrun | extern FF_IMPORT_ATTR const uint8_t ff_log2_tab[256]; |
370 | de6d9b64 | Fabrice Bellard | |
371 | a822a479 | Nick Kurshev | static inline int av_log2(unsigned int v) |
372 | de6d9b64 | Fabrice Bellard | { |
373 | int n;
|
||
374 | |||
375 | n = 0;
|
||
376 | if (v & 0xffff0000) { |
||
377 | v >>= 16;
|
||
378 | n += 16;
|
||
379 | } |
||
380 | if (v & 0xff00) { |
||
381 | v >>= 8;
|
||
382 | n += 8;
|
||
383 | } |
||
384 | c81f0349 | Michael Niedermayer | n += ff_log2_tab[v]; |
385 | |||
386 | return n;
|
||
387 | } |
||
388 | |||
389 | static inline int av_log2_16bit(unsigned int v) |
||
390 | { |
||
391 | int n;
|
||
392 | |||
393 | n = 0;
|
||
394 | if (v & 0xff00) { |
||
395 | v >>= 8;
|
||
396 | n += 8;
|
||
397 | de6d9b64 | Fabrice Bellard | } |
398 | c81f0349 | Michael Niedermayer | n += ff_log2_tab[v]; |
399 | |||
400 | de6d9b64 | Fabrice Bellard | return n;
|
401 | } |
||
402 | |||
403 | 45870f57 | Michael Niedermayer | /* median of 3 */
|
404 | static inline int mid_pred(int a, int b, int c) |
||
405 | { |
||
406 | 7a62e94a | Michael Niedermayer | #if 0
|
407 | int t= (a-b)&((a-b)>>31);
|
||
408 | a-=t;
|
||
409 | b+=t;
|
||
410 | b-= (b-c)&((b-c)>>31);
|
||
411 | b+= (a-b)&((a-b)>>31);
|
||
412 | |||
413 | return b;
|
||
414 | #else
|
||
415 | if(a>b){
|
||
416 | if(c>b){
|
||
417 | if(c>a) b=a;
|
||
418 | else b=c;
|
||
419 | } |
||
420 | }else{
|
||
421 | if(b>c){
|
||
422 | if(c>a) b=c;
|
||
423 | else b=a;
|
||
424 | } |
||
425 | } |
||
426 | return b;
|
||
427 | #endif
|
||
428 | 45870f57 | Michael Niedermayer | } |
429 | |||
430 | 77177335 | Aurelien Jacobs | /**
|
431 | * clip a signed integer value into the amin-amax range
|
||
432 | * @param a value to clip
|
||
433 | * @param amin minimum value of the clip range
|
||
434 | * @param amax maximum value of the clip range
|
||
435 | * @return cliped value
|
||
436 | */
|
||
437 | 91029be7 | Michael Niedermayer | static inline int clip(int a, int amin, int amax) |
438 | { |
||
439 | if (a < amin)
|
||
440 | return amin;
|
||
441 | else if (a > amax) |
||
442 | return amax;
|
||
443 | else
|
||
444 | return a;
|
||
445 | } |
||
446 | |||
447 | 77177335 | Aurelien Jacobs | /**
|
448 | * clip a signed integer value into the 0-255 range
|
||
449 | * @param a value to clip
|
||
450 | * @return cliped value
|
||
451 | */
|
||
452 | 3a1fda0a | Panagiotis Issaris | static inline uint8_t clip_uint8(int a) |
453 | 3ebc7e04 | Michael Niedermayer | { |
454 | if (a&(~255)) return (-a)>>31; |
||
455 | else return a; |
||
456 | } |
||
457 | |||
458 | 9dbcbd92 | Michael Niedermayer | /* math */
|
459 | 320d060a | Diego Biurrun | extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128]; |
460 | f36db5df | Michael Niedermayer | |
461 | 14bea432 | Michael Niedermayer | int64_t ff_gcd(int64_t a, int64_t b); |
462 | 9dbcbd92 | Michael Niedermayer | |
463 | 7fd08ac1 | Michael Niedermayer | static inline int ff_sqrt(int a) |
464 | { |
||
465 | int ret=0; |
||
466 | int s;
|
||
467 | int ret_sq=0; |
||
468 | 115329f1 | Diego Biurrun | |
469 | f36db5df | Michael Niedermayer | if(a<128) return ff_sqrt_tab[a]; |
470 | 115329f1 | Diego Biurrun | |
471 | 7fd08ac1 | Michael Niedermayer | for(s=15; s>=0; s--){ |
472 | int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; |
||
473 | if(b<=a){
|
||
474 | ret_sq=b; |
||
475 | ret+= 1<<s;
|
||
476 | } |
||
477 | } |
||
478 | return ret;
|
||
479 | } |
||
480 | 202ef8b8 | Michael Niedermayer | |
481 | /**
|
||
482 | * converts fourcc string to int
|
||
483 | */
|
||
484 | 6a85ec8d | Zdenek Kabelac | static inline int ff_get_fourcc(const char *s){ |
485 | 202ef8b8 | Michael Niedermayer | assert( strlen(s)==4 );
|
486 | 966df5b6 | Mike Melanson | |
487 | 202ef8b8 | Michael Niedermayer | return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24); |
488 | } |
||
489 | |||
490 | e8750b00 | Fred Rothganger | #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) |
491 | #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) |
||
492 | |||
493 | |||
494 | 053dea12 | Aurelien Jacobs | #if defined(ARCH_X86) || defined(ARCH_X86_64)
|
495 | 2ad1516a | Michael Niedermayer | #define MASK_ABS(mask, level)\
|
496 | asm volatile(\ |
||
497 | bb270c08 | Diego Biurrun | "cdq \n\t"\
|
498 | "xorl %1, %0 \n\t"\
|
||
499 | "subl %1, %0 \n\t"\
|
||
500 | : "+a" (level), "=&d" (mask)\ |
||
501 | ); |
||
502 | 2ad1516a | Michael Niedermayer | #else
|
503 | #define MASK_ABS(mask, level)\
|
||
504 | mask= level>>31;\
|
||
505 | level= (level^mask)-mask; |
||
506 | #endif
|
||
507 | |||
508 | |||
509 | 7fd08ac1 | Michael Niedermayer | #if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT) |
510 | #define COPY3_IF_LT(x,y,a,b,c,d)\
|
||
511 | asm volatile (\ |
||
512 | bb270c08 | Diego Biurrun | "cmpl %0, %3 \n\t"\
|
513 | "cmovl %3, %0 \n\t"\
|
||
514 | "cmovl %4, %1 \n\t"\
|
||
515 | "cmovl %5, %2 \n\t"\
|
||
516 | 7fd08ac1 | Michael Niedermayer | : "+r" (x), "+r" (a), "+r" (c)\ |
517 | : "r" (y), "r" (b), "r" (d)\ |
||
518 | ); |
||
519 | #else
|
||
520 | #define COPY3_IF_LT(x,y,a,b,c,d)\
|
||
521 | if((y)<(x)){\
|
||
522 | (x)=(y);\ |
||
523 | (a)=(b);\ |
||
524 | (c)=(d);\ |
||
525 | } |
||
526 | #endif
|
||
527 | |||
528 | 0775c88f | Michael Niedermayer | #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC)
|
529 | 8230cf02 | Aurelien Jacobs | #if defined(ARCH_X86_64)
|
530 | 0775c88f | Michael Niedermayer | static inline uint64_t read_time(void) |
531 | 8230cf02 | Aurelien Jacobs | { |
532 | bb270c08 | Diego Biurrun | uint64_t a, d; |
533 | asm volatile( "rdtsc\n\t" |
||
534 | : "=a" (a), "=d" (d) |
||
535 | ); |
||
536 | return (d << 32) | (a & 0xffffffff); |
||
537 | 8230cf02 | Aurelien Jacobs | } |
538 | 0775c88f | Michael Niedermayer | #elif defined(ARCH_X86)
|
539 | static inline long long read_time(void) |
||
540 | b534c7f9 | Michael Niedermayer | { |
541 | bb270c08 | Diego Biurrun | long long l; |
542 | asm volatile( "rdtsc\n\t" |
||
543 | : "=A" (l)
|
||
544 | ); |
||
545 | return l;
|
||
546 | b534c7f9 | Michael Niedermayer | } |
547 | 0775c88f | Michael Niedermayer | #else //FIXME check ppc64 |
548 | static inline uint64_t read_time(void) |
||
549 | { |
||
550 | uint32_t tbu, tbl, temp; |
||
551 | |||
552 | /* from section 2.2.1 of the 32-bit PowerPC PEM */
|
||
553 | __asm__ __volatile__( |
||
554 | "1:\n"
|
||
555 | "mftbu %2\n"
|
||
556 | "mftb %0\n"
|
||
557 | "mftbu %1\n"
|
||
558 | "cmpw %2,%1\n"
|
||
559 | "bne 1b\n"
|
||
560 | : "=r"(tbl), "=r"(tbu), "=r"(temp) |
||
561 | : |
||
562 | : "cc");
|
||
563 | |||
564 | return (((uint64_t)tbu)<<32) | (uint64_t)tbl; |
||
565 | } |
||
566 | 8230cf02 | Aurelien Jacobs | #endif
|
567 | b534c7f9 | Michael Niedermayer | |
568 | #define START_TIMER \
|
||
569 | uint64_t tend;\ |
||
570 | 0775c88f | Michael Niedermayer | uint64_t tstart= read_time();\ |
571 | b534c7f9 | Michael Niedermayer | |
572 | #define STOP_TIMER(id) \
|
||
573 | 0775c88f | Michael Niedermayer | tend= read_time();\ |
574 | d705e4a6 | Michael Niedermayer | {\ |
575 | static uint64_t tsum=0;\ |
||
576 | static int tcount=0;\ |
||
577 | static int tskip_count=0;\ |
||
578 | if(tcount<2 || tend - tstart < 8*tsum/tcount){\ |
||
579 | tsum+= tend - tstart;\ |
||
580 | tcount++;\ |
||
581 | }else\
|
||
582 | tskip_count++;\ |
||
583 | if(256*256*256*64%(tcount+tskip_count)==0){\ |
||
584 | e852beee | Alexander Strasser | av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ |
585 | d705e4a6 | Michael Niedermayer | }\ |
586 | b534c7f9 | Michael Niedermayer | } |
587 | 0187e903 | Michael Niedermayer | #else
|
588 | 115329f1 | Diego Biurrun | #define START_TIMER
|
589 | 0187e903 | Michael Niedermayer | #define STOP_TIMER(id) {}
|
590 | b534c7f9 | Michael Niedermayer | #endif
|
591 | |||
592 | 8e1e6f31 | Fabrice Bellard | /* avoid usage of various functions */
|
593 | #define malloc please_use_av_malloc
|
||
594 | #define free please_use_av_free
|
||
595 | #define realloc please_use_av_realloc
|
||
596 | 7d1bbcd4 | Michael Niedermayer | #define time time_is_forbidden_due_to_security_issues
|
597 | #define rand rand_is_forbidden_due_to_state_trashing
|
||
598 | #define srand srand_is_forbidden_due_to_state_trashing
|
||
599 | 2fc8ea24 | Michael Niedermayer | #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
|
600 | 1f3f9507 | Michael Niedermayer | #define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
|
601 | d705e4a6 | Michael Niedermayer | #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
|
602 | #define printf please_use_av_log
|
||
603 | #define fprintf please_use_av_log
|
||
604 | #endif
|
||
605 | 8e1e6f31 | Fabrice Bellard | |
606 | 7bc9090a | Michael Niedermayer | #define CHECKED_ALLOCZ(p, size)\
|
607 | {\ |
||
608 | p= av_mallocz(size);\ |
||
609 | dc939fd5 | Michael Niedermayer | if(p==NULL && (size)!=0){\ |
610 | 7bc9090a | Michael Niedermayer | perror("malloc");\
|
611 | goto fail;\
|
||
612 | }\ |
||
613 | } |
||
614 | |||
615 | 7df65455 | Diego Biurrun | #ifndef HAVE_LRINTF
|
616 | /* XXX: add ISOC specific test to avoid specific BSD testing. */
|
||
617 | /* better than nothing implementation. */
|
||
618 | /* btw, rintf() is existing on fbsd too -- alex */
|
||
619 | static always_inline long int lrintf(float x) |
||
620 | { |
||
621 | #ifdef CONFIG_WIN32
|
||
622 | # ifdef ARCH_X86
|
||
623 | int32_t i; |
||
624 | asm volatile( |
||
625 | "fistpl %0\n\t"
|
||
626 | : "=m" (i) : "t" (x) : "st" |
||
627 | ); |
||
628 | return i;
|
||
629 | # else
|
||
630 | /* XXX: incorrect, but make it compile */
|
||
631 | return (int)(x + (x < 0 ? -0.5 : 0.5)); |
||
632 | # endif /* ARCH_X86 */ |
||
633 | #else
|
||
634 | return (int)(rint(x)); |
||
635 | #endif /* CONFIG_WIN32 */ |
||
636 | } |
||
637 | #else
|
||
638 | #ifndef _ISOC9X_SOURCE
|
||
639 | #define _ISOC9X_SOURCE
|
||
640 | #endif
|
||
641 | #include <math.h> |
||
642 | #endif /* HAVE_LRINTF */ |
||
643 | |||
644 | 96707bb7 | Fabrice Bellard | #endif /* HAVE_AV_CONFIG_H */ |
645 | |||
646 | #endif /* COMMON_H */ |