[FFmpeg-cvslog] avfilter/af_asdr: add support for threads

Paul B Mahol git at videolan.org
Sun Apr 30 13:41:08 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Apr 30 12:32:37 2023 +0200| [7b2851b290f12cc8a1c8110b64bc5d364109873b] | committer: Paul B Mahol

avfilter/af_asdr: add support for threads

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

 libavfilter/af_asdr.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/libavfilter/af_asdr.c b/libavfilter/af_asdr.c
index 5c7e2bbfe4..96aa80f843 100644
--- a/libavfilter/af_asdr.c
+++ b/libavfilter/af_asdr.c
@@ -37,24 +37,32 @@ typedef struct AudioSDRContext {
     AVFrame *cache[2];
 } AudioSDRContext;
 
-static void sdr(AVFilterContext *ctx, const AVFrame *u, const AVFrame *v)
+static int sdr(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 {
     AudioSDRContext *s = ctx->priv;
-
-    for (int ch = 0; ch < u->ch_layout.nb_channels; ch++) {
+    AVFrame *u = s->cache[0];
+    AVFrame *v = s->cache[1];
+    const int channels = u->ch_layout.nb_channels;
+    const int start = (channels * jobnr) / nb_jobs;
+    const int end = (channels * (jobnr+1)) / nb_jobs;
+    const int nb_samples = u->nb_samples;
+
+    for (int ch = start; ch < end; ch++) {
         const double *const us = (double *)u->extended_data[ch];
         const double *const vs = (double *)v->extended_data[ch];
-        double sum_uv = s->sum_uv[ch];
-        double sum_u = s->sum_u[ch];
+        double sum_uv = 0.;
+        double sum_u = 0.;
 
-        for (int n = 0; n < u->nb_samples; n++) {
+        for (int n = 0; n < nb_samples; n++) {
             sum_u  += us[n] * us[n];
             sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
         }
 
-        s->sum_uv[ch] = sum_uv;
-        s->sum_u[ch]  = sum_u;
+        s->sum_uv[ch] += sum_uv;
+        s->sum_u[ch]  += sum_u;
     }
+
+    return 0;
 }
 
 static int activate(AVFilterContext *ctx)
@@ -80,7 +88,8 @@ static int activate(AVFilterContext *ctx)
         }
 
         if (!ctx->is_disabled)
-            sdr(ctx, s->cache[0], s->cache[1]);
+            ff_filter_execute(ctx, sdr, NULL, NULL,
+                              FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
 
         av_frame_free(&s->cache[1]);
         out = s->cache[0];
@@ -170,6 +179,7 @@ const AVFilter ff_af_asdr = {
     .activate       = activate,
     .uninit         = uninit,
     .flags          = AVFILTER_FLAG_METADATA_ONLY |
+                      AVFILTER_FLAG_SLICE_THREADS |
                       AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
     FILTER_INPUTS(inputs),
     FILTER_OUTPUTS(outputs),



More information about the ffmpeg-cvslog mailing list