diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2003-05-14 10:55:59 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2003-05-14 10:55:59 +0000 |
commit | 17fb5fd34e96ce472019d4f2b8d798bbd885a24b (patch) | |
tree | 2ff6cb1985d58cbd551d79c5b9347b29f3788bdf | |
parent | 924311cd9828695b42cf639c4ea5f258c1a04efd (diff) | |
download | ffmpeg-17fb5fd34e96ce472019d4f2b8d798bbd885a24b.tar.gz |
libmpeg2 style bitstream reader fixes
Originally committed as revision 1875 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/common.c | 26 | ||||
-rw-r--r-- | libavcodec/common.h | 25 | ||||
-rw-r--r-- | libavcodec/h263.c | 8 |
3 files changed, 49 insertions, 10 deletions
diff --git a/libavcodec/common.c b/libavcodec/common.c index 4f70e6f924..26165b9018 100644 --- a/libavcodec/common.c +++ b/libavcodec/common.c @@ -140,7 +140,7 @@ void init_get_bits(GetBitContext *s, #ifdef ALT_BITSTREAM_READER s->index=0; #elif defined LIBMPEG2_BITSTREAM_READER -#ifdef LIBMPEG2_BITSTREAM_HACK +#ifdef LIBMPEG2_BITSTREAM_READER_HACK if ((int)buffer&1) { /* word alignment */ s->cache = (*buffer++)<<24; @@ -170,6 +170,30 @@ void init_get_bits(GetBitContext *s, #endif } +/** + * reads 0-32 bits. + */ +unsigned int get_bits_long(GetBitContext *s, int n){ + if(n<=17) return get_bits(s, n); + else{ + int ret= get_bits(s, 16) << (n-16); + return ret | get_bits(s, n-16); + } +} + +/** + * shows 0-32 bits. + */ +unsigned int show_bits_long(GetBitContext *s, int n){ + if(n<=17) return show_bits(s, n); + else{ + GetBitContext gb= *s; + int ret= get_bits_long(s, n); + *s= gb; + return ret; + } +} + void align_get_bits(GetBitContext *s) { int n= (-get_bits_count(s)) & 7; diff --git a/libavcodec/common.h b/libavcodec/common.h index 494db42e2e..1a8202d709 100644 --- a/libavcodec/common.h +++ b/libavcodec/common.h @@ -543,8 +543,8 @@ static inline int get_bits_count(GetBitContext *s){ # define UPDATE_CACHE(name, gb)\ if(name##_bit_count >= 0){\ - name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr++) << name##_bit_count;\ - name##_buffer_ptr+=2;\ + name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\ + ((uint16_t*)name##_buffer_ptr)++;\ name##_bit_count-= 16;\ }\ @@ -654,9 +654,12 @@ static inline int get_bits_count(GetBitContext *s){ #endif -/* add BERO - if MSB not set it is negative -*/ +/** + * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). + * if MSB not set it is negative + * @param n length in bits + * @author BERO + */ static inline int get_xbits(GetBitContext *s, int n){ register int tmp; register int32_t cache; @@ -685,6 +688,10 @@ static inline int get_sbits(GetBitContext *s, int n){ return tmp; } +/** + * reads 0-17 bits. + * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant + */ static inline unsigned int get_bits(GetBitContext *s, int n){ register int tmp; OPEN_READER(re, s) @@ -695,6 +702,12 @@ static inline unsigned int get_bits(GetBitContext *s, int n){ return tmp; } +unsigned int get_bits_long(GetBitContext *s, int n); + +/** + * shows 0-17 bits. + * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant + */ static inline unsigned int show_bits(GetBitContext *s, int n){ register int tmp; OPEN_READER(re, s) @@ -704,6 +717,8 @@ static inline unsigned int show_bits(GetBitContext *s, int n){ return tmp; } +unsigned int show_bits_long(GetBitContext *s, int n); + static inline void skip_bits(GetBitContext *s, int n){ //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) OPEN_READER(re, s) diff --git a/libavcodec/h263.c b/libavcodec/h263.c index 259ca8431f..f6f2efceea 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -2708,7 +2708,7 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){ if(s->pict_type==I_TYPE){ int i; - if(show_bits(&s->gb, 19)==DC_MARKER){ + if(show_bits_long(&s->gb, 19)==DC_MARKER){ return mb_num-1; } @@ -2956,7 +2956,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) s->mb_num_left= mb_num; if(s->pict_type==I_TYPE){ - if(get_bits(&s->gb, 19)!=DC_MARKER){ + if(get_bits_long(&s->gb, 19)!=DC_MARKER){ fprintf(stderr, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y); return -1; } @@ -3885,7 +3885,7 @@ int h263_decode_picture_header(MpegEncContext *s) int format, width, height; /* picture start code */ - if (get_bits(&s->gb, 22) != 0x20) { + if (get_bits_long(&s->gb, 22) != 0x20) { fprintf(stderr, "Bad picture start code\n"); return -1; } @@ -4878,7 +4878,7 @@ int intel_h263_decode_picture_header(MpegEncContext *s) int format; /* picture header */ - if (get_bits(&s->gb, 22) != 0x20) { + if (get_bits_long(&s->gb, 22) != 0x20) { fprintf(stderr, "Bad picture start code\n"); return -1; } |