summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo_enc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-06 00:31:25 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-10 00:21:48 +0200
commit22b0141d87e1b0d9c34251c8582bf7e2ab8e2265 (patch)
treef8ebe82c417ec2b7525d26fc47bc4bbd3bc9ea39 /libavcodec/mpegvideo_enc.c
parentd87c358ee6382bb72520c09fcefda95021bbdd61 (diff)
avcodec/mpegvideo_enc: Don't allocate buffers unnecessarily
ff_alloc_picture() performs two tasks: a) In most instances, it allocates frame buffers and b) it allocates certain auxiliary buffers. The exception to a) is the case when the encoder can reuse user-supplied frames. And for these frames the auxiliary buffers are unused, because this frame will never be used as current_picture (and therefore also not as next_picture or last_picture); see select_input_picture(). This means that we can simply avoid calling ff_alloc_picture() with user-supplied frames at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r--libavcodec/mpegvideo_enc.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index daf8b4992c..9106014aa5 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1091,9 +1091,9 @@ static int get_intra_count(MpegEncContext *s, const uint8_t *src,
return acc;
}
-static int alloc_picture(MpegEncContext *s, Picture *pic, int shared)
+static int alloc_picture(MpegEncContext *s, Picture *pic)
{
- return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, shared, 1,
+ return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 1,
s->chroma_x_shift, s->chroma_y_shift, s->out_format,
s->mb_stride, s->mb_width, s->mb_height, s->b8_stride,
&s->linesize, &s->uvlinesize);
@@ -1164,12 +1164,12 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
if (direct) {
if ((ret = av_frame_ref(pic->f, pic_arg)) < 0)
return ret;
- }
- ret = alloc_picture(s, pic, direct);
- if (ret < 0)
- return ret;
+ pic->shared = 1;
+ } else {
+ ret = alloc_picture(s, pic);
+ if (ret < 0)
+ return ret;
- if (!direct) {
for (int i = 0; i < 3; i++) {
int src_stride = pic_arg->linesize[i];
int dst_stride = i ? s->uvlinesize : s->linesize;
@@ -1596,7 +1596,7 @@ no_output_pic:
pic = &s->picture[i];
pic->reference = s->reordered_input_picture[0]->reference;
- ret = alloc_picture(s, pic, 0);
+ ret = alloc_picture(s, pic);
if (ret < 0)
goto fail;