4 #define FFMPEG_VERSION_INT 0x000406
5 #define FFMPEG_VERSION "0.4.6"
7 #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
11 //#define ALT_BITSTREAM_READER
12 //#define ALIGNED_BITSTREAM
13 #define FAST_GET_FIRST_VLC
15 #ifdef HAVE_AV_CONFIG_H
16 /* only include the following when compiling package */
17 #include "../config.h"
34 typedef unsigned short UINT16;
35 typedef signed short INT16;
36 typedef unsigned char UINT8;
37 typedef unsigned int UINT32;
38 typedef unsigned __int64 UINT64;
39 typedef signed char INT8;
40 typedef signed int INT32;
41 typedef signed __int64 INT64;
43 typedef UINT8 uint8_t;
45 typedef UINT16 uint16_t;
46 typedef INT16 int16_t;
47 typedef UINT32 uint32_t;
48 typedef INT32 int32_t;
51 #define INT64_C(c) (c ## i64)
52 #define UINT64_C(c) (c ## i64)
54 #define inline __inline
57 Disable warning messages:
58 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
59 warning C4305: 'argument' : truncation from 'const double' to 'float'
61 #pragma warning( disable : 4244 )
62 #pragma warning( disable : 4305 )
65 #define INT64_C(c) (c ## LL)
66 #define UINT64_C(c) (c ## ULL)
67 #endif /* __MINGW32__ */
69 #define M_PI 3.14159265358979323846
70 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
76 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
78 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
79 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
80 #define be2me_32(x) bswap_32(x)
82 #define snprintf _snprintf
85 /* no config.h with VC */
86 #define CONFIG_ENCODERS 1
87 #define CONFIG_DECODERS 1
97 #ifndef __WINE_WINDEF16_H
98 /* workaround for typedef conflict in MPlayer (wine typedefs) */
99 typedef unsigned short UINT16;
100 typedef signed short INT16;
103 typedef unsigned char UINT8;
104 typedef unsigned int UINT32;
105 typedef unsigned long long UINT64;
106 typedef signed char INT8;
107 typedef signed int INT32;
108 typedef signed long long INT64;
110 #ifdef HAVE_AV_CONFIG_H
113 #include <sys/param.h>
117 #define INT64_C(c) (c ## LL)
118 #define UINT64_C(c) (c ## ULL)
121 #include "../bswap.h"
123 #ifdef USE_FASTMEMCPY
124 #include "fastmemcpy.h"
127 #endif /* HAVE_AV_CONFIG_H */
129 #endif /* !CONFIG_WIN32 */
133 #ifdef HAVE_AV_CONFIG_H
141 #if defined(CONFIG_WIN32) && !defined(__MINGW32__)
143 inline void dprintf(const char* fmt,...) {}
148 #define dprintf(fmt,args...) printf(fmt, ## args)
150 #define dprintf(fmt,args...)
153 #endif /* !CONFIG_WIN32 */
155 #endif /* HAVE_AV_CONFIG_H */
159 struct PutBitContext;
161 typedef void (*WriteDataFunc)(void *, UINT8 *, int);
163 typedef struct PutBitContext {
166 UINT8 *buf, *buf_ptr, *buf_end;
167 INT64 data_out_size; /* in bytes */
169 WriteDataFunc write_data;
172 void init_put_bits(PutBitContext *s,
173 UINT8 *buffer, int buffer_size,
175 void (*write_data)(void *, UINT8 *, int));
176 void put_bits(PutBitContext *s, int n, unsigned int value);
177 INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */
178 void align_put_bits(PutBitContext *s);
179 void flush_put_bits(PutBitContext *s);
181 /* jpeg specific put_bits */
182 void jput_bits(PutBitContext *s, int n, unsigned int value);
183 void jflush_put_bits(PutBitContext *s);
187 typedef struct GetBitContext {
188 #ifdef ALT_BITSTREAM_READER
194 UINT8 *buf, *buf_ptr, *buf_end;
202 int table_size, table_allocated;
205 /* used to avoid missaligned exceptions on some archs (alpha, ...) */
207 #define unaligned32(a) (*(UINT32*)(a))
210 static inline uint32_t unaligned32(const void *v) {
213 } __attribute__((packed));
215 return ((const struct Unaligned *) v)->i;
217 #elif defined(__DECC)
218 static inline uint32_t unaligned32(const void *v) {
219 return *(const __unaligned uint32_t *) v;
222 static inline uint32_t unaligned32(const void *v) {
223 return *(const uint32_t *) v;
228 void init_get_bits(GetBitContext *s,
229 UINT8 *buffer, int buffer_size);
231 #ifndef ALT_BITSTREAM_READER
232 unsigned int get_bits_long(GetBitContext *s, int n);
233 unsigned int show_bits_long(GetBitContext *s, int n);
236 static inline unsigned int get_bits(GetBitContext *s, int n){
237 #ifdef ALT_BITSTREAM_READER
238 #ifdef ALIGNED_BITSTREAM
240 uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] );
241 uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] );
243 asm ("shldl %%cl, %2, %0\n\t"
245 : "0" (result1), "r" (result2), "c" (index));
247 result1<<= (index&0x1F);
248 result2= (result2>>1) >> (31-(index&0x1F));
256 #else //ALIGNED_BITSTREAM
258 uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) );
260 result<<= (index&0x07);
266 #endif //!ALIGNED_BITSTREAM
267 #else //ALT_BITSTREAM_READER
269 /* most common case here */
270 unsigned int val = s->bit_buf >> (32 - n);
274 st_bit_counts[st_current_index] += n;
278 return get_bits_long(s,n);
279 #endif //!ALT_BITSTREAM_READER
282 static inline unsigned int get_bits1(GetBitContext *s){
283 #ifdef ALT_BITSTREAM_READER
285 uint8_t result= s->buffer[ index>>3 ];
286 result<<= (index&0x07);
294 /* most common case here */
295 unsigned int val = s->bit_buf >> 31;
299 st_bit_counts[st_current_index]++;
303 return get_bits_long(s,1);
307 /* This function is identical to get_bits(), the only */
308 /* diference is that it doesn't touch the buffer */
309 /* it is usefull to see the buffer. */
310 static inline unsigned int show_bits(GetBitContext *s, int n)
312 #ifdef ALT_BITSTREAM_READER
313 #ifdef ALIGNED_BITSTREAM
315 uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] );
316 uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] );
318 asm ("shldl %%cl, %2, %0\n\t"
320 : "0" (result1), "r" (result2), "c" (index));
322 result1<<= (index&0x1F);
323 result2= (result2>>1) >> (31-(index&0x1F));
329 #else //ALIGNED_BITSTREAM
331 uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) );
333 result<<= (index&0x07);
337 #endif //!ALIGNED_BITSTREAM
338 #else //ALT_BITSTREAM_READER
340 /* most common case here */
341 unsigned int val = s->bit_buf >> (32 - n);
344 return show_bits_long(s,n);
345 #endif //!ALT_BITSTREAM_READER
348 static inline void skip_bits(GetBitContext *s, int n){
349 #ifdef ALT_BITSTREAM_READER
353 /* most common case here */
357 st_bit_counts[st_current_index] += n;
365 static inline void skip_bits1(GetBitContext *s){
366 #ifdef ALT_BITSTREAM_READER
370 /* most common case here */
374 st_bit_counts[st_current_index]++;
382 static inline int get_bits_count(GetBitContext *s)
384 #ifdef ALT_BITSTREAM_READER
387 return (s->buf_ptr - s->buf) * 8 - s->bit_cnt;
391 void align_get_bits(GetBitContext *s);
392 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
393 const void *bits, int bits_wrap, int bits_size,
394 const void *codes, int codes_wrap, int codes_size);
395 void free_vlc(VLC *vlc);
397 #ifdef ALT_BITSTREAM_READER
398 #ifdef ALIGNED_BITSTREAM
400 #define SHOW_BITS(s, val, n) \
401 val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
402 {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
403 asm ("shldl %%cl, %2, %0\n\t"\
405 : "0" (val), "r" (result2), "c" (bit_cnt));\
406 ((uint32_t)val)>>= 32 - n;}
408 #define SHOW_BITS(s, val, n) \
409 val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
410 {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
411 val<<= (bit_cnt&0x1F);\
412 result2= (result2>>1) >> (31-(bit_cnt&0x1F));\
414 ((uint32_t)val)>>= 32 - n;}
416 #else //ALIGNED_BITSTREAM
417 #define SHOW_BITS(s, val, n) \
418 val= be2me_32( unaligned32( ((uint8_t *)(s)->buffer)+(bit_cnt>>3) ) );\
419 val<<= (bit_cnt&0x07);\
420 ((uint32_t)val)>>= 32 - n;
421 #endif // !ALIGNED_BITSTREAM
422 #define FLUSH_BITS(n) bit_cnt+=n;
423 #define SAVE_BITS(s) bit_cnt= (s)->index;
424 #define RESTORE_BITS(s) (s)->index= bit_cnt;
427 /* macro to go faster */
428 /* n must be <= 24 */
429 /* XXX: optimize buffer end test */
430 #define SHOW_BITS(s, val, n)\
432 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
433 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
435 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
436 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
438 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
439 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
444 val = bit_buf >> (32 - n);\
447 /* SHOW_BITS with n1 >= n must be been done before */
448 #define FLUSH_BITS(n)\
454 #define SAVE_BITS(s) \
456 bit_cnt = (s)->bit_cnt;\
457 bit_buf = (s)->bit_buf;\
458 buf_ptr = (s)->buf_ptr;\
461 #define RESTORE_BITS(s) \
463 (s)->buf_ptr = buf_ptr;\
464 (s)->bit_buf = bit_buf;\
465 (s)->bit_cnt = bit_cnt;\
467 #endif // !ALT_BITSTREAM_READER
469 static inline int get_vlc(GetBitContext *s, VLC *vlc)
471 int code, n, nb_bits, index;
475 #ifndef ALT_BITSTREAM_READER
482 table_codes = vlc->table_codes;
483 table_bits = vlc->table_bits;
485 #ifdef FAST_GET_FIRST_VLC
486 SHOW_BITS(s, index, nb_bits);
487 code = table_codes[index];
488 n = table_bits[index];
490 /* most common case (90%)*/
499 table_codes = vlc->table_codes + code;
500 table_bits = vlc->table_bits + code;
504 SHOW_BITS(s, index, nb_bits);
505 code = table_codes[index];
506 n = table_bits[index];
508 /* most common case */
511 st_bit_counts[st_current_index] += n;
519 st_bit_counts[st_current_index] += nb_bits;
522 table_codes = vlc->table_codes + code;
523 table_bits = vlc->table_bits + code;
531 /* define it to include statistics code (useful only for optimizing
548 extern int st_current_index;
549 extern unsigned int st_bit_counts[ST_NB];
550 extern unsigned int st_out_bit_counts[ST_NB];
552 void print_stats(void);
555 /* misc math functions */
557 static inline int av_log2(unsigned int v)
562 if (v & 0xffff0000) {
585 void *av_mallocz(int size);