2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * bitstream api header.
26 #ifndef FFMPEG_BITSTREAM_H
27 #define FFMPEG_BITSTREAM_H
32 #include "libavutil/bswap.h"
33 #include "libavutil/common.h"
34 #include "libavutil/intreadwrite.h"
35 #include "libavutil/log.h"
37 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
38 # define ALT_BITSTREAM_READER
41 //#define ALT_BITSTREAM_WRITER
42 //#define ALIGNED_BITSTREAM_WRITER
43 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
45 # define A32_BITSTREAM_READER
47 # define ALT_BITSTREAM_READER
48 //#define LIBMPEG2_BITSTREAM_READER
49 //#define A32_BITSTREAM_READER
53 extern const uint8_t ff_reverse[256];
56 // avoid +32 for shift optimization (gcc should do that ...)
57 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
58 asm ("sarl %1, %0\n\t"
60 : "ic" ((uint8_t)(-s))
64 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
65 asm ("shrl %1, %0\n\t"
67 : "ic" ((uint8_t)(-s))
72 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
73 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
78 /* buf and buf_end must be present and used by every alternative writer. */
79 typedef struct PutBitContext {
80 #ifdef ALT_BITSTREAM_WRITER
81 uint8_t *buf, *buf_end;
86 uint8_t *buf, *buf_ptr, *buf_end;
90 static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
98 s->buf_end = s->buf + buffer_size;
99 #ifdef ALT_BITSTREAM_WRITER
101 ((uint32_t*)(s->buf))[0]=0;
102 // memset(buffer, 0, buffer_size);
110 /* return the number of bits output */
111 static inline int put_bits_count(PutBitContext *s)
113 #ifdef ALT_BITSTREAM_WRITER
116 return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
120 /* pad the end of the output stream with zeros */
121 static inline void flush_put_bits(PutBitContext *s)
123 #ifdef ALT_BITSTREAM_WRITER
126 s->bit_buf<<= s->bit_left;
127 while (s->bit_left < 32) {
128 /* XXX: should test end of buffer */
129 *s->buf_ptr++=s->bit_buf >> 24;
138 void align_put_bits(PutBitContext *s);
139 void ff_put_string(PutBitContext * pbc, const char *s, int put_zero);
140 void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length);
143 /* buffer, buffer_end and size_in_bits must be present and used by every reader */
144 typedef struct GetBitContext {
145 const uint8_t *buffer, *buffer_end;
146 #ifdef ALT_BITSTREAM_READER
148 #elif defined LIBMPEG2_BITSTREAM_READER
152 #elif defined A32_BITSTREAM_READER
153 uint32_t *buffer_ptr;
161 #define VLC_TYPE int16_t
165 VLC_TYPE (*table)[2]; ///< code, bits
166 int table_size, table_allocated;
169 typedef struct RL_VLC_ELEM {
175 #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS) || defined(ARCH_BFIN)
176 #define UNALIGNED_STORES_ARE_BAD
179 #ifndef ALT_BITSTREAM_WRITER
180 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
182 unsigned int bit_buf;
185 // printf("put_bits=%d %x\n", n, value);
186 assert(n == 32 || value < (1U << n));
188 bit_buf = s->bit_buf;
189 bit_left = s->bit_left;
191 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
194 bit_buf = (bit_buf<<n) | value;
198 bit_buf |= value >> (n - bit_left);
199 #ifdef UNALIGNED_STORES_ARE_BAD
200 if (3 & (intptr_t) s->buf_ptr) {
201 s->buf_ptr[0] = bit_buf >> 24;
202 s->buf_ptr[1] = bit_buf >> 16;
203 s->buf_ptr[2] = bit_buf >> 8;
204 s->buf_ptr[3] = bit_buf ;
207 *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
208 //printf("bitbuf = %08x\n", bit_buf);
214 s->bit_buf = bit_buf;
215 s->bit_left = bit_left;
220 #ifdef ALT_BITSTREAM_WRITER
221 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
223 # ifdef ALIGNED_BITSTREAM_WRITER
224 # if defined(ARCH_X86)
226 "movl %0, %%ecx \n\t"
227 "xorl %%eax, %%eax \n\t"
228 "shrdl %%cl, %1, %%eax \n\t"
230 "movl %0, %%ecx \n\t"
231 "shrl $3, %%ecx \n\t"
232 "andl $0xFFFFFFFC, %%ecx \n\t"
234 "orl %1, (%2, %%ecx) \n\t"
237 "movl %%eax, 4(%2, %%ecx) \n\t"
238 : "=&r" (s->index), "=&r" (value)
239 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
244 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
248 ptr[0] |= be2me_32(value>>(index&31));
249 ptr[1] = be2me_32(value<<(32-(index&31)));
250 //if(n>24) printf("%d %d\n", n, value);
254 # else //ALIGNED_BITSTREAM_WRITER
255 # if defined(ARCH_X86)
257 "movl $7, %%ecx \n\t"
258 "andl %0, %%ecx \n\t"
259 "addl %3, %%ecx \n\t"
263 "movl %0, %%ecx \n\t"
264 "shrl $3, %%ecx \n\t"
265 "orl %1, (%%ecx, %2) \n\t"
267 "movl $0, 4(%%ecx, %2) \n\t"
268 : "=&r" (s->index), "=&r" (value)
269 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
274 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
276 ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
278 //if(n>24) printf("%d %d\n", n, value);
282 # endif //!ALIGNED_BITSTREAM_WRITER
286 static inline void put_sbits(PutBitContext *pb, int bits, int32_t val)
288 assert(bits >= 0 && bits <= 31);
290 put_bits(pb, bits, val & ((1<<bits)-1));
294 static inline uint8_t* pbBufPtr(PutBitContext *s)
296 #ifdef ALT_BITSTREAM_WRITER
297 return s->buf + (s->index>>3);
305 * PutBitContext must be flushed & aligned to a byte boundary before calling this.
307 static inline void skip_put_bytes(PutBitContext *s, int n){
308 assert((put_bits_count(s)&7)==0);
309 #ifdef ALT_BITSTREAM_WRITER
310 FIXME may need some cleaning of the buffer
313 assert(s->bit_left==32);
319 * Skips the given number of bits.
320 * Must only be used if the actual values in the bitstream do not matter.
322 static inline void skip_put_bits(PutBitContext *s, int n){
323 #ifdef ALT_BITSTREAM_WRITER
327 s->buf_ptr-= s->bit_left>>5;
333 * Changes the end of the buffer.
335 static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
336 s->buf_end= s->buf + size;
339 /* Bitstream reader API docs:
341 abritary name which is used as prefix for the internal variables
346 OPEN_READER(name, gb)
347 loads gb into local variables
349 CLOSE_READER(name, gb)
350 stores local vars in gb
352 UPDATE_CACHE(name, gb)
353 refills the internal cache from the bitstream
354 after this call at least MIN_CACHE_BITS will be available,
357 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
359 SHOW_UBITS(name, gb, num)
360 will return the next num bits
362 SHOW_SBITS(name, gb, num)
363 will return the next num bits and do sign extension
365 SKIP_BITS(name, gb, num)
366 will skip over the next num bits
367 note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
369 SKIP_CACHE(name, gb, num)
370 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
372 SKIP_COUNTER(name, gb, num)
373 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
375 LAST_SKIP_CACHE(name, gb, num)
376 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
378 LAST_SKIP_BITS(name, gb, num)
379 is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER
381 for examples see get_bits, show_bits, skip_bits, get_vlc
384 #ifdef ALT_BITSTREAM_READER
385 # define MIN_CACHE_BITS 25
387 # define OPEN_READER(name, gb)\
388 int name##_index= (gb)->index;\
389 int name##_cache= 0;\
391 # define CLOSE_READER(name, gb)\
392 (gb)->index= name##_index;\
394 # ifdef ALT_BITSTREAM_READER_LE
395 # define UPDATE_CACHE(name, gb)\
396 name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
398 # define SKIP_CACHE(name, gb, num)\
399 name##_cache >>= (num);
401 # define UPDATE_CACHE(name, gb)\
402 name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
404 # define SKIP_CACHE(name, gb, num)\
405 name##_cache <<= (num);
409 # define SKIP_COUNTER(name, gb, num)\
410 name##_index += (num);\
412 # define SKIP_BITS(name, gb, num)\
414 SKIP_CACHE(name, gb, num)\
415 SKIP_COUNTER(name, gb, num)\
418 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
419 # define LAST_SKIP_CACHE(name, gb, num) ;
421 # ifdef ALT_BITSTREAM_READER_LE
422 # define SHOW_UBITS(name, gb, num)\
423 ((name##_cache) & (NEG_USR32(0xffffffff,num)))
425 # define SHOW_SBITS(name, gb, num)\
426 NEG_SSR32((name##_cache)<<(32-(num)), num)
428 # define SHOW_UBITS(name, gb, num)\
429 NEG_USR32(name##_cache, num)
431 # define SHOW_SBITS(name, gb, num)\
432 NEG_SSR32(name##_cache, num)
435 # define GET_CACHE(name, gb)\
436 ((uint32_t)name##_cache)
438 static inline int get_bits_count(GetBitContext *s){
442 static inline void skip_bits_long(GetBitContext *s, int n){
446 #elif defined LIBMPEG2_BITSTREAM_READER
447 //libmpeg2 like reader
449 # define MIN_CACHE_BITS 17
451 # define OPEN_READER(name, gb)\
452 int name##_bit_count=(gb)->bit_count;\
453 int name##_cache= (gb)->cache;\
454 uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
456 # define CLOSE_READER(name, gb)\
457 (gb)->bit_count= name##_bit_count;\
458 (gb)->cache= name##_cache;\
459 (gb)->buffer_ptr= name##_buffer_ptr;\
461 # define UPDATE_CACHE(name, gb)\
462 if(name##_bit_count >= 0){\
463 name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \
464 name##_buffer_ptr+=2;\
465 name##_bit_count-= 16;\
468 # define SKIP_CACHE(name, gb, num)\
469 name##_cache <<= (num);\
471 # define SKIP_COUNTER(name, gb, num)\
472 name##_bit_count += (num);\
474 # define SKIP_BITS(name, gb, num)\
476 SKIP_CACHE(name, gb, num)\
477 SKIP_COUNTER(name, gb, num)\
480 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
481 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
483 # define SHOW_UBITS(name, gb, num)\
484 NEG_USR32(name##_cache, num)
486 # define SHOW_SBITS(name, gb, num)\
487 NEG_SSR32(name##_cache, num)
489 # define GET_CACHE(name, gb)\
490 ((uint32_t)name##_cache)
492 static inline int get_bits_count(GetBitContext *s){
493 return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
496 static inline void skip_bits_long(GetBitContext *s, int n){
499 re_buffer_ptr += 2*(re_bit_count>>4);
501 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
506 #elif defined A32_BITSTREAM_READER
508 # define MIN_CACHE_BITS 32
510 # define OPEN_READER(name, gb)\
511 int name##_bit_count=(gb)->bit_count;\
512 uint32_t name##_cache0= (gb)->cache0;\
513 uint32_t name##_cache1= (gb)->cache1;\
514 uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
516 # define CLOSE_READER(name, gb)\
517 (gb)->bit_count= name##_bit_count;\
518 (gb)->cache0= name##_cache0;\
519 (gb)->cache1= name##_cache1;\
520 (gb)->buffer_ptr= name##_buffer_ptr;\
522 # define UPDATE_CACHE(name, gb)\
523 if(name##_bit_count > 0){\
524 const uint32_t next= be2me_32( *name##_buffer_ptr );\
525 name##_cache0 |= NEG_USR32(next,name##_bit_count);\
526 name##_cache1 |= next<<name##_bit_count;\
527 name##_buffer_ptr++;\
528 name##_bit_count-= 32;\
531 #if defined(ARCH_X86)
532 # define SKIP_CACHE(name, gb, num)\
534 "shldl %2, %1, %0 \n\t"\
536 : "+r" (name##_cache0), "+r" (name##_cache1)\
537 : "Ic" ((uint8_t)(num))\
540 # define SKIP_CACHE(name, gb, num)\
541 name##_cache0 <<= (num);\
542 name##_cache0 |= NEG_USR32(name##_cache1,num);\
543 name##_cache1 <<= (num);
546 # define SKIP_COUNTER(name, gb, num)\
547 name##_bit_count += (num);\
549 # define SKIP_BITS(name, gb, num)\
551 SKIP_CACHE(name, gb, num)\
552 SKIP_COUNTER(name, gb, num)\
555 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
556 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
558 # define SHOW_UBITS(name, gb, num)\
559 NEG_USR32(name##_cache0, num)
561 # define SHOW_SBITS(name, gb, num)\
562 NEG_SSR32(name##_cache0, num)
564 # define GET_CACHE(name, gb)\
567 static inline int get_bits_count(GetBitContext *s){
568 return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
571 static inline void skip_bits_long(GetBitContext *s, int n){
574 re_buffer_ptr += re_bit_count>>5;
576 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
585 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
586 * if MSB not set it is negative
587 * @param n length in bits
590 static inline int get_xbits(GetBitContext *s, int n){
592 register int32_t cache;
595 cache = GET_CACHE(re,s);
597 LAST_SKIP_BITS(re, s, n)
599 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
602 static inline int get_sbits(GetBitContext *s, int n){
606 tmp= SHOW_SBITS(re, s, n);
607 LAST_SKIP_BITS(re, s, n)
614 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
616 static inline unsigned int get_bits(GetBitContext *s, int n){
620 tmp= SHOW_UBITS(re, s, n);
621 LAST_SKIP_BITS(re, s, n)
628 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
630 static inline unsigned int show_bits(GetBitContext *s, int n){
634 tmp= SHOW_UBITS(re, s, n);
635 // CLOSE_READER(re, s)
639 static inline void skip_bits(GetBitContext *s, int n){
640 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
643 LAST_SKIP_BITS(re, s, n)
647 static inline unsigned int get_bits1(GetBitContext *s){
648 #ifdef ALT_BITSTREAM_READER
650 uint8_t result= s->buffer[ index>>3 ];
651 #ifdef ALT_BITSTREAM_READER_LE
652 result>>= (index&0x07);
655 result<<= (index&0x07);
663 return get_bits(s, 1);
667 static inline unsigned int show_bits1(GetBitContext *s){
668 return show_bits(s, 1);
671 static inline void skip_bits1(GetBitContext *s){
678 static inline unsigned int get_bits_long(GetBitContext *s, int n){
679 if(n<=17) return get_bits(s, n);
681 #ifdef ALT_BITSTREAM_READER_LE
682 int ret= get_bits(s, 16);
683 return ret | (get_bits(s, n-16) << 16);
685 int ret= get_bits(s, 16) << (n-16);
686 return ret | get_bits(s, n-16);
694 static inline unsigned int show_bits_long(GetBitContext *s, int n){
695 if(n<=17) return show_bits(s, n);
697 GetBitContext gb= *s;
698 int ret= get_bits_long(s, n);
704 static inline int check_marker(GetBitContext *s, const char *msg)
706 int bit= get_bits1(s);
708 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
714 * init GetBitContext.
715 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
716 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
717 * @param bit_size the size of the buffer in bits
719 static inline void init_get_bits(GetBitContext *s,
720 const uint8_t *buffer, int bit_size)
722 int buffer_size= (bit_size+7)>>3;
723 if(buffer_size < 0 || bit_size < 0) {
724 buffer_size = bit_size = 0;
729 s->size_in_bits= bit_size;
730 s->buffer_end= buffer + buffer_size;
731 #ifdef ALT_BITSTREAM_READER
733 #elif defined LIBMPEG2_BITSTREAM_READER
734 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
735 s->bit_count = 16 + 8*((intptr_t)buffer&1);
736 skip_bits_long(s, 0);
737 #elif defined A32_BITSTREAM_READER
738 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
739 s->bit_count = 32 + 8*((intptr_t)buffer&3);
740 skip_bits_long(s, 0);
744 static inline void align_get_bits(GetBitContext *s)
746 int n= (-get_bits_count(s)) & 7;
747 if(n) skip_bits(s, n);
750 #define init_vlc(vlc, nb_bits, nb_codes,\
751 bits, bits_wrap, bits_size,\
752 codes, codes_wrap, codes_size,\
754 init_vlc_sparse(vlc, nb_bits, nb_codes,\
755 bits, bits_wrap, bits_size,\
756 codes, codes_wrap, codes_size,\
759 int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes,
760 const void *bits, int bits_wrap, int bits_size,
761 const void *codes, int codes_wrap, int codes_size,
762 const void *symbols, int symbols_wrap, int symbols_size,
764 #define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden
765 #define INIT_VLC_LE 2
766 #define INIT_VLC_USE_NEW_STATIC 4
767 void free_vlc(VLC *vlc);
769 #define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\
771 static VLC_TYPE table[static_size][2];\
772 (vlc)->table= table;\
773 (vlc)->table_allocated= static_size;\
774 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\
780 * if the vlc code is invalid and max_depth=1 than no bits will be removed
781 * if the vlc code is invalid and max_depth>1 than the number of bits removed
784 #define GET_VLC(code, name, gb, table, bits, max_depth)\
786 int n, index, nb_bits;\
788 index= SHOW_UBITS(name, gb, bits);\
789 code = table[index][0];\
790 n = table[index][1];\
792 if(max_depth > 1 && n < 0){\
793 LAST_SKIP_BITS(name, gb, bits)\
794 UPDATE_CACHE(name, gb)\
798 index= SHOW_UBITS(name, gb, nb_bits) + code;\
799 code = table[index][0];\
800 n = table[index][1];\
801 if(max_depth > 2 && n < 0){\
802 LAST_SKIP_BITS(name, gb, nb_bits)\
803 UPDATE_CACHE(name, gb)\
807 index= SHOW_UBITS(name, gb, nb_bits) + code;\
808 code = table[index][0];\
809 n = table[index][1];\
812 SKIP_BITS(name, gb, n)\
815 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
817 int n, index, nb_bits;\
819 index= SHOW_UBITS(name, gb, bits);\
820 level = table[index].level;\
821 n = table[index].len;\
823 if(max_depth > 1 && n < 0){\
824 SKIP_BITS(name, gb, bits)\
826 UPDATE_CACHE(name, gb)\
831 index= SHOW_UBITS(name, gb, nb_bits) + level;\
832 level = table[index].level;\
833 n = table[index].len;\
835 run= table[index].run;\
836 SKIP_BITS(name, gb, n)\
841 * parses a vlc code, faster then get_vlc()
842 * @param bits is the number of bits which will be read at once, must be
843 * identical to nb_bits in init_vlc()
844 * @param max_depth is the number of times bits bits must be read to completely
845 * read the longest vlc code
846 * = (max_vlc_length + bits - 1) / bits
848 static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
849 int bits, int max_depth)
856 GET_VLC(code, re, s, table, bits, max_depth)
865 static inline void print_bin(int bits, int n){
868 for(i=n-1; i>=0; i--){
869 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
872 av_log(NULL, AV_LOG_DEBUG, " ");
875 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
876 int r= get_bits(s, n);
879 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);
882 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
883 int show= show_bits(s, 24);
884 int pos= get_bits_count(s);
885 int r= get_vlc2(s, table, bits, max_depth);
886 int len= get_bits_count(s) - pos;
887 int bits2= show>>(24-len);
889 print_bin(bits2, len);
891 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
894 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
895 int show= show_bits(s, n);
896 int r= get_xbits(s, n);
899 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);
903 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
904 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
905 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
906 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
907 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
909 #define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__)
912 #define tprintf(p, ...) {}
915 static inline int decode012(GetBitContext *gb){
921 return get_bits1(gb) + 1;
924 static inline int decode210(GetBitContext *gb){
928 return 2 - get_bits1(gb);
931 #endif /* FFMPEG_BITSTREAM_H */