comparison mpeg12.c @ 10594:73779b8e6c5f libavcodec

Restructure dummy frame allocation. New code also allocates a dummy frame for an p field after an i field, previously that could segfault due to reading from NULL+x.
author michael
date Sun, 29 Nov 2009 03:05:11 +0000
parents 46cb472ecc1e
children c58c770b17f5
comparison
equal deleted inserted replaced
10593:46cb472ecc1e 10594:73779b8e6c5f
2369 last_code= SLICE_MIN_START_CODE; 2369 last_code= SLICE_MIN_START_CODE;
2370 2370
2371 if(s2->last_picture_ptr==NULL){ 2371 if(s2->last_picture_ptr==NULL){
2372 /* Skip B-frames if we do not have reference frames and gop is not closed */ 2372 /* Skip B-frames if we do not have reference frames and gop is not closed */
2373 if(s2->pict_type==FF_B_TYPE){ 2373 if(s2->pict_type==FF_B_TYPE){
2374 int i;
2375 if(!s2->closed_gop) 2374 if(!s2->closed_gop)
2376 break; 2375 break;
2377 /* Allocate a dummy frame */
2378 i= ff_find_unused_picture(s2, 0);
2379 s2->last_picture_ptr= &s2->picture[i];
2380 if(ff_alloc_picture(s2, s2->last_picture_ptr, 0) < 0)
2381 return -1;
2382 } 2376 }
2383 } 2377 }
2384 if(s2->next_picture_ptr==NULL){ 2378 if(s2->next_picture_ptr==NULL){
2385 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ 2379 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */
2386 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; 2380 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break;
2412 return -1; 2406 return -1;
2413 } 2407 }
2414 if(!s2->current_picture_ptr){ 2408 if(!s2->current_picture_ptr){
2415 av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n"); 2409 av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n");
2416 return -1; 2410 return -1;
2411 }
2412
2413 if(s2->last_picture_ptr==NULL && s2->pict_type!=FF_I_TYPE){
2414 int i;
2415 /* Allocate a dummy frame */
2416 i= ff_find_unused_picture(s2, 0);
2417 s2->last_picture_ptr= &s2->picture[i];
2418 if(ff_alloc_picture(s2, s2->last_picture_ptr, 0) < 0)
2419 return -1;
2420 s2->last_picture= *s2->last_picture_ptr;
2421 }
2422 if(s2->next_picture_ptr==NULL && s2->pict_type==FF_B_TYPE){
2423 int i;
2424 /* Allocate a dummy frame */
2425 i= ff_find_unused_picture(s2, 0);
2426 s2->next_picture_ptr= &s2->picture[i];
2427 if(ff_alloc_picture(s2, s2->next_picture_ptr, 0) < 0)
2428 return -1;
2429 s2->next_picture= *s2->next_picture_ptr;
2417 } 2430 }
2418 2431
2419 if (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) { 2432 if (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) {
2420 s->slice_count++; 2433 s->slice_count++;
2421 break; 2434 break;