Mercurial > libavcodec.hg
annotate common.h @ 80:f2d17413c4e3 libavcodec
memalign autodetection
author | nickols_k |
---|---|
date | Thu, 13 Sep 2001 07:16:59 +0000 |
parents | 0b09bd08ef4b |
children | b0bdab6b8bc6 |
rev | line source |
---|---|
0 | 1 #ifndef COMMON_H |
2 #define COMMON_H | |
3 | |
66 | 4 #define FFMPEG_VERSION_INT 0x000405 |
5 #define FFMPEG_VERSION "0.4.5" | |
64 | 6 |
76 | 7 #if defined(WIN32) && !defined(__MINGW32__) |
64 | 8 #define CONFIG_WIN32 |
9 #endif | |
10 | |
10 | 11 #ifdef HAVE_AV_CONFIG_H |
64 | 12 /* only include the following when compiling package */ |
0 | 13 #include "../config.h" |
64 | 14 |
15 #include <stdlib.h> | |
16 #include <stdio.h> | |
17 #include <string.h> | |
18 #include <errno.h> | |
19 | |
20 #ifndef ENODATA | |
21 #define ENODATA 61 | |
10 | 22 #endif |
0 | 23 |
64 | 24 #endif |
25 | |
26 #ifdef CONFIG_WIN32 | |
27 | |
28 /* windows */ | |
29 | |
30 typedef unsigned short UINT16; | |
31 typedef signed short INT16; | |
32 typedef unsigned char UINT8; | |
33 typedef unsigned int UINT32; | |
34 typedef unsigned __int64 UINT64; | |
35 typedef signed char INT8; | |
36 typedef signed int INT32; | |
37 typedef signed __int64 INT64; | |
38 | |
39 typedef UINT8 uint8_t; | |
40 typedef INT8 int8_t; | |
41 typedef UINT16 uint16_t; | |
42 typedef INT16 int16_t; | |
43 typedef UINT32 uint32_t; | |
44 typedef INT32 int32_t; | |
45 | |
76 | 46 #ifndef __MINGW32__ |
64 | 47 #define INT64_C(c) (c ## i64) |
48 #define UINT64_C(c) (c ## i64) | |
49 | |
50 #define inline __inline | |
51 | |
52 /* | |
53 Disable warning messages: | |
54 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data | |
55 warning C4305: 'argument' : truncation from 'const double' to 'float' | |
56 */ | |
57 #pragma warning( disable : 4244 ) | |
58 #pragma warning( disable : 4305 ) | |
59 | |
76 | 60 #else |
61 #define INT64_C(c) (c ## LL) | |
62 #define UINT64_C(c) (c ## ULL) | |
63 #endif /* __MINGW32__ */ | |
64 | |
64 | 65 #define M_PI 3.14159265358979323846 |
66 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | |
67 | |
68 #ifdef _DEBUG | |
69 #define DEBUG | |
70 #endif | |
71 | |
72 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | |
73 #define bswap_32(x) \ | |
74 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
75 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
76 #define be2me_32(x) bswap_32(x) | |
77 | |
78 #define snprintf _snprintf | |
79 | |
76 | 80 #ifndef __MINGW32__ |
81 /* no config.h with VC */ | |
64 | 82 #define CONFIG_ENCODERS 1 |
83 #define CONFIG_DECODERS 1 | |
84 #define CONFIG_AC3 1 | |
85 #define CONFIG_MPGLIB 1 | |
76 | 86 #endif |
64 | 87 |
88 #else | |
89 | |
90 /* unix */ | |
91 | |
92 #include <inttypes.h> | |
93 | |
2 | 94 #ifndef __WINE_WINDEF16_H |
95 /* workaround for typedef conflict in MPlayer (wine typedefs) */ | |
0 | 96 typedef unsigned short UINT16; |
97 typedef signed short INT16; | |
98 #endif | |
99 | |
100 typedef unsigned char UINT8; | |
101 typedef unsigned int UINT32; | |
102 typedef unsigned long long UINT64; | |
103 typedef signed char INT8; | |
104 typedef signed int INT32; | |
105 typedef signed long long INT64; | |
106 | |
64 | 107 #ifdef HAVE_AV_CONFIG_H |
108 | |
109 #ifdef __FreeBSD__ | |
110 #include <sys/param.h> | |
111 #endif | |
112 | |
113 #ifndef INT64_C | |
114 #define INT64_C(c) (c ## LL) | |
115 #define UINT64_C(c) (c ## ULL) | |
116 #endif | |
117 | |
118 #include "../bswap.h" | |
119 | |
120 #ifdef USE_FASTMEMCPY | |
121 #include "fastmemcpy.h" | |
122 #endif | |
123 | |
76 | 124 #endif /* HAVE_AV_CONFIG_H */ |
125 | |
126 #endif /* !CONFIG_WIN32 */ | |
127 | |
128 /* debug stuff */ | |
129 #ifdef HAVE_AV_CONFIG_H | |
130 | |
64 | 131 #ifndef DEBUG |
132 #define NDEBUG | |
133 #endif | |
134 #include <assert.h> | |
135 | |
76 | 136 /* dprintf macros */ |
137 #if defined(CONFIG_WIN32) && !defined(__MINGW32__) | |
138 | |
139 inline void dprintf(const char* fmt,...) {} | |
140 | |
141 #else | |
142 | |
143 #ifdef DEBUG | |
144 #define dprintf(fmt,args...) printf(fmt, ## args) | |
145 #else | |
146 #define dprintf(fmt,args...) | |
147 #endif | |
64 | 148 |
149 #endif /* !CONFIG_WIN32 */ | |
150 | |
76 | 151 #endif /* HAVE_AV_CONFIG_H */ |
152 | |
0 | 153 /* bit output */ |
154 | |
155 struct PutBitContext; | |
156 | |
157 typedef void (*WriteDataFunc)(void *, UINT8 *, int); | |
158 | |
159 typedef struct PutBitContext { | |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
160 UINT32 bit_buf; |
0 | 161 int bit_cnt; |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
162 UINT8 *buf, *buf_ptr, *buf_end; |
64 | 163 INT64 data_out_size; /* in bytes */ |
0 | 164 void *opaque; |
165 WriteDataFunc write_data; | |
166 } PutBitContext; | |
167 | |
168 void init_put_bits(PutBitContext *s, | |
169 UINT8 *buffer, int buffer_size, | |
170 void *opaque, | |
171 void (*write_data)(void *, UINT8 *, int)); | |
172 void put_bits(PutBitContext *s, int n, unsigned int value); | |
64 | 173 INT64 get_bit_count(PutBitContext *s); |
0 | 174 void align_put_bits(PutBitContext *s); |
175 void flush_put_bits(PutBitContext *s); | |
176 | |
177 /* jpeg specific put_bits */ | |
178 void jput_bits(PutBitContext *s, int n, unsigned int value); | |
179 void jflush_put_bits(PutBitContext *s); | |
180 | |
181 /* bit input */ | |
182 | |
183 typedef struct GetBitContext { | |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
184 UINT32 bit_buf; |
0 | 185 int bit_cnt; |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
186 UINT8 *buf, *buf_ptr, *buf_end; |
0 | 187 } GetBitContext; |
188 | |
189 typedef struct VLC { | |
190 int bits; | |
191 INT16 *table_codes; | |
192 INT8 *table_bits; | |
193 int table_size, table_allocated; | |
194 } VLC; | |
195 | |
196 void init_get_bits(GetBitContext *s, | |
197 UINT8 *buffer, int buffer_size); | |
198 | |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
199 unsigned int get_bits_long(GetBitContext *s, int n); |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
200 |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
201 static inline unsigned int get_bits(GetBitContext *s, int n){ |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
202 if(s->bit_cnt>=n){ |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
203 /* most common case here */ |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
204 unsigned int val = s->bit_buf >> (32 - n); |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
205 s->bit_buf <<= n; |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
206 s->bit_cnt -= n; |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
207 #ifdef STATS |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
208 st_bit_counts[st_current_index] += n; |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
209 #endif |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
210 return val; |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
211 } |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
212 return get_bits_long(s,n); |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
213 } |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
214 |
21 | 215 static inline unsigned int get_bits1(GetBitContext *s){ |
216 if(s->bit_cnt>0){ | |
217 /* most common case here */ | |
218 unsigned int val = s->bit_buf >> 31; | |
219 s->bit_buf <<= 1; | |
220 s->bit_cnt--; | |
221 #ifdef STATS | |
222 st_bit_counts[st_current_index]++; | |
223 #endif | |
224 return val; | |
225 } | |
226 return get_bits_long(s,1); | |
227 } | |
228 | |
229 static inline void skip_bits(GetBitContext *s, int n){ | |
230 if(s->bit_cnt>=n){ | |
231 /* most common case here */ | |
232 s->bit_buf <<= n; | |
233 s->bit_cnt -= n; | |
234 #ifdef STATS | |
235 st_bit_counts[st_current_index] += n; | |
236 #endif | |
237 } else { | |
238 get_bits_long(s,n); | |
239 } | |
240 } | |
241 | |
242 static inline void skip_bits1(GetBitContext *s){ | |
243 if(s->bit_cnt>0){ | |
244 /* most common case here */ | |
245 s->bit_buf <<= 1; | |
246 s->bit_cnt--; | |
247 #ifdef STATS | |
248 st_bit_counts[st_current_index]++; | |
249 #endif | |
250 } else { | |
251 get_bits_long(s,1); | |
252 } | |
253 } | |
254 | |
255 | |
0 | 256 void align_get_bits(GetBitContext *s); |
257 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |
258 const void *bits, int bits_wrap, int bits_size, | |
259 const void *codes, int codes_wrap, int codes_size); | |
260 void free_vlc(VLC *vlc); | |
261 int get_vlc(GetBitContext *s, VLC *vlc); | |
262 | |
263 /* macro to go faster */ | |
264 /* n must be <= 24 */ | |
265 /* XXX: optimize buffer end test */ | |
266 #define SHOW_BITS(s, val, n)\ | |
267 {\ | |
268 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
269 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
270 bit_cnt += 8;\ | |
271 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
272 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
273 bit_cnt += 8;\ | |
274 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ | |
275 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ | |
276 bit_cnt += 8;\ | |
277 }\ | |
278 }\ | |
279 }\ | |
280 val = bit_buf >> (32 - n);\ | |
281 } | |
282 | |
283 /* SHOW_BITS with n1 >= n must be been done before */ | |
284 #define FLUSH_BITS(n)\ | |
285 {\ | |
286 bit_buf <<= n;\ | |
287 bit_cnt -= n;\ | |
288 } | |
289 | |
290 #define SAVE_BITS(s) \ | |
291 {\ | |
292 bit_cnt = (s)->bit_cnt;\ | |
293 bit_buf = (s)->bit_buf;\ | |
294 buf_ptr = (s)->buf_ptr;\ | |
295 } | |
296 | |
297 #define RESTORE_BITS(s) \ | |
298 {\ | |
299 (s)->buf_ptr = buf_ptr;\ | |
300 (s)->bit_buf = bit_buf;\ | |
301 (s)->bit_cnt = bit_cnt;\ | |
302 } | |
303 | |
304 /* define it to include statistics code (useful only for optimizing | |
305 codec efficiency */ | |
306 //#define STATS | |
307 | |
308 #ifdef STATS | |
309 | |
310 enum { | |
311 ST_UNKNOWN, | |
312 ST_DC, | |
313 ST_INTRA_AC, | |
314 ST_INTER_AC, | |
315 ST_INTRA_MB, | |
316 ST_INTER_MB, | |
317 ST_MV, | |
318 ST_NB, | |
319 }; | |
320 | |
321 extern int st_current_index; | |
322 extern unsigned int st_bit_counts[ST_NB]; | |
323 extern unsigned int st_out_bit_counts[ST_NB]; | |
324 | |
325 void print_stats(void); | |
326 #endif | |
327 | |
328 /* misc math functions */ | |
329 | |
66 | 330 extern inline int av_log2(unsigned int v) |
0 | 331 { |
332 int n; | |
333 | |
334 n = 0; | |
335 if (v & 0xffff0000) { | |
336 v >>= 16; | |
337 n += 16; | |
338 } | |
339 if (v & 0xff00) { | |
340 v >>= 8; | |
341 n += 8; | |
342 } | |
343 if (v & 0xf0) { | |
344 v >>= 4; | |
345 n += 4; | |
346 } | |
347 if (v & 0xc) { | |
348 v >>= 2; | |
349 n += 2; | |
350 } | |
351 if (v & 0x2) { | |
352 n++; | |
353 } | |
354 return n; | |
355 } | |
356 | |
357 /* memory */ | |
358 void *av_mallocz(int size); | |
359 | |
360 #endif |