Commit 7b2851b2 authored by Paul B Mahol's avatar Paul B Mahol

avfilter/af_asdr: add support for threads

parent 4f63e049
...@@ -37,24 +37,32 @@ typedef struct AudioSDRContext { ...@@ -37,24 +37,32 @@ typedef struct AudioSDRContext {
AVFrame *cache[2]; AVFrame *cache[2];
} AudioSDRContext; } 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; AudioSDRContext *s = ctx->priv;
AVFrame *u = s->cache[0];
for (int ch = 0; ch < u->ch_layout.nb_channels; ch++) { 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 us = (double *)u->extended_data[ch];
const double *const vs = (double *)v->extended_data[ch]; const double *const vs = (double *)v->extended_data[ch];
double sum_uv = s->sum_uv[ch]; double sum_uv = 0.;
double sum_u = s->sum_u[ch]; 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_u += us[n] * us[n];
sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]);
} }
s->sum_uv[ch] = sum_uv; s->sum_uv[ch] += sum_uv;
s->sum_u[ch] = sum_u; s->sum_u[ch] += sum_u;
} }
return 0;
} }
static int activate(AVFilterContext *ctx) static int activate(AVFilterContext *ctx)
...@@ -80,7 +88,8 @@ static int activate(AVFilterContext *ctx) ...@@ -80,7 +88,8 @@ static int activate(AVFilterContext *ctx)
} }
if (!ctx->is_disabled) 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]); av_frame_free(&s->cache[1]);
out = s->cache[0]; out = s->cache[0];
...@@ -170,6 +179,7 @@ const AVFilter ff_af_asdr = { ...@@ -170,6 +179,7 @@ const AVFilter ff_af_asdr = {
.activate = activate, .activate = activate,
.uninit = uninit, .uninit = uninit,
.flags = AVFILTER_FLAG_METADATA_ONLY | .flags = AVFILTER_FLAG_METADATA_ONLY |
AVFILTER_FLAG_SLICE_THREADS |
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
FILTER_INPUTS(inputs), FILTER_INPUTS(inputs),
FILTER_OUTPUTS(outputs), FILTER_OUTPUTS(outputs),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment