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