avcodec/snow: Only allocate emu_edge_buffer for encoder

Also allocate it during init and move it to the encoder's context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2026-02-09 14:33:01 +01:00
parent c7b5f1537d
commit bb92009386
3 changed files with 9 additions and 7 deletions

View File

@@ -540,10 +540,7 @@ int ff_snow_common_init_after_header(AVCodecContext *avctx) {
int plane_index, level, orientation;
if(!s->scratchbuf) {
int emu_buf_size;
emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
!FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf, FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE))
return AVERROR(ENOMEM);
}
@@ -642,7 +639,6 @@ av_cold void ff_snow_common_end(SnowContext *s)
av_freep(&s->block);
av_freep(&s->scratchbuf);
av_freep(&s->emu_edge_buffer);
for(i=0; i<MAX_REF_FRAMES; i++){
av_frame_free(&s->last_picture[i]);

View File

@@ -168,7 +168,6 @@ typedef struct SnowContext{
slice_buffer sb;
uint8_t *scratchbuf;
uint8_t *emu_edge_buffer;
AVMotionVector *avmv;
unsigned avmv_size;

View File

@@ -68,6 +68,8 @@ typedef struct SnowEncContext {
uint64_t encoding_error[SNOW_MAX_PLANES];
uint8_t *emu_edge_buffer;
IDWTELEM obmc_scratchpad[MB_SIZE * MB_SIZE * 12 * 2];
} SnowEncContext;
@@ -286,6 +288,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
if ((ret = get_encode_buffer(s, s->input_picture)) < 0)
return ret;
enc->emu_edge_buffer = av_calloc(avctx->width + 128, 2 * (2 * MB_SIZE + HTAPS_MAX - 1));
if (!enc->emu_edge_buffer)
return AVERROR(ENOMEM);
if (enc->motion_est == FF_ME_ITER) {
int size= s->b_width * s->b_height << 2*s->block_max_depth;
for(i=0; i<s->max_ref_frames; i++){
@@ -770,7 +776,7 @@ static int get_block_rd(SnowEncContext *enc, int mb_x, int mb_y,
const uint8_t *src = s->input_picture->data[plane_index];
IDWTELEM *pred = enc->obmc_scratchpad + plane_index * block_size * block_size * 4;
uint8_t *cur = s->scratchbuf;
uint8_t *tmp = s->emu_edge_buffer;
uint8_t *tmp = enc->emu_edge_buffer;
const int b_stride = s->b_width << s->block_max_depth;
const int b_height = s->b_height<< s->block_max_depth;
const int w= p->width;
@@ -2088,6 +2094,7 @@ static av_cold int encode_end(AVCodecContext *avctx)
enc->m.s.me.temp = NULL;
av_freep(&enc->m.s.me.scratchpad);
av_freep(&enc->emu_edge_buffer);
av_freep(&avctx->stats_out);