comparison common.h @ 306:ebfd518cbbbf libavcodec

dump_stream support (nicely formated 0s and 1s)
author michaelni
date Thu, 04 Apr 2002 20:04:10 +0000
parents 2899263586cd
children 9c6f056f0e41
comparison
equal deleted inserted replaced
305:1de85b419387 306:ebfd518cbbbf
11 //#define ALT_BITSTREAM_WRITER 11 //#define ALT_BITSTREAM_WRITER
12 //#define ALIGNED_BITSTREAM_WRITER 12 //#define ALIGNED_BITSTREAM_WRITER
13 //#define ALT_BITSTREAM_READER 13 //#define ALT_BITSTREAM_READER
14 //#define ALIGNED_BITSTREAM 14 //#define ALIGNED_BITSTREAM
15 #define FAST_GET_FIRST_VLC 15 #define FAST_GET_FIRST_VLC
16 //#define DUMP_STREAM // only works with the ALT_BITSTREAM_READER
16 17
17 #ifdef HAVE_AV_CONFIG_H 18 #ifdef HAVE_AV_CONFIG_H
18 /* only include the following when compiling package */ 19 /* only include the following when compiling package */
19 #include "../config.h" 20 #include "../config.h"
20 21
241 #ifdef STATS 242 #ifdef STATS
242 st_out_bit_counts[st_current_index] += n; 243 st_out_bit_counts[st_current_index] += n;
243 #endif 244 #endif
244 // printf("put_bits=%d %x\n", n, value); 245 // printf("put_bits=%d %x\n", n, value);
245 assert(n == 32 || value < (1U << n)); 246 assert(n == 32 || value < (1U << n));
246 247
247 bit_buf = s->bit_buf; 248 bit_buf = s->bit_buf;
248 bit_left = s->bit_left; 249 bit_left = s->bit_left;
249 250
250 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); 251 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
251 /* XXX: optimize */ 252 /* XXX: optimize */
467 468
468 result<<= (index&0x07); 469 result<<= (index&0x07);
469 result>>= 32 - n; 470 result>>= 32 - n;
470 index+= n; 471 index+= n;
471 s->index= index; 472 s->index= index;
472 473 #ifdef DUMP_STREAM
474 while(n){
475 printf("%d", (result>>(n-1))&1);
476 n--;
477 }
478 printf(" ");
479 #endif
473 return result; 480 return result;
474 #endif //!ALIGNED_BITSTREAM 481 #endif //!ALIGNED_BITSTREAM
475 #else //ALT_BITSTREAM_READER 482 #else //ALT_BITSTREAM_READER
476 if(s->bit_cnt>=n){ 483 if(s->bit_cnt>=n){
477 /* most common case here */ 484 /* most common case here */
494 result<<= (index&0x07); 501 result<<= (index&0x07);
495 result>>= 8 - 1; 502 result>>= 8 - 1;
496 index++; 503 index++;
497 s->index= index; 504 s->index= index;
498 505
506 #ifdef DUMP_STREAM
507 printf("%d ", result);
508 #endif
499 return result; 509 return result;
500 #else 510 #else
501 if(s->bit_cnt>0){ 511 if(s->bit_cnt>0){
502 /* most common case here */ 512 /* most common case here */
503 unsigned int val = s->bit_buf >> 31; 513 unsigned int val = s->bit_buf >> 31;
591 } 601 }
592 602
593 static inline void skip_bits(GetBitContext *s, int n){ 603 static inline void skip_bits(GetBitContext *s, int n){
594 #ifdef ALT_BITSTREAM_READER 604 #ifdef ALT_BITSTREAM_READER
595 s->index+= n; 605 s->index+= n;
606 #ifdef DUMP_STREAM
607 {
608 int result;
609 s->index-= n;
610 result= get_bits(s, n);
611 }
612 #endif
613
596 #else 614 #else
597 if(s->bit_cnt>=n){ 615 if(s->bit_cnt>=n){
598 /* most common case here */ 616 /* most common case here */
599 s->bit_buf <<= n; 617 s->bit_buf <<= n;
600 s->bit_cnt -= n; 618 s->bit_cnt -= n;
608 } 626 }
609 627
610 static inline void skip_bits1(GetBitContext *s){ 628 static inline void skip_bits1(GetBitContext *s){
611 #ifdef ALT_BITSTREAM_READER 629 #ifdef ALT_BITSTREAM_READER
612 s->index++; 630 s->index++;
631 #ifdef DUMP_STREAM
632 s->index--;
633 printf("%d ", get_bits1(s));
634 #endif
613 #else 635 #else
614 if(s->bit_cnt>0){ 636 if(s->bit_cnt>0){
615 /* most common case here */ 637 /* most common case here */
616 s->bit_buf <<= 1; 638 s->bit_buf <<= 1;
617 s->bit_cnt--; 639 s->bit_cnt--;
733 code = table_codes[index]; 755 code = table_codes[index];
734 n = table_bits[index]; 756 n = table_bits[index];
735 if (n > 0) { 757 if (n > 0) {
736 /* most common case (90%)*/ 758 /* most common case (90%)*/
737 FLUSH_BITS(n); 759 FLUSH_BITS(n);
760 #ifdef DUMP_STREAM
761 {
762 int n= bit_cnt - s->index;
763 skip_bits(s, n);
764 RESTORE_BITS(s);
765 }
766 #endif
738 RESTORE_BITS(s); 767 RESTORE_BITS(s);
739 return code; 768 return code;
740 } else if (n == 0) { 769 } else if (n == 0) {
741 return -1; 770 return -1;
742 } else { 771 } else {
767 nb_bits = -n; 796 nb_bits = -n;
768 table_codes = vlc->table_codes + code; 797 table_codes = vlc->table_codes + code;
769 table_bits = vlc->table_bits + code; 798 table_bits = vlc->table_bits + code;
770 } 799 }
771 } 800 }
801 #ifdef DUMP_STREAM
802 {
803 int n= bit_cnt - s->index;
804 skip_bits(s, n);
805 RESTORE_BITS(s);
806 }
807 #endif
772 RESTORE_BITS(s); 808 RESTORE_BITS(s);
773 return code; 809 return code;
774 } 810 }
775 811
776 812