[FFmpeg-cvslog] avfilter/af_afir: add way to control loading interval of impulses

Paul B Mahol git at videolan.org
Tue Apr 25 22:25:04 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Apr 25 15:42:44 2023 +0200| [bee265e5d50a6d6057fb2cf77d55851b867a41d9] | committer: Paul B Mahol

avfilter/af_afir: add way to control loading interval of impulses

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

 doc/filters.texi      |  6 ++++++
 libavfilter/af_afir.c | 45 ++++++++++++++++++++++++++++-----------------
 libavfilter/af_afir.h |  1 +
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 120fe6664a..a7972ff736 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1849,6 +1849,12 @@ Always use double-floating point precision sample format.
 @end table
 
 Default value is auto.
+
+ at item irload
+Set when to load IR stream. Can be @code{init} or @code{access}.
+First one load and prepares all IRs on initialization, second one
+once on first access of specific IR.
+Default is @code{init}.
 @end table
 
 @subsection Examples
diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 338e23063c..24fb8c1abe 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -472,27 +472,35 @@ static int activate(AVFilterContext *ctx)
     FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
     if (s->response)
         FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[1], ctx);
-    if (!s->eof_coeffs[s->selir]) {
-        ret = check_ir(ctx->inputs[1 + s->selir]);
-        if (ret < 0)
-            return ret;
 
-        if (ff_outlink_get_status(ctx->inputs[1 + s->selir]) == AVERROR_EOF)
-            s->eof_coeffs[s->selir] = 1;
+    for (int i = 0; i < s->nb_irs; i++) {
+        const int selir = i;
 
-        if (!s->eof_coeffs[s->selir]) {
-            if (ff_outlink_frame_wanted(ctx->outputs[0]))
-                ff_inlink_request_frame(ctx->inputs[1 + s->selir]);
-            else if (s->response && ff_outlink_frame_wanted(ctx->outputs[1]))
-                ff_inlink_request_frame(ctx->inputs[1 + s->selir]);
-            return 0;
+        if (s->ir_load && selir != s->selir)
+            continue;
+
+        if (!s->eof_coeffs[selir]) {
+            ret = check_ir(ctx->inputs[1 + selir]);
+            if (ret < 0)
+                return ret;
+
+            if (ff_outlink_get_status(ctx->inputs[1 + selir]) == AVERROR_EOF)
+                s->eof_coeffs[selir] = 1;
+
+            if (!s->eof_coeffs[selir]) {
+                if (ff_outlink_frame_wanted(ctx->outputs[0]))
+                    ff_inlink_request_frame(ctx->inputs[1 + selir]);
+                else if (s->response && ff_outlink_frame_wanted(ctx->outputs[1]))
+                    ff_inlink_request_frame(ctx->inputs[1 + selir]);
+                return 0;
+            }
         }
-    }
 
-    if (!s->have_coeffs[s->selir] && s->eof_coeffs[s->selir]) {
-        ret = convert_coeffs(ctx, s->selir);
-        if (ret < 0)
-            return ret;
+        if (!s->have_coeffs[selir] && s->eof_coeffs[selir]) {
+            ret = convert_coeffs(ctx, selir);
+            if (ret < 0)
+                return ret;
+        }
     }
 
     if (s->selir != s->prev_selir && s->loading[0] <= 0) {
@@ -830,6 +838,9 @@ static const AVOption afir_options[] = {
     {  "auto", "set auto processing precision",                   0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision" },
     {  "float", "set single-floating point processing precision", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision" },
     {  "double","set double-floating point processing precision", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision" },
+    { "irload", "set IR loading type", OFFSET(ir_load), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, AF, "irload" },
+    {  "init",   "load all IRs on init", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "irload" },
+    {  "access", "load IR on access",    0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "irload" },
     { NULL }
 };
 
diff --git a/libavfilter/af_afir.h b/libavfilter/af_afir.h
index 099897d0bb..7c9a3b3e31 100644
--- a/libavfilter/af_afir.h
+++ b/libavfilter/af_afir.h
@@ -65,6 +65,7 @@ typedef struct AudioFIRContext {
     int gtype;
     float ir_gain;
     int ir_format;
+    int ir_load;
     float max_ir_len;
     int response;
     int w, h;



More information about the ffmpeg-cvslog mailing list