Message ID | 20230616092959.5247-9-ffmpeg@haasn.xyz |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,01/22] lavfi/vf_libplacebo: drop redundant case | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
Niklas Haas: > From: Niklas Haas <git@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. > pl_vulkan_destroy(&s->vulkan); > pl_log_destroy(&s->log); > ff_vk_uninit(&s->vkctx); > @@ -774,7 +782,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) > { > int err = 0, ok, changed_csp; > LibplaceboContext *s = ctx->priv; > - LibplaceboInput *in = &s->input; > + LibplaceboInput *in = &s->inputs[0]; > AVFilterLink *outlink = ctx->outputs[0]; > const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format); > const AVFrame *ref = ref_frame(&in->mix); > @@ -942,7 +950,7 @@ static int libplacebo_activate(AVFilterContext *ctx) > { > int ret; > LibplaceboContext *s = ctx->priv; > - LibplaceboInput *in = &s->input; > + LibplaceboInput *in = &s->inputs[0]; > AVFilterLink *outlink = ctx->outputs[0]; > int64_t pts; >
On Fri, 16 Jun 2023 14:09:56 +0200 Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote: > Niklas Haas: > > From: Niklas Haas <git@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.
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); pl_vulkan_destroy(&s->vulkan); pl_log_destroy(&s->log); ff_vk_uninit(&s->vkctx); @@ -774,7 +782,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) { int err = 0, ok, changed_csp; LibplaceboContext *s = ctx->priv; - LibplaceboInput *in = &s->input; + LibplaceboInput *in = &s->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format); const AVFrame *ref = ref_frame(&in->mix); @@ -942,7 +950,7 @@ static int libplacebo_activate(AVFilterContext *ctx) { int ret; LibplaceboContext *s = ctx->priv; - LibplaceboInput *in = &s->input; + LibplaceboInput *in = &s->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; int64_t pts;
From: Niklas Haas <git@haasn.dev> For now, hard-coded to 1 element. --- libavfilter/vf_libplacebo.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)