avfilter/af_adenorm: add timeline and slice threading support

This commit is contained in:
Paul B Mahol 2020-11-24 11:27:14 +01:00
parent ee8ecc2730
commit 68429b9465
1 changed files with 29 additions and 5 deletions

View File

@ -219,11 +219,34 @@ static int config_output(AVFilterLink *outlink)
return 0; 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) static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
ADenormContext *s = ctx->priv; ADenormContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0]; AVFilterLink *outlink = ctx->outputs[0];
ThreadData td;
AVFrame *out; AVFrame *out;
if (av_frame_is_writable(in)) { 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); s->level = exp(s->level_db / 20. * M_LN10);
for (int ch = 0; ch < inlink->channels; ch++) { td.in = in; td.out = out;
s->filter(ctx, out->extended_data[ch], ctx->internal->execute(ctx, filter_channels, &td, NULL, FFMIN(inlink->channels,
in->extended_data[ch], ff_filter_get_nb_threads(ctx)));
in->nb_samples);
}
s->in_samples += in->nb_samples; s->in_samples += in->nb_samples;
if (out != in) if (out != in)
@ -305,4 +327,6 @@ AVFilter ff_af_adenorm = {
.outputs = adenorm_outputs, .outputs = adenorm_outputs,
.priv_class = &adenorm_class, .priv_class = &adenorm_class,
.process_command = process_command, .process_command = process_command,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
AVFILTER_FLAG_SLICE_THREADS,
}; };