[FFmpeg-devel] [PATCH 21/24] lavfi/vf_scale: factorize freeing the sws contexts
Anton Khirnov
anton at khirnov.net
Mon May 31 10:55:12 EEST 2021
---
libavfilter/vf_scale.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 759499395f..8516919556 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -328,16 +328,24 @@ static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
return 0;
}
+static void scaler_free(ScaleContext *s)
+{
+ sws_freeContext(s->sws);
+ sws_freeContext(s->isws[0]);
+ sws_freeContext(s->isws[1]);
+
+ s->sws = NULL;
+ s->isws[0] = NULL;
+ s->isws[1] = NULL;
+}
+
static av_cold void uninit(AVFilterContext *ctx)
{
ScaleContext *scale = ctx->priv;
av_expr_free(scale->w_pexpr);
av_expr_free(scale->h_pexpr);
scale->w_pexpr = scale->h_pexpr = NULL;
- sws_freeContext(scale->sws);
- sws_freeContext(scale->isws[0]);
- sws_freeContext(scale->isws[1]);
- scale->sws = NULL;
+ scaler_free(scale);
av_dict_free(&scale->opts);
}
@@ -512,13 +520,8 @@ static int config_props(AVFilterLink *outlink)
if (outfmt == AV_PIX_FMT_PAL8) outfmt = AV_PIX_FMT_BGR8;
scale->output_is_pal = av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PAL;
- if (scale->sws)
- sws_freeContext(scale->sws);
- if (scale->isws[0])
- sws_freeContext(scale->isws[0]);
- if (scale->isws[1])
- sws_freeContext(scale->isws[1]);
- scale->isws[0] = scale->isws[1] = scale->sws = NULL;
+ scaler_free(scale);
+
if (inlink0->w == outlink->w &&
inlink0->h == outlink->h &&
!scale->out_color_matrix &&
--
2.30.2
More information about the ffmpeg-devel
mailing list