Unified · Split
| @@ -60,6 +60,9 @@ typedef struct AudioCrossoverContext { · 59 unmodified lines | ||
| 60 | 60 | float *splits; |
| 61 | 61 | |
| 62 | 62 | CrossoverChannel *xover; |
| 63 | + | |
| 64 | + AVFrame *input_frame; | |
| 65 | + AVFrame *frames[MAX_BANDS]; | |
| 63 | 66 | } AudioCrossoverContext; |
| 64 | 67 | |
| 65 | 68 | #define OFFSET(x) offsetof(AudioCrossoverContext, x) |
| @@ -230,32 +233,20 @@ static double biquad_process(BiquadContext *b, double in) · 164 unmodified lines | ||
| 230 | 233 | return out; |
| 231 | 234 | } |
| 232 | 235 | |
| 233 | −static int filter_frame(AVFilterLink *inlink, AVFrame *in) | |
| 236 | +static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | |
| 234 | 237 | { |
| 235 | − AVFilterContext *ctx = inlink->dst; | |
| 236 | 238 | 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; | |
| 247 | 244 | |
| 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++) { | |
| 255 | 246 | const double *src = (const double *)in->extended_data[ch]; |
| 256 | 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 | 250 | double sample = src[i], lo, hi; |
| 260 | 251 | |
| 261 | 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 | + | |
| 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 | + | |
| 279 | 298 | for (i = 0; i < ctx->nb_outputs; i++) { |
| 280 | 299 | ret = ff_filter_frame(ctx->outputs[i], frames[i]); |
| 300 | + frames[i] = NULL; | |
| 281 | 301 | if (ret < 0) |
| 282 | 302 | break; |
| 283 | 303 | } |
| 284 | 304 | |
| 285 | 305 | fail: |
| 286 | 306 | av_frame_free(&in); |
| 307 | + s->input_frame = NULL; | |
| 287 | 308 | |
| 288 | 309 | return ret; |
| 289 | 310 | } |
| @@ -320,5 +341,6 @@ AVFilter ff_af_acrossover = { · 30 unmodified lines | ||
| 320 | 341 | .query_formats = query_formats, |
| 321 | 342 | .inputs = inputs, |
| 322 | 343 | .outputs = NULL, |
| 323 | − .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS, | |
| 344 | + .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS | | |
| 345 | + AVFILTER_FLAG_SLICE_THREADS, | |
| 324 | 346 | }; |