[FFmpeg-devel,12/13] avfilter/af_rubberband: use ff_filter_process_command()

Submitted by Paul B Mahol on Oct. 9, 2019, 9:56 a.m.

Details

Message ID 20191009095651.2928-12-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Oct. 9, 2019, 9:56 a.m.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/af_rubberband.c | 33 +++++++++------------------------
 1 file changed, 9 insertions(+), 24 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavfilter/af_rubberband.c b/libavfilter/af_rubberband.c
index ef937f4415..8db87fda1e 100644
--- a/libavfilter/af_rubberband.c
+++ b/libavfilter/af_rubberband.c
@@ -43,10 +43,11 @@  typedef struct RubberBandContext {
 
 #define OFFSET(x) offsetof(RubberBandContext, x)
 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define C AV_OPT_FLAG_COMMAND_PARAM
 
 static const AVOption rubberband_options[] = {
-    { "tempo",      "set tempo scale factor", OFFSET(tempo), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.01, 100, A },
-    { "pitch",      "set pitch scale factor", OFFSET(pitch), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.01, 100, A },
+    { "tempo",      "set tempo scale factor", OFFSET(tempo), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.01, 100, A|C },
+    { "pitch",      "set pitch scale factor", OFFSET(pitch), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.01, 100, A|C },
     { "transients", "set transients", OFFSET(transients), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, A, "transients" },
         { "crisp",  0,                0,                  AV_OPT_TYPE_CONST, {.i64=RubberBandOptionTransientsCrisp},  0, 0, A, "transients" },
         { "mixed",  0,                0,                  AV_OPT_TYPE_CONST, {.i64=RubberBandOptionTransientsMixed},  0, 0, A, "transients" },
@@ -200,30 +201,14 @@  static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar
                            char *res, int res_len, int flags)
 {
     RubberBandContext *s = ctx->priv;
+    int ret;
 
-    if (!strcmp(cmd, "tempo")) {
-        double arg;
-
-        sscanf(args, "%lf", &arg);
-        if (arg < 0.01 || arg > 100) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Tempo scale factor '%f' out of range\n", arg);
-            return AVERROR(EINVAL);
-        }
-        rubberband_set_time_ratio(s->rbs, 1. / arg);
-    }
-
-    if (!strcmp(cmd, "pitch")) {
-        double arg;
+    ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+    if (ret < 0)
+        return ret;
 
-        sscanf(args, "%lf", &arg);
-        if (arg < 0.01 || arg > 100) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Pitch scale factor '%f' out of range\n", arg);
-            return AVERROR(EINVAL);
-        }
-        rubberband_set_pitch_scale(s->rbs, arg);
-    }
+    rubberband_set_time_ratio(s->rbs, 1. / s->tempo);
+    rubberband_set_pitch_scale(s->rbs, s->pitch);
 
     return 0;
 }