FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/af_acrossover.c
Date: 2026-09-24 20:08:24
Exec Total Coverage
Lines: 0 248 0.0%
Functions: 0 16 0.0%
Branches: 0 159 0.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /**
20 * @file
21 * Crossover filter
22 *
23 * Split an audio stream into several bands.
24 */
25
26 #include "libavutil/attributes.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/float_dsp.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33
34 #include "audio.h"
35 #include "avfilter.h"
36 #include "filters.h"
37 #include "formats.h"
38
39 #define MAX_SPLITS 16
40 #define MAX_BANDS MAX_SPLITS + 1
41
42 #define B0 0
43 #define B1 1
44 #define B2 2
45 #define A1 3
46 #define A2 4
47
48 typedef struct BiquadCoeffs {
49 double cd[5];
50 float cf[5];
51 } BiquadCoeffs;
52
53 typedef struct AudioCrossoverContext {
54 const AVClass *class;
55
56 char *splits_str;
57 char *gains_str;
58 int order_opt;
59 float level_in;
60 int precision;
61
62 int order;
63 int filter_count;
64 int first_order;
65 int ap_filter_count;
66 int nb_splits;
67 float splits[MAX_SPLITS];
68
69 float gains[MAX_BANDS];
70
71 BiquadCoeffs lp[MAX_BANDS][20];
72 BiquadCoeffs hp[MAX_BANDS][20];
73 BiquadCoeffs ap[MAX_BANDS][20];
74
75 AVFrame *xover;
76
77 AVFrame *frames[MAX_BANDS];
78
79 int (*filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
80
81 AVFloatDSPContext *fdsp;
82 } AudioCrossoverContext;
83
84 #define OFFSET(x) offsetof(AudioCrossoverContext, x)
85 #define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
86
87 static const AVOption acrossover_options[] = {
88 { "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },
89 { "order", "set filter order", OFFSET(order_opt), AV_OPT_TYPE_INT, {.i64=1}, 0, 9, AF, .unit = "m" },
90 { "2nd", "2nd order (12 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, .unit = "m" },
91 { "4th", "4th order (24 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, .unit = "m" },
92 { "6th", "6th order (36 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, .unit = "m" },
93 { "8th", "8th order (48 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, .unit = "m" },
94 { "10th", "10th order (60 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, .unit = "m" },
95 { "12th", "12th order (72 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, AF, .unit = "m" },
96 { "14th", "14th order (84 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, AF, .unit = "m" },
97 { "16th", "16th order (96 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, AF, .unit = "m" },
98 { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, .unit = "m" },
99 { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, .unit = "m" },
100 { "level", "set input gain", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, AF },
101 { "gain", "set output bands gain", OFFSET(gains_str), AV_OPT_TYPE_STRING, {.str="1.f"}, 0, 0, AF },
102 { "precision", "set processing precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, AF, .unit = "precision" },
103 { "auto", "set auto processing precision", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, .unit = "precision" },
104 { "float", "set single-floating point processing precision", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, .unit = "precision" },
105 { "double","set double-floating point processing precision", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, .unit = "precision" },
106 { NULL }
107 };
108
109 AVFILTER_DEFINE_CLASS(acrossover);
110
111 ✗ static int query_formats(const AVFilterContext *ctx,
112 AVFilterFormatsConfig **cfg_in,
113 AVFilterFormatsConfig **cfg_out)
114 {
115 ✗ const AudioCrossoverContext *s = ctx->priv;
116 static const enum AVSampleFormat auto_sample_fmts[] = {
117 AV_SAMPLE_FMT_FLTP,
118 AV_SAMPLE_FMT_DBLP,
119 AV_SAMPLE_FMT_NONE
120 };
121 ✗ enum AVSampleFormat sample_fmts[] = {
122 AV_SAMPLE_FMT_FLTP,
123 AV_SAMPLE_FMT_NONE
124 };
125 ✗ const enum AVSampleFormat *sample_fmts_list = sample_fmts;
126 int ret;
127
128 ✗ switch (s->precision) {
129 ✗ case 0:
130 ✗ sample_fmts_list = auto_sample_fmts;
131 ✗ break;
132 ✗ case 1:
133 ✗ sample_fmts[0] = AV_SAMPLE_FMT_FLTP;
134 ✗ break;
135 ✗ case 2:
136 ✗ sample_fmts[0] = AV_SAMPLE_FMT_DBLP;
137 ✗ break;
138 ✗ default:
139 ✗ break;
140 }
141 ✗ ret = ff_set_sample_formats_from_list2(ctx, cfg_in, cfg_out, sample_fmts_list);
142 ✗ if (ret < 0)
143 ✗ return ret;
144
145 ✗ return 0;
146 }
147
148 ✗ static int parse_gains(AVFilterContext *ctx)
149 {
150 ✗ AudioCrossoverContext *s = ctx->priv;
151 ✗ char *p, *arg, *saveptr = NULL;
152 ✗ int i, ret = 0;
153
154 ✗ saveptr = NULL;
155 ✗ p = s->gains_str;
156 ✗ for (i = 0; i < MAX_BANDS; i++) {
157 float gain;
158 ✗ char c[3] = { 0 };
159
160 ✗ if (!(arg = av_strtok(p, " |", &saveptr)))
161 ✗ break;
162
163 ✗ p = NULL;
164
165 ✗ if (av_sscanf(arg, "%f%2s", &gain, c) < 1) {
166 ✗ av_log(ctx, AV_LOG_ERROR, "Invalid syntax for gain[%d].\n", i);
167 ✗ ret = AVERROR(EINVAL);
168 ✗ break;
169 }
170
171 ✗ if (c[0] == 'd' && c[1] == 'B')
172 ✗ s->gains[i] = expf(gain * M_LN10 / 20.f);
173 else
174 ✗ s->gains[i] = gain;
175 ✗ if (!isfinite(s->gains[i])) {
176 ✗ av_log(ctx, AV_LOG_ERROR, "Gain %f must be finite.\n", gain);
177 ✗ return AVERROR(EINVAL);
178 }
179 }
180
181 ✗ for (; i < MAX_BANDS; i++)
182 ✗ s->gains[i] = 1.f;
183
184 ✗ return ret;
185 }
186
187 ✗ static av_cold int init(AVFilterContext *ctx)
188 {
189 ✗ AudioCrossoverContext *s = ctx->priv;
190 ✗ char *p, *arg, *saveptr = NULL;
191 ✗ int i, ret = 0;
192
193 ✗ s->fdsp = avpriv_float_dsp_alloc(0);
194 ✗ if (!s->fdsp)
195 ✗ return AVERROR(ENOMEM);
196
197 ✗ p = s->splits_str;
198 ✗ for (i = 0; i < MAX_SPLITS; i++) {
199 float freq;
200
201 ✗ if (!(arg = av_strtok(p, " |", &saveptr)))
202 ✗ break;
203
204 ✗ p = NULL;
205
206 ✗ if (av_sscanf(arg, "%f", &freq) != 1) {
207 ✗ av_log(ctx, AV_LOG_ERROR, "Invalid syntax for frequency[%d].\n", i);
208 ✗ return AVERROR(EINVAL);
209 }
210 ✗ if (!isfinite(freq) || freq <= 0) {
211 ✗ av_log(ctx, AV_LOG_ERROR, "Frequency %f must be a positive finite number.\n", freq);
212 ✗ return AVERROR(EINVAL);
213 }
214
215 ✗ if (i > 0 && freq <= s->splits[i-1]) {
216 ✗ av_log(ctx, AV_LOG_ERROR, "Frequency %f must be in increasing order.\n", freq);
217 ✗ return AVERROR(EINVAL);
218 }
219
220 ✗ s->splits[i] = freq;
221 }
222
223 ✗ s->nb_splits = i;
224
225 ✗ ret = parse_gains(ctx);
226 ✗ if (ret < 0)
227 ✗ return ret;
228
229 ✗ for (i = 0; i <= s->nb_splits; i++) {
230 ✗ AVFilterPad pad = { 0 };
231 char *name;
232
233 ✗ pad.type = AVMEDIA_TYPE_AUDIO;
234 ✗ name = av_asprintf("out%d", ctx->nb_outputs);
235 ✗ if (!name)
236 ✗ return AVERROR(ENOMEM);
237 ✗ pad.name = name;
238
239 ✗ if ((ret = ff_append_outpad_free_name(ctx, &pad)) < 0)
240 ✗ return ret;
241 }
242
243 ✗ return ret;
244 }
245
246 ✗ static void set_lp(BiquadCoeffs *b, double fc, double q, double sr)
247 {
248 ✗ double omega = 2. * M_PI * fc / sr;
249 ✗ double cosine = cos(omega);
250 ✗ double alpha = sin(omega) / (2. * q);
251
252 ✗ double b0 = (1. - cosine) / 2.;
253 ✗ double b1 = 1. - cosine;
254 ✗ double b2 = (1. - cosine) / 2.;
255 ✗ double a0 = 1. + alpha;
256 ✗ double a1 = -2. * cosine;
257 ✗ double a2 = 1. - alpha;
258
259 ✗ b->cd[B0] = b0 / a0;
260 ✗ b->cd[B1] = b1 / a0;
261 ✗ b->cd[B2] = b2 / a0;
262 ✗ b->cd[A1] = -a1 / a0;
263 ✗ b->cd[A2] = -a2 / a0;
264
265 ✗ b->cf[B0] = b->cd[B0];
266 ✗ b->cf[B1] = b->cd[B1];
267 ✗ b->cf[B2] = b->cd[B2];
268 ✗ b->cf[A1] = b->cd[A1];
269 ✗ b->cf[A2] = b->cd[A2];
270 ✗ }
271
272 ✗ static void set_hp(BiquadCoeffs *b, double fc, double q, double sr)
273 {
274 ✗ double omega = 2. * M_PI * fc / sr;
275 ✗ double cosine = cos(omega);
276 ✗ double alpha = sin(omega) / (2. * q);
277
278 ✗ double b0 = (1. + cosine) / 2.;
279 ✗ double b1 = -1. - cosine;
280 ✗ double b2 = (1. + cosine) / 2.;
281 ✗ double a0 = 1. + alpha;
282 ✗ double a1 = -2. * cosine;
283 ✗ double a2 = 1. - alpha;
284
285 ✗ b->cd[B0] = b0 / a0;
286 ✗ b->cd[B1] = b1 / a0;
287 ✗ b->cd[B2] = b2 / a0;
288 ✗ b->cd[A1] = -a1 / a0;
289 ✗ b->cd[A2] = -a2 / a0;
290
291 ✗ b->cf[B0] = b->cd[B0];
292 ✗ b->cf[B1] = b->cd[B1];
293 ✗ b->cf[B2] = b->cd[B2];
294 ✗ b->cf[A1] = b->cd[A1];
295 ✗ b->cf[A2] = b->cd[A2];
296 ✗ }
297
298 ✗ static void set_ap(BiquadCoeffs *b, double fc, double q, double sr)
299 {
300 ✗ double omega = 2. * M_PI * fc / sr;
301 ✗ double cosine = cos(omega);
302 ✗ double alpha = sin(omega) / (2. * q);
303
304 ✗ double a0 = 1. + alpha;
305 ✗ double a1 = -2. * cosine;
306 ✗ double a2 = 1. - alpha;
307 ✗ double b0 = a2;
308 ✗ double b1 = a1;
309 ✗ double b2 = a0;
310
311 ✗ b->cd[B0] = b0 / a0;
312 ✗ b->cd[B1] = b1 / a0;
313 ✗ b->cd[B2] = b2 / a0;
314 ✗ b->cd[A1] = -a1 / a0;
315 ✗ b->cd[A2] = -a2 / a0;
316
317 ✗ b->cf[B0] = b->cd[B0];
318 ✗ b->cf[B1] = b->cd[B1];
319 ✗ b->cf[B2] = b->cd[B2];
320 ✗ b->cf[A1] = b->cd[A1];
321 ✗ b->cf[A2] = b->cd[A2];
322 ✗ }
323
324 ✗ static void set_ap1(BiquadCoeffs *b, double fc, double sr)
325 {
326 ✗ double omega = 2. * M_PI * fc / sr;
327
328 ✗ b->cd[A1] = exp(-omega);
329 ✗ b->cd[A2] = 0.;
330 ✗ b->cd[B0] = -b->cd[A1];
331 ✗ b->cd[B1] = 1.;
332 ✗ b->cd[B2] = 0.;
333
334 ✗ b->cf[B0] = b->cd[B0];
335 ✗ b->cf[B1] = b->cd[B1];
336 ✗ b->cf[B2] = b->cd[B2];
337 ✗ b->cf[A1] = b->cd[A1];
338 ✗ b->cf[A2] = b->cd[A2];
339 ✗ }
340
341 ✗ static void calc_q_factors(int order, double *q)
342 {
343 ✗ double n = order / 2.;
344
345 ✗ for (int i = 0; i < n / 2; i++)
346 ✗ q[i] = 1. / (-2. * cos(M_PI * (2. * (i + 1) + n - 1.) / (2. * n)));
347 ✗ }
348
349 #define BIQUAD_PROCESS(name, type) \
350 static void biquad_process_## name(const type *const c, \
351 type *b, \
352 type *dst, const type *src, \
353 int nb_samples) \
354 { \
355 const type b0 = c[B0]; \
356 const type b1 = c[B1]; \
357 const type b2 = c[B2]; \
358 const type a1 = c[A1]; \
359 const type a2 = c[A2]; \
360 type z1 = b[0]; \
361 type z2 = b[1]; \
362 \
363 for (int n = 0; n + 1 < nb_samples; n++) { \
364 type in = src[n]; \
365 type out; \
366 \
367 out = in * b0 + z1; \
368 z1 = b1 * in + z2 + a1 * out; \
369 z2 = b2 * in + a2 * out; \
370 dst[n] = out; \
371 \
372 n++; \
373 in = src[n]; \
374 out = in * b0 + z1; \
375 z1 = b1 * in + z2 + a1 * out; \
376 z2 = b2 * in + a2 * out; \
377 dst[n] = out; \
378 } \
379 \
380 if (nb_samples & 1) { \
381 const int n = nb_samples - 1; \
382 const type in = src[n]; \
383 type out; \
384 \
385 out = in * b0 + z1; \
386 z1 = b1 * in + z2 + a1 * out; \
387 z2 = b2 * in + a2 * out; \
388 dst[n] = out; \
389 } \
390 \
391 b[0] = z1; \
392 b[1] = z2; \
393 }
394
395 ✗ BIQUAD_PROCESS(fltp, float)
396 ✗ BIQUAD_PROCESS(dblp, double)
397
398 #define XOVER_PROCESS(name, type, one, ff) \
399 static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
400 { \
401 AudioCrossoverContext *s = ctx->priv; \
402 AVFrame *in = arg; \
403 AVFrame **frames = s->frames; \
404 const int start = ff_slice_pos(in->ch_layout.nb_channels, jobnr, nb_jobs); \
405 const int end = ff_slice_pos(in->ch_layout.nb_channels, jobnr + 1, nb_jobs); \
406 const int nb_samples = in->nb_samples; \
407 const int nb_outs = ctx->nb_outputs; \
408 const int first_order = s->first_order; \
409 \
410 for (int ch = start; ch < end; ch++) { \
411 const type *src = (const type *)in->extended_data[ch]; \
412 type *xover = (type *)s->xover->extended_data[ch]; \
413 \
414 s->fdsp->vector_## ff ##mul_scalar((type *)frames[0]->extended_data[ch], src, \
415 s->level_in, FFALIGN(nb_samples, sizeof(type))); \
416 \
417 for (int band = 0; band < nb_outs; band++) { \
418 for (int f = 0; band + 1 < nb_outs && f < s->filter_count; f++) { \
419 const type *prv = (const type *)frames[band]->extended_data[ch]; \
420 type *dst = (type *)frames[band + 1]->extended_data[ch]; \
421 const type *hsrc = f == 0 ? prv : dst; \
422 type *hp = xover + nb_outs * 20 + band * 20 + f * 2; \
423 const type *const hpc = (type *)&s->hp[band][f].c ## ff; \
424 \
425 biquad_process_## name(hpc, hp, dst, hsrc, nb_samples); \
426 } \
427 \
428 for (int f = 0; band + 1 < nb_outs && f < s->filter_count; f++) { \
429 type *dst = (type *)frames[band]->extended_data[ch]; \
430 const type *lsrc = dst; \
431 type *lp = xover + band * 20 + f * 2; \
432 const type *const lpc = (type *)&s->lp[band][f].c ## ff; \
433 \
434 biquad_process_## name(lpc, lp, dst, lsrc, nb_samples); \
435 } \
436 \
437 for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \
438 if (first_order) { \
439 const type *asrc = (const type *)frames[band]->extended_data[ch]; \
440 type *dst = (type *)frames[band]->extended_data[ch]; \
441 type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \
442 const type *const apc = (type *)&s->ap[aband][0].c ## ff; \
443 \
444 biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
445 } \
446 \
447 for (int f = first_order; f < s->ap_filter_count; f++) { \
448 const type *asrc = (const type *)frames[band]->extended_data[ch]; \
449 type *dst = (type *)frames[band]->extended_data[ch]; \
450 type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\
451 const type *const apc = (type *)&s->ap[aband][f].c ## ff; \
452 \
453 biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
454 } \
455 } \
456 } \
457 \
458 for (int band = 0; band < nb_outs; band++) { \
459 const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \
460 type *dst = (type *)frames[band]->extended_data[ch]; \
461 \
462 s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \
463 FFALIGN(nb_samples, sizeof(type))); \
464 } \
465 } \
466 \
467 return 0; \
468 }
469
470 ✗ XOVER_PROCESS(fltp, float, 1.f, f)
471 ✗ XOVER_PROCESS(dblp, double, 1.0, d)
472
473 ✗ static int config_input(AVFilterLink *inlink)
474 {
475 ✗ AVFilterContext *ctx = inlink->dst;
476 ✗ AudioCrossoverContext *s = ctx->priv;
477 ✗ int sample_rate = inlink->sample_rate;
478 double q[16];
479
480 ✗ s->order = (s->order_opt + 1) * 2;
481 ✗ s->filter_count = s->order / 2;
482 ✗ s->first_order = s->filter_count & 1;
483 ✗ s->ap_filter_count = s->filter_count / 2 + s->first_order;
484 ✗ calc_q_factors(s->order, q);
485
486 ✗ for (int band = 0; band <= s->nb_splits; band++) {
487 ✗ if (s->first_order) {
488 ✗ set_lp(&s->lp[band][0], s->splits[band], 0.5, sample_rate);
489 ✗ set_hp(&s->hp[band][0], s->splits[band], 0.5, sample_rate);
490 }
491
492 ✗ for (int n = s->first_order; n < s->filter_count; n++) {
493 ✗ const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1;
494
495 ✗ set_lp(&s->lp[band][n], s->splits[band], q[idx], sample_rate);
496 ✗ set_hp(&s->hp[band][n], s->splits[band], q[idx], sample_rate);
497 }
498
499 ✗ if (s->first_order)
500 ✗ set_ap1(&s->ap[band][0], s->splits[band], sample_rate);
501
502 ✗ for (int n = s->first_order; n < s->ap_filter_count; n++) {
503 ✗ const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1);
504
505 ✗ set_ap(&s->ap[band][n], s->splits[band], q[idx], sample_rate);
506 }
507 }
508
509 ✗ switch (inlink->format) {
510 ✗ case AV_SAMPLE_FMT_FLTP: s->filter_channels = filter_channels_fltp; break;
511 ✗ case AV_SAMPLE_FMT_DBLP: s->filter_channels = filter_channels_dblp; break;
512 ✗ default: return AVERROR_BUG;
513 }
514
515 ✗ s->xover = ff_get_audio_buffer(inlink, 2 * (ctx->nb_outputs * 10 + ctx->nb_outputs * 10 +
516 ✗ ctx->nb_outputs * ctx->nb_outputs * 10));
517 ✗ if (!s->xover)
518 ✗ return AVERROR(ENOMEM);
519
520 ✗ return 0;
521 }
522
523 ✗ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
524 {
525 ✗ AVFilterContext *ctx = inlink->dst;
526 ✗ AudioCrossoverContext *s = ctx->priv;
527 ✗ AVFrame **frames = s->frames;
528 ✗ int ret = 0;
529
530 ✗ for (int i = 0; i < ctx->nb_outputs; i++) {
531 ✗ frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
532 ✗ if (!frames[i]) {
533 ✗ ret = AVERROR(ENOMEM);
534 ✗ break;
535 }
536
537 ✗ frames[i]->pts = in->pts;
538 }
539
540 ✗ if (ret < 0)
541 ✗ goto fail;
542
543 ✗ ff_filter_execute(ctx, s->filter_channels, in, NULL,
544 ✗ FFMIN(inlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
545
546 ✗ for (int i = 0; i < ctx->nb_outputs; i++) {
547 ✗ if (ff_outlink_get_status(ctx->outputs[i])) {
548 ✗ av_frame_free(&frames[i]);
549 ✗ continue;
550 }
551
552 ✗ ret = ff_filter_frame(ctx->outputs[i], frames[i]);
553 ✗ frames[i] = NULL;
554 ✗ if (ret < 0)
555 ✗ break;
556 }
557
558 ✗ fail:
559 ✗ for (int i = 0; i < ctx->nb_outputs; i++)
560 ✗ av_frame_free(&frames[i]);
561
562 ✗ return ret;
563 }
564
565 ✗ static int activate(AVFilterContext *ctx)
566 {
567 ✗ AVFilterLink *inlink = ctx->inputs[0];
568 int status, ret;
569 AVFrame *in;
570 int64_t pts;
571
572 ✗ for (int i = 0; i < ctx->nb_outputs; i++) {
573 ✗ FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[i], ctx);
574 }
575
576 ✗ ret = ff_inlink_consume_frame(inlink, &in);
577 ✗ if (ret < 0)
578 ✗ return ret;
579 ✗ if (ret > 0) {
580 ✗ ret = filter_frame(inlink, in);
581 ✗ av_frame_free(&in);
582 ✗ if (ret < 0)
583 ✗ return ret;
584 }
585
586 ✗ if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
587 ✗ for (int i = 0; i < ctx->nb_outputs; i++) {
588 ✗ if (ff_outlink_get_status(ctx->outputs[i]))
589 ✗ continue;
590 ✗ ff_outlink_set_status(ctx->outputs[i], status, pts);
591 }
592 ✗ return 0;
593 }
594
595 ✗ FF_FILTER_FORWARD_WANTED_ANY(ctx, inlink);
596
597 ✗ return FFERROR_NOT_READY;
598 }
599
600 ✗ static av_cold void uninit(AVFilterContext *ctx)
601 {
602 ✗ AudioCrossoverContext *s = ctx->priv;
603
604 ✗ av_freep(&s->fdsp);
605 ✗ av_frame_free(&s->xover);
606 ✗ }
607
608 static const AVFilterPad inputs[] = {
609 {
610 .name = "default",
611 .type = AVMEDIA_TYPE_AUDIO,
612 .config_props = config_input,
613 },
614 };
615
616 const FFFilter ff_af_acrossover = {
617 .p.name = "acrossover",
618 .p.description = NULL_IF_CONFIG_SMALL("Split audio into per-bands streams."),
619 .p.priv_class = &acrossover_class,
620 .p.outputs = NULL,
621 .p.flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS |
622 AVFILTER_FLAG_SLICE_THREADS,
623 .priv_size = sizeof(AudioCrossoverContext),
624 .init = init,
625 .activate = activate,
626 .uninit = uninit,
627 FILTER_INPUTS(inputs),
628 FILTER_QUERY_FUNC2(query_formats),
629 };
630