[PATCH 1/2] avfilter/af_ladspa: refactor code setting input control ports values
Signed-off-by: Paul B Mahol <onemda@gmail.com> --- libavfilter/af_ladspa.c | 61 ++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c index d1e3e23..f25699e 100644 --- a/libavfilter/af_ladspa.c +++ b/libavfilter/af_ladspa.c @@ -349,6 +349,40 @@ static void *try_load(const char *dir, const char *soname) return ret; } +static int set_control(AVFilterContext *ctx, int port, LADSPA_Data value) +{ + LADSPAContext *s = ctx->priv; + const char *label = s->desc->Label; + LADSPA_PortRangeHint *h = (LADSPA_PortRangeHint *)s->desc->PortRangeHints + + s->icmap[port]; + + if (port < 0 || port >= s->nb_inputcontrols) { + av_log(ctx, AV_LOG_ERROR, "Control c%d is out of range [0 - %lu].\n", + port, s->nb_inputcontrols); + return AVERROR(EINVAL); + } + + if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor) && + value < h->LowerBound) { + av_log(ctx, AV_LOG_ERROR, + "%s: input control c%d is below lower boundary of %0.4f.\n", + label, port, h->LowerBound); + return AVERROR(EINVAL); + } + + if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor) && + value > h->UpperBound) { + av_log(ctx, AV_LOG_ERROR, + "%s: input control c%d is above upper boundary of %0.4f.\n", + label, port, h->UpperBound); + return AVERROR(EINVAL); + } + + s->ictlv[port] = value; + + return 0; +} + static av_cold int init(AVFilterContext *ctx) { LADSPAContext *s = ctx->priv; @@ -495,8 +529,8 @@ static av_cold int init(AVFilterContext *ctx) // Parse control parameters p = s->options; while (s->options) { - LADSPA_PortRangeHint *h; LADSPA_Data val; + int ret; if (!(arg = av_strtok(p, "|", &saveptr))) break; @@ -507,30 +541,9 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } - if (i < 0 || i >= s->nb_inputcontrols) { - av_log(ctx, AV_LOG_ERROR, - "Control c%d is out of range [0 - %lu].\n", - i, s->nb_inputcontrols); - return AVERROR(EINVAL); - } - - h = (LADSPA_PortRangeHint *)s->desc->PortRangeHints + s->icmap[i]; - s->ictlv[i] = val; + if ((ret = set_control(ctx, i, val)) < 0) + return ret; s->ctl_needs_value[i] = 0; - if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor) && - val < h->LowerBound) { - av_log(ctx, AV_LOG_ERROR, - "%s: input control c%d is below lower boundary of %0.4f.\n", - s->desc->Label, i, h->LowerBound); - return AVERROR(EINVAL); - } - if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor) && - val > h->UpperBound) { - av_log(ctx, AV_LOG_ERROR, - "%s: input control c%d is above upper boundary of %0.4f.\n", - s->desc->Label, i, h->UpperBound); - return AVERROR(EINVAL); - } } // Check if any controls are not set -- 1.7.11.2
Signed-off-by: Paul B Mahol <onemda@gmail.com> --- doc/filters.texi | 10 ++++++++++ libavfilter/af_ladspa.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 800a666..a349bee 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1502,6 +1502,16 @@ ladspa=caps:Eq10X2:c=c0=-48|c9=-24|c3=12|c4=2 @end example @end itemize +@subsection Commands + +This filter supports the following commands: +@table @option +@item ci +Modify the @var{i}-th control value. + +If the specified value is not valid, it is ignored and prior one is kept. +@end table + @section lowpass Apply a low-pass filter with 3dB point frequency. diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c index f25699e..904ad14 100644 --- a/libavfilter/af_ladspa.c +++ b/libavfilter/af_ladspa.c @@ -662,6 +662,18 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&ctx->input_pads[0].name); } +static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + LADSPA_Data value; + int port; + + if (sscanf(cmd, "c%d", &port) + sscanf(args, "%f", &value) != 2) + return AVERROR(EINVAL); + + return set_control(ctx, port, value); +} + static const AVFilterPad ladspa_outputs[] = { { .name = "default", @@ -680,6 +692,7 @@ AVFilter avfilter_af_ladspa = { .init = init, .uninit = uninit, .query_formats = query_formats, + .process_command = process_command, .inputs = 0, .outputs = ladspa_outputs, .flags = AVFILTER_FLAG_DYNAMIC_INPUTS, -- 1.7.11.2
On date Tuesday 2013-09-24 16:49:00 +0000, Paul B Mahol encoded:
Signed-off-by: Paul B Mahol <onemda@gmail.com> --- doc/filters.texi | 10 ++++++++++ libavfilter/af_ladspa.c | 13 +++++++++++++ 2 files changed, 23 insertions(+)
diff --git a/doc/filters.texi b/doc/filters.texi index 800a666..a349bee 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1502,6 +1502,16 @@ ladspa=caps:Eq10X2:c=c0=-48|c9=-24|c3=12|c4=2 @end example @end itemize
+@subsection Commands + +This filter supports the following commands: +@table @option +@item ci
Nit: probably "cN" to make clear that N is something special.
+Modify the @var{i}-th control value. + +If the specified value is not valid, it is ignored and prior one is kept. +@end table + @section lowpass
Apply a low-pass filter with 3dB point frequency. diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c index f25699e..904ad14 100644 --- a/libavfilter/af_ladspa.c +++ b/libavfilter/af_ladspa.c @@ -662,6 +662,18 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&ctx->input_pads[0].name); }
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + LADSPA_Data value; + int port; + + if (sscanf(cmd, "c%d", &port) + sscanf(args, "%f", &value) != 2) + return AVERROR(EINVAL); + + return set_control(ctx, port, value); +} + static const AVFilterPad ladspa_outputs[] = { { .name = "default", @@ -680,6 +692,7 @@ AVFilter avfilter_af_ladspa = { .init = init, .uninit = uninit, .query_formats = query_formats, + .process_command = process_command, .inputs = 0, .outputs = ladspa_outputs, .flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
LGTM, thanks. -- FFmpeg = Foolish and Freak Mournful Purposeless Ephemeral Guru
On date Tuesday 2013-09-24 16:48:59 +0000, Paul B Mahol encoded:
Signed-off-by: Paul B Mahol <onemda@gmail.com> --- libavfilter/af_ladspa.c | 61 ++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 24 deletions(-)
diff --git a/libavfilter/af_ladspa.c b/libavfilter/af_ladspa.c index d1e3e23..f25699e 100644 --- a/libavfilter/af_ladspa.c +++ b/libavfilter/af_ladspa.c @@ -349,6 +349,40 @@ static void *try_load(const char *dir, const char *soname) return ret; }
+static int set_control(AVFilterContext *ctx, int port, LADSPA_Data value) +{ + LADSPAContext *s = ctx->priv; + const char *label = s->desc->Label; + LADSPA_PortRangeHint *h = (LADSPA_PortRangeHint *)s->desc->PortRangeHints + + s->icmap[port]; + + if (port < 0 || port >= s->nb_inputcontrols) { + av_log(ctx, AV_LOG_ERROR, "Control c%d is out of range [0 - %lu].\n", + port, s->nb_inputcontrols); + return AVERROR(EINVAL); + } + + if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor) && + value < h->LowerBound) { + av_log(ctx, AV_LOG_ERROR, + "%s: input control c%d is below lower boundary of %0.4f.\n", + label, port, h->LowerBound); + return AVERROR(EINVAL); + } + + if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor) && + value > h->UpperBound) { + av_log(ctx, AV_LOG_ERROR, + "%s: input control c%d is above upper boundary of %0.4f.\n", + label, port, h->UpperBound); + return AVERROR(EINVAL); + } + + s->ictlv[port] = value; + + return 0; +} + static av_cold int init(AVFilterContext *ctx) { LADSPAContext *s = ctx->priv; @@ -495,8 +529,8 @@ static av_cold int init(AVFilterContext *ctx) // Parse control parameters p = s->options; while (s->options) { - LADSPA_PortRangeHint *h; LADSPA_Data val; + int ret;
if (!(arg = av_strtok(p, "|", &saveptr))) break; @@ -507,30 +541,9 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); }
- if (i < 0 || i >= s->nb_inputcontrols) { - av_log(ctx, AV_LOG_ERROR, - "Control c%d is out of range [0 - %lu].\n", - i, s->nb_inputcontrols); - return AVERROR(EINVAL); - } - - h = (LADSPA_PortRangeHint *)s->desc->PortRangeHints + s->icmap[i]; - s->ictlv[i] = val; + if ((ret = set_control(ctx, i, val)) < 0) + return ret; s->ctl_needs_value[i] = 0; - if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor) && - val < h->LowerBound) { - av_log(ctx, AV_LOG_ERROR, - "%s: input control c%d is below lower boundary of %0.4f.\n", - s->desc->Label, i, h->LowerBound); - return AVERROR(EINVAL); - } - if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor) && - val > h->UpperBound) { - av_log(ctx, AV_LOG_ERROR, - "%s: input control c%d is above upper boundary of %0.4f.\n", - s->desc->Label, i, h->UpperBound); - return AVERROR(EINVAL); - } }
// Check if any controls are not set
LGTM. -- FFmpeg = Fundamental and Foolish Mere Pure Exuberant Gangster
participants (2)
-
Paul B Mahol -
Stefano Sabatini