diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-04-30 12:32:37 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-04-30 12:38:02 +0200 |
commit | 7b2851b290f12cc8a1c8110b64bc5d364109873b (patch) | |
tree | b855a69dea47561d57e2aa6ba1915239384d4193 /libavfilter/af_asdr.c | |
parent | 4f63e049a2358cc9a22c2344810eff389aa78d85 (diff) | |
download | ffmpeg-7b2851b290f12cc8a1c8110b64bc5d364109873b.tar.gz |
avfilter/af_asdr: add support for threads
Diffstat (limited to 'libavfilter/af_asdr.c')
-rw-r--r-- | libavfilter/af_asdr.c | 28 |
1 files 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), |