00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef FFMPEG_INTERNAL_H
00027 #define FFMPEG_INTERNAL_H
00028
00029 #if !defined(DEBUG) && !defined(NDEBUG)
00030 # define NDEBUG
00031 #endif
00032
00033 #include <stdint.h>
00034 #include <stddef.h>
00035 #include <assert.h>
00036
00037 #ifndef attribute_align_arg
00038 #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1)
00039 # define attribute_align_arg __attribute__((force_align_arg_pointer))
00040 #else
00041 # define attribute_align_arg
00042 #endif
00043 #endif
00044
00045 #ifndef attribute_used
00046 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
00047 # define attribute_used __attribute__((used))
00048 #else
00049 # define attribute_used
00050 #endif
00051 #endif
00052
00053
00054 #ifdef __APPLE_CC__
00055 #define AVV(x...) (x)
00056 #else
00057 #define AVV(x...) {x}
00058 #endif
00059
00060 #ifndef M_PI
00061 #define M_PI 3.14159265358979323846
00062 #endif
00063
00064 #ifndef INT16_MIN
00065 #define INT16_MIN (-0x7fff-1)
00066 #endif
00067
00068 #ifndef INT16_MAX
00069 #define INT16_MAX 0x7fff
00070 #endif
00071
00072 #ifndef INT32_MIN
00073 #define INT32_MIN (-0x7fffffff-1)
00074 #endif
00075
00076 #ifndef INT32_MAX
00077 #define INT32_MAX 0x7fffffff
00078 #endif
00079
00080 #ifndef UINT32_MAX
00081 #define UINT32_MAX 0xffffffff
00082 #endif
00083
00084 #ifndef INT64_MIN
00085 #define INT64_MIN (-0x7fffffffffffffffLL-1)
00086 #endif
00087
00088 #ifndef INT64_MAX
00089 #define INT64_MAX INT64_C(9223372036854775807)
00090 #endif
00091
00092 #ifndef UINT64_MAX
00093 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
00094 #endif
00095
00096 #ifndef INT_BIT
00097 # if INT_MAX != 2147483647
00098 # define INT_BIT 64
00099 # else
00100 # define INT_BIT 32
00101 # endif
00102 #endif
00103
00104 #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
00105 # define PIC
00106 #endif
00107
00108 #include "intreadwrite.h"
00109 #include "bswap.h"
00110
00111 #ifndef offsetof
00112 # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
00113 #endif
00114
00115 #ifdef USE_FASTMEMCPY
00116 # include "libvo/fastmemcpy.h"
00117 # define memcpy(a,b,c) fast_memcpy(a,b,c)
00118 #endif
00119
00120
00121 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__DJGPP__) || \
00122 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
00123 # if defined(ARCH_X86_64) && defined(PIC)
00124 # define MANGLE(a) "_" #a"(%%rip)"
00125 # else
00126 # define MANGLE(a) "_" #a
00127 # endif
00128 #else
00129 # if defined(ARCH_X86_64) && defined(PIC)
00130 # define MANGLE(a) #a"(%%rip)"
00131 # elif defined(__APPLE__)
00132 # define MANGLE(a) "_" #a
00133 # else
00134 # define MANGLE(a) #a
00135 # endif
00136 #endif
00137
00138
00139
00140
00141 #ifdef DEBUG
00142 # define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
00143 #else
00144 # define dprintf(pctx, ...)
00145 #endif
00146
00147 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
00148
00149
00150
00151 extern const uint32_t ff_inverse[256];
00152
00153 #if defined(ARCH_X86)
00154 # define FASTDIV(a,b) \
00155 ({\
00156 int ret,dmy;\
00157 asm volatile(\
00158 "mull %3"\
00159 :"=d"(ret),"=a"(dmy)\
00160 :"1"(a),"g"(ff_inverse[b])\
00161 );\
00162 ret;\
00163 })
00164 #elif defined(ARCH_ARMV4L)
00165 # define FASTDIV(a,b) \
00166 ({\
00167 int ret,dmy;\
00168 asm volatile(\
00169 "umull %1, %0, %2, %3"\
00170 :"=&r"(ret),"=&r"(dmy)\
00171 :"r"(a),"r"(ff_inverse[b])\
00172 );\
00173 ret;\
00174 })
00175 #elif defined(CONFIG_FASTDIV)
00176 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
00177 #else
00178 # define FASTDIV(a,b) ((a)/(b))
00179 #endif
00180
00181 extern const uint8_t ff_sqrt_tab[256];
00182
00183 static inline int av_log2_16bit(unsigned int v);
00184
00185 static inline unsigned int ff_sqrt(unsigned int a)
00186 {
00187 unsigned int b;
00188
00189 if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
00190 else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
00191 #ifndef CONFIG_SMALL
00192 else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
00193 else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ;
00194 #endif
00195 else{
00196 int s= av_log2_16bit(a>>16)>>1;
00197 unsigned int c= a>>(s+2);
00198 b= ff_sqrt_tab[c>>(s+8)];
00199 b= FASTDIV(c,b) + (b<<s);
00200 }
00201
00202 return b - (a<b*b);
00203 }
00204
00205 #if defined(ARCH_X86)
00206 #define MASK_ABS(mask, level)\
00207 asm volatile(\
00208 "cdq \n\t"\
00209 "xorl %1, %0 \n\t"\
00210 "subl %1, %0 \n\t"\
00211 : "+a" (level), "=&d" (mask)\
00212 );
00213 #else
00214 #define MASK_ABS(mask, level)\
00215 mask= level>>31;\
00216 level= (level^mask)-mask;
00217 #endif
00218
00219 #ifdef HAVE_CMOV
00220 #define COPY3_IF_LT(x,y,a,b,c,d)\
00221 asm volatile (\
00222 "cmpl %0, %3 \n\t"\
00223 "cmovl %3, %0 \n\t"\
00224 "cmovl %4, %1 \n\t"\
00225 "cmovl %5, %2 \n\t"\
00226 : "+&r" (x), "+&r" (a), "+r" (c)\
00227 : "r" (y), "r" (b), "r" (d)\
00228 );
00229 #else
00230 #define COPY3_IF_LT(x,y,a,b,c,d)\
00231 if((y)<(x)){\
00232 (x)=(y);\
00233 (a)=(b);\
00234 (c)=(d);\
00235 }
00236 #endif
00237
00238
00239 #undef malloc
00240 #define malloc please_use_av_malloc
00241 #undef free
00242 #define free please_use_av_free
00243 #undef realloc
00244 #define realloc please_use_av_realloc
00245 #undef time
00246 #define time time_is_forbidden_due_to_security_issues
00247 #undef rand
00248 #define rand rand_is_forbidden_due_to_state_trashing_use_av_random
00249 #undef srand
00250 #define srand srand_is_forbidden_due_to_state_trashing_use_av_init_random
00251 #undef random
00252 #define random random_is_forbidden_due_to_state_trashing_use_av_random
00253 #undef sprintf
00254 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
00255 #undef strcat
00256 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
00257 #undef exit
00258 #define exit exit_is_forbidden
00259 #if !(defined(LIBAVFORMAT_BUILD) || defined(FFMPEG_FRAMEHOOK_H))
00260 #undef printf
00261 #define printf please_use_av_log
00262 #undef fprintf
00263 #define fprintf please_use_av_log
00264 #undef puts
00265 #define puts please_use_av_log
00266 #undef perror
00267 #define perror please_use_av_log_instead_of_perror
00268 #endif
00269
00270 #define CHECKED_ALLOCZ(p, size)\
00271 {\
00272 p= av_mallocz(size);\
00273 if(p==NULL && (size)!=0){\
00274 av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\
00275 goto fail;\
00276 }\
00277 }
00278
00279 #ifndef HAVE_LLRINT
00280 static av_always_inline long long llrint(double x)
00281 {
00282 return rint(x);
00283 }
00284 #endif
00285
00286 #ifndef HAVE_LRINT
00287 static av_always_inline long int lrint(double x)
00288 {
00289 return rint(x);
00290 }
00291 #endif
00292
00293 #ifndef HAVE_LRINTF
00294 static av_always_inline long int lrintf(float x)
00295 {
00296 return (int)(rint(x));
00297 }
00298 #endif
00299
00300 #ifndef HAVE_ROUND
00301 static av_always_inline double round(double x)
00302 {
00303 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
00304 }
00305 #endif
00306
00307 #ifndef HAVE_ROUNDF
00308 static av_always_inline float roundf(float x)
00309 {
00310 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
00311 }
00312 #endif
00313
00314 #endif