Mercurial > libavcodec.hg
comparison mpegvideo_parser.c @ 10641:9311c65558c0 libavcodec
Make sure the parsers do not overwrite width/height as this can interfere
with the decoder.
Fixes issue1135.
author | michael |
---|---|
date | Sat, 05 Dec 2009 03:53:12 +0000 |
parents | cecf81f93756 |
children | 48ecbc11c8dc |
comparison
equal
deleted
inserted
replaced
10640:e3e0c834590e | 10641:9311c65558c0 |
---|---|
32 uint32_t start_code; | 32 uint32_t start_code; |
33 int frame_rate_index, ext_type, bytes_left; | 33 int frame_rate_index, ext_type, bytes_left; |
34 int frame_rate_ext_n, frame_rate_ext_d; | 34 int frame_rate_ext_n, frame_rate_ext_d; |
35 int picture_structure, top_field_first, repeat_first_field, progressive_frame; | 35 int picture_structure, top_field_first, repeat_first_field, progressive_frame; |
36 int horiz_size_ext, vert_size_ext, bit_rate_ext; | 36 int horiz_size_ext, vert_size_ext, bit_rate_ext; |
37 int did_set_size=0; | |
37 //FIXME replace the crap with get_bits() | 38 //FIXME replace the crap with get_bits() |
38 s->repeat_pict = 0; | 39 s->repeat_pict = 0; |
39 buf_end = buf + buf_size; | 40 buf_end = buf + buf_size; |
40 while (buf < buf_end) { | 41 while (buf < buf_end) { |
41 start_code= -1; | 42 start_code= -1; |
49 break; | 50 break; |
50 case SEQ_START_CODE: | 51 case SEQ_START_CODE: |
51 if (bytes_left >= 7) { | 52 if (bytes_left >= 7) { |
52 pc->width = (buf[0] << 4) | (buf[1] >> 4); | 53 pc->width = (buf[0] << 4) | (buf[1] >> 4); |
53 pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; | 54 pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; |
55 if(!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height){ | |
54 avcodec_set_dimensions(avctx, pc->width, pc->height); | 56 avcodec_set_dimensions(avctx, pc->width, pc->height); |
57 did_set_size=1; | |
58 } | |
55 frame_rate_index = buf[3] & 0xf; | 59 frame_rate_index = buf[3] & 0xf; |
56 pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num; | 60 pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num; |
57 pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den; | 61 pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den; |
58 avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; | 62 avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; |
59 avctx->codec_id = CODEC_ID_MPEG1VIDEO; | 63 avctx->codec_id = CODEC_ID_MPEG1VIDEO; |
75 avctx->has_b_frames= !(buf[5] >> 7); | 79 avctx->has_b_frames= !(buf[5] >> 7); |
76 | 80 |
77 pc->width |=(horiz_size_ext << 12); | 81 pc->width |=(horiz_size_ext << 12); |
78 pc->height |=( vert_size_ext << 12); | 82 pc->height |=( vert_size_ext << 12); |
79 avctx->bit_rate += (bit_rate_ext << 18) * 400; | 83 avctx->bit_rate += (bit_rate_ext << 18) * 400; |
84 if(did_set_size) | |
80 avcodec_set_dimensions(avctx, pc->width, pc->height); | 85 avcodec_set_dimensions(avctx, pc->width, pc->height); |
81 avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1) * 2; | 86 avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1) * 2; |
82 avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1); | 87 avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1); |
83 avctx->codec_id = CODEC_ID_MPEG2VIDEO; | 88 avctx->codec_id = CODEC_ID_MPEG2VIDEO; |
84 avctx->sub_id = 2; /* forces MPEG2 */ | 89 avctx->sub_id = 2; /* forces MPEG2 */ |