[FFmpeg-cvslog] avfilter/af_compensationdelay: add commands support

Paul B Mahol git at videolan.org
Fri Feb 11 22:19:31 EET 2022


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Feb 11 21:15:48 2022 +0100| [1ca19cf37121c1e162c86b22e0349a7e864faf52] | committer: Paul B Mahol

avfilter/af_compensationdelay: add commands support

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1ca19cf37121c1e162c86b22e0349a7e864faf52
---

 doc/filters.texi                   |  4 ++++
 libavfilter/af_compensationdelay.c | 32 +++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 04c34cb1fb..d71292e565 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4066,6 +4066,10 @@ Set temperature in degrees Celsius. This is the temperature of the environment.
 Default is 20.
 @end table
 
+ at subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section crossfeed
 Apply headphone crossfeed filter.
 
diff --git a/libavfilter/af_compensationdelay.c b/libavfilter/af_compensationdelay.c
index 6a58fd21bd..90c2d13c00 100644
--- a/libavfilter/af_compensationdelay.c
+++ b/libavfilter/af_compensationdelay.c
@@ -40,7 +40,7 @@ typedef struct CompensationDelayContext {
 } CompensationDelayContext;
 
 #define OFFSET(x) offsetof(CompensationDelayContext, x)
-#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+#define A (AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM)
 
 static const AVOption compensationdelay_options[] = {
     { "mm",   "set mm distance",    OFFSET(distance_mm), AV_OPT_TYPE_INT,    {.i64=0},    0,  10, A },
@@ -84,6 +84,7 @@ static int config_input(AVFilterLink *inlink)
     s->delay_frame->format         = inlink->format;
     s->delay_frame->nb_samples     = new_size;
     s->delay_frame->channel_layout = inlink->channel_layout;
+    s->delay_frame->channels       = inlink->channels;
 
     return av_frame_get_buffer(s->delay_frame, 0);
 }
@@ -91,6 +92,7 @@ static int config_input(AVFilterLink *inlink)
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
     AVFilterContext *ctx = inlink->dst;
+    AVFilterLink *outlink = ctx->outputs[0];
     CompensationDelayContext *s = ctx->priv;
     const unsigned b_mask = s->buf_size - 1;
     const unsigned buf_size = s->buf_size;
@@ -101,7 +103,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFrame *out;
     int n, ch;
 
-    out = ff_get_audio_buffer(ctx->outputs[0], in->nb_samples);
+    out = ff_get_audio_buffer(outlink, in->nb_samples);
     if (!out) {
         av_frame_free(&in);
         return AVERROR(ENOMEM);
@@ -127,8 +129,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
     s->w_ptr = w_ptr;
 
+    if (ctx->is_disabled) {
+        av_frame_free(&out);
+        return ff_filter_frame(outlink, in);
+    }
+
     av_frame_free(&in);
-    return ff_filter_frame(ctx->outputs[0], out);
+    return ff_filter_frame(outlink, out);
+}
+
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+                           char *res, int res_len, int flags)
+{
+    CompensationDelayContext *s = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    int ret;
+
+    ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
+    if (ret < 0)
+        return ret;
+
+    s->delay = (s->distance_m * 100. + s->distance_cm * 1. + s->distance_mm * .1) *
+               COMP_DELAY_SOUND_FRONT_DELAY(s->temp) * outlink->sample_rate;
+
+    return 0;
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
@@ -163,4 +187,6 @@ const AVFilter ff_af_compensationdelay = {
     FILTER_INPUTS(compensationdelay_inputs),
     FILTER_OUTPUTS(compensationdelay_outputs),
     FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP),
+    .process_command = process_command,
+    .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
 };



More information about the ffmpeg-cvslog mailing list