Mercurial > libavcodec.hg
comparison bitstream.h @ 2967:ef2149182f1c libavcodec
COSMETICS: Remove all trailing whitespace.
| author | diego |
|---|---|
| date | Sat, 17 Dec 2005 18:14:38 +0000 |
| parents | 26f8974c3d66 |
| children | bfabfdf9ce55 |
comparison
equal
deleted
inserted
replaced
| 2966:564788471dd4 | 2967:ef2149182f1c |
|---|---|
| 11 | 11 |
| 12 #define ALT_BITSTREAM_READER | 12 #define ALT_BITSTREAM_READER |
| 13 //#define LIBMPEG2_BITSTREAM_READER | 13 //#define LIBMPEG2_BITSTREAM_READER |
| 14 //#define A32_BITSTREAM_READER | 14 //#define A32_BITSTREAM_READER |
| 15 #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO | 15 #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO |
| 16 | 16 |
| 17 extern const uint8_t ff_reverse[256]; | 17 extern const uint8_t ff_reverse[256]; |
| 18 | 18 |
| 19 #if defined(ARCH_X86) || defined(ARCH_X86_64) | 19 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
| 20 // avoid +32 for shift optimization (gcc should do that ...) | 20 // avoid +32 for shift optimization (gcc should do that ...) |
| 21 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | 21 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ |
| 171 #ifdef STATS | 171 #ifdef STATS |
| 172 st_out_bit_counts[st_current_index] += n; | 172 st_out_bit_counts[st_current_index] += n; |
| 173 #endif | 173 #endif |
| 174 // printf("put_bits=%d %x\n", n, value); | 174 // printf("put_bits=%d %x\n", n, value); |
| 175 assert(n == 32 || value < (1U << n)); | 175 assert(n == 32 || value < (1U << n)); |
| 176 | 176 |
| 177 bit_buf = s->bit_buf; | 177 bit_buf = s->bit_buf; |
| 178 bit_left = s->bit_left; | 178 bit_left = s->bit_left; |
| 179 | 179 |
| 180 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); | 180 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); |
| 181 /* XXX: optimize */ | 181 /* XXX: optimize */ |
| 229 : "%eax", "%ecx" | 229 : "%eax", "%ecx" |
| 230 ); | 230 ); |
| 231 # else | 231 # else |
| 232 int index= s->index; | 232 int index= s->index; |
| 233 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); | 233 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); |
| 234 | 234 |
| 235 value<<= 32-n; | 235 value<<= 32-n; |
| 236 | 236 |
| 237 ptr[0] |= be2me_32(value>>(index&31)); | 237 ptr[0] |= be2me_32(value>>(index&31)); |
| 238 ptr[1] = be2me_32(value<<(32-(index&31))); | 238 ptr[1] = be2me_32(value<<(32-(index&31))); |
| 239 //if(n>24) printf("%d %d\n", n, value); | 239 //if(n>24) printf("%d %d\n", n, value); |
| 240 index+= n; | 240 index+= n; |
| 241 s->index= index; | 241 s->index= index; |
| 259 : "%ecx" | 259 : "%ecx" |
| 260 ); | 260 ); |
| 261 # else | 261 # else |
| 262 int index= s->index; | 262 int index= s->index; |
| 263 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); | 263 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); |
| 264 | 264 |
| 265 ptr[0] |= be2me_32(value<<(32-n-(index&7) )); | 265 ptr[0] |= be2me_32(value<<(32-n-(index&7) )); |
| 266 ptr[1] = 0; | 266 ptr[1] = 0; |
| 267 //if(n>24) printf("%d %d\n", n, value); | 267 //if(n>24) printf("%d %d\n", n, value); |
| 268 index+= n; | 268 index+= n; |
| 269 s->index= index; | 269 s->index= index; |
| 292 FIXME may need some cleaning of the buffer | 292 FIXME may need some cleaning of the buffer |
| 293 s->index += n<<3; | 293 s->index += n<<3; |
| 294 #else | 294 #else |
| 295 assert(s->bit_left==32); | 295 assert(s->bit_left==32); |
| 296 s->buf_ptr += n; | 296 s->buf_ptr += n; |
| 297 #endif | 297 #endif |
| 298 } | 298 } |
| 299 | 299 |
| 300 /** | 300 /** |
| 301 * skips the given number of bits. | 301 * skips the given number of bits. |
| 302 * must only be used if the actual values in the bitstream dont matter | 302 * must only be used if the actual values in the bitstream dont matter |
| 306 s->index += n; | 306 s->index += n; |
| 307 #else | 307 #else |
| 308 s->bit_left -= n; | 308 s->bit_left -= n; |
| 309 s->buf_ptr-= s->bit_left>>5; | 309 s->buf_ptr-= s->bit_left>>5; |
| 310 s->bit_left &= 31; | 310 s->bit_left &= 31; |
| 311 #endif | 311 #endif |
| 312 } | 312 } |
| 313 | 313 |
| 314 /** | 314 /** |
| 315 * Changes the end of the buffer. | 315 * Changes the end of the buffer. |
| 316 */ | 316 */ |
| 567 | 567 |
| 568 #endif | 568 #endif |
| 569 | 569 |
| 570 /** | 570 /** |
| 571 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | 571 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). |
| 572 * if MSB not set it is negative | 572 * if MSB not set it is negative |
| 573 * @param n length in bits | 573 * @param n length in bits |
| 574 * @author BERO | 574 * @author BERO |
| 575 */ | 575 */ |
| 576 static inline int get_xbits(GetBitContext *s, int n){ | 576 static inline int get_xbits(GetBitContext *s, int n){ |
| 577 register int tmp; | 577 register int tmp; |
| 578 register int32_t cache; | 578 register int32_t cache; |
| 579 OPEN_READER(re, s) | 579 OPEN_READER(re, s) |
| 793 // deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly | 793 // deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly |
| 794 static inline int get_vlc(GetBitContext *s, VLC *vlc) | 794 static inline int get_vlc(GetBitContext *s, VLC *vlc) |
| 795 { | 795 { |
| 796 int code; | 796 int code; |
| 797 VLC_TYPE (*table)[2]= vlc->table; | 797 VLC_TYPE (*table)[2]= vlc->table; |
| 798 | 798 |
| 799 OPEN_READER(re, s) | 799 OPEN_READER(re, s) |
| 800 UPDATE_CACHE(re, s) | 800 UPDATE_CACHE(re, s) |
| 801 | 801 |
| 802 GET_VLC(code, re, s, table, vlc->bits, 3) | 802 GET_VLC(code, re, s, table, vlc->bits, 3) |
| 803 | 803 |
| 804 CLOSE_READER(re, s) | 804 CLOSE_READER(re, s) |
| 805 return code; | 805 return code; |
| 806 } | 806 } |
| 807 | 807 |
| 808 /** | 808 /** |
| 809 * parses a vlc code, faster then get_vlc() | 809 * parses a vlc code, faster then get_vlc() |
| 810 * @param bits is the number of bits which will be read at once, must be | 810 * @param bits is the number of bits which will be read at once, must be |
| 811 * identical to nb_bits in init_vlc() | 811 * identical to nb_bits in init_vlc() |
| 812 * @param max_depth is the number of times bits bits must be readed to completly | 812 * @param max_depth is the number of times bits bits must be readed to completly |
| 813 * read the longest vlc code | 813 * read the longest vlc code |
| 814 * = (max_vlc_length + bits - 1) / bits | 814 * = (max_vlc_length + bits - 1) / bits |
| 815 */ | 815 */ |
| 816 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], | 816 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], |
| 817 int bits, int max_depth) | 817 int bits, int max_depth) |
| 818 { | 818 { |
| 819 int code; | 819 int code; |
| 820 | 820 |
| 821 OPEN_READER(re, s) | 821 OPEN_READER(re, s) |
| 822 UPDATE_CACHE(re, s) | 822 UPDATE_CACHE(re, s) |
| 823 | 823 |
| 824 GET_VLC(code, re, s, table, bits, max_depth) | 824 GET_VLC(code, re, s, table, bits, max_depth) |
| 825 | 825 |
| 831 | 831 |
| 832 #ifdef TRACE | 832 #ifdef TRACE |
| 833 #include "avcodec.h" | 833 #include "avcodec.h" |
| 834 static inline void print_bin(int bits, int n){ | 834 static inline void print_bin(int bits, int n){ |
| 835 int i; | 835 int i; |
| 836 | 836 |
| 837 for(i=n-1; i>=0; i--){ | 837 for(i=n-1; i>=0; i--){ |
| 838 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); | 838 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); |
| 839 } | 839 } |
| 840 for(i=n; i<24; i++) | 840 for(i=n; i<24; i++) |
| 841 av_log(NULL, AV_LOG_DEBUG, " "); | 841 av_log(NULL, AV_LOG_DEBUG, " "); |
| 842 } | 842 } |
| 843 | 843 |
| 844 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | 844 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
| 845 int r= get_bits(s, n); | 845 int r= get_bits(s, n); |
| 846 | 846 |
| 847 print_bin(r, n); | 847 print_bin(r, n); |
| 848 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); | 848 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); |
| 849 return r; | 849 return r; |
| 850 } | 850 } |
| 851 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ | 851 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ |
| 852 int show= show_bits(s, 24); | 852 int show= show_bits(s, 24); |
| 853 int pos= get_bits_count(s); | 853 int pos= get_bits_count(s); |
| 854 int r= get_vlc2(s, table, bits, max_depth); | 854 int r= get_vlc2(s, table, bits, max_depth); |
| 855 int len= get_bits_count(s) - pos; | 855 int len= get_bits_count(s) - pos; |
| 856 int bits2= show>>(24-len); | 856 int bits2= show>>(24-len); |
| 857 | 857 |
| 858 print_bin(bits2, len); | 858 print_bin(bits2, len); |
| 859 | 859 |
| 860 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); | 860 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); |
| 861 return r; | 861 return r; |
| 862 } | 862 } |
| 863 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | 863 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
| 864 int show= show_bits(s, n); | 864 int show= show_bits(s, n); |
| 865 int r= get_xbits(s, n); | 865 int r= get_xbits(s, n); |
| 866 | 866 |
| 867 print_bin(show, n); | 867 print_bin(show, n); |
| 868 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); | 868 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); |
| 869 return r; | 869 return r; |
| 870 } | 870 } |
| 871 | 871 |
