minor dststride bugfix for i420 output
[libav.git] / libavcodec / common.h
CommitLineData
de6d9b64
FB
1#ifndef COMMON_H
2#define COMMON_H
3
73120e55
FB
4#define FFMPEG_VERSION_INT 0x000406
5#define FFMPEG_VERSION "0.4.6"
1a565432 6
4bdd9157 7#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
1a565432
FB
8#define CONFIG_WIN32
9#endif
10
17592475 11//#define ALT_BITSTREAM_WRITER
4f0f8bfc 12//#define ALIGNED_BITSTREAM_WRITER
27a3e2c5 13//#define ALT_BITSTREAM_READER
3587d501 14//#define ALIGNED_BITSTREAM
05f361f0 15#define FAST_GET_FIRST_VLC
27a3e2c5 16
420b073b 17#ifdef HAVE_AV_CONFIG_H
1a565432 18/* only include the following when compiling package */
de6d9b64 19#include "../config.h"
1a565432
FB
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25
26#ifndef ENODATA
27#define ENODATA 61
28#endif
29
30#endif
31
32#ifdef CONFIG_WIN32
33
34/* windows */
35
36typedef unsigned short UINT16;
37typedef signed short INT16;
38typedef unsigned char UINT8;
39typedef unsigned int UINT32;
40typedef unsigned __int64 UINT64;
41typedef signed char INT8;
42typedef signed int INT32;
43typedef signed __int64 INT64;
44
45typedef UINT8 uint8_t;
46typedef INT8 int8_t;
47typedef UINT16 uint16_t;
48typedef INT16 int16_t;
49typedef UINT32 uint32_t;
50typedef INT32 int32_t;
51
a74127c0 52#ifndef __MINGW32__
1a565432
FB
53#define INT64_C(c) (c ## i64)
54#define UINT64_C(c) (c ## i64)
55
56#define inline __inline
57
58/*
59 Disable warning messages:
60 warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
61 warning C4305: 'argument' : truncation from 'const double' to 'float'
62*/
63#pragma warning( disable : 4244 )
64#pragma warning( disable : 4305 )
65
a74127c0
FB
66#else
67#define INT64_C(c) (c ## LL)
68#define UINT64_C(c) (c ## ULL)
69#endif /* __MINGW32__ */
70
1a565432
FB
71#define M_PI 3.14159265358979323846
72#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
73
74#ifdef _DEBUG
75#define DEBUG
420b073b 76#endif
de6d9b64 77
1a565432
FB
78// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
79#define bswap_32(x) \
80 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
81 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
82#define be2me_32(x) bswap_32(x)
83
84#define snprintf _snprintf
85
a74127c0
FB
86#ifndef __MINGW32__
87/* no config.h with VC */
1a565432
FB
88#define CONFIG_ENCODERS 1
89#define CONFIG_DECODERS 1
90#define CONFIG_AC3 1
a74127c0 91#endif
1a565432
FB
92
93#else
94
95/* unix */
96
97#include <inttypes.h>
98
980fc7b8
FB
99#ifndef __WINE_WINDEF16_H
100/* workaround for typedef conflict in MPlayer (wine typedefs) */
de6d9b64
FB
101typedef unsigned short UINT16;
102typedef signed short INT16;
103#endif
104
105typedef unsigned char UINT8;
106typedef unsigned int UINT32;
107typedef unsigned long long UINT64;
108typedef signed char INT8;
109typedef signed int INT32;
110typedef signed long long INT64;
111
1a565432
FB
112#ifdef HAVE_AV_CONFIG_H
113
114#ifdef __FreeBSD__
115#include <sys/param.h>
116#endif
117
118#ifndef INT64_C
119#define INT64_C(c) (c ## LL)
120#define UINT64_C(c) (c ## ULL)
121#endif
122
123#include "../bswap.h"
124
125#ifdef USE_FASTMEMCPY
126#include "fastmemcpy.h"
127#endif
128
a74127c0
FB
129#endif /* HAVE_AV_CONFIG_H */
130
131#endif /* !CONFIG_WIN32 */
132
27a3e2c5 133
a74127c0
FB
134/* debug stuff */
135#ifdef HAVE_AV_CONFIG_H
136
1a565432
FB
137#ifndef DEBUG
138#define NDEBUG
139#endif
140#include <assert.h>
141
a74127c0
FB
142/* dprintf macros */
143#if defined(CONFIG_WIN32) && !defined(__MINGW32__)
144
145inline void dprintf(const char* fmt,...) {}
146
147#else
148
149#ifdef DEBUG
150#define dprintf(fmt,args...) printf(fmt, ## args)
151#else
152#define dprintf(fmt,args...)
153#endif
1a565432
FB
154
155#endif /* !CONFIG_WIN32 */
156
a74127c0
FB
157#endif /* HAVE_AV_CONFIG_H */
158
de6d9b64
FB
159/* bit output */
160
161struct PutBitContext;
162
163typedef void (*WriteDataFunc)(void *, UINT8 *, int);
164
165typedef struct PutBitContext {
17592475
MN
166#ifdef ALT_BITSTREAM_WRITER
167 UINT8 *buf, *buf_end;
168 int index;
169#else
de6d9b64 170 UINT32 bit_buf;
2931ecb9
A
171 int bit_cnt;
172 UINT8 *buf, *buf_ptr, *buf_end;
de6d9b64
FB
173 void *opaque;
174 WriteDataFunc write_data;
17592475
MN
175#endif
176 INT64 data_out_size; /* in bytes */
de6d9b64
FB
177} PutBitContext;
178
179void init_put_bits(PutBitContext *s,
180 UINT8 *buffer, int buffer_size,
181 void *opaque,
182 void (*write_data)(void *, UINT8 *, int));
17592475
MN
183
184#ifndef ALT_BITSTREAM_WRITER
de6d9b64 185void put_bits(PutBitContext *s, int n, unsigned int value);
17592475
MN
186#endif
187
9dbf9389 188INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */
de6d9b64
FB
189void align_put_bits(PutBitContext *s);
190void flush_put_bits(PutBitContext *s);
191
192/* jpeg specific put_bits */
17592475 193#ifndef ALT_BITSTREAM_WRITER
de6d9b64 194void jput_bits(PutBitContext *s, int n, unsigned int value);
17592475 195#endif
de6d9b64
FB
196void jflush_put_bits(PutBitContext *s);
197
198/* bit input */
199
200typedef struct GetBitContext {
27a3e2c5
MN
201#ifdef ALT_BITSTREAM_READER
202 int index;
203 UINT8 *buffer;
204#else
de6d9b64 205 UINT32 bit_buf;
2931ecb9
A
206 int bit_cnt;
207 UINT8 *buf, *buf_ptr, *buf_end;
27a3e2c5 208#endif
de6d9b64
FB
209} GetBitContext;
210
211typedef struct VLC {
212 int bits;
213 INT16 *table_codes;
214 INT8 *table_bits;
215 int table_size, table_allocated;
216} VLC;
217
3587d501
MN
218/* used to avoid missaligned exceptions on some archs (alpha, ...) */
219#ifdef ARCH_X86
220#define unaligned32(a) (*(UINT32*)(a))
221#else
222#ifdef __GNUC__
223static inline uint32_t unaligned32(const void *v) {
224 struct Unaligned {
225 uint32_t i;
226 } __attribute__((packed));
227
228 return ((const struct Unaligned *) v)->i;
229}
230#elif defined(__DECC)
231static inline uint32_t unaligned32(const void *v) {
232 return *(const __unaligned uint32_t *) v;
233}
234#else
235static inline uint32_t unaligned32(const void *v) {
236 return *(const uint32_t *) v;
237}
238#endif
239#endif //!ARCH_X86
240
17592475 241#ifdef ALT_BITSTREAM_WRITER
4f0f8bfc 242static inline void put_bits(PutBitContext *s, int n, unsigned int value)
17592475 243{
4f0f8bfc
MN
244#ifdef ALIGNED_BITSTREAM_WRITER
245#ifdef ARCH_X86
246 asm volatile(
247 "movl %0, %%ecx \n\t"
248 "xorl %%eax, %%eax \n\t"
249 "shrdl %%cl, %1, %%eax \n\t"
250 "shrl %%cl, %1 \n\t"
251 "movl %0, %%ecx \n\t"
252 "shrl $3, %%ecx \n\t"
253 "andl $0xFFFFFFFC, %%ecx \n\t"
254 "bswapl %1 \n\t"
255 "orl %1, (%2, %%ecx) \n\t"
256 "bswapl %%eax \n\t"
257 "addl %3, %0 \n\t"
258 "movl %%eax, 4(%2, %%ecx) \n\t"
259 : "=&r" (s->index), "=&r" (value)
260 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
261 : "%eax", "%ecx"
262 );
263#else
264 int index= s->index;
265 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
266
267 value<<= 32-n;
268
269 ptr[0] |= be2me_32(value>>(index&31));
270 ptr[1] = be2me_32(value<<(32-(index&31)));
271//if(n>24) printf("%d %d\n", n, value);
272 index+= n;
273 s->index= index;
274#endif
275#else //ALIGNED_BITSTREAM_WRITER
17592475
MN
276#ifdef ARCH_X86
277 asm volatile(
278 "movl $7, %%ecx \n\t"
279 "andl %0, %%ecx \n\t"
280 "addl %3, %%ecx \n\t"
281 "negl %%ecx \n\t"
282 "shll %%cl, %1 \n\t"
283 "bswapl %1 \n\t"
284 "movl %0, %%ecx \n\t"
285 "shrl $3, %%ecx \n\t"
286 "orl %1, (%%ecx, %2) \n\t"
287 "addl %3, %0 \n\t"
288 "movl $0, 4(%%ecx, %2) \n\t"
289 : "=&r" (s->index), "=&r" (value)
290 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
291 : "%ecx"
292 );
293#else
294 int index= s->index;
295 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
296
297 ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
298 ptr[1] = 0;
299//if(n>24) printf("%d %d\n", n, value);
300 index+= n;
301 s->index= index;
302#endif
4f0f8bfc 303#endif //!ALIGNED_BITSTREAM_WRITER
17592475
MN
304}
305#endif
306
307#ifdef ALT_BITSTREAM_WRITER
308static inline void jput_bits(PutBitContext *s, int n, int value)
309{
310 int index= s->index;
311 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
312 int v= ptr[0];
313//if(n>24) printf("%d %d\n", n, value);
314
315 v |= be2me_32(value<<(32-n-(index&7) ));
316 if(((v+0x01010101)^0xFFFFFFFF)&v&0x80808080)
317 {
318 /* handle idiotic (m)jpeg escapes */
319 uint8_t *bPtr= (uint8_t*)ptr;
320 int numChecked= ((index+n)>>3) - (index>>3);
321
322 v= be2me_32(v);
323
324 *(bPtr++)= v>>24;
325 if((v&0xFF000000)==0xFF000000 && numChecked>0){
326 *(bPtr++)= 0x00;
327 index+=8;
328 }
329 *(bPtr++)= (v>>16)&0xFF;
330 if((v&0x00FF0000)==0x00FF0000 && numChecked>1){
331 *(bPtr++)= 0x00;
332 index+=8;
333 }
334 *(bPtr++)= (v>>8)&0xFF;
335 if((v&0x0000FF00)==0x0000FF00 && numChecked>2){
336 *(bPtr++)= 0x00;
337 index+=8;
338 }
339 *(bPtr++)= v&0xFF;
340 if((v&0x000000FF)==0x000000FF && numChecked>3){
341 *(bPtr++)= 0x00;
342 index+=8;
343 }
344 *((uint32_t*)bPtr)= 0;
345 }
346 else
347 {
348 ptr[0] = v;
349 ptr[1] = 0;
350 }
351
352 index+= n;
353 s->index= index;
354 }
355#endif
356
357
358static inline uint8_t* pbBufPtr(PutBitContext *s)
359{
360#ifdef ALT_BITSTREAM_WRITER
361 return s->buf + (s->index>>3);
362#else
363 return s->buf_ptr;
364#endif
365}
366
de6d9b64
FB
367void init_get_bits(GetBitContext *s,
368 UINT8 *buffer, int buffer_size);
369
27a3e2c5 370#ifndef ALT_BITSTREAM_READER
2931ecb9 371unsigned int get_bits_long(GetBitContext *s, int n);
4949028f 372unsigned int show_bits_long(GetBitContext *s, int n);
27a3e2c5 373#endif
2931ecb9
A
374
375static inline unsigned int get_bits(GetBitContext *s, int n){
27a3e2c5 376#ifdef ALT_BITSTREAM_READER
3587d501
MN
377#ifdef ALIGNED_BITSTREAM
378 int index= s->index;
379 uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] );
380 uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] );
381#ifdef ARCH_X86
382 asm ("shldl %%cl, %2, %0\n\t"
383 : "=r" (result1)
384 : "0" (result1), "r" (result2), "c" (index));
385#else
386 result1<<= (index&0x1F);
05f361f0
MN
387 result2= (result2>>1) >> (31-(index&0x1F));
388 result1|= result2;
3587d501
MN
389#endif
390 result1>>= 32 - n;
391 index+= n;
392 s->index= index;
393
394 return result1;
395#else //ALIGNED_BITSTREAM
27a3e2c5 396 int index= s->index;
3587d501 397 uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) );
27a3e2c5
MN
398
399 result<<= (index&0x07);
400 result>>= 32 - n;
401 index+= n;
402 s->index= index;
403
404 return result;
3587d501
MN
405#endif //!ALIGNED_BITSTREAM
406#else //ALT_BITSTREAM_READER
2931ecb9
A
407 if(s->bit_cnt>=n){
408 /* most common case here */
409 unsigned int val = s->bit_buf >> (32 - n);
410 s->bit_buf <<= n;
411 s->bit_cnt -= n;
412#ifdef STATS
413 st_bit_counts[st_current_index] += n;
414#endif
415 return val;
416 }
417 return get_bits_long(s,n);
3587d501 418#endif //!ALT_BITSTREAM_READER
2931ecb9
A
419}
420
612476ef 421static inline unsigned int get_bits1(GetBitContext *s){
27a3e2c5
MN
422#ifdef ALT_BITSTREAM_READER
423 int index= s->index;
3587d501 424 uint8_t result= s->buffer[ index>>3 ];
05f361f0
MN
425 result<<= (index&0x07);
426 result>>= 8 - 1;
27a3e2c5
MN
427 index++;
428 s->index= index;
429
430 return result;
431#else
612476ef
A
432 if(s->bit_cnt>0){
433 /* most common case here */
434 unsigned int val = s->bit_buf >> 31;
435 s->bit_buf <<= 1;
436 s->bit_cnt--;
437#ifdef STATS
438 st_bit_counts[st_current_index]++;
439#endif
440 return val;
441 }
442 return get_bits_long(s,1);
27a3e2c5 443#endif
612476ef
A
444}
445
4949028f
J
446/* This function is identical to get_bits(), the only */
447/* diference is that it doesn't touch the buffer */
448/* it is usefull to see the buffer. */
449static inline unsigned int show_bits(GetBitContext *s, int n)
450{
27a3e2c5 451#ifdef ALT_BITSTREAM_READER
3587d501
MN
452#ifdef ALIGNED_BITSTREAM
453 int index= s->index;
454 uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] );
455 uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] );
456#ifdef ARCH_X86
457 asm ("shldl %%cl, %2, %0\n\t"
458 : "=r" (result1)
459 : "0" (result1), "r" (result2), "c" (index));
460#else
461 result1<<= (index&0x1F);
05f361f0
MN
462 result2= (result2>>1) >> (31-(index&0x1F));
463 result1|= result2;
3587d501
MN
464#endif
465 result1>>= 32 - n;
466
467 return result1;
468#else //ALIGNED_BITSTREAM
27a3e2c5 469 int index= s->index;
3587d501 470 uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) );
27a3e2c5
MN
471
472 result<<= (index&0x07);
473 result>>= 32 - n;
474
475 return result;
3587d501
MN
476#endif //!ALIGNED_BITSTREAM
477#else //ALT_BITSTREAM_READER
4949028f
J
478 if(s->bit_cnt>=n) {
479 /* most common case here */
480 unsigned int val = s->bit_buf >> (32 - n);
481 return val;
482 }
483 return show_bits_long(s,n);
3587d501 484#endif //!ALT_BITSTREAM_READER
4949028f
J
485}
486
612476ef 487static inline void skip_bits(GetBitContext *s, int n){
27a3e2c5
MN
488#ifdef ALT_BITSTREAM_READER
489 s->index+= n;
490#else
612476ef
A
491 if(s->bit_cnt>=n){
492 /* most common case here */
493 s->bit_buf <<= n;
494 s->bit_cnt -= n;
495#ifdef STATS
496 st_bit_counts[st_current_index] += n;
497#endif
498 } else {
499 get_bits_long(s,n);
500 }
27a3e2c5 501#endif
612476ef
A
502}
503
504static inline void skip_bits1(GetBitContext *s){
27a3e2c5
MN
505#ifdef ALT_BITSTREAM_READER
506 s->index++;
507#else
612476ef
A
508 if(s->bit_cnt>0){
509 /* most common case here */
510 s->bit_buf <<= 1;
511 s->bit_cnt--;
512#ifdef STATS
513 st_bit_counts[st_current_index]++;
514#endif
515 } else {
516 get_bits_long(s,1);
517 }
27a3e2c5 518#endif
612476ef
A
519}
520
9dbf9389
FB
521static inline int get_bits_count(GetBitContext *s)
522{
27a3e2c5
MN
523#ifdef ALT_BITSTREAM_READER
524 return s->index;
525#else
9dbf9389 526 return (s->buf_ptr - s->buf) * 8 - s->bit_cnt;
27a3e2c5 527#endif
9dbf9389 528}
612476ef 529
de6d9b64
FB
530void align_get_bits(GetBitContext *s);
531int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
532 const void *bits, int bits_wrap, int bits_size,
533 const void *codes, int codes_wrap, int codes_size);
534void free_vlc(VLC *vlc);
de6d9b64 535
27a3e2c5 536#ifdef ALT_BITSTREAM_READER
05f361f0
MN
537#ifdef ALIGNED_BITSTREAM
538#ifdef ARCH_X86
539#define SHOW_BITS(s, val, n) \
540 val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
541 {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
542 asm ("shldl %%cl, %2, %0\n\t"\
543 : "=r" (val)\
544 : "0" (val), "r" (result2), "c" (bit_cnt));\
545 ((uint32_t)val)>>= 32 - n;}
546#else //ARCH_X86
547#define SHOW_BITS(s, val, n) \
548 val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
549 {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
550 val<<= (bit_cnt&0x1F);\
551 result2= (result2>>1) >> (31-(bit_cnt&0x1F));\
552 val|= result2;\
553 ((uint32_t)val)>>= 32 - n;}
554#endif //!ARCH_X86
555#else //ALIGNED_BITSTREAM
556#define SHOW_BITS(s, val, n) \
557 val= be2me_32( unaligned32( ((uint8_t *)(s)->buffer)+(bit_cnt>>3) ) );\
558 val<<= (bit_cnt&0x07);\
559 ((uint32_t)val)>>= 32 - n;
560#endif // !ALIGNED_BITSTREAM
561#define FLUSH_BITS(n) bit_cnt+=n;
562#define SAVE_BITS(s) bit_cnt= (s)->index;
563#define RESTORE_BITS(s) (s)->index= bit_cnt;
27a3e2c5
MN
564#else
565
de6d9b64
FB
566/* macro to go faster */
567/* n must be <= 24 */
568/* XXX: optimize buffer end test */
569#define SHOW_BITS(s, val, n)\
570{\
571 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
572 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
573 bit_cnt += 8;\
574 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
575 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
576 bit_cnt += 8;\
577 if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
578 bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
579 bit_cnt += 8;\
580 }\
581 }\
582 }\
583 val = bit_buf >> (32 - n);\
584}
585
586/* SHOW_BITS with n1 >= n must be been done before */
587#define FLUSH_BITS(n)\
588{\
589 bit_buf <<= n;\
590 bit_cnt -= n;\
591}
592
593#define SAVE_BITS(s) \
594{\
595 bit_cnt = (s)->bit_cnt;\
596 bit_buf = (s)->bit_buf;\
597 buf_ptr = (s)->buf_ptr;\
598}
599
600#define RESTORE_BITS(s) \
601{\
602 (s)->buf_ptr = buf_ptr;\
603 (s)->bit_buf = bit_buf;\
604 (s)->bit_cnt = bit_cnt;\
605}
27a3e2c5 606#endif // !ALT_BITSTREAM_READER
3587d501
MN
607
608static inline int get_vlc(GetBitContext *s, VLC *vlc)
609{
610 int code, n, nb_bits, index;
611 INT16 *table_codes;
612 INT8 *table_bits;
3587d501 613 int bit_cnt;
05f361f0 614#ifndef ALT_BITSTREAM_READER
3587d501
MN
615 UINT32 bit_buf;
616 UINT8 *buf_ptr;
617#endif
618
619 SAVE_BITS(s);
620 nb_bits = vlc->bits;
621 table_codes = vlc->table_codes;
622 table_bits = vlc->table_bits;
05f361f0
MN
623
624#ifdef FAST_GET_FIRST_VLC
3587d501
MN
625 SHOW_BITS(s, index, nb_bits);
626 code = table_codes[index];
627 n = table_bits[index];
628 if (n > 0) {
629 /* most common case (90%)*/
630 FLUSH_BITS(n);
631 RESTORE_BITS(s);
632 return code;
633 } else if (n == 0) {
634 return -1;
635 } else {
636 FLUSH_BITS(nb_bits);
637 nb_bits = -n;
638 table_codes = vlc->table_codes + code;
639 table_bits = vlc->table_bits + code;
640 }
05f361f0 641#endif
3587d501
MN
642 for(;;) {
643 SHOW_BITS(s, index, nb_bits);
644 code = table_codes[index];
645 n = table_bits[index];
646 if (n > 0) {
647 /* most common case */
648 FLUSH_BITS(n);
649#ifdef STATS
650 st_bit_counts[st_current_index] += n;
651#endif
652 break;
653 } else if (n == 0) {
654 return -1;
655 } else {
656 FLUSH_BITS(nb_bits);
657#ifdef STATS
658 st_bit_counts[st_current_index] += nb_bits;
659#endif
660 nb_bits = -n;
661 table_codes = vlc->table_codes + code;
662 table_bits = vlc->table_bits + code;
663 }
664 }
665 RESTORE_BITS(s);
666 return code;
667}
668
669
de6d9b64
FB
670/* define it to include statistics code (useful only for optimizing
671 codec efficiency */
672//#define STATS
673
674#ifdef STATS
675
676enum {
677 ST_UNKNOWN,
678 ST_DC,
679 ST_INTRA_AC,
680 ST_INTER_AC,
681 ST_INTRA_MB,
682 ST_INTER_MB,
683 ST_MV,
684 ST_NB,
685};
686
687extern int st_current_index;
688extern unsigned int st_bit_counts[ST_NB];
689extern unsigned int st_out_bit_counts[ST_NB];
690
691void print_stats(void);
692#endif
693
694/* misc math functions */
695
a822a479 696static inline int av_log2(unsigned int v)
de6d9b64
FB
697{
698 int n;
699
700 n = 0;
701 if (v & 0xffff0000) {
702 v >>= 16;
703 n += 16;
704 }
705 if (v & 0xff00) {
706 v >>= 8;
707 n += 8;
708 }
709 if (v & 0xf0) {
710 v >>= 4;
711 n += 4;
712 }
713 if (v & 0xc) {
714 v >>= 2;
715 n += 2;
716 }
717 if (v & 0x2) {
718 n++;
719 }
720 return n;
721}
722
723/* memory */
724void *av_mallocz(int size);
725
726#endif