comparison mpeg12.c @ 10590:0c6e62729784 libavcodec

Check order of startcodes, ignore some obviously wrong ones. Fixes issue487.
author michael
date Sat, 28 Nov 2009 22:51:53 +0000
parents 02c7c0a5ad7d
children 8aff2b05e978
comparison
equal deleted inserted replaced
10589:02c7c0a5ad7d 10590:0c6e62729784
2258 Mpeg1Context *s = avctx->priv_data; 2258 Mpeg1Context *s = avctx->priv_data;
2259 MpegEncContext *s2 = &s->mpeg_enc_ctx; 2259 MpegEncContext *s2 = &s->mpeg_enc_ctx;
2260 const uint8_t *buf_ptr = buf; 2260 const uint8_t *buf_ptr = buf;
2261 const uint8_t *buf_end = buf + buf_size; 2261 const uint8_t *buf_end = buf + buf_size;
2262 int ret, input_size; 2262 int ret, input_size;
2263 int last_code= 0;
2263 2264
2264 for(;;) { 2265 for(;;) {
2265 /* find next start code */ 2266 /* find next start code */
2266 uint32_t start_code = -1; 2267 uint32_t start_code = -1;
2267 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code); 2268 buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
2294 } 2295 }
2295 2296
2296 /* prepare data for next start code */ 2297 /* prepare data for next start code */
2297 switch(start_code) { 2298 switch(start_code) {
2298 case SEQ_START_CODE: 2299 case SEQ_START_CODE:
2300 if(last_code == 0){
2299 mpeg1_decode_sequence(avctx, buf_ptr, 2301 mpeg1_decode_sequence(avctx, buf_ptr,
2300 input_size); 2302 input_size);
2303 }else{
2304 av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code);
2305 }
2301 break; 2306 break;
2302 2307
2303 case PICTURE_START_CODE: 2308 case PICTURE_START_CODE:
2304 if(mpeg_decode_postinit(avctx) < 0){ 2309 if(mpeg_decode_postinit(avctx) < 0){
2305 av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n"); 2310 av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
2308 2313
2309 /* we have a complete image: we try to decompress it */ 2314 /* we have a complete image: we try to decompress it */
2310 if(mpeg1_decode_picture(avctx, 2315 if(mpeg1_decode_picture(avctx,
2311 buf_ptr, input_size) < 0) 2316 buf_ptr, input_size) < 0)
2312 s2->pict_type=0; 2317 s2->pict_type=0;
2318 last_code= PICTURE_START_CODE;
2313 break; 2319 break;
2314 case EXT_START_CODE: 2320 case EXT_START_CODE:
2315 init_get_bits(&s2->gb, buf_ptr, input_size*8); 2321 init_get_bits(&s2->gb, buf_ptr, input_size*8);
2316 2322
2317 switch(get_bits(&s2->gb, 4)) { 2323 switch(get_bits(&s2->gb, 4)) {
2318 case 0x1: 2324 case 0x1:
2325 if(last_code == 0){
2319 mpeg_decode_sequence_extension(s); 2326 mpeg_decode_sequence_extension(s);
2327 }else{
2328 av_log(avctx, AV_LOG_ERROR, "ignoring seq ext after %X\n", last_code);
2329 }
2320 break; 2330 break;
2321 case 0x2: 2331 case 0x2:
2322 mpeg_decode_sequence_display_extension(s); 2332 mpeg_decode_sequence_display_extension(s);
2323 break; 2333 break;
2324 case 0x3: 2334 case 0x3:
2327 case 0x7: 2337 case 0x7:
2328 mpeg_decode_picture_display_extension(s); 2338 mpeg_decode_picture_display_extension(s);
2329 break; 2339 break;
2330 case 0x8: 2340 case 0x8:
2331 mpeg_decode_picture_coding_extension(s); 2341 mpeg_decode_picture_coding_extension(s);
2342 last_code= PICTURE_START_CODE;
2332 break; 2343 break;
2333 } 2344 }
2334 break; 2345 break;
2335 case USER_START_CODE: 2346 case USER_START_CODE:
2336 mpeg_decode_user_data(avctx, 2347 mpeg_decode_user_data(avctx,
2337 buf_ptr, input_size); 2348 buf_ptr, input_size);
2338 break; 2349 break;
2339 case GOP_START_CODE: 2350 case GOP_START_CODE:
2351 if(last_code == 0){
2340 s2->first_field=0; 2352 s2->first_field=0;
2341 mpeg_decode_gop(avctx, 2353 mpeg_decode_gop(avctx,
2342 buf_ptr, input_size); 2354 buf_ptr, input_size);
2355 }else{
2356 av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code);
2357 }
2343 break; 2358 break;
2344 default: 2359 default:
2345 if (start_code >= SLICE_MIN_START_CODE && 2360 if (start_code >= SLICE_MIN_START_CODE &&
2346 start_code <= SLICE_MAX_START_CODE) { 2361 start_code <= SLICE_MAX_START_CODE && last_code!=0) {
2347 int mb_y= start_code - SLICE_MIN_START_CODE; 2362 int mb_y= start_code - SLICE_MIN_START_CODE;
2363 last_code= SLICE_MIN_START_CODE;
2348 2364
2349 if(s2->last_picture_ptr==NULL){ 2365 if(s2->last_picture_ptr==NULL){
2350 /* Skip B-frames if we do not have reference frames and gop is not closed */ 2366 /* Skip B-frames if we do not have reference frames and gop is not closed */
2351 if(s2->pict_type==FF_B_TYPE){ 2367 if(s2->pict_type==FF_B_TYPE){
2352 int i; 2368 int i;