3 * bitstream api header.
11 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
12 #define ALT_BITSTREAM_READER
15 //#define ALT_BITSTREAM_WRITER
16 //#define ALIGNED_BITSTREAM_WRITER
17 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
19 # define A32_BITSTREAM_READER
21 #define ALT_BITSTREAM_READER
22 //#define LIBMPEG2_BITSTREAM_READER
23 //#define A32_BITSTREAM_READER
26 #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
28 extern const uint8_t ff_reverse[256];
30 #if defined(ARCH_X86) || defined(ARCH_X86_64)
31 // avoid +32 for shift optimization (gcc should do that ...)
32 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
33 asm ("sarl %1, %0\n\t"
35 : "ic" ((uint8_t)(-s))
39 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
40 asm ("shrl %1, %0\n\t"
42 : "ic" ((uint8_t)(-s))
47 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
48 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
53 /* buf and buf_end must be present and used by every alternative writer. */
54 typedef struct PutBitContext {
55 #ifdef ALT_BITSTREAM_WRITER
56 uint8_t *buf, *buf_end;
61 uint8_t *buf, *buf_ptr, *buf_end;
65 static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
73 s->buf_end = s->buf + buffer_size;
74 #ifdef ALT_BITSTREAM_WRITER
76 ((uint32_t*)(s->buf))[0]=0;
77 // memset(buffer, 0, buffer_size);
85 /* return the number of bits output */
86 static inline int put_bits_count(PutBitContext *s)
88 #ifdef ALT_BITSTREAM_WRITER
91 return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
95 /* pad the end of the output stream with zeros */
96 static inline void flush_put_bits(PutBitContext *s)
98 #ifdef ALT_BITSTREAM_WRITER
101 s->bit_buf<<= s->bit_left;
102 while (s->bit_left < 32) {
103 /* XXX: should test end of buffer */
104 *s->buf_ptr++=s->bit_buf >> 24;
113 void align_put_bits(PutBitContext *s);
114 void ff_put_string(PutBitContext * pbc, char *s, int put_zero);
117 /* buffer, buffer_end and size_in_bits must be present and used by every reader */
118 typedef struct GetBitContext {
119 const uint8_t *buffer, *buffer_end;
120 #ifdef ALT_BITSTREAM_READER
122 #elif defined LIBMPEG2_BITSTREAM_READER
126 #elif defined A32_BITSTREAM_READER
127 uint32_t *buffer_ptr;
135 #define VLC_TYPE int16_t
139 VLC_TYPE (*table)[2]; ///< code, bits
140 int table_size, table_allocated;
143 typedef struct RL_VLC_ELEM {
149 #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS)
150 #define UNALIGNED_STORES_ARE_BAD
153 /* used to avoid missaligned exceptions on some archs (alpha, ...) */
154 #if defined(ARCH_X86) || defined(ARCH_X86_64)
155 # define unaligned16(a) (*(const uint16_t*)(a))
156 # define unaligned32(a) (*(const uint32_t*)(a))
157 # define unaligned64(a) (*(const uint64_t*)(a))
160 # define unaligned(x) \
161 static inline uint##x##_t unaligned##x(const void *v) { \
164 } __attribute__((packed)); \
166 return ((const struct Unaligned *) v)->i; \
168 # elif defined(__DECC)
169 # define unaligned(x) \
170 static inline uint##x##_t unaligned##x##(const void *v) { \
171 return *(const __unaligned uint##x##_t *) v; \
174 # define unaligned(x) \
175 static inline uint##x##_t unaligned##x##(const void *v) { \
176 return *(const uint##x##_t *) v; \
185 #ifndef ALT_BITSTREAM_WRITER
186 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
188 unsigned int bit_buf;
191 // printf("put_bits=%d %x\n", n, value);
192 assert(n == 32 || value < (1U << n));
194 bit_buf = s->bit_buf;
195 bit_left = s->bit_left;
197 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
200 bit_buf = (bit_buf<<n) | value;
204 bit_buf |= value >> (n - bit_left);
205 #ifdef UNALIGNED_STORES_ARE_BAD
206 if (3 & (intptr_t) s->buf_ptr) {
207 s->buf_ptr[0] = bit_buf >> 24;
208 s->buf_ptr[1] = bit_buf >> 16;
209 s->buf_ptr[2] = bit_buf >> 8;
210 s->buf_ptr[3] = bit_buf ;
213 *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
214 //printf("bitbuf = %08x\n", bit_buf);
220 s->bit_buf = bit_buf;
221 s->bit_left = bit_left;
226 #ifdef ALT_BITSTREAM_WRITER
227 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
229 # ifdef ALIGNED_BITSTREAM_WRITER
230 # if defined(ARCH_X86) || defined(ARCH_X86_64)
232 "movl %0, %%ecx \n\t"
233 "xorl %%eax, %%eax \n\t"
234 "shrdl %%cl, %1, %%eax \n\t"
236 "movl %0, %%ecx \n\t"
237 "shrl $3, %%ecx \n\t"
238 "andl $0xFFFFFFFC, %%ecx \n\t"
240 "orl %1, (%2, %%ecx) \n\t"
243 "movl %%eax, 4(%2, %%ecx) \n\t"
244 : "=&r" (s->index), "=&r" (value)
245 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
250 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
254 ptr[0] |= be2me_32(value>>(index&31));
255 ptr[1] = be2me_32(value<<(32-(index&31)));
256 //if(n>24) printf("%d %d\n", n, value);
260 # else //ALIGNED_BITSTREAM_WRITER
261 # if defined(ARCH_X86) || defined(ARCH_X86_64)
263 "movl $7, %%ecx \n\t"
264 "andl %0, %%ecx \n\t"
265 "addl %3, %%ecx \n\t"
269 "movl %0, %%ecx \n\t"
270 "shrl $3, %%ecx \n\t"
271 "orl %1, (%%ecx, %2) \n\t"
273 "movl $0, 4(%%ecx, %2) \n\t"
274 : "=&r" (s->index), "=&r" (value)
275 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
280 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
282 ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
284 //if(n>24) printf("%d %d\n", n, value);
288 # endif //!ALIGNED_BITSTREAM_WRITER
293 static inline uint8_t* pbBufPtr(PutBitContext *s)
295 #ifdef ALT_BITSTREAM_WRITER
296 return s->buf + (s->index>>3);
304 * PutBitContext must be flushed & aligned to a byte boundary before calling this.
306 static inline void skip_put_bytes(PutBitContext *s, int n){
307 assert((put_bits_count(s)&7)==0);
308 #ifdef ALT_BITSTREAM_WRITER
309 FIXME may need some cleaning of the buffer
312 assert(s->bit_left==32);
318 * skips the given number of bits.
319 * must only be used if the actual values in the bitstream dont matter
321 static inline void skip_put_bits(PutBitContext *s, int n){
322 #ifdef ALT_BITSTREAM_WRITER
326 s->buf_ptr-= s->bit_left>>5;
332 * Changes the end of the buffer.
334 static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
335 s->buf_end= s->buf + size;
338 /* Bitstream reader API docs:
340 abritary name which is used as prefix for the internal variables
345 OPEN_READER(name, gb)
346 loads gb into local variables
348 CLOSE_READER(name, gb)
349 stores local vars in gb
351 UPDATE_CACHE(name, gb)
352 refills the internal cache from the bitstream
353 after this call at least MIN_CACHE_BITS will be available,
356 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
358 SHOW_UBITS(name, gb, num)
359 will return the next num bits
361 SHOW_SBITS(name, gb, num)
362 will return the next num bits and do sign extension
364 SKIP_BITS(name, gb, num)
365 will skip over the next num bits
366 note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
368 SKIP_CACHE(name, gb, num)
369 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
371 SKIP_COUNTER(name, gb, num)
372 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
374 LAST_SKIP_CACHE(name, gb, num)
375 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
377 LAST_SKIP_BITS(name, gb, num)
378 is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER
380 for examples see get_bits, show_bits, skip_bits, get_vlc
383 static inline int unaligned32_be(const void *v)
387 return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
389 return be2me_32( unaligned32(v)); //original
393 static inline int unaligned32_le(const void *v)
397 return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]);
399 return le2me_32( unaligned32(v)); //original
403 #ifdef ALT_BITSTREAM_READER
404 # define MIN_CACHE_BITS 25
406 # define OPEN_READER(name, gb)\
407 int name##_index= (gb)->index;\
408 int name##_cache= 0;\
410 # define CLOSE_READER(name, gb)\
411 (gb)->index= name##_index;\
413 # ifdef ALT_BITSTREAM_READER_LE
414 # define UPDATE_CACHE(name, gb)\
415 name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
417 # define SKIP_CACHE(name, gb, num)\
418 name##_cache >>= (num);
420 # define UPDATE_CACHE(name, gb)\
421 name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
423 # define SKIP_CACHE(name, gb, num)\
424 name##_cache <<= (num);
428 # define SKIP_COUNTER(name, gb, num)\
429 name##_index += (num);\
431 # define SKIP_BITS(name, gb, num)\
433 SKIP_CACHE(name, gb, num)\
434 SKIP_COUNTER(name, gb, num)\
437 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
438 # define LAST_SKIP_CACHE(name, gb, num) ;
440 # ifdef ALT_BITSTREAM_READER_LE
441 # define SHOW_UBITS(name, gb, num)\
442 ((name##_cache) & (NEG_USR32(0xffffffff,num)))
444 # define SHOW_UBITS(name, gb, num)\
445 NEG_USR32(name##_cache, num)
448 # define SHOW_SBITS(name, gb, num)\
449 NEG_SSR32(name##_cache, num)
451 # define GET_CACHE(name, gb)\
452 ((uint32_t)name##_cache)
454 static inline int get_bits_count(GetBitContext *s){
458 static inline void skip_bits_long(GetBitContext *s, int n){
462 #elif defined LIBMPEG2_BITSTREAM_READER
463 //libmpeg2 like reader
465 # define MIN_CACHE_BITS 17
467 # define OPEN_READER(name, gb)\
468 int name##_bit_count=(gb)->bit_count;\
469 int name##_cache= (gb)->cache;\
470 uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
472 # define CLOSE_READER(name, gb)\
473 (gb)->bit_count= name##_bit_count;\
474 (gb)->cache= name##_cache;\
475 (gb)->buffer_ptr= name##_buffer_ptr;\
477 #ifdef LIBMPEG2_BITSTREAM_READER_HACK
479 # define UPDATE_CACHE(name, gb)\
480 if(name##_bit_count >= 0){\
481 name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
482 name##_buffer_ptr += 2;\
483 name##_bit_count-= 16;\
488 # define UPDATE_CACHE(name, gb)\
489 if(name##_bit_count >= 0){\
490 name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
491 name##_buffer_ptr+=2;\
492 name##_bit_count-= 16;\
497 # define SKIP_CACHE(name, gb, num)\
498 name##_cache <<= (num);\
500 # define SKIP_COUNTER(name, gb, num)\
501 name##_bit_count += (num);\
503 # define SKIP_BITS(name, gb, num)\
505 SKIP_CACHE(name, gb, num)\
506 SKIP_COUNTER(name, gb, num)\
509 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
510 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
512 # define SHOW_UBITS(name, gb, num)\
513 NEG_USR32(name##_cache, num)
515 # define SHOW_SBITS(name, gb, num)\
516 NEG_SSR32(name##_cache, num)
518 # define GET_CACHE(name, gb)\
519 ((uint32_t)name##_cache)
521 static inline int get_bits_count(GetBitContext *s){
522 return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
525 static inline void skip_bits_long(GetBitContext *s, int n){
528 re_buffer_ptr += 2*(re_bit_count>>4);
530 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
535 #elif defined A32_BITSTREAM_READER
537 # define MIN_CACHE_BITS 32
539 # define OPEN_READER(name, gb)\
540 int name##_bit_count=(gb)->bit_count;\
541 uint32_t name##_cache0= (gb)->cache0;\
542 uint32_t name##_cache1= (gb)->cache1;\
543 uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
545 # define CLOSE_READER(name, gb)\
546 (gb)->bit_count= name##_bit_count;\
547 (gb)->cache0= name##_cache0;\
548 (gb)->cache1= name##_cache1;\
549 (gb)->buffer_ptr= name##_buffer_ptr;\
551 # define UPDATE_CACHE(name, gb)\
552 if(name##_bit_count > 0){\
553 const uint32_t next= be2me_32( *name##_buffer_ptr );\
554 name##_cache0 |= NEG_USR32(next,name##_bit_count);\
555 name##_cache1 |= next<<name##_bit_count;\
556 name##_buffer_ptr++;\
557 name##_bit_count-= 32;\
560 #if defined(ARCH_X86) || defined(ARCH_X86_64)
561 # define SKIP_CACHE(name, gb, num)\
563 "shldl %2, %1, %0 \n\t"\
565 : "+r" (name##_cache0), "+r" (name##_cache1)\
566 : "Ic" ((uint8_t)(num))\
569 # define SKIP_CACHE(name, gb, num)\
570 name##_cache0 <<= (num);\
571 name##_cache0 |= NEG_USR32(name##_cache1,num);\
572 name##_cache1 <<= (num);
575 # define SKIP_COUNTER(name, gb, num)\
576 name##_bit_count += (num);\
578 # define SKIP_BITS(name, gb, num)\
580 SKIP_CACHE(name, gb, num)\
581 SKIP_COUNTER(name, gb, num)\
584 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
585 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
587 # define SHOW_UBITS(name, gb, num)\
588 NEG_USR32(name##_cache0, num)
590 # define SHOW_SBITS(name, gb, num)\
591 NEG_SSR32(name##_cache0, num)
593 # define GET_CACHE(name, gb)\
596 static inline int get_bits_count(GetBitContext *s){
597 return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
600 static inline void skip_bits_long(GetBitContext *s, int n){
603 re_buffer_ptr += re_bit_count>>5;
605 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
614 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
615 * if MSB not set it is negative
616 * @param n length in bits
619 static inline int get_xbits(GetBitContext *s, int n){
621 register int32_t cache;
624 cache = GET_CACHE(re,s);
626 LAST_SKIP_BITS(re, s, n)
628 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
631 static inline int get_sbits(GetBitContext *s, int n){
635 tmp= SHOW_SBITS(re, s, n);
636 LAST_SKIP_BITS(re, s, n)
643 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
645 static inline unsigned int get_bits(GetBitContext *s, int n){
649 tmp= SHOW_UBITS(re, s, n);
650 LAST_SKIP_BITS(re, s, n)
657 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
659 static inline unsigned int show_bits(GetBitContext *s, int n){
663 tmp= SHOW_UBITS(re, s, n);
664 // CLOSE_READER(re, s)
668 static inline void skip_bits(GetBitContext *s, int n){
669 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
672 LAST_SKIP_BITS(re, s, n)
676 static inline unsigned int get_bits1(GetBitContext *s){
677 #ifdef ALT_BITSTREAM_READER
679 uint8_t result= s->buffer[ index>>3 ];
680 #ifdef ALT_BITSTREAM_READER_LE
681 result>>= (index&0x07);
684 result<<= (index&0x07);
692 return get_bits(s, 1);
696 static inline unsigned int show_bits1(GetBitContext *s){
697 return show_bits(s, 1);
700 static inline void skip_bits1(GetBitContext *s){
707 static inline unsigned int get_bits_long(GetBitContext *s, int n){
708 if(n<=17) return get_bits(s, n);
710 int ret= get_bits(s, 16) << (n-16);
711 return ret | get_bits(s, n-16);
718 static inline unsigned int show_bits_long(GetBitContext *s, int n){
719 if(n<=17) return show_bits(s, n);
721 GetBitContext gb= *s;
722 int ret= get_bits_long(s, n);
728 static inline int check_marker(GetBitContext *s, const char *msg)
730 int bit= get_bits1(s);
732 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
738 * init GetBitContext.
739 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
740 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
741 * @param bit_size the size of the buffer in bits
743 static inline void init_get_bits(GetBitContext *s,
744 const uint8_t *buffer, int bit_size)
746 int buffer_size= (bit_size+7)>>3;
747 if(buffer_size < 0 || bit_size < 0) {
748 buffer_size = bit_size = 0;
753 s->size_in_bits= bit_size;
754 s->buffer_end= buffer + buffer_size;
755 #ifdef ALT_BITSTREAM_READER
757 #elif defined LIBMPEG2_BITSTREAM_READER
758 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
759 s->bit_count = 16 + 8*((intptr_t)buffer&1);
760 skip_bits_long(s, 0);
761 #elif defined A32_BITSTREAM_READER
762 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
763 s->bit_count = 32 + 8*((intptr_t)buffer&3);
764 skip_bits_long(s, 0);
768 static void align_get_bits(GetBitContext *s)
770 int n= (-get_bits_count(s)) & 7;
771 if(n) skip_bits(s, n);
774 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
775 const void *bits, int bits_wrap, int bits_size,
776 const void *codes, int codes_wrap, int codes_size,
778 #define INIT_VLC_USE_STATIC 1
779 #define INIT_VLC_LE 2
780 void free_vlc(VLC *vlc);
784 * if the vlc code is invalid and max_depth=1 than no bits will be removed
785 * if the vlc code is invalid and max_depth>1 than the number of bits removed
788 #define GET_VLC(code, name, gb, table, bits, max_depth)\
790 int n, index, nb_bits;\
792 index= SHOW_UBITS(name, gb, bits);\
793 code = table[index][0];\
794 n = table[index][1];\
796 if(max_depth > 1 && n < 0){\
797 LAST_SKIP_BITS(name, gb, bits)\
798 UPDATE_CACHE(name, gb)\
802 index= SHOW_UBITS(name, gb, nb_bits) + code;\
803 code = table[index][0];\
804 n = table[index][1];\
805 if(max_depth > 2 && n < 0){\
806 LAST_SKIP_BITS(name, gb, nb_bits)\
807 UPDATE_CACHE(name, gb)\
811 index= SHOW_UBITS(name, gb, nb_bits) + code;\
812 code = table[index][0];\
813 n = table[index][1];\
816 SKIP_BITS(name, gb, n)\
819 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
821 int n, index, nb_bits;\
823 index= SHOW_UBITS(name, gb, bits);\
824 level = table[index].level;\
825 n = table[index].len;\
827 if(max_depth > 1 && n < 0){\
828 SKIP_BITS(name, gb, bits)\
830 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)\
845 * parses a vlc code, faster then get_vlc()
846 * @param bits is the number of bits which will be read at once, must be
847 * identical to nb_bits in init_vlc()
848 * @param max_depth is the number of times bits bits must be readed to completly
849 * read the longest vlc code
850 * = (max_vlc_length + bits - 1) / bits
852 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
853 int bits, int max_depth)
860 GET_VLC(code, re, s, table, bits, max_depth)
869 static inline void print_bin(int bits, int n){
872 for(i=n-1; i>=0; i--){
873 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
876 av_log(NULL, AV_LOG_DEBUG, " ");
879 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
880 int r= get_bits(s, n);
883 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
886 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
887 int show= show_bits(s, 24);
888 int pos= get_bits_count(s);
889 int r= get_vlc2(s, table, bits, max_depth);
890 int len= get_bits_count(s) - pos;
891 int bits2= show>>(24-len);
893 print_bin(bits2, len);
895 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
898 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
899 int show= show_bits(s, n);
900 int r= get_xbits(s, n);
903 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
907 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
908 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
909 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
910 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
911 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
913 #define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__)
916 #define tprintf(...) {}
919 static inline int decode012(GetBitContext *gb){
925 return get_bits1(gb) + 1;
928 #endif /* BITSTREAM_H */