[FFmpeg-cvslog] avfilter/af_afir: fix overhead for small partitions

Paul B Mahol git at videolan.org
Mon Dec 31 19:08:10 EET 2018


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Dec 31 18:04:59 2018 +0100| [86555a2fbf3339ec7cd3487d7e21739c6730db2e] | committer: Paul B Mahol

avfilter/af_afir: fix overhead for small partitions

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

 libavfilter/af_afir.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 73a613f153..c4baf63c02 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -56,12 +56,12 @@ static void fcmul_add_c(float *sum, const float *t, const float *c, ptrdiff_t le
     sum[2 * n] += t[2 * n] * c[2 * n];
 }
 
-static int fir_channel(AVFilterContext *ctx, void *arg, int ch)
+static int fir_quantum(AVFilterContext *ctx, AVFrame *out, int ch, int offset)
 {
     AudioFIRContext *s = ctx->priv;
-    const float *in = (const float *)s->in[0]->extended_data[ch];
-    AVFrame *out = arg;
-    float *block, *buf, *ptr = (float *)out->extended_data[ch];
+    const float *in = (const float *)s->in[0]->extended_data[ch] + offset;
+    float *block, *buf, *ptr = (float *)out->extended_data[ch] + offset;
+    const int nb_samples = FFMIN(s->min_part_size, out->nb_samples - offset);
     int n, i, j;
 
     for (int segment = 0; segment < s->nb_segments; segment++) {
@@ -70,7 +70,7 @@ static int fir_channel(AVFilterContext *ctx, void *arg, int ch)
         float *dst = (float *)seg->output->extended_data[ch];
         float *sum = (float *)seg->sum->extended_data[ch];
 
-        s->fdsp->vector_fmul_scalar(src + seg->input_offset, in, s->dry_gain, FFALIGN(out->nb_samples, 4));
+        s->fdsp->vector_fmul_scalar(src + seg->input_offset, in, s->dry_gain, FFALIGN(nb_samples, 4));
         emms_c();
 
         seg->output_offset[ch] += s->min_part_size;
@@ -80,7 +80,7 @@ static int fir_channel(AVFilterContext *ctx, void *arg, int ch)
             memmove(src, src + s->min_part_size, (seg->input_size - s->min_part_size) * sizeof(*src));
 
             dst += seg->output_offset[ch];
-            for (n = 0; n < out->nb_samples; n++) {
+            for (n = 0; n < nb_samples; n++) {
                 ptr[n] += dst[n];
             }
             continue;
@@ -127,17 +127,28 @@ static int fir_channel(AVFilterContext *ctx, void *arg, int ch)
 
         memmove(src, src + s->min_part_size, (seg->input_size - s->min_part_size) * sizeof(*src));
 
-        for (n = 0; n < out->nb_samples; n++) {
+        for (n = 0; n < nb_samples; n++) {
             ptr[n] += dst[n];
         }
     }
 
-    s->fdsp->vector_fmul_scalar(ptr, ptr, s->wet_gain, FFALIGN(out->nb_samples, 4));
+    s->fdsp->vector_fmul_scalar(ptr, ptr, s->wet_gain, FFALIGN(nb_samples, 4));
     emms_c();
 
     return 0;
 }
 
+static int fir_channel(AVFilterContext *ctx, AVFrame *out, int ch)
+{
+    AudioFIRContext *s = ctx->priv;
+
+    for (int offset = 0; offset < out->nb_samples; offset += s->min_part_size) {
+        fir_quantum(ctx, out, ch, offset);
+    }
+
+    return 0;
+}
+
 static int fir_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
     AVFrame *out = arg;
@@ -525,8 +536,8 @@ static int activate(AVFilterContext *ctx)
 {
     AudioFIRContext *s = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
+    int ret, status, available, wanted;
     AVFrame *in = NULL;
-    int ret, status;
     int64_t pts;
 
     FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
@@ -557,7 +568,9 @@ static int activate(AVFilterContext *ctx)
             return ret;
     }
 
-    ret = ff_inlink_consume_samples(ctx->inputs[0], s->min_part_size, s->min_part_size, &in);
+    available = ff_inlink_queued_samples(ctx->inputs[0]);
+    wanted = FFMAX(s->min_part_size, (available / s->min_part_size) * s->min_part_size);
+    ret = ff_inlink_consume_samples(ctx->inputs[0], wanted, wanted, &in);
     if (ret > 0)
         ret = fir_frame(s, in, outlink);
 



More information about the ffmpeg-cvslog mailing list