From 6e44ba15504c05adb4ba610d83205bb7c499fb58 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Mon, 16 Nov 2009 17:42:43 +0000 Subject: [PATCH] Use get_bits_left() instead of size_in_bits - get_bits_count(). Originally committed as revision 20543 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/alsdec.c | 2 +- libavcodec/h261dec.c | 4 ++-- libavcodec/h263.c | 8 ++++---- libavcodec/h263dec.c | 8 ++++---- libavcodec/h264.c | 2 +- libavcodec/huffyuv.c | 4 ++-- libavcodec/mpeg12.c | 2 +- libavcodec/mpeg4audio.c | 2 +- libavcodec/mpegaudiodec.c | 4 ++-- libavcodec/msmpeg4.c | 2 +- libavcodec/wavpack.c | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index 064e143f74..ac4a1f86a3 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -380,7 +380,7 @@ static void parse_bs_info(const uint32_t bs_info, unsigned int n, */ static int32_t decode_rice(GetBitContext *gb, unsigned int k) { - int max = gb->size_in_bits - get_bits_count(gb) - k; + int max = get_bits_left(gb) - k; int q = get_unary(gb, 0, max); int r = k ? get_bits1(gb) : !(q & 1); diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index d5dcc0b2c4..9c2db71bff 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -170,7 +170,7 @@ static int ff_h261_resync(H261Context *h){ //OK, it is not where it is supposed to be ... s->gb= s->last_resync_gb; align_get_bits(&s->gb); - left= s->gb.size_in_bits - get_bits_count(&s->gb); + left= get_bits_left(&s->gb); for(;left>15+1+4+5; left-=8){ if(show_bits(&s->gb, 15)==0){ @@ -444,7 +444,7 @@ static int h261_decode_picture_header(H261Context *h){ int format, i; uint32_t startcode= 0; - for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){ + for(i= get_bits_left(&s->gb); i>24; i-=1){ startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF; if(startcode == 0x10) diff --git a/libavcodec/h263.c b/libavcodec/h263.c index a8c03339e6..85da205815 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -2994,7 +2994,7 @@ static int h263_decode_gob_header(MpegEncContext *s) /* We have a GBSC probably with GSTUFF */ skip_bits(&s->gb, 16); /* Drop the zeros */ - left= s->gb.size_in_bits - get_bits_count(&s->gb); + left= get_bits_left(&s->gb); //MN: we must check the bits left or we might end in a infinite loop (or segfault) for(;left>13; left--){ if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ @@ -3329,7 +3329,7 @@ int ff_h263_resync(MpegEncContext *s){ //OK, it's not where it is supposed to be ... s->gb= s->last_resync_gb; align_get_bits(&s->gb); - left= s->gb.size_in_bits - get_bits_count(&s->gb); + left= get_bits_left(&s->gb); for(;left>16+1+5+5; left-=8){ if(show_bits(&s->gb, 16)==0){ @@ -3774,7 +3774,7 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64]) /* per-MB end of slice check */ if(--s->mb_num_left <= 0){ -//printf("%06X %d\n", show_bits(&s->gb, 24), s->gb.size_in_bits - get_bits_count(&s->gb)); +//printf("%06X %d\n", show_bits(&s->gb, 24), get_bits_left(&s->gb)); if(mpeg4_is_resync(s)) return SLICE_END; else @@ -5034,7 +5034,7 @@ int h263_decode_picture_header(MpegEncContext *s) startcode= get_bits(&s->gb, 22-8); - for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=8) { + for(i= get_bits_left(&s->gb); i>24; i-=8) { startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; if(startcode == 0x20) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index c158436574..d75904cec4 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -268,8 +268,8 @@ static int decode_slice(MpegEncContext *s){ /* try to detect the padding bug */ if( s->codec_id==CODEC_ID_MPEG4 && (s->workaround_bugs&FF_BUG_AUTODETECT) - && s->gb.size_in_bits - get_bits_count(&s->gb) >=0 - && s->gb.size_in_bits - get_bits_count(&s->gb) < 48 + && get_bits_left(&s->gb) >=0 + && get_bits_left(&s->gb) < 48 // && !s->resync_marker && !s->data_partitioning){ @@ -300,7 +300,7 @@ static int decode_slice(MpegEncContext *s){ // handle formats which don't have unique end markers if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){ //FIXME perhaps solve this more cleanly - int left= s->gb.size_in_bits - get_bits_count(&s->gb); + int left= get_bits_left(&s->gb); int max_extra=7; /* no markers in M$ crap */ @@ -325,7 +325,7 @@ static int decode_slice(MpegEncContext *s){ } av_log(s->avctx, AV_LOG_ERROR, "slice end not reached but screenspace end (%d left %06X, score= %d)\n", - s->gb.size_in_bits - get_bits_count(&s->gb), + get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score); ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); diff --git a/libavcodec/h264.c b/libavcodec/h264.c index daf6c3ea77..cf6771aa79 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -6692,7 +6692,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ ff_init_cabac_states( &h->cabac); ff_init_cabac_decoder( &h->cabac, s->gb.buffer + get_bits_count(&s->gb)/8, - ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8); + (get_bits_left(&s->gb) + 7)/8); /* calculate pre-state */ for( i= 0; i < 460; i++ ) { int pre; diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c index 3c64029bad..4fa6ddf7f8 100644 --- a/libavcodec/huffyuv.c +++ b/libavcodec/huffyuv.c @@ -693,7 +693,7 @@ static void decode_422_bitstream(HYuvContext *s, int count){ count/=2; - if(count >= (s->gb.size_in_bits - get_bits_count(&s->gb))/(31*4)){ + if(count >= (get_bits_left(&s->gb))/(31*4)){ for(i=0; igb) < s->gb.size_in_bits; i++){ READ_2PIX(s->temp[0][2*i ], s->temp[1][i], 1); READ_2PIX(s->temp[0][2*i+1], s->temp[2][i], 2); @@ -711,7 +711,7 @@ static void decode_gray_bitstream(HYuvContext *s, int count){ count/=2; - if(count >= (s->gb.size_in_bits - get_bits_count(&s->gb))/(31*2)){ + if(count >= (get_bits_left(&s->gb))/(31*2)){ for(i=0; igb) < s->gb.size_in_bits; i++){ READ_2PIX(s->temp[0][2*i ], s->temp[0][2*i+1], 0); } diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 08dea404b4..f226602004 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1818,7 +1818,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->mb_y++; if(s->mb_y<= s->mb_height){ - int left= s->gb.size_in_bits - get_bits_count(&s->gb); + int left= get_bits_left(&s->gb); int is_d10= s->chroma_format==2 && s->pict_type==FF_I_TYPE && avctx->profile==0 && avctx->level==5 && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0 && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/; diff --git a/libavcodec/mpeg4audio.c b/libavcodec/mpeg4audio.c index ab51a61e3c..7fe25bd3d6 100644 --- a/libavcodec/mpeg4audio.c +++ b/libavcodec/mpeg4audio.c @@ -32,7 +32,7 @@ */ static int parse_config_ALS(GetBitContext *gb, MPEG4AudioConfig *c) { - if (gb->size_in_bits - get_bits_count(gb) < 112) + if (get_bits_left(gb) < 112) return -1; if (get_bits_long(gb, 32) != MKBETAG('A','L','S','\0')) diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c index 658e22fcda..c3efd8657a 100644 --- a/libavcodec/mpegaudiodec.c +++ b/libavcodec/mpegaudiodec.c @@ -2162,7 +2162,7 @@ static int mp_decode_frame(MPADecodeContext *s, s->last_buf_size=0; if(s->in_gb.buffer){ align_get_bits(&s->gb); - i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3; + i= get_bits_left(&s->gb)>>3; if(i >= 0 && i <= BACKSTEP_SIZE){ memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i); s->last_buf_size=i; @@ -2174,7 +2174,7 @@ static int mp_decode_frame(MPADecodeContext *s, align_get_bits(&s->gb); assert((get_bits_count(&s->gb) & 7) == 0); - i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3; + i= get_bits_left(&s->gb)>>3; if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){ if(i<0) diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index 8c0da0ae10..c94d2a2639 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -1823,7 +1823,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, if (i > 62){ i-= 192; if(i&(~63)){ - const int left= s->gb.size_in_bits - get_bits_count(&s->gb); + const int left= get_bits_left(&s->gb); if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){ av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); break; diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 95f1d7123b..783e7d70bf 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -378,7 +378,7 @@ static float wv_get_value_float(WavpackContext *s, uint32_t *crc, int S) if(s->got_extra_bits){ const int max_bits = 1 + 23 + 8 + 1; - const int left_bits = s->gb_extra_bits.size_in_bits - get_bits_count(&s->gb_extra_bits); + const int left_bits = get_bits_left(&s->gb_extra_bits); if(left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits) return 0.0; @@ -897,7 +897,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, return -1; } if(s->got_extra_bits && avctx->sample_fmt != SAMPLE_FMT_FLT){ - const int size = s->gb_extra_bits.size_in_bits - get_bits_count(&s->gb_extra_bits); + const int size = get_bits_left(&s->gb_extra_bits); const int wanted = s->samples * s->extra_bits << s->stereo_in; if(size < wanted){ av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");