avcodec/mpegvideo: Move allocating new_picture to the encoder

It is only used by encoders; this unfortunately necessitated
to add separate allocations to the SVQ1 encoder which uses
motion estimation without being a full member of mpegvideo.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2023-10-03 17:22:44 +02:00
parent 27fcc8dd9f
commit 4c422de1db
3 changed files with 7 additions and 7 deletions

View File

@ -632,7 +632,6 @@ static void clear_context(MpegEncContext *s)
memset(&s->next_picture, 0, sizeof(s->next_picture));
memset(&s->last_picture, 0, sizeof(s->last_picture));
memset(&s->current_picture, 0, sizeof(s->current_picture));
memset(&s->new_picture, 0, sizeof(s->new_picture));
memset(s->thread_context, 0, sizeof(s->thread_context));
@ -720,8 +719,7 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
if (!(s->next_picture.f = av_frame_alloc()) ||
!(s->last_picture.f = av_frame_alloc()) ||
!(s->current_picture.f = av_frame_alloc()) ||
!(s->new_picture = av_frame_alloc()))
!(s->current_picture.f = av_frame_alloc()))
goto fail_nomem;
if ((ret = ff_mpv_init_context_frame(s)))
@ -801,7 +799,6 @@ void ff_mpv_common_end(MpegEncContext *s)
ff_mpv_picture_free(s->avctx, &s->last_picture);
ff_mpv_picture_free(s->avctx, &s->current_picture);
ff_mpv_picture_free(s->avctx, &s->next_picture);
av_frame_free(&s->new_picture);
s->context_initialized = 0;
s->context_reinit = 0;

View File

@ -821,7 +821,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) ||
!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16, 32) ||
!FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_PICTURE_COUNT) ||
!FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT))
!FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT) ||
!(s->new_picture = av_frame_alloc()))
return AVERROR(ENOMEM);
/* Allocate MV tables; the MV and MB tables will be copied

View File

@ -570,6 +570,7 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx)
av_frame_free(&s->current_picture);
av_frame_free(&s->last_picture);
av_frame_free(&s->m.new_picture);
return 0;
}
@ -632,10 +633,11 @@ static av_cold int svq1_encode_init(AVCodecContext *avctx)
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->m.new_picture = av_frame_alloc();
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->mb_type || !s->dummy)
if (!s->m.me.scratchpad || !s->m.me.map ||
!s->mb_type || !s->dummy || !s->m.new_picture)
return AVERROR(ENOMEM);
s->m.me.score_map = s->m.me.map + ME_MAP_SIZE;