comparison mpegvideo_enc.c @ 11534:baece61a55cf libavcodec

Always check if ff_alloc_picture() succeeds. Patch by Pavel Pavlov, pavel summit-tech ca
author cehoyos
date Tue, 23 Mar 2010 17:58:39 +0000
parents 31033caa5344
children 8a4984c5cacc
comparison
equal deleted inserted replaced
11533:e9640e8aeea3 11534:baece61a55cf
849 849
850 for(i=0; i<4; i++){ 850 for(i=0; i<4; i++){
851 pic->data[i]= pic_arg->data[i]; 851 pic->data[i]= pic_arg->data[i];
852 pic->linesize[i]= pic_arg->linesize[i]; 852 pic->linesize[i]= pic_arg->linesize[i];
853 } 853 }
854 ff_alloc_picture(s, (Picture*)pic, 1); 854 if(ff_alloc_picture(s, (Picture*)pic, 1) < 0){
855 return -1;
856 }
855 }else{ 857 }else{
856 i= ff_find_unused_picture(s, 0); 858 i= ff_find_unused_picture(s, 0);
857 859
858 pic= (AVFrame*)&s->picture[i]; 860 pic= (AVFrame*)&s->picture[i];
859 pic->reference= 3; 861 pic->reference= 3;
860 862
861 ff_alloc_picture(s, (Picture*)pic, 0); 863 if(ff_alloc_picture(s, (Picture*)pic, 0) < 0){
864 return -1;
865 }
862 866
863 if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] 867 if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0]
864 && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] 868 && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1]
865 && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){ 869 && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){
866 // empty 870 // empty
1046 } 1050 }
1047 1051
1048 return best_b_count; 1052 return best_b_count;
1049 } 1053 }
1050 1054
1051 static void select_input_picture(MpegEncContext *s){ 1055 static int select_input_picture(MpegEncContext *s){
1052 int i; 1056 int i;
1053 1057
1054 for(i=1; i<MAX_PICTURE_COUNT; i++) 1058 for(i=1; i<MAX_PICTURE_COUNT; i++)
1055 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; 1059 s->reordered_input_picture[i-1]= s->reordered_input_picture[i];
1056 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; 1060 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL;
1182 1186
1183 int i= ff_find_unused_picture(s, 0); 1187 int i= ff_find_unused_picture(s, 0);
1184 Picture *pic= &s->picture[i]; 1188 Picture *pic= &s->picture[i];
1185 1189
1186 pic->reference = s->reordered_input_picture[0]->reference; 1190 pic->reference = s->reordered_input_picture[0]->reference;
1187 ff_alloc_picture(s, pic, 0); 1191 if(ff_alloc_picture(s, pic, 0) < 0){
1192 return -1;
1193 }
1188 1194
1189 /* mark us unused / free shared pic */ 1195 /* mark us unused / free shared pic */
1190 if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL) 1196 if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL)
1191 s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]); 1197 s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]);
1192 for(i=0; i<4; i++) 1198 for(i=0; i<4; i++)
1212 s->picture_number= s->new_picture.display_picture_number; 1218 s->picture_number= s->new_picture.display_picture_number;
1213 //printf("dpn:%d\n", s->picture_number); 1219 //printf("dpn:%d\n", s->picture_number);
1214 }else{ 1220 }else{
1215 memset(&s->new_picture, 0, sizeof(Picture)); 1221 memset(&s->new_picture, 0, sizeof(Picture));
1216 } 1222 }
1223 return 0;
1217 } 1224 }
1218 1225
1219 int MPV_encode_picture(AVCodecContext *avctx, 1226 int MPV_encode_picture(AVCodecContext *avctx,
1220 unsigned char *buf, int buf_size, void *data) 1227 unsigned char *buf, int buf_size, void *data)
1221 { 1228 {
1236 s->picture_in_gop_number++; 1243 s->picture_in_gop_number++;
1237 1244
1238 if(load_input_picture(s, pic_arg) < 0) 1245 if(load_input_picture(s, pic_arg) < 0)
1239 return -1; 1246 return -1;
1240 1247
1241 select_input_picture(s); 1248 if(select_input_picture(s) < 0){
1249 return -1;
1250 }
1242 1251
1243 /* output? */ 1252 /* output? */
1244 if(s->new_picture.data[0]){ 1253 if(s->new_picture.data[0]){
1245 s->pict_type= s->new_picture.pict_type; 1254 s->pict_type= s->new_picture.pict_type;
1246 //emms_c(); 1255 //emms_c();