mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
libmpeg2 style bitstream reader fixes
Originally committed as revision 1875 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
924311cd98
commit
17fb5fd34e
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user