comparison bitstream.h @ 3648:c44d798b06b5 libavcodec

move some functions to bitstream.h to avoid conflicts between different bitstream readers in different codecs
author aurel
date Mon, 28 Aug 2006 18:44:49 +0000
parents 62b3b622f798
children 3335f51b6cd3
comparison
equal deleted inserted replaced
3647:4a93d7102793 3648:c44d798b06b5
3 * bitstream api header. 3 * bitstream api header.
4 */ 4 */
5 5
6 #ifndef BITSTREAM_H 6 #ifndef BITSTREAM_H
7 #define BITSTREAM_H 7 #define BITSTREAM_H
8
9 #include "log.h"
8 10
9 //#define ALT_BITSTREAM_WRITER 11 //#define ALT_BITSTREAM_WRITER
10 //#define ALIGNED_BITSTREAM_WRITER 12 //#define ALIGNED_BITSTREAM_WRITER
11 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) 13 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
12 #define ALT_BITSTREAM_READER 14 #define ALT_BITSTREAM_READER
640 LAST_SKIP_BITS(re, s, n) 642 LAST_SKIP_BITS(re, s, n)
641 CLOSE_READER(re, s) 643 CLOSE_READER(re, s)
642 return tmp; 644 return tmp;
643 } 645 }
644 646
645 unsigned int get_bits_long(GetBitContext *s, int n);
646
647 /** 647 /**
648 * shows 0-17 bits. 648 * shows 0-17 bits.
649 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't 649 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
650 */ 650 */
651 static inline unsigned int show_bits(GetBitContext *s, int n){ 651 static inline unsigned int show_bits(GetBitContext *s, int n){
655 tmp= SHOW_UBITS(re, s, n); 655 tmp= SHOW_UBITS(re, s, n);
656 // CLOSE_READER(re, s) 656 // CLOSE_READER(re, s)
657 return tmp; 657 return tmp;
658 } 658 }
659 659
660 unsigned int show_bits_long(GetBitContext *s, int n);
661
662 static inline void skip_bits(GetBitContext *s, int n){ 660 static inline void skip_bits(GetBitContext *s, int n){
663 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) 661 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
664 OPEN_READER(re, s) 662 OPEN_READER(re, s)
665 UPDATE_CACHE(re, s) 663 UPDATE_CACHE(re, s)
666 LAST_SKIP_BITS(re, s, n) 664 LAST_SKIP_BITS(re, s, n)
691 return show_bits(s, 1); 689 return show_bits(s, 1);
692 } 690 }
693 691
694 static inline void skip_bits1(GetBitContext *s){ 692 static inline void skip_bits1(GetBitContext *s){
695 skip_bits(s, 1); 693 skip_bits(s, 1);
694 }
695
696 /**
697 * reads 0-32 bits.
698 */
699 static inline unsigned int get_bits_long(GetBitContext *s, int n){
700 if(n<=17) return get_bits(s, n);
701 else{
702 int ret= get_bits(s, 16) << (n-16);
703 return ret | get_bits(s, n-16);
704 }
705 }
706
707 /**
708 * shows 0-32 bits.
709 */
710 static inline unsigned int show_bits_long(GetBitContext *s, int n){
711 if(n<=17) return show_bits(s, n);
712 else{
713 GetBitContext gb= *s;
714 int ret= get_bits_long(s, n);
715 *s= gb;
716 return ret;
717 }
718 }
719
720 static inline int check_marker(GetBitContext *s, const char *msg)
721 {
722 int bit= get_bits1(s);
723 if(!bit)
724 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
725
726 return bit;
696 } 727 }
697 728
698 /** 729 /**
699 * init GetBitContext. 730 * init GetBitContext.
700 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits 731 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
826 } 857 }
827 858
828 //#define TRACE 859 //#define TRACE
829 860
830 #ifdef TRACE 861 #ifdef TRACE
831 #include "avcodec.h"
832 static inline void print_bin(int bits, int n){ 862 static inline void print_bin(int bits, int n){
833 int i; 863 int i;
834 864
835 for(i=n-1; i>=0; i--){ 865 for(i=n-1; i>=0; i--){
836 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); 866 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);