aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2003-01-21 17:34:12 +0000
committerMichael Niedermayer <michaelni@gmx.at>2003-01-21 17:34:12 +0000
commit68f593b48433842f3407586679fe07f3e5199ab9 (patch)
treed4630fb579685c92841ecf5b78d3cc47456d07d1
parentfe50f38577887ea8e1a66a95503a97438e2d768f (diff)
downloadffmpeg-68f593b48433842f3407586679fe07f3e5199ab9.tar.gz
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
Originally committed as revision 1486 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/common.c6
-rw-r--r--libavcodec/common.h8
-rw-r--r--libavcodec/dv.c10
-rw-r--r--libavcodec/h263.c22
-rw-r--r--libavcodec/h263dec.c18
-rw-r--r--libavcodec/huffyuv.c8
-rw-r--r--libavcodec/mjpeg.c18
-rw-r--r--libavcodec/mpeg12.c8
-rw-r--r--libavcodec/mpegaudiodec.c4
-rw-r--r--libavcodec/msmpeg4.c4
-rw-r--r--libavcodec/rv10.c2
-rw-r--r--libavcodec/svq1.c2
-rw-r--r--libavcodec/wmadec.c6
-rw-r--r--libavcodec/wmv2.c2
14 files changed, 63 insertions, 55 deletions
diff --git a/libavcodec/common.c b/libavcodec/common.c
index 40ba49811d..a2580ba281 100644
--- a/libavcodec/common.c
+++ b/libavcodec/common.c
@@ -99,10 +99,12 @@ void put_string(PutBitContext * pbc, char *s)
/* bit input functions */
void init_get_bits(GetBitContext *s,
- UINT8 *buffer, int buffer_size)
+ UINT8 *buffer, int bit_size)
{
+ const int buffer_size= (bit_size+7)>>3;
+
s->buffer= buffer;
- s->size= buffer_size;
+ s->size_in_bits= bit_size;
s->buffer_end= buffer + buffer_size;
#ifdef ALT_BITSTREAM_READER
s->index=0;
diff --git a/libavcodec/common.h b/libavcodec/common.h
index afa085bc2b..31bfbb1c90 100644
--- a/libavcodec/common.h
+++ b/libavcodec/common.h
@@ -261,7 +261,7 @@ typedef struct GetBitContext {
UINT32 cache1;
int bit_count;
#endif
- int size;
+ int size_in_bits;
} GetBitContext;
static inline int get_bits_count(GetBitContext *s);
@@ -690,6 +690,12 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
const void *codes, int codes_wrap, int codes_size);
void free_vlc(VLC *vlc);
+/**
+ *
+ * if the vlc code is invalid and max_depth=1 than no bits will be removed
+ * if the vlc code is invalid and max_depth>1 than the number of bits removed
+ * is undefined
+ */
#define GET_VLC(code, name, gb, table, bits, max_depth)\
{\
int n, index, nb_bits;\
diff --git a/libavcodec/dv.c b/libavcodec/dv.c
index 404f018f14..f312c0264c 100644
--- a/libavcodec/dv.c
+++ b/libavcodec/dv.c
@@ -195,7 +195,7 @@ static void dv_decode_ac(DVVideoDecodeContext *s,
v, partial_bit_count, (mb->partial_bit_buffer << l));
#endif
/* try to read the codeword */
- init_get_bits(&gb1, buf, 4);
+ init_get_bits(&gb1, buf, 4*8);
{
OPEN_READER(re1, &gb1);
UPDATE_CACHE(re1, &gb1);
@@ -333,7 +333,7 @@ static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
block = block1;
for(j = 0;j < 6; j++) {
/* NOTE: size is not important here */
- init_get_bits(&s->gb, buf_ptr, 14);
+ init_get_bits(&s->gb, buf_ptr, 14*8);
/* get the dc */
dc = get_bits(&s->gb, 9);
@@ -382,7 +382,7 @@ static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
#endif
block = block1;
mb = mb1;
- init_get_bits(&s->gb, mb_bit_buffer, 80);
+ init_get_bits(&s->gb, mb_bit_buffer, 80*8);
for(j = 0;j < 6; j++) {
if (!mb->eob_reached && s->gb.index < mb_bit_count) {
dv_decode_ac(s, mb, block, mb_bit_count);
@@ -421,7 +421,7 @@ static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
#endif
block = &s->block[0][0];
mb = mb_data;
- init_get_bits(&s->gb, vs_bit_buffer, 5 * 80);
+ init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8);
for(mb_index = 0; mb_index < 5; mb_index++) {
for(j = 0;j < 6; j++) {
if (!mb->eob_reached) {
@@ -501,7 +501,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
const UINT16 *mb_pos_ptr;
/* parse id */
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
sct = get_bits(&s->gb, 3);
if (sct != 0)
return -1;
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index 27fc223f4f..38cd153199 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -2335,7 +2335,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*8 - get_bits_count(&s->gb);
+ left= s->gb.size_in_bits - get_bits_count(&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 */
@@ -2435,7 +2435,7 @@ static inline int mpeg4_is_resync(MpegEncContext *s){
return 0;
}
- if(bits_count + 8 >= s->gb.size*8){
+ if(bits_count + 8 >= s->gb.size_in_bits){
int v= show_bits(&s->gb, 8);
v|= 0x7F >> (7-(bits_count&7));
@@ -2472,7 +2472,7 @@ static int mpeg4_decode_video_packet_header(MpegEncContext *s)
int header_extension=0, mb_num, len;
/* is there enough space left for a video packet + header */
- if( get_bits_count(&s->gb) > s->gb.size*8-20) return -1;
+ if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1;
for(len=0; len<32; len++){
if(get_bits1(&s->gb)) break;
@@ -2604,7 +2604,7 @@ int ff_h263_resync(MpegEncContext *s){
//ok, its not where its supposed to be ...
s->gb= s->last_resync_gb;
align_get_bits(&s->gb);
- left= s->gb.size*8 - get_bits_count(&s->gb);
+ left= s->gb.size_in_bits - get_bits_count(&s->gb);
for(;left>16+1+5+5; left-=8){
if(show_bits(&s->gb, 16)==0){
@@ -3058,7 +3058,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*8 - get_bits_count(&s->gb));
+//printf("%06X %d\n", show_bits(&s->gb, 24), s->gb.size_in_bits - get_bits_count(&s->gb));
if(mpeg4_is_resync(s))
return SLICE_END;
else
@@ -3422,8 +3422,8 @@ end:
}else{
int v= show_bits(&s->gb, 16);
- if(get_bits_count(&s->gb) + 16 > s->gb.size*8){
- v>>= get_bits_count(&s->gb) + 16 - s->gb.size*8;
+ if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){
+ v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits;
}
if(v==0)
@@ -4688,7 +4688,7 @@ static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
printf("qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d\n",
s->qscale, s->f_code, s->b_code,
s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")),
- gb->size,s->progressive_sequence, s->alternate_scan, s->top_field_first,
+ gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first,
s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points,
s->sprite_warping_accuracy);
}
@@ -4743,9 +4743,9 @@ int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
v = get_bits(gb, 8);
startcode = ((startcode << 8) | v) & 0xffffffff;
- if(get_bits_count(gb) >= gb->size*8){
- if(gb->size==1 && s->divx_version){
- printf("frame skip %d\n", gb->size);
+ if(get_bits_count(gb) >= gb->size_in_bits){
+ if(gb->size_in_bits==8 && s->divx_version){
+ printf("frame skip %d\n", gb->size_in_bits);
return FRAME_SKIPED; //divx bug
}else
return -1; //end of stream
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index b0e7a0a7ea..3e4610658c 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -249,13 +249,13 @@ 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*8 - get_bits_count(&s->gb) >=0
- && s->gb.size*8 - get_bits_count(&s->gb) < 48
+ && s->gb.size_in_bits - get_bits_count(&s->gb) >=0
+ && s->gb.size_in_bits - get_bits_count(&s->gb) < 48
// && !s->resync_marker
&& !s->data_partitioning){
const int bits_count= get_bits_count(&s->gb);
- const int bits_left = s->gb.size*8 - bits_count;
+ const int bits_left = s->gb.size_in_bits - bits_count;
if(bits_left==0){
s->padding_bug_score+=16;
@@ -274,7 +274,7 @@ static int decode_slice(MpegEncContext *s){
// handle formats which dont 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*8 - get_bits_count(&s->gb);
+ int left= s->gb.size_in_bits - get_bits_count(&s->gb);
int max_extra=7;
/* no markers in M$ crap */
@@ -299,7 +299,7 @@ static int decode_slice(MpegEncContext *s){
}
fprintf(stderr, "slice end not reached but screenspace end (%d left %06X)\n",
- s->gb.size*8 - get_bits_count(&s->gb),
+ s->gb.size_in_bits - get_bits_count(&s->gb),
show_bits(&s->gb, 24));
return -1;
}
@@ -441,9 +441,9 @@ uint64_t time= rdtsc();
retry:
if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder
- init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size);
+ init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
}else
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
s->bitstream_buffer_size=0;
if (!s->context_initialized) {
@@ -460,7 +460,7 @@ retry:
if(s->avctx->extradata_size && s->picture_number==0){
GetBitContext gb;
- init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size);
+ init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
ret = ff_mpeg4_decode_picture_header(s, &gb);
}
ret = ff_mpeg4_decode_picture_header(s, &s->gb);
@@ -632,7 +632,7 @@ retry:
decode_slice(s);
s->error_status_table[0]|= VP_START;
- while(s->mb_y<s->mb_height && s->gb.size*8 - get_bits_count(&s->gb)>16){
+ while(s->mb_y<s->mb_height && s->gb.size_in_bits - get_bits_count(&s->gb)>16){
if(s->msmpeg4_version){
if(s->mb_x!=0 || (s->mb_y%s->slice_height)!=0)
break;
diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c
index 31801a32d5..cff642d11c 100644
--- a/libavcodec/huffyuv.c
+++ b/libavcodec/huffyuv.c
@@ -271,7 +271,7 @@ static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
GetBitContext gb;
int i;
- init_get_bits(&gb, src, length);
+ init_get_bits(&gb, src, length*8);
for(i=0; i<3; i++){
read_len_table(s->len[i], &gb);
@@ -295,9 +295,9 @@ static int read_old_huffman_tables(HYuvContext *s){
GetBitContext gb;
int i;
- init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma));
+ init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8);
read_len_table(s->len[0], &gb);
- init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma));
+ init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8);
read_len_table(s->len[1], &gb);
for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i];
@@ -680,7 +680,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4);
- init_get_bits(&s->gb, s->bitstream_buffer, buf_size);
+ init_get_bits(&s->gb, s->bitstream_buffer, buf_size*8);
p->reference= 0;
if(avctx->get_buffer(avctx, p) < 0){
diff --git a/libavcodec/mjpeg.c b/libavcodec/mjpeg.c
index 9b49435825..9617816bb9 100644
--- a/libavcodec/mjpeg.c
+++ b/libavcodec/mjpeg.c
@@ -735,7 +735,7 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
{
printf("mjpeg: using external huffman table\n");
- init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size);
+ init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
mjpeg_decode_dht(s);
/* should check for error - but dunno */
}
@@ -1404,13 +1404,13 @@ static int mjpeg_decode_frame(AVCodecContext *avctx,
break;
}
}
- init_get_bits(&s->gb, s->buffer, dst - s->buffer);
+ init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
dprintf("escaping removed %d bytes\n",
(buf_end - buf_ptr) - (dst - s->buffer));
}
else
- init_get_bits(&s->gb, buf_ptr, buf_end - buf_ptr);
+ init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
s->start_code = start_code;
@@ -1548,7 +1548,7 @@ read_header:
/* reset on every SOI */
s->restart_interval = 0;
- init_get_bits(&hgb, buf_ptr, /*buf_size*/buf_end - buf_ptr);
+ init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8);
skip_bits(&hgb, 32); /* reserved zeros */
@@ -1570,7 +1570,7 @@ read_header:
dprintf("dqt offs: 0x%x\n", dqt_offs);
if (dqt_offs)
{
- init_get_bits(&s->gb, buf+dqt_offs, buf_end - (buf+dqt_offs));
+ init_get_bits(&s->gb, buf+dqt_offs, (buf_end - (buf+dqt_offs))*8);
s->start_code = DQT;
mjpeg_decode_dqt(s);
}
@@ -1579,7 +1579,7 @@ read_header:
dprintf("dht offs: 0x%x\n", dht_offs);
if (dht_offs)
{
- init_get_bits(&s->gb, buf+dht_offs, buf_end - (buf+dht_offs));
+ init_get_bits(&s->gb, buf+dht_offs, (buf_end - (buf+dht_offs))*8);
s->start_code = DHT;
mjpeg_decode_dht(s);
}
@@ -1588,7 +1588,7 @@ read_header:
dprintf("sof offs: 0x%x\n", sof_offs);
if (sof_offs)
{
- init_get_bits(&s->gb, buf+sof_offs, buf_end - (buf+sof_offs));
+ init_get_bits(&s->gb, buf+sof_offs, (buf_end - (buf+sof_offs))*8);
s->start_code = SOF0;
if (mjpeg_decode_sof0(s) < 0)
return -1;
@@ -1598,8 +1598,8 @@ read_header:
dprintf("sos offs: 0x%x\n", sos_offs);
if (sos_offs)
{
-// init_get_bits(&s->gb, buf+sos_offs, buf_end - (buf+sos_offs));
- init_get_bits(&s->gb, buf+sos_offs, field_size);
+// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8);
+ init_get_bits(&s->gb, buf+sos_offs, field_size*8);
s->start_code = SOS;
mjpeg_decode_sos(s);
}
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 5ef4e06280..9c32aa493c 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -1467,7 +1467,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
MpegEncContext *s = &s1->mpeg_enc_ctx;
int ref, f_code;
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
ref = get_bits(&s->gb, 10); /* temporal ref */
s->pict_type = get_bits(&s->gb, 3);
@@ -1619,7 +1619,7 @@ static void mpeg_decode_extension(AVCodecContext *avctx,
MpegEncContext *s = &s1->mpeg_enc_ctx;
int ext_type;
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
ext_type = get_bits(&s->gb, 4);
switch(ext_type) {
@@ -1684,7 +1684,7 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
}
}
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
s->qscale = get_qscale(s);
/* extra slice info */
@@ -1793,7 +1793,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
int width, height, i, v, j;
float aspect;
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
width = get_bits(&s->gb, 12);
height = get_bits(&s->gb, 12);
diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index 6b2f004a3b..9a066c905b 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -1460,7 +1460,7 @@ static void seek_to_maindata(MPADecodeContext *s, long backstep)
memcpy(ptr, s->inbuf1[s->inbuf_index ^ 1] +
BACKSTEP_SIZE + s->old_frame_size - backstep, backstep);
/* init get bits again */
- init_get_bits(&s->gb, ptr, s->frame_size + backstep);
+ init_get_bits(&s->gb, ptr, (s->frame_size + backstep)*8);
/* prepare next buffer */
s->inbuf_index ^= 1;
@@ -2280,7 +2280,7 @@ static int mp_decode_frame(MPADecodeContext *s,
short *samples_ptr;
init_get_bits(&s->gb, s->inbuf + HEADER_SIZE,
- s->inbuf_ptr - s->inbuf - HEADER_SIZE);
+ (s->inbuf_ptr - s->inbuf - HEADER_SIZE)*8);
/* skip error protection field */
if (s->error_protection)
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index f2647cf0da..2c524a0675 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -1195,7 +1195,7 @@ int msmpeg4_decode_picture_header(MpegEncContext * s)
#if 0
{
int i;
-for(i=0; i<s->gb.size*8; i++)
+for(i=0; i<s->gb.size_in_bits; i++)
printf("%d", get_bits1(&s->gb));
// get_bits1(&s->gb);
printf("END\n");
@@ -1869,7 +1869,7 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
if (i > 62){
i-= 192;
if(i&(~63)){
- const int left= s->gb.size*8 - get_bits_count(&s->gb);
+ const int left= s->gb.size_in_bits - get_bits_count(&s->gb);
if(((i+192 == 64 && level/qmul==-1) || s->error_resilience<=1) && left>=0){
fprintf(stderr, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
break;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 4907c23478..012b1dc5c6 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -395,7 +395,7 @@ static int rv10_decode_packet(AVCodecContext *avctx,
MpegEncContext *s = avctx->priv_data;
int i, mb_count, mb_pos, left;
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
mb_count = rv10_decode_picture_header(s);
if (mb_count < 0) {
diff --git a/libavcodec/svq1.c b/libavcodec/svq1.c
index 363a90261c..5a9a290b8f 100644
--- a/libavcodec/svq1.c
+++ b/libavcodec/svq1.c
@@ -1066,7 +1066,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
AVFrame *pict = data;
/* initialize bit buffer */
- init_get_bits(&s->gb,buf,buf_size);
+ init_get_bits(&s->gb,buf,buf_size*8);
/* decode frame header */
s->f_code = get_bits (&s->gb, 22);
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index a6fa2f8b2a..a80e030aa5 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -1226,7 +1226,7 @@ static int wma_decode_superframe(AVCodecContext *avctx,
samples = data;
- init_get_bits(&s->gb, buf, buf_size);
+ init_get_bits(&s->gb, buf, buf_size*8);
if (s->use_bit_reservoir) {
/* read super frame header */
@@ -1252,7 +1252,7 @@ static int wma_decode_superframe(AVCodecContext *avctx,
}
/* XXX: bit_offset bits into last frame */
- init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE);
+ init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
/* skip unused bits */
if (s->last_bitoffset > 0)
skip_bits(&s->gb, s->last_bitoffset);
@@ -1265,7 +1265,7 @@ static int wma_decode_superframe(AVCodecContext *avctx,
/* read each frame starting from bit_offset */
pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
- init_get_bits(&s->gb, buf + (pos >> 3), MAX_CODED_SUPERFRAME_SIZE - (pos >> 3));
+ init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
len = pos & 7;
if (len > 0)
skip_bits(&s->gb, len);
diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c
index bdd5652285..ae8176798d 100644
--- a/libavcodec/wmv2.c
+++ b/libavcodec/wmv2.c
@@ -313,7 +313,7 @@ static int decode_ext_header(Wmv2Context *w){
if(s->avctx->extradata_size<4) return -1;
- init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size);
+ init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
fps = get_bits(&gb, 5);
s->bit_rate = get_bits(&gb, 11)*1024;