3
* common internal api header.
9
#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
13
//#define ALT_BITSTREAM_WRITER
14
//#define ALIGNED_BITSTREAM_WRITER
16
#define ALT_BITSTREAM_READER
17
//#define LIBMPEG2_BITSTREAM_READER
18
//#define A32_BITSTREAM_READER
19
#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
21
#ifdef HAVE_AV_CONFIG_H
22
/* only include the following when compiling package */
41
#define M_PI 3.14159265358979323846
46
# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
49
#define AVOPTION_CODEC_BOOL(name, help, field) \
50
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
51
#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
52
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
53
#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
54
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
55
#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
56
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
57
#define AVOPTION_CODEC_STRING(name, help, field, str, val) \
58
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
59
#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
60
{ name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
61
#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
62
#define AVOPTION_END() AVOPTION_SUB(NULL)
66
extern const struct AVOption avoptions_common[3 + 5];
68
extern const struct AVOption avoptions_common[3];
70
extern const struct AVOption avoptions_workaround_bug[11];
72
#endif /* HAVE_AV_CONFIG_H */
74
/* Suppress restrict if it was not defined in config.h. */
79
#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
80
# define always_inline __attribute__((always_inline)) inline
82
# define always_inline inline
89
typedef unsigned short uint16_t;
90
typedef signed short int16_t;
91
typedef unsigned char uint8_t;
92
typedef unsigned int uint32_t;
93
typedef unsigned __int64 uint64_t;
94
typedef signed char int8_t;
95
typedef signed int int32_t;
96
typedef signed __int64 int64_t;
99
# define int64_t_C(c) (c ## i64)
100
# define uint64_t_C(c) (c ## i64)
102
# define inline __inline
105
# define int64_t_C(c) (c ## LL)
106
# define uint64_t_C(c) (c ## ULL)
107
# endif /* __MINGW32__ */
113
# define snprintf _snprintf
114
# define vsnprintf _vsnprintf
116
/* CONFIG_WIN32 end */
117
#elif defined (CONFIG_OS2)
120
#include <inttypes.h>
123
#define int64_t_C(c) (c ## LL)
124
#define uint64_t_C(c) (c ## ULL)
127
#ifdef HAVE_AV_CONFIG_H
129
#ifdef USE_FASTMEMCPY
130
#include "fastmemcpy.h"
135
#endif /* HAVE_AV_CONFIG_H */
142
#include <inttypes.h>
145
#define int64_t_C(c) (c ## LL)
146
#define uint64_t_C(c) (c ## ULL)
149
#ifdef HAVE_AV_CONFIG_H
151
# ifdef USE_FASTMEMCPY
152
# include "fastmemcpy.h"
154
# endif /* HAVE_AV_CONFIG_H */
156
#endif /* !CONFIG_WIN32 && !CONFIG_OS2 */
158
#ifdef HAVE_AV_CONFIG_H
162
# if defined(__MINGW32__) || defined(__CYGWIN__) || \
163
defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
164
# define MANGLE(a) "_" #a
166
# define MANGLE(a) #a
177
# if defined(CONFIG_WIN32) && !defined(__MINGW32__)
179
inline void dprintf(const char* fmt,...) {}
184
# define dprintf(fmt,args...) printf(fmt, ## args)
186
# define dprintf(fmt,args...)
189
# endif /* !CONFIG_WIN32 */
191
# define av_abort() do { fprintf(stderr, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
193
//rounded divison & shift
194
#define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
196
#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
197
#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
199
#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
200
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
202
extern const uint32_t inverse[256];
205
# define FASTDIV(a,b) \
210
:"=d"(ret),"=a"(dmy)\
211
:"1"(a),"g"(inverse[b])\
215
#elif defined(CONFIG_FASTDIV)
216
# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
218
# define FASTDIV(a,b) ((a)/(b))
222
// avoid +32 for shift optimization (gcc should do that ...)
223
static inline int32_t NEG_SSR32( int32_t a, int8_t s){
224
asm ("sarl %1, %0\n\t"
226
: "ic" ((uint8_t)(-s))
230
static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
231
asm ("shrl %1, %0\n\t"
233
: "ic" ((uint8_t)(-s))
238
# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
239
# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
244
struct PutBitContext;
246
typedef void (*WriteDataFunc)(void *, uint8_t *, int);
248
typedef struct PutBitContext {
249
#ifdef ALT_BITSTREAM_WRITER
250
uint8_t *buf, *buf_end;
255
uint8_t *buf, *buf_ptr, *buf_end;
257
int64_t data_out_size; /* in bytes */
260
void init_put_bits(PutBitContext *s,
261
uint8_t *buffer, int buffer_size,
263
void (*write_data)(void *, uint8_t *, int));
265
int64_t get_bit_count(PutBitContext *s); /* XXX: change function name */
266
void align_put_bits(PutBitContext *s);
267
void flush_put_bits(PutBitContext *s);
268
void put_string(PutBitContext * pbc, char *s);
272
typedef struct GetBitContext {
273
const uint8_t *buffer, *buffer_end;
274
#ifdef ALT_BITSTREAM_READER
276
#elif defined LIBMPEG2_BITSTREAM_READER
280
#elif defined A32_BITSTREAM_READER
281
uint32_t *buffer_ptr;
289
static inline int get_bits_count(GetBitContext *s);
291
#define VLC_TYPE int16_t
295
VLC_TYPE (*table)[2]; ///< code, bits
296
int table_size, table_allocated;
299
typedef struct RL_VLC_ELEM {
306
#define UNALIGNED_STORES_ARE_BAD
309
/* used to avoid missaligned exceptions on some archs (alpha, ...) */
311
# define unaligned32(a) (*(uint32_t*)(a))
314
static inline uint32_t unaligned32(const void *v) {
317
} __attribute__((packed));
319
return ((const struct Unaligned *) v)->i;
321
# elif defined(__DECC)
322
static inline uint32_t unaligned32(const void *v) {
323
return *(const __unaligned uint32_t *) v;
326
static inline uint32_t unaligned32(const void *v) {
327
return *(const uint32_t *) v;
332
#ifndef ALT_BITSTREAM_WRITER
333
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
335
unsigned int bit_buf;
339
st_out_bit_counts[st_current_index] += n;
341
// printf("put_bits=%d %x\n", n, value);
342
assert(n == 32 || value < (1U << n));
344
bit_buf = s->bit_buf;
345
bit_left = s->bit_left;
347
// printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
350
bit_buf = (bit_buf<<n) | value;
354
bit_buf |= value >> (n - bit_left);
355
#ifdef UNALIGNED_STORES_ARE_BAD
356
if (3 & (int) s->buf_ptr) {
357
s->buf_ptr[0] = bit_buf >> 24;
358
s->buf_ptr[1] = bit_buf >> 16;
359
s->buf_ptr[2] = bit_buf >> 8;
360
s->buf_ptr[3] = bit_buf ;
363
*(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
364
//printf("bitbuf = %08x\n", bit_buf);
370
s->bit_buf = bit_buf;
371
s->bit_left = bit_left;
376
#ifdef ALT_BITSTREAM_WRITER
377
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
379
# ifdef ALIGNED_BITSTREAM_WRITER
382
"movl %0, %%ecx \n\t"
383
"xorl %%eax, %%eax \n\t"
384
"shrdl %%cl, %1, %%eax \n\t"
386
"movl %0, %%ecx \n\t"
387
"shrl $3, %%ecx \n\t"
388
"andl $0xFFFFFFFC, %%ecx \n\t"
390
"orl %1, (%2, %%ecx) \n\t"
393
"movl %%eax, 4(%2, %%ecx) \n\t"
394
: "=&r" (s->index), "=&r" (value)
395
: "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
400
uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
404
ptr[0] |= be2me_32(value>>(index&31));
405
ptr[1] = be2me_32(value<<(32-(index&31)));
406
//if(n>24) printf("%d %d\n", n, value);
410
# else //ALIGNED_BITSTREAM_WRITER
413
"movl $7, %%ecx \n\t"
414
"andl %0, %%ecx \n\t"
415
"addl %3, %%ecx \n\t"
419
"movl %0, %%ecx \n\t"
420
"shrl $3, %%ecx \n\t"
421
"orl %1, (%%ecx, %2) \n\t"
423
"movl $0, 4(%%ecx, %2) \n\t"
424
: "=&r" (s->index), "=&r" (value)
425
: "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
430
uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
432
ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
434
//if(n>24) printf("%d %d\n", n, value);
438
# endif //!ALIGNED_BITSTREAM_WRITER
443
static inline uint8_t* pbBufPtr(PutBitContext *s)
445
#ifdef ALT_BITSTREAM_WRITER
446
return s->buf + (s->index>>3);
452
/* Bitstream reader API docs:
454
abritary name which is used as prefix for the internal variables
459
OPEN_READER(name, gb)
460
loads gb into local variables
462
CLOSE_READER(name, gb)
463
stores local vars in gb
465
UPDATE_CACHE(name, gb)
466
refills the internal cache from the bitstream
467
after this call at least MIN_CACHE_BITS will be available,
470
will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
472
SHOW_UBITS(name, gb, num)
473
will return the nest num bits
475
SHOW_SBITS(name, gb, num)
476
will return the nest num bits and do sign extension
478
SKIP_BITS(name, gb, num)
479
will skip over the next num bits
480
note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER
482
SKIP_CACHE(name, gb, num)
483
will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
485
SKIP_COUNTER(name, gb, num)
486
will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
488
LAST_SKIP_CACHE(name, gb, num)
489
will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
491
LAST_SKIP_BITS(name, gb, num)
492
is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER
494
for examples see get_bits, show_bits, skip_bits, get_vlc
497
static inline int unaligned32_be(const void *v)
501
return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
503
return be2me_32( unaligned32(v)); //original
507
#ifdef ALT_BITSTREAM_READER
508
# define MIN_CACHE_BITS 25
510
# define OPEN_READER(name, gb)\
511
int name##_index= (gb)->index;\
512
int name##_cache= 0;\
514
# define CLOSE_READER(name, gb)\
515
(gb)->index= name##_index;\
517
# define UPDATE_CACHE(name, gb)\
518
name##_cache= unaligned32_be( ((uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
520
# define SKIP_CACHE(name, gb, num)\
521
name##_cache <<= (num);\
524
# define SKIP_COUNTER(name, gb, num)\
525
name##_index += (num);\
527
# define SKIP_BITS(name, gb, num)\
529
SKIP_CACHE(name, gb, num)\
530
SKIP_COUNTER(name, gb, num)\
533
# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
534
# define LAST_SKIP_CACHE(name, gb, num) ;
536
# define SHOW_UBITS(name, gb, num)\
537
NEG_USR32(name##_cache, num)
539
# define SHOW_SBITS(name, gb, num)\
540
NEG_SSR32(name##_cache, num)
542
# define GET_CACHE(name, gb)\
543
((uint32_t)name##_cache)
545
static inline int get_bits_count(GetBitContext *s){
548
#elif defined LIBMPEG2_BITSTREAM_READER
549
//libmpeg2 like reader
551
# define MIN_CACHE_BITS 17
553
# define OPEN_READER(name, gb)\
554
int name##_bit_count=(gb)->bit_count;\
555
int name##_cache= (gb)->cache;\
556
uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
558
# define CLOSE_READER(name, gb)\
559
(gb)->bit_count= name##_bit_count;\
560
(gb)->cache= name##_cache;\
561
(gb)->buffer_ptr= name##_buffer_ptr;\
563
#ifdef LIBMPEG2_BITSTREAM_READER_HACK
565
# define UPDATE_CACHE(name, gb)\
566
if(name##_bit_count >= 0){\
567
name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
568
((uint16_t*)name##_buffer_ptr)++;\
569
name##_bit_count-= 16;\
574
# define UPDATE_CACHE(name, gb)\
575
if(name##_bit_count >= 0){\
576
name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
577
name##_buffer_ptr+=2;\
578
name##_bit_count-= 16;\
583
# define SKIP_CACHE(name, gb, num)\
584
name##_cache <<= (num);\
586
# define SKIP_COUNTER(name, gb, num)\
587
name##_bit_count += (num);\
589
# define SKIP_BITS(name, gb, num)\
591
SKIP_CACHE(name, gb, num)\
592
SKIP_COUNTER(name, gb, num)\
595
# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
596
# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
598
# define SHOW_UBITS(name, gb, num)\
599
NEG_USR32(name##_cache, num)
601
# define SHOW_SBITS(name, gb, num)\
602
NEG_SSR32(name##_cache, num)
604
# define GET_CACHE(name, gb)\
605
((uint32_t)name##_cache)
607
static inline int get_bits_count(GetBitContext *s){
608
return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
611
#elif defined A32_BITSTREAM_READER
613
# define MIN_CACHE_BITS 32
615
# define OPEN_READER(name, gb)\
616
int name##_bit_count=(gb)->bit_count;\
617
uint32_t name##_cache0= (gb)->cache0;\
618
uint32_t name##_cache1= (gb)->cache1;\
619
uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
621
# define CLOSE_READER(name, gb)\
622
(gb)->bit_count= name##_bit_count;\
623
(gb)->cache0= name##_cache0;\
624
(gb)->cache1= name##_cache1;\
625
(gb)->buffer_ptr= name##_buffer_ptr;\
627
# define UPDATE_CACHE(name, gb)\
628
if(name##_bit_count > 0){\
629
const uint32_t next= be2me_32( *name##_buffer_ptr );\
630
name##_cache0 |= NEG_USR32(next,name##_bit_count);\
631
name##_cache1 |= next<<name##_bit_count;\
632
name##_buffer_ptr++;\
633
name##_bit_count-= 32;\
637
# define SKIP_CACHE(name, gb, num)\
639
"shldl %2, %1, %0 \n\t"\
641
: "+r" (name##_cache0), "+r" (name##_cache1)\
642
: "Ic" ((uint8_t)num)\
645
# define SKIP_CACHE(name, gb, num)\
646
name##_cache0 <<= (num);\
647
name##_cache0 |= NEG_USR32(name##_cache1,num);\
648
name##_cache1 <<= (num);
651
# define SKIP_COUNTER(name, gb, num)\
652
name##_bit_count += (num);\
654
# define SKIP_BITS(name, gb, num)\
656
SKIP_CACHE(name, gb, num)\
657
SKIP_COUNTER(name, gb, num)\
660
# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
661
# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
663
# define SHOW_UBITS(name, gb, num)\
664
NEG_USR32(name##_cache0, num)
666
# define SHOW_SBITS(name, gb, num)\
667
NEG_SSR32(name##_cache0, num)
669
# define GET_CACHE(name, gb)\
672
static inline int get_bits_count(GetBitContext *s){
673
return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
679
* read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
680
* if MSB not set it is negative
681
* @param n length in bits
684
static inline int get_xbits(GetBitContext *s, int n){
686
register int32_t cache;
689
cache = GET_CACHE(re,s);
690
if ((int32_t)cache<0) { //MSB=1
691
tmp = NEG_USR32(cache,n);
693
// tmp = (-1<<n) | NEG_USR32(cache,n) + 1; mpeg12.c algo
694
// tmp = - (NEG_USR32(cache,n) ^ ((1 << n) - 1)); h263.c algo
695
tmp = - NEG_USR32(~cache,n);
697
LAST_SKIP_BITS(re, s, n)
702
static inline int get_sbits(GetBitContext *s, int n){
706
tmp= SHOW_SBITS(re, s, n);
707
LAST_SKIP_BITS(re, s, n)
714
* Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
716
static inline unsigned int get_bits(GetBitContext *s, int n){
720
tmp= SHOW_UBITS(re, s, n);
721
LAST_SKIP_BITS(re, s, n)
726
unsigned int get_bits_long(GetBitContext *s, int n);
730
* Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
732
static inline unsigned int show_bits(GetBitContext *s, int n){
736
tmp= SHOW_UBITS(re, s, n);
737
// CLOSE_READER(re, s)
741
unsigned int show_bits_long(GetBitContext *s, int n);
743
static inline void skip_bits(GetBitContext *s, int n){
744
//Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
747
LAST_SKIP_BITS(re, s, n)
751
static inline unsigned int get_bits1(GetBitContext *s){
752
#ifdef ALT_BITSTREAM_READER
754
uint8_t result= s->buffer[ index>>3 ];
755
result<<= (index&0x07);
762
return get_bits(s, 1);
766
static inline unsigned int show_bits1(GetBitContext *s){
767
return show_bits(s, 1);
770
static inline void skip_bits1(GetBitContext *s){
774
void init_get_bits(GetBitContext *s,
775
const uint8_t *buffer, int buffer_size);
777
int check_marker(GetBitContext *s, const char *msg);
778
void align_get_bits(GetBitContext *s);
779
int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
780
const void *bits, int bits_wrap, int bits_size,
781
const void *codes, int codes_wrap, int codes_size);
782
void free_vlc(VLC *vlc);
786
* if the vlc code is invalid and max_depth=1 than no bits will be removed
787
* if the vlc code is invalid and max_depth>1 than the number of bits removed
790
#define GET_VLC(code, name, gb, table, bits, max_depth)\
792
int n, index, nb_bits;\
794
index= SHOW_UBITS(name, gb, bits);\
795
code = table[index][0];\
796
n = table[index][1];\
798
if(max_depth > 1 && n < 0){\
799
LAST_SKIP_BITS(name, gb, bits)\
800
UPDATE_CACHE(name, gb)\
804
index= SHOW_UBITS(name, gb, nb_bits) + code;\
805
code = table[index][0];\
806
n = table[index][1];\
807
if(max_depth > 2 && n < 0){\
808
LAST_SKIP_BITS(name, gb, nb_bits)\
809
UPDATE_CACHE(name, gb)\
813
index= SHOW_UBITS(name, gb, nb_bits) + code;\
814
code = table[index][0];\
815
n = table[index][1];\
818
SKIP_BITS(name, gb, n)\
821
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth)\
823
int n, index, nb_bits;\
825
index= SHOW_UBITS(name, gb, bits);\
826
level = table[index].level;\
827
n = table[index].len;\
829
if(max_depth > 1 && n < 0){\
830
LAST_SKIP_BITS(name, gb, bits)\
831
UPDATE_CACHE(name, gb)\
835
index= SHOW_UBITS(name, gb, nb_bits) + level;\
836
level = table[index].level;\
837
n = table[index].len;\
839
run= table[index].run;\
840
SKIP_BITS(name, gb, n)\
843
// deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly
844
static inline int get_vlc(GetBitContext *s, VLC *vlc)
847
VLC_TYPE (*table)[2]= vlc->table;
852
GET_VLC(code, re, s, table, vlc->bits, 3)
859
* parses a vlc code, faster then get_vlc()
860
* @param bits is the number of bits which will be read at once, must be
861
* identical to nb_bits in init_vlc()
862
* @param max_depth is the number of times bits bits must be readed to completly
863
* read the longest vlc code
864
* = (max_vlc_length + bits - 1) / bits
866
static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
867
int bits, int max_depth)
874
GET_VLC(code, re, s, table, bits, max_depth)
884
static inline void print_bin(int bits, int n){
887
for(i=n-1; i>=0; i--){
888
printf("%d", (bits>>i)&1);
894
static inline int get_bits_trace(GetBitContext *s, int n, char *file, char *func, int line){
895
int r= get_bits(s, n);
898
printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
901
static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, char *func, int line){
902
int show= show_bits(s, 24);
903
int pos= get_bits_count(s);
904
int r= get_vlc2(s, table, bits, max_depth);
905
int len= get_bits_count(s) - pos;
906
int bits2= show>>(24-len);
908
print_bin(bits2, len);
910
printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
913
static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *func, int line){
914
int show= show_bits(s, n);
915
int r= get_xbits(s, n);
918
printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
922
#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
923
#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
924
#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
925
#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
926
#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
928
#define tprintf printf
931
#define tprintf(_arg...) {}
934
/* define it to include statistics code (useful only for optimizing
951
extern int st_current_index;
952
extern unsigned int st_bit_counts[ST_NB];
953
extern unsigned int st_out_bit_counts[ST_NB];
955
void print_stats(void);
958
/* misc math functions */
959
extern const uint8_t ff_log2_tab[256];
961
static inline int av_log2(unsigned int v)
966
if (v & 0xffff0000) {
979
static inline int av_log2_16bit(unsigned int v)
995
static inline int mid_pred(int a, int b, int c)
1009
return a + b + c - vmin - vmax;
1012
static inline int clip(int a, int amin, int amax)
1023
extern const uint8_t ff_sqrt_tab[128];
1025
int64_t ff_gcd(int64_t a, int64_t b);
1027
static inline int ff_sqrt(int a)
1033
if(a<128) return ff_sqrt_tab[a];
1035
for(s=15; s>=0; s--){
1036
int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
1046
* converts fourcc string to int
1048
static inline int ff_get_fourcc(const char *s){
1049
assert( strlen(s)==4 );
1051
return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
1054
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
1055
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
1058
void ff_float2fraction(int *nom_arg, int *denom_arg, double f, int max);
1062
#define MASK_ABS(mask, level)\
1067
: "+a" (level), "=&d" (mask)\
1070
#define MASK_ABS(mask, level)\
1072
level= (level^mask)-mask;
1076
#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
1077
#define COPY3_IF_LT(x,y,a,b,c,d)\
1080
"cmovl %3, %0 \n\t"\
1081
"cmovl %4, %1 \n\t"\
1082
"cmovl %5, %2 \n\t"\
1083
: "+r" (x), "+r" (a), "+r" (c)\
1084
: "r" (y), "r" (b), "r" (d)\
1087
#define COPY3_IF_LT(x,y,a,b,c,d)\
1096
static inline long long rdtsc()
1099
asm volatile( "rdtsc\n\t"
1105
#define START_TIMER \
1106
static uint64_t tsum=0;\
1107
static int tcount=0;\
1108
static int tskip_count=0;\
1110
uint64_t tstart= rdtsc();\
1112
#define STOP_TIMER(id) \
1114
if(tcount<2 || tend - tstart < 4*tsum/tcount){\
1115
tsum+= tend - tstart;\
1119
if(256*256*256*64%(tcount+tskip_count)==0){\
1120
fprintf(stderr, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
1124
#define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d)
1126
/* avoid usage of various functions */
1127
#define malloc please_use_av_malloc
1128
#define free please_use_av_free
1129
#define realloc please_use_av_realloc
1131
#define CHECKED_ALLOCZ(p, size)\
1133
p= av_mallocz(size);\
1134
if(p==NULL && (size)!=0){\
1140
#endif /* HAVE_AV_CONFIG_H */
1142
#endif /* COMMON_H */