[FFmpeg-devel] [PATCH 12/12] avcodec/mpegvideo: Move allocating new_picture to the encoder

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Oct 6 05:21:57 EEST 2023


Andreas Rheinhardt:
> 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 at outlook.com>
> ---
>  libavcodec/mpegvideo.c     | 5 +----
>  libavcodec/mpegvideo_enc.c | 3 ++-
>  libavcodec/svq1enc.c       | 6 ++++--
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index fc73abab9c..9ed158ac57 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -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;
> diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
> index 5bf4b06a11..f669658127 100644
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -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
> diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
> index 46a484e15f..894ae552bb 100644
> --- a/libavcodec/svq1enc.c
> +++ b/libavcodec/svq1enc.c
> @@ -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;
>  

Will apply this patch tonight unless there are objections.

- Andreas



More information about the ffmpeg-devel mailing list