mpeg12parser: cleanup bitrate parsing.
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 30 Oct 2012 01:05:56 +0000 (02:05 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 30 Oct 2012 01:19:21 +0000 (02:19 +0100)
This fixes several bugs in the code.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/mpegvideo_parser.c

index c60d3cd..bea83a2 100644 (file)
@@ -43,6 +43,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
     int top_field_first, repeat_first_field, progressive_frame;
     int horiz_size_ext, vert_size_ext, bit_rate_ext;
     int did_set_size=0;
     int top_field_first, repeat_first_field, progressive_frame;
     int horiz_size_ext, vert_size_ext, bit_rate_ext;
     int did_set_size=0;
+    int bit_rate = 0;
 //FIXME replace the crap with get_bits()
     s->repeat_pict = 0;
 
 //FIXME replace the crap with get_bits()
     s->repeat_pict = 0;
 
@@ -67,7 +68,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
                 frame_rate_index = buf[3] & 0xf;
                 pc->frame_rate.den = avctx->time_base.den = ff_mpeg12_frame_rate_tab[frame_rate_index].num;
                 pc->frame_rate.num = avctx->time_base.num = ff_mpeg12_frame_rate_tab[frame_rate_index].den;
                 frame_rate_index = buf[3] & 0xf;
                 pc->frame_rate.den = avctx->time_base.den = ff_mpeg12_frame_rate_tab[frame_rate_index].num;
                 pc->frame_rate.num = avctx->time_base.num = ff_mpeg12_frame_rate_tab[frame_rate_index].den;
-                avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400;
+                bit_rate = (buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6);
                 avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO;
             }
             break;
                 avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO;
             }
             break;
@@ -87,7 +88,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
 
                         pc->width  |=(horiz_size_ext << 12);
                         pc->height |=( vert_size_ext << 12);
 
                         pc->width  |=(horiz_size_ext << 12);
                         pc->height |=( vert_size_ext << 12);
-                        avctx->bit_rate += (bit_rate_ext << 18) * 400;
+                        bit_rate = (bit_rate&0x3FFFF) | (bit_rate_ext << 18);
                         if(did_set_size)
                             avcodec_set_dimensions(avctx, pc->width, pc->height);
                         avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1) * 2;
                         if(did_set_size)
                             avcodec_set_dimensions(avctx, pc->width, pc->height);
                         avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1) * 2;
@@ -130,6 +131,9 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
         }
     }
  the_end: ;
         }
     }
  the_end: ;
+    if (bit_rate) {
+        avctx->bit_rate = 400 * bit_rate;
+    }
 }
 
 static int mpegvideo_parse(AVCodecParserContext *s,
 }
 
 static int mpegvideo_parse(AVCodecParserContext *s,