[FFmpeg-cvslog] avfilter/af_sidechaincompress: do not require writable input frames for acompressor filter

Paul B Mahol git at videolan.org
Mon Nov 30 12:31:33 CET 2015


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Nov 30 12:25:32 2015 +0100| [6b978dadc654906130de46a8b83b6f67f90d3e17] | committer: Paul B Mahol

avfilter/af_sidechaincompress: do not require writable input frames for acompressor filter

Signed-off-by: Paul B Mahol <onemda at gmail.com>

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

 libavfilter/af_sidechaincompress.c |   35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_sidechaincompress.c b/libavfilter/af_sidechaincompress.c
index 3862bf8..717ddcf 100644
--- a/libavfilter/af_sidechaincompress.c
+++ b/libavfilter/af_sidechaincompress.c
@@ -145,7 +145,7 @@ static int compressor_config_output(AVFilterLink *outlink)
 }
 
 static void compressor(SidechainCompressContext *s,
-                       double *sample, const double *scsrc, int nb_samples,
+                       const double *src, double *dst, const double *scsrc, int nb_samples,
                        double level_in, double level_sc,
                        AVFilterLink *inlink, AVFilterLink *sclink)
 {
@@ -179,9 +179,10 @@ static void compressor(SidechainCompressContext *s,
                                s->compressed_knee_stop, s->detection);
 
         for (c = 0; c < inlink->channels; c++)
-            sample[c] *= level_in * (gain * makeup * mix + (1. - mix));
+            dst[c] = src[c] * level_in * (gain * makeup * mix + (1. - mix));
 
-        sample += inlink->channels;
+        src += inlink->channels;
+        dst += inlink->channels;
         scsrc += sclink->channels;
     }
 }
@@ -212,7 +213,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame)
     sample = (double *)s->input_frame[0]->data[0];
     scsrc = (const double *)s->input_frame[1]->data[0];
 
-    compressor(s, sample, scsrc, nb_samples,
+    compressor(s, sample, sample, scsrc, nb_samples,
                s->level_in, s->level_sc,
                ctx->inputs[0], ctx->inputs[1]);
     ret = ff_filter_frame(outlink, s->input_frame[0]);
@@ -340,19 +341,34 @@ AVFilter ff_af_sidechaincompress = {
 #endif  /* CONFIG_SIDECHAINCOMPRESS_FILTER */
 
 #if CONFIG_ACOMPRESSOR_FILTER
-static int acompressor_filter_frame(AVFilterLink *inlink, AVFrame *frame)
+static int acompressor_filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
+    const double *src = (const double *)in->data[0];
     AVFilterContext *ctx = inlink->dst;
     SidechainCompressContext *s = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
-    double *sample;
+    AVFrame *out;
+    double *dst;
+
+    if (av_frame_is_writable(in)) {
+        out = in;
+    } else {
+        out = ff_get_audio_buffer(inlink, in->nb_samples);
+        if (!out) {
+            av_frame_free(&in);
+            return AVERROR(ENOMEM);
+        }
+        av_frame_copy_props(out, in);
+    }
+    dst = (double *)out->data[0];
 
-    sample = (double *)frame->data[0];
-    compressor(s, sample, sample, frame->nb_samples,
+    compressor(s, src, dst, src, in->nb_samples,
                s->level_in, s->level_in,
                inlink, inlink);
 
-    return ff_filter_frame(outlink, frame);
+    if (out != in)
+        av_frame_free(&in);
+    return ff_filter_frame(outlink, out);
 }
 
 static int acompressor_query_formats(AVFilterContext *ctx)
@@ -393,7 +409,6 @@ static const AVFilterPad acompressor_inputs[] = {
         .name           = "default",
         .type           = AVMEDIA_TYPE_AUDIO,
         .filter_frame   = acompressor_filter_frame,
-        .needs_writable = 1,
     },
     { NULL }
 };



More information about the ffmpeg-cvslog mailing list