From d5c66d9c561283b4c9e862ce185fead8f27f37ce Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 18 Mar 2013 21:31:54 +0100 Subject: [PATCH 1/3] vf_setdar: make config_props work properly when called multiple times. Do not overwrite the variable set through AVOptions. --- libavfilter/vf_aspect.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c index 50b4a7f963..11cd000e53 100644 --- a/libavfilter/vf_aspect.c +++ b/libavfilter/vf_aspect.c @@ -35,7 +35,8 @@ typedef struct { const AVClass *class; - AVRational aspect; + AVRational dar; + AVRational sar; #if FF_API_OLD_FILTER_OPTS float aspect_num, aspect_den; #endif @@ -49,7 +50,7 @@ static av_cold int init(AVFilterContext *ctx) if (s->aspect_num > 0 && s->aspect_den > 0) { av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use " "dar= or dar=num/den.\n"); - s->aspect = av_d2q(s->aspect_num / s->aspect_den, INT_MAX); + s->sar = s->dar = av_d2q(s->aspect_num / s->aspect_den, INT_MAX); } return 0; @@ -60,7 +61,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) { AspectContext *s = link->dst->priv; - frame->sample_aspect_ratio = s->aspect; + frame->sample_aspect_ratio = s->sar; return ff_filter_frame(link->dst->outputs[0], frame); } @@ -72,13 +73,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) static int setdar_config_props(AVFilterLink *inlink) { AspectContext *s = inlink->dst->priv; - AVRational dar = s->aspect; + AVRational dar; - if (s->aspect.num && s->aspect.den) { - av_reduce(&s->aspect.num, &s->aspect.den, - s->aspect.num * inlink->h, - s->aspect.den * inlink->w, 100); - inlink->sample_aspect_ratio = s->aspect; + if (s->dar.num && s->dar.den) { + av_reduce(&s->sar.num, &s->sar.den, + s->dar.num * inlink->h, + s->dar.den * inlink->w, 100); + inlink->sample_aspect_ratio = s->sar; + dar = s->dar; } else { inlink->sample_aspect_ratio = (AVRational){ 1, 1 }; dar = (AVRational){ inlink->w, inlink->h }; @@ -96,7 +98,7 @@ static const AVOption setdar_options[] = { { "dar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, { "dar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, #endif - { "dar", "display aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, FLAGS }, + { "dar", "display aspect ratio", OFFSET(dar), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, FLAGS }, { NULL }, }; @@ -149,7 +151,7 @@ static int setsar_config_props(AVFilterLink *inlink) { AspectContext *s = inlink->dst->priv; - inlink->sample_aspect_ratio = s->aspect; + inlink->sample_aspect_ratio = s->sar; return 0; } @@ -159,7 +161,7 @@ static const AVOption setsar_options[] = { { "sar_num", NULL, OFFSET(aspect_num), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, { "sar_den", NULL, OFFSET(aspect_den), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, FLT_MAX, FLAGS }, #endif - { "sar", "sample (pixel) aspect ratio", OFFSET(aspect), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, INT_MAX, FLAGS }, + { "sar", "sample (pixel) aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, INT_MAX, FLAGS }, { NULL }, }; From 6592cd22a2307dbbeb621c7499ba81961e6face8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 18 Mar 2013 21:31:54 +0100 Subject: [PATCH 2/3] vf_crop: make config_props work properly when called multiple times. Do not leak the x/y expressions. --- libavfilter/vf_crop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c index bf9e85f424..c039c454a2 100644 --- a/libavfilter/vf_crop.c +++ b/libavfilter/vf_crop.c @@ -193,6 +193,9 @@ static int config_input(AVFilterLink *link) s->w &= ~((1 << s->hsub) - 1); s->h &= ~((1 << s->vsub) - 1); + av_expr_free(s->x_pexpr); + av_expr_free(s->y_pexpr); + s->x_pexpr = s->y_pexpr = NULL; if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0 || (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names, From 3fb29588a27a711132106b924e27b53789a58dcb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 18 Mar 2013 22:13:35 +0100 Subject: [PATCH 3/3] vf_drawtext: don't leak the expressions. --- libavfilter/vf_drawtext.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 2989bd5034..53340c84ab 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -402,6 +402,10 @@ static av_cold void uninit(AVFilterContext *ctx) DrawTextContext *s = ctx->priv; int i; + av_expr_free(s->x_pexpr); + av_expr_free(s->y_pexpr); + av_expr_free(s->d_pexpr); + s->x_pexpr = s->y_pexpr = s->d_pexpr = NULL; av_freep(&s->expanded_text); av_freep(&s->positions); av_tree_enumerate(s->glyphs, NULL, NULL, glyph_enu_free); @@ -573,6 +577,10 @@ static int config_input(AVFilterLink *inlink) av_lfg_init(&s->prng, av_get_random_seed()); + av_expr_free(s->x_pexpr); + av_expr_free(s->y_pexpr); + av_expr_free(s->d_pexpr); + s->x_pexpr = s->y_pexpr = s->d_pexpr = NULL; if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names, NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names,