Disable B-frames decoding until they produce correct picture
[libav.git] / libavutil / internal.h
CommitLineData
05020c89
RD
1/**
2 * @file internal.h
3 * common internal api header.
4 */
5
6#ifndef INTERNAL_H
7#define INTERNAL_H
8
9#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
10# define PIC
11#endif
12
13# ifndef ENODATA
14# define ENODATA 61
15# endif
16
aab77159
RD
17#include "bswap.h"
18
05020c89
RD
19#include <stddef.h>
20#ifndef offsetof
21# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
22#endif
23
05020c89
RD
24#ifdef __MINGW32__
25# ifdef _DEBUG
26# define DEBUG
27# endif
28
29# define snprintf _snprintf
30# define vsnprintf _vsnprintf
31
32# ifdef CONFIG_WINCE
33# define perror(a)
34# endif
35
36/* __MINGW32__ end */
37#elif defined (CONFIG_OS2)
38/* OS/2 EMX */
39
40#include <float.h>
41
42#endif /* !__MINGW32__ && CONFIG_OS2 */
43
44# ifdef USE_FASTMEMCPY
f4bd289a 45# include "libvo/fastmemcpy.h"
05020c89
RD
46# endif
47
48// Use rip-relative addressing if compiling PIC code on x86-64.
49# if defined(__MINGW32__) || defined(__CYGWIN__) || \
50 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
51# if defined(ARCH_X86_64) && defined(PIC)
52# define MANGLE(a) "_" #a"(%%rip)"
53# else
54# define MANGLE(a) "_" #a
55# endif
56# else
57# if defined(ARCH_X86_64) && defined(PIC)
58# define MANGLE(a) #a"(%%rip)"
59# elif defined(CONFIG_DARWIN)
60# define MANGLE(a) "_" #a
61# else
62# define MANGLE(a) #a
63# endif
64# endif
65
66/* debug stuff */
67
68# if !defined(DEBUG) && !defined(NDEBUG)
69# define NDEBUG
70# endif
71# include <assert.h>
72
73/* dprintf macros */
74# ifdef DEBUG
75# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
76# else
77# define dprintf(fmt,...)
78# endif
79
80# ifdef CONFIG_WINCE
81# define abort()
82# endif
83
84# define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
85
86extern const uint32_t inverse[256];
87
88#if defined(ARCH_X86) || defined(ARCH_X86_64)
89# define FASTDIV(a,b) \
90 ({\
91 int ret,dmy;\
92 asm volatile(\
93 "mull %3"\
94 :"=d"(ret),"=a"(dmy)\
95 :"1"(a),"g"(inverse[b])\
96 );\
97 ret;\
98 })
99#elif defined(CONFIG_FASTDIV)
100# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
101#else
102# define FASTDIV(a,b) ((a)/(b))
103#endif
104
105/* math */
106extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128];
107
108static inline int ff_sqrt(int a)
109{
110 int ret=0;
111 int s;
112 int ret_sq=0;
113
114 if(a<128) return ff_sqrt_tab[a];
115
116 for(s=15; s>=0; s--){
117 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
118 if(b<=a){
119 ret_sq=b;
120 ret+= 1<<s;
121 }
122 }
123 return ret;
124}
125
126#if defined(ARCH_X86) || defined(ARCH_X86_64)
127#define MASK_ABS(mask, level)\
128 asm volatile(\
129 "cdq \n\t"\
130 "xorl %1, %0 \n\t"\
131 "subl %1, %0 \n\t"\
132 : "+a" (level), "=&d" (mask)\
133 );
134#else
135#define MASK_ABS(mask, level)\
136 mask= level>>31;\
137 level= (level^mask)-mask;
138#endif
139
140#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
141#define COPY3_IF_LT(x,y,a,b,c,d)\
142asm volatile (\
143 "cmpl %0, %3 \n\t"\
144 "cmovl %3, %0 \n\t"\
145 "cmovl %4, %1 \n\t"\
146 "cmovl %5, %2 \n\t"\
147 : "+r" (x), "+r" (a), "+r" (c)\
148 : "r" (y), "r" (b), "r" (d)\
149);
150#else
151#define COPY3_IF_LT(x,y,a,b,c,d)\
152if((y)<(x)){\
153 (x)=(y);\
154 (a)=(b);\
155 (c)=(d);\
156}
157#endif
158
159/* avoid usage of various functions */
160#define malloc please_use_av_malloc
161#define free please_use_av_free
162#define realloc please_use_av_realloc
163#define time time_is_forbidden_due_to_security_issues
164#define rand rand_is_forbidden_due_to_state_trashing
165#define srand srand_is_forbidden_due_to_state_trashing
166#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
167#define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
168#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
169#define printf please_use_av_log
170#define fprintf please_use_av_log
171#endif
172
173#define CHECKED_ALLOCZ(p, size)\
174{\
175 p= av_mallocz(size);\
176 if(p==NULL && (size)!=0){\
177 perror("malloc");\
178 goto fail;\
179 }\
180}
181
182#ifndef HAVE_LRINTF
183/* XXX: add ISOC specific test to avoid specific BSD testing. */
184/* better than nothing implementation. */
185/* btw, rintf() is existing on fbsd too -- alex */
186static always_inline long int lrintf(float x)
187{
188#ifdef __MINGW32__
189# ifdef ARCH_X86
190 int32_t i;
191 asm volatile(
192 "fistpl %0\n\t"
193 : "=m" (i) : "t" (x) : "st"
194 );
195 return i;
196# else
197 /* XXX: incorrect, but make it compile */
198 return (int)(x + (x < 0 ? -0.5 : 0.5));
199# endif /* ARCH_X86 */
200#else
201 return (int)(rint(x));
202#endif /* __MINGW32__ */
203}
204#endif /* HAVE_LRINTF */
205
206#endif /* INTERNAL_H */