This way said function sets everything (except for the actual contents of the frame's data). Also rename it to prepare_picture() given its new role.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -1091,7 +1091,11 @@ static int get_intra_count(MpegEncContext *s, const uint8_t *src, · 1090 unmodified lines | ||
| 1091 | 1091 | return acc; |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | −static int alloc_picture(MpegEncContext *s, AVFrame *f) | |
| 1094 | +/** | |
| 1095 | + * Allocates new buffers for an AVFrame and copies the properties | |
| 1096 | + * from another AVFrame. | |
| 1097 | + */ | |
| 1098 | +static int prepare_picture(MpegEncContext *s, AVFrame *f, const AVFrame *props_frame) | |
| 1095 | 1099 | { |
| 1096 | 1100 | AVCodecContext *avctx = s->avctx; |
| 1097 | 1101 | int ret; |
| @@ -1116,6 +1120,10 @@ static int alloc_picture(MpegEncContext *s, AVFrame *f) · 18 unmodified lines | ||
| 1116 | 1120 | f->width = avctx->width; |
| 1117 | 1121 | f->height = avctx->height; |
| 1118 | 1122 | |
| 1123 | + ret = av_frame_copy_props(f, props_frame); | |
| 1124 | + if (ret < 0) | |
| 1125 | + return ret; | |
| 1126 | + | |
| 1119 | 1127 | return 0; |
| 1120 | 1128 | } |
| 1121 | 1129 | |
| @@ -1186,14 +1194,9 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) · 64 unmodified lines | ||
| 1186 | 1194 | return ret; |
| 1187 | 1195 | pic->shared = 1; |
| 1188 | 1196 | } else { |
| 1189 | − ret = alloc_picture(s, pic->f); | |
| 1197 | + ret = prepare_picture(s, pic->f, pic_arg); | |
| 1190 | 1198 | if (ret < 0) |
| 1191 | 1199 | goto fail; |
| 1192 | − ret = av_frame_copy_props(pic->f, pic_arg); | |
| 1193 | − if (ret < 0) { | |
| 1194 | − ff_mpeg_unref_picture(pic); | |
| 1195 | − return ret; | |
| 1196 | − } | |
| 1197 | 1200 | |
| 1198 | 1201 | for (int i = 0; i < 3; i++) { |
| 1199 | 1202 | ptrdiff_t src_stride = pic_arg->linesize[i]; |
| @@ -1607,11 +1610,8 @@ no_output_pic: · 407 unmodified lines | ||
| 1607 | 1610 | // input is a shared pix, so we can't modify it -> allocate a new |
| 1608 | 1611 | // one & ensure that the shared one is reuseable |
| 1609 | 1612 | av_frame_move_ref(s->new_pic, s->reordered_input_picture[0]->f); |
| 1610 | − ret = alloc_picture(s, s->reordered_input_picture[0]->f); | |
| 1611 | − if (ret < 0) | |
| 1612 | − goto fail; | |
| 1613 | 1613 | |
| 1614 | − ret = av_frame_copy_props(s->reordered_input_picture[0]->f, s->new_pic); | |
| 1614 | + ret = prepare_picture(s, s->reordered_input_picture[0]->f, s->new_pic); | |
| 1615 | 1615 | if (ret < 0) |
| 1616 | 1616 | goto fail; |
| 1617 | 1617 | } else { |