3 * common internal api header.
9 #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
14 #define M_PI 3.14159265358979323846
17 #ifdef HAVE_AV_CONFIG_H
18 /* only include the following when compiling package */
19 # include "avconfig.h"
39 # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
42 #define AVOPTION_CODEC_BOOL(name, help, field) \
43 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
44 #define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
45 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
46 #define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
47 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
48 #define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
49 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
50 #define AVOPTION_CODEC_STRING(name, help, field, str, val) \
51 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
52 #define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
53 { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
54 #define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
55 #define AVOPTION_END() AVOPTION_SUB(NULL)
57 #endif /* HAVE_AV_CONFIG_H */
59 /* Suppress restrict if it was not defined in config.h. */
65 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
66 # define always_inline __attribute__((always_inline)) inline
68 # define always_inline inline
72 #ifndef attribute_used
73 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
74 # define attribute_used __attribute__((used))
76 # define attribute_used
80 #ifndef attribute_unused
81 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
82 # define attribute_unused __attribute__((unused))
84 # define attribute_unused
88 #ifndef EMULATE_INTTYPES
89 # include <inttypes.h>
91 typedef signed char int8_t;
92 typedef signed short int16_t;
93 typedef signed int int32_t;
94 typedef unsigned char uint8_t;
95 typedef unsigned short uint16_t;
96 typedef unsigned int uint32_t;
99 typedef signed __int64
int64_t;
100 typedef unsigned __int64
uint64_t;
101 # else /* other OS */
102 typedef signed long long int64_t;
103 typedef unsigned long long uint64_t;
104 # endif /* other OS */
105 #endif /* HAVE_INTTYPES_H */
108 #define INT16_MIN (-0x7fff-1)
112 #define INT16_MAX 0x7fff
116 #define INT64_MIN (-0x7fffffffffffffffLL-1)
120 #define INT64_MAX int64_t_C(9223372036854775807)
124 #define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF)
127 #ifdef EMULATE_FAST_INT
128 typedef signed char int_fast8_t;
129 typedef signed int int_fast16_t;
130 typedef signed int int_fast32_t;
131 typedef unsigned char uint_fast8_t;
132 typedef unsigned int uint_fast16_t;
133 typedef unsigned int uint_fast32_t;
134 typedef uint64_t uint_fast64_t;
138 # if INT_MAX != 2147483647
145 #if defined(CONFIG_OS2) || defined(CONFIG_SUNOS)
146 static inline float floorf(float f
) {
155 # if !defined(__MINGW32__) && !defined(__CYGWIN__)
156 # define int64_t_C(c) (c ## i64)
157 # define uint64_t_C(c) (c ## i64)
159 # ifdef HAVE_AV_CONFIG_H
160 # define inline __inline
164 # define int64_t_C(c) (c ## LL)
165 # define uint64_t_C(c) (c ## ULL)
166 # endif /* __MINGW32__ */
168 # ifdef HAVE_AV_CONFIG_H
173 # define snprintf _snprintf
174 # define vsnprintf _vsnprintf
177 /* CONFIG_WIN32 end */
178 #elif defined (CONFIG_OS2)
182 #define int64_t_C(c) (c ## LL)
183 #define uint64_t_C(c) (c ## ULL)
186 #ifdef HAVE_AV_CONFIG_H
188 #ifdef USE_FASTMEMCPY
189 #include "fastmemcpy.h"
194 #endif /* HAVE_AV_CONFIG_H */
202 #define int64_t_C(c) (c ## LL)
203 #define uint64_t_C(c) (c ## ULL)
206 #ifdef HAVE_AV_CONFIG_H
208 # ifdef USE_FASTMEMCPY
209 # include "fastmemcpy.h"
211 # endif /* HAVE_AV_CONFIG_H */
213 #endif /* !CONFIG_WIN32 && !CONFIG_OS2 */
215 #ifdef HAVE_AV_CONFIG_H
219 // Use rip-relative addressing if compiling PIC code on x86-64.
220 # if defined(__MINGW32__) || defined(__CYGWIN__) || \
221 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
222 # if defined(ARCH_X86_64) && defined(PIC)
223 # define MANGLE(a) "_" #a"(%%rip)"
225 # define MANGLE(a) "_" #a
228 # if defined(ARCH_X86_64) && defined(PIC)
229 # define MANGLE(a) #a"(%%rip)"
231 # define MANGLE(a) #a
243 # if defined(CONFIG_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
245 inline void dprintf(const char* fmt
,...) {}
250 # define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
252 # define dprintf(fmt,...)
255 # endif /* !CONFIG_WIN32 */
257 # define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
259 //rounded divison & shift
260 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
262 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
263 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
265 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
266 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
268 extern const uint32_t inverse
[256];
270 #if defined(ARCH_X86) || defined(ARCH_X86_64)
271 # define FASTDIV(a,b) \
276 :"=d"(ret),"=a"(dmy)\
277 :"1"(a),"g"(inverse[b])\
281 #elif defined(CONFIG_FASTDIV)
282 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
284 # define FASTDIV(a,b) ((a)/(b))
287 /* define it to include statistics code (useful only for optimizing
304 extern int st_current_index
;
305 extern unsigned int st_bit_counts
[ST_NB
];
306 extern unsigned int st_out_bit_counts
[ST_NB
];
308 void print_stats(void);
311 /* misc math functions */
312 extern const uint8_t ff_log2_tab
[256];
314 static inline int av_log2(unsigned int v
)
319 if (v
& 0xffff0000) {
332 static inline int av_log2_16bit(unsigned int v
)
347 static inline int mid_pred(int a
, int b
, int c
)
350 int t
= (a
-b
)&((a
-b
)>>31);
353 b
-= (b
-c
)&((b
-c
)>>31);
354 b
+= (a
-b
)&((a
-b
)>>31);
373 static inline int clip(int a
, int amin
, int amax
)
383 static inline int clip_uint8(int a
)
385 if (a
&(~255)) return (-a
)>>31;
390 extern const uint8_t ff_sqrt_tab
[128];
392 int64_t ff_gcd(int64_t a
, int64_t b
);
394 static inline int ff_sqrt(int a
)
400 if(a
<128) return ff_sqrt_tab
[a
];
402 for(s
=15; s
>=0; s
--){
403 int b
= ret_sq
+ (1<<(s
*2)) + (ret
<<s
)*2;
413 * converts fourcc string to int
415 static inline int ff_get_fourcc(const char *s
){
416 assert( strlen(s
)==4 );
418 return (s
[0]) + (s
[1]<<8) + (s
[2]<<16) + (s
[3]<<24);
421 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
422 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
425 #if defined(ARCH_X86) || defined(ARCH_X86_64)
426 #define MASK_ABS(mask, level)\
431 : "+a" (level), "=&d" (mask)\
434 #define MASK_ABS(mask, level)\
436 level= (level^mask)-mask;
440 #if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
441 #define COPY3_IF_LT(x,y,a,b,c,d)\
447 : "+r" (x), "+r" (a), "+r" (c)\
448 : "r" (y), "r" (b), "r" (d)\
451 #define COPY3_IF_LT(x,y,a,b,c,d)\
459 #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC)
460 #if defined(ARCH_X86_64)
461 static inline uint64_t read_time(void)
464 asm volatile( "rdtsc\n\t"
467 return (d
<< 32) | (a
& 0xffffffff);
469 #elif defined(ARCH_X86)
470 static inline long long read_time(void)
473 asm volatile( "rdtsc\n\t"
478 #else //FIXME check ppc64
479 static inline uint64_t read_time(void)
481 uint32_t tbu
, tbl
, temp
;
483 /* from section 2.2.1 of the 32-bit PowerPC PEM */
484 __asm__
__volatile__(
491 : "=r"(tbl
), "=r"(tbu
), "=r"(temp
)
495 return (((uint64_t)tbu
)<<32) | (uint64_t)tbl
;
499 #define START_TIMER \
501 uint64_t tstart= read_time();\
503 #define STOP_TIMER(id) \
506 static uint64_t tsum=0;\
507 static int tcount=0;\
508 static int tskip_count=0;\
509 if(tcount<2 || tend - tstart < 8*tsum/tcount){\
510 tsum+= tend - tstart;\
514 if(256*256*256*64%(tcount+tskip_count)==0){\
515 av_log(NULL, AV_LOG_DEBUG, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
520 #define STOP_TIMER(id) {}
523 /* avoid usage of various functions */
524 #define malloc please_use_av_malloc
525 #define free please_use_av_free
526 #define realloc please_use_av_realloc
527 #define time time_is_forbidden_due_to_security_issues
528 #define rand rand_is_forbidden_due_to_state_trashing
529 #define srand srand_is_forbidden_due_to_state_trashing
530 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
531 #define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
532 #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
533 #define printf please_use_av_log
534 #define fprintf please_use_av_log
537 #define CHECKED_ALLOCZ(p, size)\
539 p= av_mallocz(size);\
540 if(p==NULL && (size)!=0){\
546 #endif /* HAVE_AV_CONFIG_H */
548 #endif /* COMMON_H */