@@ -373,9 +373,10 @@ static int init_duplicate_context(MpegEncContext *s)
yc_size += 2*s->b8_stride + 2*s->mb_stride;
if (s->encoding) {
- if (!FF_ALLOCZ_TYPED_ARRAY(s->me.map, ME_MAP_SIZE) ||
- !FF_ALLOCZ_TYPED_ARRAY(s->me.score_map, ME_MAP_SIZE))
+ s->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->me.map));
+ if (!s->me.map)
return AVERROR(ENOMEM);
+ s->me.score_map = s->me.map + ME_MAP_SIZE;
if (s->noise_reduction) {
if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_error_sum, 2))
@@ -445,7 +446,7 @@ static void free_duplicate_context(MpegEncContext *s)
av_freep(&s->dct_error_sum);
av_freep(&s->me.map);
- av_freep(&s->me.score_map);
+ s->me.score_map = NULL;
av_freep(&s->blocks);
av_freep(&s->ac_val_base);
s->block = NULL;
@@ -635,7 +635,6 @@ av_cold void ff_snow_common_end(SnowContext *s)
s->m.me.temp= NULL;
av_freep(&s->m.me.scratchpad);
av_freep(&s->m.me.map);
- av_freep(&s->m.me.score_map);
av_freep(&s->m.sc.obmc_scratchpad);
av_freep(&s->block);
@@ -82,11 +82,11 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->m.me.temp =
s->m.me.scratchpad = av_calloc(avctx->width + 64, 2*16*2*sizeof(uint8_t));
- s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
- s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t));
s->m.sc.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t));
- if (!s->m.me.scratchpad || !s->m.me.map || !s->m.me.score_map || !s->m.sc.obmc_scratchpad)
+ s->m.me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->m.me.map));
+ if (!s->m.me.scratchpad || !s->m.me.map || !s->m.sc.obmc_scratchpad)
return AVERROR(ENOMEM);
+ s->m.me.score_map = s->m.me.map + ME_MAP_SIZE;
ff_h263_encode_init(&s->m); //mv_penalty
@@ -552,7 +552,6 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
av_freep(&s->m.me.scratchpad);
av_freep(&s->m.me.map);
- av_freep(&s->m.me.score_map);
av_freep(&s->mb_type);
av_freep(&s->dummy);
av_freep(&s->scratchbuf);
@@ -608,18 +607,17 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
s->m.me.temp =
s->m.me.scratchpad = av_mallocz((avctx->width + 64) *
2 * 16 * 2 * sizeof(uint8_t));
- s->m.me.map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t));
- s->m.me.score_map = av_mallocz(ME_MAP_SIZE * sizeof(uint32_t));
s->mb_type = av_mallocz((s->y_block_width + 1) *
s->y_block_height * sizeof(int16_t));
s->dummy = av_mallocz((s->y_block_width + 1) *
s->y_block_height * sizeof(int32_t));
+ s->m.me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->m.me.map));
s->svq1encdsp.ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
if (!s->m.me.temp || !s->m.me.scratchpad || !s->m.me.map ||
- !s->m.me.score_map || !s->mb_type || !s->dummy) {
+ !s->mb_type || !s->dummy)
return AVERROR(ENOMEM);
- }
+ s->m.me.score_map = s->m.me.map + ME_MAP_SIZE;
#if ARCH_PPC
ff_svq1enc_init_ppc(&s->svq1encdsp);
Reduces the amounts of allocs, frees and allocation checks. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mpegvideo.c | 7 ++++--- libavcodec/snow.c | 1 - libavcodec/snowenc.c | 6 +++--- libavcodec/svq1enc.c | 8 +++----- 4 files changed, 10 insertions(+), 12 deletions(-)