[FFmpeg-devel] [PATCH 09/22] lavfi/vf_libplacebo: replace s->input by dynamic array

Niklas Haas ffmpeg at haasn.xyz
Fri Jun 16 15:22:34 EEST 2023


On Fri, 16 Jun 2023 14:09:56 +0200 Andreas Rheinhardt <andreas.rheinhardt at outlook.com> wrote:
> Niklas Haas:
> > From: Niklas Haas <git at haasn.dev>
> > 
> > For now, hard-coded to 1 element.
> > ---
> >  libavfilter/vf_libplacebo.c | 18 +++++++++++++-----
> >  1 file changed, 13 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
> > index 408fb3918a..fbac1b0354 100644
> > --- a/libavfilter/vf_libplacebo.c
> > +++ b/libavfilter/vf_libplacebo.c
> > @@ -136,7 +136,8 @@ typedef struct LibplaceboContext {
> >      pl_tex tex[4];
> >  
> >      /* input state */
> > -    LibplaceboInput input;
> > +    LibplaceboInput *inputs;
> > +    int nb_inputs;
> >  
> >      /* settings */
> >      char *out_format_string;
> > @@ -660,7 +661,12 @@ static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwct
> >      }
> >  
> >      /* Initialize inputs */
> > -    RET(input_init(avctx, avctx->inputs[0], &s->input));
> > +    s->nb_inputs = 1;
> > +    s->inputs = av_calloc(s->nb_inputs, sizeof(*s->inputs));
> > +    if (!s->inputs)
> > +        return AVERROR(ENOMEM);
> > +    for (int i = 0; i < s->nb_inputs; i++)
> > +        RET(input_init(avctx, avctx->inputs[i], &s->inputs[i]));
> >  
> >      /* fall through */
> >  fail:
> > @@ -677,7 +683,9 @@ static void libplacebo_uninit(AVFilterContext *avctx)
> >          pl_tex_destroy(s->gpu, &s->tex[i]);
> >      for (int i = 0; i < s->num_hooks; i++)
> >          pl_mpv_user_shader_destroy(&s->hooks[i]);
> > -    input_uninit(&s->input);
> > +    for (int i = 0; i < s->nb_inputs && s->inputs; i++)
> > +        input_uninit(&s->inputs[i]);
> > +    av_freep(&s->inputs);
> 
> In case the allocation of s->inputs fails, nb_inputs is 1 and the above
> loop will try to uninit a non-existant input.

There's an extra `s->inputs` check in the loop condition. I'll make it more
explicit.


More information about the ffmpeg-devel mailing list