History

avfilter/af_acrossover: add slice threading support

Paul B Mahol committed 6 years ago

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

Unified · Split

libavfilter/af_acrossover.c+43−21
@@ -60,6 +60,9 @@ typedef struct AudioCrossoverContext { · 59 unmodified lines
60 float *splits;60 float *splits;
61 61
62 CrossoverChannel *xover;62 CrossoverChannel *xover;
63
64 AVFrame *input_frame;
65 AVFrame *frames[MAX_BANDS];
63} AudioCrossoverContext;66} AudioCrossoverContext;
64 67
65#define OFFSET(x) offsetof(AudioCrossoverContext, x)68#define OFFSET(x) offsetof(AudioCrossoverContext, x)
@@ -230,32 +233,20 @@ static double biquad_process(BiquadContext *b, double in) · 164 unmodified lines
230 return out;233 return out;
231}234}
232 235
233static int filter_frame(AVFilterLink *inlink, AVFrame *in)236static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
234{237{
235 AVFilterContext *ctx = inlink->dst;
236 AudioCrossoverContext *s = ctx->priv;238 AudioCrossoverContext *s = ctx->priv;
237 AVFrame *frames[MAX_BANDS] = { NULL };239 AVFrame *in = s->input_frame;
238 int i, f, ch, band, ret = 0;240 AVFrame **frames = s->frames;
239 241 const int start = (in->channels * jobnr) / nb_jobs;
240 for (i = 0; i < ctx->nb_outputs; i++) {242 const int end = (in->channels * (jobnr+1)) / nb_jobs;
241 frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);243 int f, band;
242
243 if (!frames[i]) {
244 ret = AVERROR(ENOMEM);
245 break;
246 }
247 244
248 frames[i]->pts = in->pts;245 for (int ch = start; ch < end; ch++) {
249 }
250
251 if (ret < 0)
252 goto fail;
253
254 for (ch = 0; ch < inlink->channels; ch++) {
255 const double *src = (const double *)in->extended_data[ch];246 const double *src = (const double *)in->extended_data[ch];
256 CrossoverChannel *xover = &s->xover[ch];247 CrossoverChannel *xover = &s->xover[ch];
257 248
258 for (i = 0; i < in->nb_samples; i++) {249 for (int i = 0; i < in->nb_samples; i++) {
259 double sample = src[i], lo, hi;250 double sample = src[i], lo, hi;
260 251
261 for (band = 0; band < ctx->nb_outputs; band++) {252 for (band = 0; band < ctx->nb_outputs; band++) {
@@ -276,14 +267,44 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 14 unmodified lines
276 }267 }
277 }268 }
278 269
270 return 0;
271}
272
273static 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
279 for (i = 0; i < ctx->nb_outputs; i++) {298 for (i = 0; i < ctx->nb_outputs; i++) {
280 ret = ff_filter_frame(ctx->outputs[i], frames[i]);299 ret = ff_filter_frame(ctx->outputs[i], frames[i]);
300 frames[i] = NULL;
281 if (ret < 0)301 if (ret < 0)
282 break;302 break;
283 }303 }
284 304
285fail:305fail:
286 av_frame_free(&in);306 av_frame_free(&in);
307 s->input_frame = NULL;
287 308
288 return ret;309 return ret;
289}310}
@@ -320,5 +341,6 @@ AVFilter ff_af_acrossover = { · 30 unmodified lines
320 .query_formats = query_formats,341 .query_formats = query_formats,
321 .inputs = inputs,342 .inputs = inputs,
322 .outputs = NULL,343 .outputs = NULL,
323 .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS,344 .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS |
345 AVFILTER_FLAG_SLICE_THREADS,
324};346};

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