History

avfilter/af_acrossover: add slice threading support

Paul B Mahol committed 6 years ago

Commit cd671ea1 parent 2ca14d81 file · +43 −21Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_acrossover.c+43−21
@@ -60,6 +60,9 @@ typedef struct AudioCrossoverContext { · 59 unmodified lines
6060 float *splits;
6161
6262 CrossoverChannel *xover;
63+
64+ AVFrame *input_frame;
65+ AVFrame *frames[MAX_BANDS];
6366 } AudioCrossoverContext;
6467
6568 #define OFFSET(x) offsetof(AudioCrossoverContext, x)
@@ -230,32 +233,20 @@ static double biquad_process(BiquadContext *b, double in) · 164 unmodified lines
230233 return out;
231234 }
232235
233−static int filter_frame(AVFilterLink *inlink, AVFrame *in)
236+static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
234237 {
235− AVFilterContext *ctx = inlink->dst;
236238 AudioCrossoverContext *s = ctx->priv;
237− AVFrame *frames[MAX_BANDS] = { NULL };
238− int i, f, ch, band, ret = 0;
239−
240− for (i = 0; i < ctx->nb_outputs; i++) {
241− frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
242−
243− if (!frames[i]) {
244− ret = AVERROR(ENOMEM);
245− break;
246− }
239+ AVFrame *in = s->input_frame;
240+ AVFrame **frames = s->frames;
241+ const int start = (in->channels * jobnr) / nb_jobs;
242+ const int end = (in->channels * (jobnr+1)) / nb_jobs;
243+ int f, band;
247244
248− frames[i]->pts = in->pts;
249− }
250−
251− if (ret < 0)
252− goto fail;
253−
254− for (ch = 0; ch < inlink->channels; ch++) {
245+ for (int ch = start; ch < end; ch++) {
255246 const double *src = (const double *)in->extended_data[ch];
256247 CrossoverChannel *xover = &s->xover[ch];
257248
258− for (i = 0; i < in->nb_samples; i++) {
249+ for (int i = 0; i < in->nb_samples; i++) {
259250 double sample = src[i], lo, hi;
260251
261252 for (band = 0; band < ctx->nb_outputs; band++) {
@@ -276,14 +267,44 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 14 unmodified lines
276267 }
277268 }
278269
270+ return 0;
271+}
272+
273+static int filter_frame(AVFilterLink *inlink, AVFrame *in)
274+{
275+ AVFilterContext *ctx = inlink->dst;
276+ AudioCrossoverContext *s = ctx->priv;
277+ AVFrame **frames = s->frames;
278+ int i, ret = 0;
279+
280+ for (i = 0; i < ctx->nb_outputs; i++) {
281+ frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
282+
283+ if (!frames[i]) {
284+ ret = AVERROR(ENOMEM);
285+ break;
286+ }
287+
288+ frames[i]->pts = in->pts;
289+ }
290+
291+ if (ret < 0)
292+ goto fail;
293+
294+ s->input_frame = in;
295+ ctx->internal->execute(ctx, filter_channels, NULL, NULL, FFMIN(inlink->channels,
296+ ff_filter_get_nb_threads(ctx)));
297+
279298 for (i = 0; i < ctx->nb_outputs; i++) {
280299 ret = ff_filter_frame(ctx->outputs[i], frames[i]);
300+ frames[i] = NULL;
281301 if (ret < 0)
282302 break;
283303 }
284304
285305 fail:
286306 av_frame_free(&in);
307+ s->input_frame = NULL;
287308
288309 return ret;
289310 }
@@ -320,5 +341,6 @@ AVFilter ff_af_acrossover = { · 30 unmodified lines
320341 .query_formats = query_formats,
321342 .inputs = inputs,
322343 .outputs = NULL,
323− .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,
344+ .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS |
345+ AVFILTER_FLAG_SLICE_THREADS,
324346 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t