Commit | Line | Data |
---|---|---|
04d7f601 DB |
1 | /* |
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | |
3 | * | |
b78e7197 DB |
4 | * This file is part of FFmpeg. |
5 | * | |
6 | * FFmpeg is free software; you can redistribute it and/or | |
04d7f601 DB |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either | |
b78e7197 | 9 | * version 2.1 of the License, or (at your option) any later version. |
04d7f601 | 10 | * |
b78e7197 | 11 | * FFmpeg is distributed in the hope that it will be useful, |
04d7f601 DB |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
b78e7197 | 17 | * License along with FFmpeg; if not, write to the Free Software |
04d7f601 DB |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | */ | |
20 | ||
05020c89 RD |
21 | /** |
22 | * @file internal.h | |
23 | * common internal api header. | |
24 | */ | |
25 | ||
26 | #ifndef INTERNAL_H | |
27 | #define INTERNAL_H | |
28 | ||
29 | #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC) | |
30 | # define PIC | |
31 | #endif | |
32 | ||
635eb0cc MR |
33 | #ifndef ENODATA |
34 | # define ENODATA 61 | |
35 | #endif | |
05020c89 | 36 | |
aab77159 RD |
37 | #include "bswap.h" |
38 | ||
05020c89 RD |
39 | #include <stddef.h> |
40 | #ifndef offsetof | |
635eb0cc | 41 | # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) |
05020c89 RD |
42 | #endif |
43 | ||
05020c89 RD |
44 | #ifdef __MINGW32__ |
45 | # ifdef _DEBUG | |
46 | # define DEBUG | |
47 | # endif | |
48 | ||
49 | # define snprintf _snprintf | |
50 | # define vsnprintf _vsnprintf | |
51 | ||
52 | # ifdef CONFIG_WINCE | |
53 | # define perror(a) | |
f940f7c9 | 54 | # define abort() |
05020c89 RD |
55 | # endif |
56 | ||
57 | /* __MINGW32__ end */ | |
58 | #elif defined (CONFIG_OS2) | |
59 | /* OS/2 EMX */ | |
60 | ||
635eb0cc | 61 | # include <float.h> |
05020c89 RD |
62 | |
63 | #endif /* !__MINGW32__ && CONFIG_OS2 */ | |
64 | ||
635eb0cc MR |
65 | #ifdef USE_FASTMEMCPY |
66 | # include "libvo/fastmemcpy.h" | |
67 | #endif | |
05020c89 RD |
68 | |
69 | // Use rip-relative addressing if compiling PIC code on x86-64. | |
635eb0cc MR |
70 | #if defined(__MINGW32__) || defined(__CYGWIN__) || \ |
71 | defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) | |
72 | # if defined(ARCH_X86_64) && defined(PIC) | |
73 | # define MANGLE(a) "_" #a"(%%rip)" | |
05020c89 | 74 | # else |
635eb0cc | 75 | # define MANGLE(a) "_" #a |
05020c89 | 76 | # endif |
635eb0cc MR |
77 | #else |
78 | # if defined(ARCH_X86_64) && defined(PIC) | |
79 | # define MANGLE(a) #a"(%%rip)" | |
80 | # elif defined(CONFIG_DARWIN) | |
81 | # define MANGLE(a) "_" #a | |
82 | # else | |
83 | # define MANGLE(a) #a | |
84 | # endif | |
85 | #endif | |
05020c89 RD |
86 | |
87 | /* debug stuff */ | |
88 | ||
635eb0cc MR |
89 | #if !defined(DEBUG) && !defined(NDEBUG) |
90 | # define NDEBUG | |
91 | #endif | |
92 | #include <assert.h> | |
05020c89 RD |
93 | |
94 | /* dprintf macros */ | |
635eb0cc MR |
95 | #ifdef DEBUG |
96 | # define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__) | |
97 | #else | |
98 | # define dprintf(fmt,...) | |
99 | #endif | |
05020c89 | 100 | |
635eb0cc | 101 | #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) |
05020c89 | 102 | |
36cd3069 | 103 | extern const uint32_t ff_inverse[256]; |
05020c89 | 104 | |
3cd52279 | 105 | #if defined(ARCH_X86) |
05020c89 RD |
106 | # define FASTDIV(a,b) \ |
107 | ({\ | |
108 | int ret,dmy;\ | |
109 | asm volatile(\ | |
110 | "mull %3"\ | |
111 | :"=d"(ret),"=a"(dmy)\ | |
36cd3069 | 112 | :"1"(a),"g"(ff_inverse[b])\ |
05020c89 RD |
113 | );\ |
114 | ret;\ | |
115 | }) | |
eeebe6ad SS |
116 | #elif defined(ARCH_ARMV4L) |
117 | # define FASTDIV(a,b) \ | |
118 | ({\ | |
119 | int ret,dmy;\ | |
120 | asm volatile(\ | |
121 | "umull %1, %0, %2, %3"\ | |
122 | :"=&r"(ret),"=&r"(dmy)\ | |
36cd3069 | 123 | :"r"(a),"r"(ff_inverse[b])\ |
eeebe6ad SS |
124 | );\ |
125 | ret;\ | |
126 | }) | |
05020c89 | 127 | #elif defined(CONFIG_FASTDIV) |
36cd3069 | 128 | # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32)) |
05020c89 RD |
129 | #else |
130 | # define FASTDIV(a,b) ((a)/(b)) | |
131 | #endif | |
132 | ||
133 | /* math */ | |
134 | extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128]; | |
135 | ||
136 | static inline int ff_sqrt(int a) | |
137 | { | |
138 | int ret=0; | |
139 | int s; | |
140 | int ret_sq=0; | |
141 | ||
142 | if(a<128) return ff_sqrt_tab[a]; | |
143 | ||
144 | for(s=15; s>=0; s--){ | |
145 | int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; | |
146 | if(b<=a){ | |
147 | ret_sq=b; | |
148 | ret+= 1<<s; | |
149 | } | |
150 | } | |
151 | return ret; | |
152 | } | |
153 | ||
3cd52279 | 154 | #if defined(ARCH_X86) |
05020c89 RD |
155 | #define MASK_ABS(mask, level)\ |
156 | asm volatile(\ | |
157 | "cdq \n\t"\ | |
158 | "xorl %1, %0 \n\t"\ | |
159 | "subl %1, %0 \n\t"\ | |
160 | : "+a" (level), "=&d" (mask)\ | |
161 | ); | |
162 | #else | |
163 | #define MASK_ABS(mask, level)\ | |
164 | mask= level>>31;\ | |
165 | level= (level^mask)-mask; | |
166 | #endif | |
167 | ||
94e4c3a3 | 168 | #ifdef HAVE_CMOV |
05020c89 RD |
169 | #define COPY3_IF_LT(x,y,a,b,c,d)\ |
170 | asm volatile (\ | |
171 | "cmpl %0, %3 \n\t"\ | |
172 | "cmovl %3, %0 \n\t"\ | |
173 | "cmovl %4, %1 \n\t"\ | |
174 | "cmovl %5, %2 \n\t"\ | |
175 | : "+r" (x), "+r" (a), "+r" (c)\ | |
176 | : "r" (y), "r" (b), "r" (d)\ | |
177 | ); | |
178 | #else | |
179 | #define COPY3_IF_LT(x,y,a,b,c,d)\ | |
180 | if((y)<(x)){\ | |
181 | (x)=(y);\ | |
182 | (a)=(b);\ | |
183 | (c)=(d);\ | |
184 | } | |
185 | #endif | |
186 | ||
187 | /* avoid usage of various functions */ | |
188 | #define malloc please_use_av_malloc | |
189 | #define free please_use_av_free | |
190 | #define realloc please_use_av_realloc | |
191 | #define time time_is_forbidden_due_to_security_issues | |
192 | #define rand rand_is_forbidden_due_to_state_trashing | |
193 | #define srand srand_is_forbidden_due_to_state_trashing | |
194 | #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf | |
195 | #define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat | |
196 | #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H)) | |
197 | #define printf please_use_av_log | |
198 | #define fprintf please_use_av_log | |
199 | #endif | |
200 | ||
201 | #define CHECKED_ALLOCZ(p, size)\ | |
202 | {\ | |
203 | p= av_mallocz(size);\ | |
204 | if(p==NULL && (size)!=0){\ | |
205 | perror("malloc");\ | |
206 | goto fail;\ | |
207 | }\ | |
208 | } | |
209 | ||
210 | #ifndef HAVE_LRINTF | |
211 | /* XXX: add ISOC specific test to avoid specific BSD testing. */ | |
212 | /* better than nothing implementation. */ | |
213 | /* btw, rintf() is existing on fbsd too -- alex */ | |
214 | static always_inline long int lrintf(float x) | |
215 | { | |
216 | #ifdef __MINGW32__ | |
419b8784 | 217 | # ifdef ARCH_X86_32 |
05020c89 RD |
218 | int32_t i; |
219 | asm volatile( | |
220 | "fistpl %0\n\t" | |
221 | : "=m" (i) : "t" (x) : "st" | |
222 | ); | |
223 | return i; | |
224 | # else | |
225 | /* XXX: incorrect, but make it compile */ | |
226 | return (int)(x + (x < 0 ? -0.5 : 0.5)); | |
419b8784 | 227 | # endif /* ARCH_X86_32 */ |
05020c89 RD |
228 | #else |
229 | return (int)(rint(x)); | |
230 | #endif /* __MINGW32__ */ | |
231 | } | |
232 | #endif /* HAVE_LRINTF */ | |
233 | ||
234 | #endif /* INTERNAL_H */ |