3 * common internal and external api header.
10 #define M_PI 3.14159265358979323846
13 #ifdef HAVE_AV_CONFIG_H
14 /* only include the following when compiling package */
28 #endif /* HAVE_AV_CONFIG_H */
30 /* Suppress restrict if it was not defined in config.h. */
36 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
37 # define always_inline __attribute__((always_inline)) inline
39 # define always_inline inline
43 #ifndef attribute_used
44 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
45 # define attribute_used __attribute__((used))
47 # define attribute_used
51 #ifndef attribute_unused
52 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
53 # define attribute_unused __attribute__((unused))
55 # define attribute_unused
59 #ifndef attribute_deprecated
60 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
61 # define attribute_deprecated __attribute__((deprecated))
63 # define attribute_deprecated
67 #ifndef EMULATE_INTTYPES
68 # include <inttypes.h>
70 typedef signed char int8_t;
71 typedef signed short int16_t;
72 typedef signed int int32_t;
73 typedef unsigned char uint8_t;
74 typedef unsigned short uint16_t;
75 typedef unsigned int uint32_t;
76 typedef signed long long int64_t;
77 typedef unsigned long long uint64_t;
78 #endif /* EMULATE_INTTYPES */
97 #define PRIdFAST16 PRId32
101 #define PRIdFAST32 PRId32
105 #define INT16_MIN (-0x7fff-1)
109 #define INT16_MAX 0x7fff
113 #define INT32_MIN (-0x7fffffff-1)
117 #define INT32_MAX 0x7fffffff
121 #define UINT32_MAX 0xffffffff
125 #define INT64_MIN (-0x7fffffffffffffffLL-1)
129 #define INT64_MAX int64_t_C(9223372036854775807)
133 #define UINT64_MAX uint64_t_C(0xFFFFFFFFFFFFFFFF)
136 #ifdef EMULATE_FAST_INT
137 typedef signed char int_fast8_t;
138 typedef signed int int_fast16_t;
139 typedef signed int int_fast32_t;
140 typedef unsigned char uint_fast8_t;
141 typedef unsigned int uint_fast16_t;
142 typedef unsigned int uint_fast32_t;
143 typedef uint64_t uint_fast64_t;
147 # if INT_MAX != 2147483647
155 #define int64_t_C(c) (c ## LL)
156 #define uint64_t_C(c) (c ## ULL)
159 #if defined(__MINGW32__) && !defined(BUILD_AVUTIL) && defined(BUILD_SHARED_AV)
160 # define FF_IMPORT_ATTR __declspec(dllimport)
162 # define FF_IMPORT_ATTR
166 #ifdef HAVE_AV_CONFIG_H
167 /* only include the following when compiling package */
168 # include "internal.h"
171 //rounded divison & shift
172 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
174 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
175 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
177 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
178 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
180 #define SWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
182 /* misc math functions */
183 extern FF_IMPORT_ATTR const uint8_t ff_log2_tab[256];
185 static inline int av_log2(unsigned int v)
190 if (v & 0xffff0000) {
203 static inline int av_log2_16bit(unsigned int v)
218 static inline int mid_pred(int a, int b, int c)
221 int t= (a-b)&((a-b)>>31);
224 b-= (b-c)&((b-c)>>31);
225 b+= (a-b)&((a-b)>>31);
245 * clip a signed integer value into the amin-amax range
246 * @param a value to clip
247 * @param amin minimum value of the clip range
248 * @param amax maximum value of the clip range
249 * @return cliped value
251 static inline int clip(int a, int amin, int amax)
253 if (a < amin) return amin;
254 else if (a > amax) return amax;
259 * clip a signed integer value into the 0-255 range
260 * @param a value to clip
261 * @return cliped value
263 static inline uint8_t clip_uint8(int a)
265 if (a&(~255)) return (-a)>>31;
270 int64_t ff_gcd(int64_t a, int64_t b);
273 * converts fourcc string to int
275 static inline int ff_get_fourcc(const char *s){
276 #ifdef HAVE_AV_CONFIG_H
277 assert( strlen(s)==4 );
280 return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
283 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
284 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
287 #define GET_UTF8(val, GET_BYTE, ERROR)\
290 int ones= 7 - av_log2(val ^ 255);\
295 int tmp= GET_BYTE - 128;\
298 val= (val<<6) + tmp;\
302 #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC)
303 #if defined(ARCH_X86_64)
304 static inline uint64_t read_time(void)
307 asm volatile( "rdtsc\n\t"
310 return (d << 32) | (a & 0xffffffff);
312 #elif defined(ARCH_X86)
313 static inline long long read_time(void)
316 asm volatile( "rdtsc\n\t"
321 #else //FIXME check ppc64
322 static inline uint64_t read_time(void)
324 uint32_t tbu, tbl, temp;
326 /* from section 2.2.1 of the 32-bit PowerPC PEM */
327 __asm__ __volatile__(
334 : "=r"(tbl), "=r"(tbu), "=r"(temp)
338 return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
342 #define START_TIMER \
344 uint64_t tstart= read_time();\
346 #define STOP_TIMER(id) \
349 static uint64_t tsum=0;\
350 static int tcount=0;\
351 static int tskip_count=0;\
352 if(tcount<2 || tend - tstart < 8*tsum/tcount){\
353 tsum+= tend - tstart;\
357 if(256*256*256*64%(tcount+tskip_count)==0){\
358 av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
363 #define STOP_TIMER(id) {}
367 void *av_malloc(unsigned int size);
368 void *av_realloc(void *ptr, unsigned int size);
369 void av_free(void *ptr);
371 #endif /* COMMON_H */