]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_ladspa.c
Merge commit 'ad0560fe7491a85c3e71d5a3d6a0443f10b33ab1'
[ffmpeg] / libavfilter / af_ladspa.c
index d1e3e23721ebd92e0ec449c347975a30a35a3267..7578a385ff6d10c25897b32a7472fc0b3fbfc36c 100644 (file)
@@ -349,6 +349,40 @@ static void *try_load(const char *dir, const char *soname)
     return ret;
 }
 
+static int set_control(AVFilterContext *ctx, unsigned long 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 >= s->nb_inputcontrols) {
+        av_log(ctx, AV_LOG_ERROR, "Control c%ld 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%ld 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%ld 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
@@ -599,6 +612,8 @@ static int query_formats(AVFilterContext *ctx)
 
         ff_set_common_channel_layouts(ctx, layouts);
     } else {
+        AVFilterLink *outlink = ctx->outputs[0];
+
         if (s->nb_inputs >= 1) {
             AVFilterLink *inlink = ctx->inputs[0];
             int64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
@@ -606,10 +621,12 @@ static int query_formats(AVFilterContext *ctx)
             layouts = NULL;
             ff_add_channel_layout(&layouts, inlayout);
             ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
+
+            if (!s->nb_outputs)
+                ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
         }
 
         if (s->nb_outputs >= 1) {
-            AVFilterLink *outlink = ctx->outputs[0];
             int64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
 
             layouts = NULL;
@@ -649,6 +666,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;
+    unsigned long port;
+
+    if (sscanf(cmd, "c%ld", &port) + sscanf(args, "%f", &value) != 2)
+        return AVERROR(EINVAL);
+
+    return set_control(ctx, port, value);
+}
+
 static const AVFilterPad ladspa_outputs[] = {
     {
         .name          = "default",
@@ -667,6 +696,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,