[FFmpeg-cvslog] avfilter/af_adenorm: add timeline and slice threading support

Paul B Mahol git at videolan.org
Tue Nov 24 12:33:22 EET 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Nov 24 11:27:14 2020 +0100| [68429b9465b53bbb64bf8f35ea601f7ec2ead407] | committer: Paul B Mahol

avfilter/af_adenorm: add timeline and slice threading support

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

 libavfilter/af_adenorm.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/libavfilter/af_adenorm.c b/libavfilter/af_adenorm.c
index e689fe556e..992a1fe56a 100644
--- a/libavfilter/af_adenorm.c
+++ b/libavfilter/af_adenorm.c
@@ -219,11 +219,34 @@ static int config_output(AVFilterLink *outlink)
     return 0;
 }
 
+typedef struct ThreadData {
+    AVFrame *in, *out;
+} ThreadData;
+
+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
+{
+    ADenormContext *s = ctx->priv;
+    ThreadData *td = arg;
+    AVFrame *out = td->out;
+    AVFrame *in = td->in;
+    const int start = (in->channels * jobnr) / nb_jobs;
+    const int end = (in->channels * (jobnr+1)) / nb_jobs;
+
+    for (int ch = start; ch < end; ch++) {
+        s->filter(ctx, out->extended_data[ch],
+                  in->extended_data[ch],
+                  in->nb_samples);
+    }
+
+    return 0;
+}
+
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 {
     AVFilterContext *ctx = inlink->dst;
     ADenormContext *s = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
+    ThreadData td;
     AVFrame *out;
 
     if (av_frame_is_writable(in)) {
@@ -238,11 +261,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
     s->level = exp(s->level_db / 20. * M_LN10);
-    for (int ch = 0; ch < inlink->channels; ch++) {
-        s->filter(ctx, out->extended_data[ch],
-                  in->extended_data[ch],
-                  in->nb_samples);
-    }
+    td.in = in; td.out = out;
+    ctx->internal->execute(ctx, filter_channels, &td, NULL, FFMIN(inlink->channels,
+                                                            ff_filter_get_nb_threads(ctx)));
+
     s->in_samples += in->nb_samples;
 
     if (out != in)
@@ -305,4 +327,6 @@ AVFilter ff_af_adenorm = {
     .outputs         = adenorm_outputs,
     .priv_class      = &adenorm_class,
     .process_command = process_command,
+    .flags           = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
+                       AVFILTER_FLAG_SLICE_THREADS,
 };



More information about the ffmpeg-cvslog mailing list