diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2023-09-25 18:21:55 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2023-09-28 00:17:47 +0200 |
commit | 418332e01ce99d43f218504e4e4e1b4ea89c9a49 (patch) | |
tree | 53db7aa3c53bdfecde26b54e2d9c2154386c53c7 /libavcodec/snowenc.c | |
parent | 0228e27dedc66c98e5b25dee0f95e664a185bbf1 (diff) |
avcodec/snow: Split ff_snow_get_buffer()
The part of said function that is common to both encoder and decoder
is negligible since c954cf1e1b766a0d1992d5be0a8be0055a8e1a6a
and more than offset by the costs of "Am I an encoder?" checks.
So move allocating the frames to the encoder and decoder directly.
Also rename ff_snow_frame_start() to ff_snow_frames_prepare(),
because a frame without a buffer has not been properly started.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/snowenc.c')
-rw-r--r-- | libavcodec/snowenc.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c index 14a59ca67b..f954a686c1 100644 --- a/libavcodec/snowenc.c +++ b/libavcodec/snowenc.c @@ -39,6 +39,28 @@ #include "mpegvideo.h" #include "h263enc.h" +static int get_encode_buffer(SnowContext *s, AVFrame *frame) +{ + int ret; + + frame->width = s->avctx->width + 2 * EDGE_WIDTH; + frame->height = s->avctx->height + 2 * EDGE_WIDTH; + + ret = ff_encode_alloc_frame(s->avctx, frame); + if (ret < 0) + return ret; + for (int i = 0; frame->data[i]; i++) { + int offset = (EDGE_WIDTH >> (i ? s->chroma_v_shift : 0)) * + frame->linesize[i] + + (EDGE_WIDTH >> (i ? s->chroma_h_shift : 0)); + frame->data[i] += offset; + } + frame->width = s->avctx->width; + frame->height = s->avctx->height; + + return 0; +} + static av_cold int encode_init(AVCodecContext *avctx) { SnowContext *s = avctx->priv_data; @@ -140,7 +162,7 @@ static av_cold int encode_init(AVCodecContext *avctx) if (!s->input_picture) return AVERROR(ENOMEM); - if ((ret = ff_snow_get_buffer(s, s->input_picture)) < 0) + if ((ret = get_encode_buffer(s, s->input_picture)) < 0) return ret; if(s->motion_est == FF_ME_ITER){ @@ -1659,7 +1681,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, emms_c(); } - ff_snow_frame_start(s); + ff_snow_frames_prepare(s); + ret = get_encode_buffer(s, s->current_picture); + if (ret < 0) + return ret; s->m.current_picture_ptr= &s->m.current_picture; s->m.current_picture.f = s->current_picture; |