• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavutil/internal.h

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #ifndef AVUTIL_INTERNAL_H
00027 #define AVUTIL_INTERNAL_H
00028 
00029 #if !defined(DEBUG) && !defined(NDEBUG)
00030 #    define NDEBUG
00031 #endif
00032 
00033 #include <limits.h>
00034 #include <stdint.h>
00035 #include <stddef.h>
00036 #include <assert.h>
00037 #include "config.h"
00038 #include "common.h"
00039 #include "mem.h"
00040 #include "timer.h"
00041 
00042 #ifndef attribute_align_arg
00043 #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,2)
00044 #    define attribute_align_arg __attribute__((force_align_arg_pointer))
00045 #else
00046 #    define attribute_align_arg
00047 #endif
00048 #endif
00049 
00050 #ifndef attribute_used
00051 #if AV_GCC_VERSION_AT_LEAST(3,1)
00052 #    define attribute_used __attribute__((used))
00053 #else
00054 #    define attribute_used
00055 #endif
00056 #endif
00057 
00058 #ifndef INT16_MIN
00059 #define INT16_MIN       (-0x7fff-1)
00060 #endif
00061 
00062 #ifndef INT16_MAX
00063 #define INT16_MAX       0x7fff
00064 #endif
00065 
00066 #ifndef INT32_MIN
00067 #define INT32_MIN       (-0x7fffffff-1)
00068 #endif
00069 
00070 #ifndef INT32_MAX
00071 #define INT32_MAX       0x7fffffff
00072 #endif
00073 
00074 #ifndef UINT32_MAX
00075 #define UINT32_MAX      0xffffffff
00076 #endif
00077 
00078 #ifndef INT64_MIN
00079 #define INT64_MIN       (-0x7fffffffffffffffLL-1)
00080 #endif
00081 
00082 #ifndef INT64_MAX
00083 #define INT64_MAX INT64_C(9223372036854775807)
00084 #endif
00085 
00086 #ifndef UINT64_MAX
00087 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
00088 #endif
00089 
00090 #ifndef INT_BIT
00091 #    define INT_BIT (CHAR_BIT * sizeof(int))
00092 #endif
00093 
00094 #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
00095 #    define PIC
00096 #endif
00097 
00098 #ifndef offsetof
00099 #    define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
00100 #endif
00101 
00102 // Use rip-relative addressing if compiling PIC code on x86-64.
00103 #if ARCH_X86_64 && defined(PIC)
00104 #    define LOCAL_MANGLE(a) #a "(%%rip)"
00105 #else
00106 #    define LOCAL_MANGLE(a) #a
00107 #endif
00108 
00109 #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
00110 
00111 /* debug stuff */
00112 
00113 /* dprintf macros */
00114 #ifdef DEBUG
00115 #    define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
00116 #else
00117 #    define dprintf(pctx, ...)
00118 #endif
00119 
00120 #define av_abort()      do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
00121 
00122 /* math */
00123 
00124 extern const uint32_t ff_inverse[256];
00125 
00126 #if ARCH_X86
00127 #    define FASTDIV(a,b) \
00128     ({\
00129         int ret,dmy;\
00130         __asm__ volatile(\
00131             "mull %3"\
00132             :"=d"(ret),"=a"(dmy)\
00133             :"1"(a),"g"(ff_inverse[b])\
00134             );\
00135         ret;\
00136     })
00137 #elif HAVE_ARMV6
00138 static inline av_const int FASTDIV(int a, int b)
00139 {
00140     int r, t;
00141     __asm__ volatile("cmp     %3, #2               \n\t"
00142                      "ldr     %1, [%4, %3, lsl #2] \n\t"
00143                      "lsrle   %0, %2, #1           \n\t"
00144                      "smmulgt %0, %1, %2           \n\t"
00145                      : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse));
00146     return r;
00147 }
00148 #elif ARCH_ARM
00149 static inline av_const int FASTDIV(int a, int b)
00150 {
00151     int r, t;
00152     __asm__ volatile ("umull %1, %0, %2, %3"
00153                       : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
00154     return r;
00155 }
00156 #elif CONFIG_FASTDIV
00157 #    define FASTDIV(a,b)   ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
00158 #else
00159 #    define FASTDIV(a,b)   ((a)/(b))
00160 #endif
00161 
00162 extern const uint8_t ff_sqrt_tab[256];
00163 
00164 static inline av_const unsigned int ff_sqrt(unsigned int a)
00165 {
00166     unsigned int b;
00167 
00168     if(a<255) return (ff_sqrt_tab[a+1]-1)>>4;
00169     else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2;
00170 #if !CONFIG_SMALL
00171     else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1;
00172     else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ]   ;
00173 #endif
00174     else{
00175         int s= av_log2_16bit(a>>16)>>1;
00176         unsigned int c= a>>(s+2);
00177         b= ff_sqrt_tab[c>>(s+8)];
00178         b= FASTDIV(c,b) + (b<<s);
00179     }
00180 
00181     return b - (a<b*b);
00182 }
00183 
00184 #if ARCH_X86
00185 #define MASK_ABS(mask, level)\
00186             __asm__ volatile(\
00187                 "cltd                   \n\t"\
00188                 "xorl %1, %0            \n\t"\
00189                 "subl %1, %0            \n\t"\
00190                 : "+a" (level), "=&d" (mask)\
00191             );
00192 #else
00193 #define MASK_ABS(mask, level)\
00194             mask= level>>31;\
00195             level= (level^mask)-mask;
00196 #endif
00197 
00198 #if HAVE_CMOV
00199 #define COPY3_IF_LT(x,y,a,b,c,d)\
00200 __asm__ volatile (\
00201     "cmpl %0, %3        \n\t"\
00202     "cmovl %3, %0       \n\t"\
00203     "cmovl %4, %1       \n\t"\
00204     "cmovl %5, %2       \n\t"\
00205     : "+&r" (x), "+&r" (a), "+r" (c)\
00206     : "r" (y), "r" (b), "r" (d)\
00207 );
00208 #else
00209 #define COPY3_IF_LT(x,y,a,b,c,d)\
00210 if((y)<(x)){\
00211      (x)=(y);\
00212      (a)=(b);\
00213      (c)=(d);\
00214 }
00215 #endif
00216 
00217 /* avoid usage of dangerous/inappropriate system functions */
00218 #undef  malloc
00219 #define malloc please_use_av_malloc
00220 #undef  free
00221 #define free please_use_av_free
00222 #undef  realloc
00223 #define realloc please_use_av_realloc
00224 #undef  time
00225 #define time time_is_forbidden_due_to_security_issues
00226 #undef  rand
00227 #define rand rand_is_forbidden_due_to_state_trashing_use_av_random
00228 #undef  srand
00229 #define srand srand_is_forbidden_due_to_state_trashing_use_av_random_init
00230 #undef  random
00231 #define random random_is_forbidden_due_to_state_trashing_use_av_random
00232 #undef  sprintf
00233 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
00234 #undef  strcat
00235 #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
00236 #undef  exit
00237 #define exit exit_is_forbidden
00238 #ifndef LIBAVFORMAT_BUILD
00239 #undef  printf
00240 #define printf please_use_av_log_instead_of_printf
00241 #undef  fprintf
00242 #define fprintf please_use_av_log_instead_of_fprintf
00243 #undef  puts
00244 #define puts please_use_av_log_instead_of_puts
00245 #undef  perror
00246 #define perror please_use_av_log_instead_of_perror
00247 #endif
00248 
00249 #define CHECKED_ALLOCZ(p, size)\
00250 {\
00251     p= av_mallocz(size);\
00252     if(p==NULL && (size)!=0){\
00253         av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\
00254         goto fail;\
00255     }\
00256 }
00257 
00258 #if defined(__ICC) || defined(__SUNPRO_C)
00259     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
00260     #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
00261 #elif defined(__GNUC__)
00262     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
00263     #define DECLARE_ASM_CONST(n,t,v)    static const t attribute_used __attribute__ ((aligned (n))) v
00264 #elif defined(_MSC_VER)
00265     #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
00266     #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
00267 #elif HAVE_INLINE_ASM
00268     #error The asm code needs alignment, but we do not know how to do it for this compiler.
00269 #else
00270     #define DECLARE_ALIGNED(n,t,v)      t v
00271     #define DECLARE_ASM_CONST(n,t,v)    static const t v
00272 #endif
00273 
00274 
00275 #if !HAVE_LLRINT
00276 static av_always_inline av_const long long llrint(double x)
00277 {
00278     return rint(x);
00279 }
00280 #endif /* HAVE_LLRINT */
00281 
00282 #if !HAVE_LRINT
00283 static av_always_inline av_const long int lrint(double x)
00284 {
00285     return rint(x);
00286 }
00287 #endif /* HAVE_LRINT */
00288 
00289 #if !HAVE_LRINTF
00290 static av_always_inline av_const long int lrintf(float x)
00291 {
00292     return (int)(rint(x));
00293 }
00294 #endif /* HAVE_LRINTF */
00295 
00296 #if !HAVE_ROUND
00297 static av_always_inline av_const double round(double x)
00298 {
00299     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
00300 }
00301 #endif /* HAVE_ROUND */
00302 
00303 #if !HAVE_ROUNDF
00304 static av_always_inline av_const float roundf(float x)
00305 {
00306     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
00307 }
00308 #endif /* HAVE_ROUNDF */
00309 
00310 #if !HAVE_TRUNCF
00311 static av_always_inline av_const float truncf(float x)
00312 {
00313     return (x > 0) ? floor(x) : ceil(x);
00314 }
00315 #endif /* HAVE_TRUNCF */
00316 
00322 #if CONFIG_SMALL
00323 #   define NULL_IF_CONFIG_SMALL(x) NULL
00324 #else
00325 #   define NULL_IF_CONFIG_SMALL(x) x
00326 #endif
00327 
00328 #endif /* AVUTIL_INTERNAL_H */

Generated on Sat Feb 16 2013 09:23:12 for ffmpeg by  doxygen 1.7.1