[FFmpeg-cvslog] avfilter/af_afir: introduce init_segment() and use it

Paul B Mahol git at videolan.org
Sun Dec 30 14:42:44 EET 2018


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Dec 28 18:31:36 2018 +0100| [c343e81ffd3008e6df9440bf66e2850e41574099] | committer: Paul B Mahol

avfilter/af_afir: introduce init_segment() and use it

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

 libavfilter/af_afir.c | 69 +++++++++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 30 deletions(-)

diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 077c64cd6a..743f7d2658 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -274,6 +274,42 @@ end:
     av_free(mag);
 }
 
+static int init_segment(AVFilterContext *ctx, AudioFIRSegment *seg, int nb_partitions, int part_size)
+{
+    seg->coeff = av_calloc(ctx->inputs[1]->channels, sizeof(*seg->coeff));
+    seg->rdft  = av_calloc(ctx->inputs[0]->channels, sizeof(*seg->rdft));
+    seg->irdft = av_calloc(ctx->inputs[0]->channels, sizeof(*seg->irdft));
+    if (!seg->coeff || !seg->rdft || !seg->irdft)
+        return AVERROR(ENOMEM);
+
+    seg->fft_length = part_size * 4 + 1;
+    seg->part_size = part_size;
+    seg->block_size = FFALIGN(seg->fft_length, 32);
+    seg->coeff_size = FFALIGN(seg->part_size + 1, 32);
+    seg->nb_partitions = nb_partitions;
+
+    for (int ch = 0; ch < ctx->inputs[1]->channels; ch++) {
+        seg->coeff[ch] = av_calloc(seg->nb_partitions * seg->coeff_size, sizeof(**seg->coeff));
+        if (!seg->coeff[ch])
+            return AVERROR(ENOMEM);
+    }
+
+    for (int ch = 0; ch < ctx->inputs[0]->channels; ch++) {
+        seg->rdft[ch]  = av_rdft_init(av_log2(2 * part_size), DFT_R2C);
+        seg->irdft[ch] = av_rdft_init(av_log2(2 * part_size), IDFT_C2R);
+        if (!seg->rdft[ch] || !seg->irdft[ch])
+            return AVERROR(ENOMEM);
+    }
+
+    seg->sum    = ff_get_audio_buffer(ctx->inputs[0], seg->fft_length);
+    seg->block  = ff_get_audio_buffer(ctx->inputs[0], seg->nb_partitions * seg->block_size);
+    seg->buffer = ff_get_audio_buffer(ctx->inputs[0], seg->part_size);
+    if (!seg->buffer || !seg->sum || !seg->block)
+        return AVERROR(ENOMEM);
+
+    return 0;
+}
+
 static int convert_coeffs(AVFilterContext *ctx)
 {
     AudioFIRContext *s = ctx->priv;
@@ -287,36 +323,9 @@ static int convert_coeffs(AVFilterContext *ctx)
     for (n = av_log2(s->minp); (1 << n) < s->nb_taps; n++);
     N = FFMIN(n, av_log2(s->maxp));
 
-    s->seg.coeff = av_calloc(ctx->inputs[1]->channels, sizeof(*s->seg.coeff));
-    s->seg.rdft  = av_calloc(ctx->inputs[0]->channels, sizeof(*s->seg.rdft));
-    s->seg.irdft = av_calloc(ctx->inputs[0]->channels, sizeof(*s->seg.irdft));
-    if (!s->seg.coeff || !s->seg.rdft || !s->seg.irdft)
-        return AVERROR(ENOMEM);
-
-    s->seg.fft_length = (1 << (N + 1)) + 1;
-    s->seg.part_size = 1 << (N - 1);
-    s->seg.block_size = FFALIGN(s->seg.fft_length, 32);
-    s->seg.coeff_size = FFALIGN(s->seg.part_size + 1, 32);
-    s->seg.nb_partitions = (s->nb_taps + s->seg.part_size - 1) / s->seg.part_size;
-
-    for (ch = 0; ch < ctx->inputs[1]->channels; ch++) {
-        s->seg.coeff[ch] = av_calloc(s->seg.nb_partitions * s->seg.coeff_size, sizeof(**s->seg.coeff));
-        if (!s->seg.coeff[ch])
-            return AVERROR(ENOMEM);
-    }
-
-    for (ch = 0; ch < ctx->inputs[0]->channels; ch++) {
-        s->seg.rdft[ch]  = av_rdft_init(N, DFT_R2C);
-        s->seg.irdft[ch] = av_rdft_init(N, IDFT_C2R);
-        if (!s->seg.rdft[ch] || !s->seg.irdft[ch])
-            return AVERROR(ENOMEM);
-    }
-
-    s->seg.sum    = ff_get_audio_buffer(ctx->inputs[0], s->seg.fft_length);
-    s->seg.block  = ff_get_audio_buffer(ctx->inputs[0], s->seg.nb_partitions * s->seg.block_size);
-    s->seg.buffer = ff_get_audio_buffer(ctx->inputs[0], s->seg.part_size);
-    if (!s->seg.buffer || !s->seg.sum || !s->seg.block)
-        return AVERROR(ENOMEM);
+    ret = init_segment(ctx, &s->seg, (s->nb_taps + (1 << N) - 1) / (1 << N), 1 << N);
+    if (ret < 0)
+        return ret;
 
     ret = ff_inlink_consume_samples(ctx->inputs[1], s->nb_taps, s->nb_taps, &s->in[1]);
     if (ret < 0)



More information about the ffmpeg-cvslog mailing list