mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-02-04 06:08:26 +02:00
avfilter/af_asdr: add support for threads
This commit is contained in:
parent
4f63e049a2
commit
7b2851b290
@ -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;
|
||||
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 = 0; ch < u->ch_layout.nb_channels; ch++) {
|
||||
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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user