]> git.sesse.net Git - ffmpeg/blob - libavfilter/af_firequalizer.c
lavf/utils: Fix DTS for short H264 streams.
[ffmpeg] / libavfilter / af_firequalizer.c
1 /*
2  * Copyright (c) 2016 Muhammad Faiz <mfcc64@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "libavutil/opt.h"
22 #include "libavutil/eval.h"
23 #include "libavutil/avassert.h"
24 #include "libavcodec/avfft.h"
25 #include "avfilter.h"
26 #include "internal.h"
27 #include "audio.h"
28
29 #define RDFT_BITS_MIN 4
30 #define RDFT_BITS_MAX 16
31
32 enum WindowFunc {
33     WFUNC_MIN,
34     WFUNC_RECTANGULAR = WFUNC_MIN,
35     WFUNC_HANN,
36     WFUNC_HAMMING,
37     WFUNC_BLACKMAN,
38     WFUNC_NUTTALL3,
39     WFUNC_MNUTTALL3,
40     WFUNC_NUTTALL,
41     WFUNC_BNUTTALL,
42     WFUNC_BHARRIS,
43     WFUNC_MAX = WFUNC_BHARRIS
44 };
45
46 #define NB_GAIN_ENTRY_MAX 4096
47 typedef struct {
48     double  freq;
49     double  gain;
50 } GainEntry;
51
52 typedef struct {
53     int buf_idx;
54     int overlap_idx;
55 } OverlapIndex;
56
57 typedef struct {
58     const AVClass *class;
59
60     RDFTContext   *analysis_irdft;
61     RDFTContext   *rdft;
62     RDFTContext   *irdft;
63     int           analysis_rdft_len;
64     int           rdft_len;
65
66     float         *analysis_buf;
67     float         *kernel_tmp_buf;
68     float         *kernel_buf;
69     float         *conv_buf;
70     OverlapIndex  *conv_idx;
71     int           fir_len;
72     int           nsamples_max;
73     int64_t       next_pts;
74     int           frame_nsamples_max;
75     int           remaining;
76
77     char          *gain_cmd;
78     char          *gain_entry_cmd;
79     const char    *gain;
80     const char    *gain_entry;
81     double        delay;
82     double        accuracy;
83     int           wfunc;
84     int           fixed;
85     int           multi;
86
87     int           nb_gain_entry;
88     int           gain_entry_err;
89     GainEntry     gain_entry_tbl[NB_GAIN_ENTRY_MAX];
90 } FIREqualizerContext;
91
92 #define OFFSET(x) offsetof(FIREqualizerContext, x)
93 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
94
95 static const AVOption firequalizer_options[] = {
96     { "gain", "set gain curve", OFFSET(gain), AV_OPT_TYPE_STRING, { .str = "gain_interpolate(f)" }, 0, 0, FLAGS },
97     { "gain_entry", "set gain entry", OFFSET(gain_entry), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
98     { "delay", "set delay", OFFSET(delay), AV_OPT_TYPE_DOUBLE, { .dbl = 0.01 }, 0.0, 1e10, FLAGS },
99     { "accuracy", "set accuracy", OFFSET(accuracy), AV_OPT_TYPE_DOUBLE, { .dbl = 5.0 }, 0.0, 1e10, FLAGS },
100     { "wfunc", "set window function", OFFSET(wfunc), AV_OPT_TYPE_INT, { .i64 = WFUNC_HANN }, WFUNC_MIN, WFUNC_MAX, FLAGS, "wfunc" },
101         { "rectangular", "rectangular window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_RECTANGULAR }, 0, 0, FLAGS, "wfunc" },
102         { "hann", "hann window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HANN }, 0, 0, FLAGS, "wfunc" },
103         { "hamming", "hamming window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HAMMING }, 0, 0, FLAGS, "wfunc" },
104         { "blackman", "blackman window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BLACKMAN }, 0, 0, FLAGS, "wfunc" },
105         { "nuttall3", "3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL3 }, 0, 0, FLAGS, "wfunc" },
106         { "mnuttall3", "minimum 3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_MNUTTALL3 }, 0, 0, FLAGS, "wfunc" },
107         { "nuttall", "nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL }, 0, 0, FLAGS, "wfunc" },
108         { "bnuttall", "blackman-nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BNUTTALL }, 0, 0, FLAGS, "wfunc" },
109         { "bharris", "blackman-harris window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BHARRIS }, 0, 0, FLAGS, "wfunc" },
110     { "fixed", "set fixed frame samples", OFFSET(fixed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
111     { "multi", "set multi channels mode", OFFSET(multi), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
112     { NULL }
113 };
114
115 AVFILTER_DEFINE_CLASS(firequalizer);
116
117 static void common_uninit(FIREqualizerContext *s)
118 {
119     av_rdft_end(s->analysis_irdft);
120     av_rdft_end(s->rdft);
121     av_rdft_end(s->irdft);
122     s->analysis_irdft = s->rdft = s->irdft = NULL;
123
124     av_freep(&s->analysis_buf);
125     av_freep(&s->kernel_tmp_buf);
126     av_freep(&s->kernel_buf);
127     av_freep(&s->conv_buf);
128     av_freep(&s->conv_idx);
129 }
130
131 static av_cold void uninit(AVFilterContext *ctx)
132 {
133     FIREqualizerContext *s = ctx->priv;
134
135     common_uninit(s);
136     av_freep(&s->gain_cmd);
137     av_freep(&s->gain_entry_cmd);
138 }
139
140 static int query_formats(AVFilterContext *ctx)
141 {
142     AVFilterChannelLayouts *layouts;
143     AVFilterFormats *formats;
144     static const enum AVSampleFormat sample_fmts[] = {
145         AV_SAMPLE_FMT_FLTP,
146         AV_SAMPLE_FMT_NONE
147     };
148     int ret;
149
150     layouts = ff_all_channel_counts();
151     if (!layouts)
152         return AVERROR(ENOMEM);
153     ret = ff_set_common_channel_layouts(ctx, layouts);
154     if (ret < 0)
155         return ret;
156
157     formats = ff_make_format_list(sample_fmts);
158     if (!formats)
159         return AVERROR(ENOMEM);
160     ret = ff_set_common_formats(ctx, formats);
161     if (ret < 0)
162         return ret;
163
164     formats = ff_all_samplerates();
165     if (!formats)
166         return AVERROR(ENOMEM);
167     return ff_set_common_samplerates(ctx, formats);
168 }
169
170 static void fast_convolute(FIREqualizerContext *s, const float *kernel_buf, float *conv_buf,
171                            OverlapIndex *idx, float *data, int nsamples)
172 {
173     if (nsamples <= s->nsamples_max) {
174         float *buf = conv_buf + idx->buf_idx * s->rdft_len;
175         float *obuf = conv_buf + !idx->buf_idx * s->rdft_len + idx->overlap_idx;
176         int k;
177
178         memcpy(buf, data, nsamples * sizeof(*data));
179         memset(buf + nsamples, 0, (s->rdft_len - nsamples) * sizeof(*data));
180         av_rdft_calc(s->rdft, buf);
181
182         buf[0] *= kernel_buf[0];
183         buf[1] *= kernel_buf[1];
184         for (k = 2; k < s->rdft_len; k += 2) {
185             float re, im;
186             re = buf[k] * kernel_buf[k] - buf[k+1] * kernel_buf[k+1];
187             im = buf[k] * kernel_buf[k+1] + buf[k+1] * kernel_buf[k];
188             buf[k] = re;
189             buf[k+1] = im;
190         }
191
192         av_rdft_calc(s->irdft, buf);
193         for (k = 0; k < s->rdft_len - idx->overlap_idx; k++)
194             buf[k] += obuf[k];
195         memcpy(data, buf, nsamples * sizeof(*data));
196         idx->buf_idx = !idx->buf_idx;
197         idx->overlap_idx = nsamples;
198     } else {
199         while (nsamples > s->nsamples_max * 2) {
200             fast_convolute(s, kernel_buf, conv_buf, idx, data, s->nsamples_max);
201             data += s->nsamples_max;
202             nsamples -= s->nsamples_max;
203         }
204         fast_convolute(s, kernel_buf, conv_buf, idx, data, nsamples/2);
205         fast_convolute(s, kernel_buf, conv_buf, idx, data + nsamples/2, nsamples - nsamples/2);
206     }
207 }
208
209 static double entry_func(void *p, double freq, double gain)
210 {
211     AVFilterContext *ctx = p;
212     FIREqualizerContext *s = ctx->priv;
213
214     if (s->nb_gain_entry >= NB_GAIN_ENTRY_MAX) {
215         av_log(ctx, AV_LOG_ERROR, "entry table overflow.\n");
216         s->gain_entry_err = AVERROR(EINVAL);
217         return 0;
218     }
219
220     if (isnan(freq)) {
221         av_log(ctx, AV_LOG_ERROR, "nan frequency (%g, %g).\n", freq, gain);
222         s->gain_entry_err = AVERROR(EINVAL);
223         return 0;
224     }
225
226     if (s->nb_gain_entry > 0 && freq <= s->gain_entry_tbl[s->nb_gain_entry - 1].freq) {
227         av_log(ctx, AV_LOG_ERROR, "unsorted frequency (%g, %g).\n", freq, gain);
228         s->gain_entry_err = AVERROR(EINVAL);
229         return 0;
230     }
231
232     s->gain_entry_tbl[s->nb_gain_entry].freq = freq;
233     s->gain_entry_tbl[s->nb_gain_entry].gain = gain;
234     s->nb_gain_entry++;
235     return 0;
236 }
237
238 static int gain_entry_compare(const void *key, const void *memb)
239 {
240     const double *freq = key;
241     const GainEntry *entry = memb;
242
243     if (*freq < entry[0].freq)
244         return -1;
245     if (*freq > entry[1].freq)
246         return 1;
247     return 0;
248 }
249
250 static double gain_interpolate_func(void *p, double freq)
251 {
252     AVFilterContext *ctx = p;
253     FIREqualizerContext *s = ctx->priv;
254     GainEntry *res;
255     double d0, d1, d;
256
257     if (isnan(freq))
258         return freq;
259
260     if (!s->nb_gain_entry)
261         return 0;
262
263     if (freq <= s->gain_entry_tbl[0].freq)
264         return s->gain_entry_tbl[0].gain;
265
266     if (freq >= s->gain_entry_tbl[s->nb_gain_entry-1].freq)
267         return s->gain_entry_tbl[s->nb_gain_entry-1].gain;
268
269     res = bsearch(&freq, &s->gain_entry_tbl, s->nb_gain_entry - 1, sizeof(*res), gain_entry_compare);
270     av_assert0(res);
271
272     d  = res[1].freq - res[0].freq;
273     d0 = freq - res[0].freq;
274     d1 = res[1].freq - freq;
275
276     if (d0 && d1)
277         return (d0 * res[1].gain + d1 * res[0].gain) / d;
278
279     if (d0)
280         return res[1].gain;
281
282     return res[0].gain;
283 }
284
285 static const char *const var_names[] = {
286     "f",
287     "sr",
288     "ch",
289     "chid",
290     "chs",
291     "chlayout",
292     NULL
293 };
294
295 enum VarOffset {
296     VAR_F,
297     VAR_SR,
298     VAR_CH,
299     VAR_CHID,
300     VAR_CHS,
301     VAR_CHLAYOUT,
302     VAR_NB
303 };
304
305 static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *gain_entry)
306 {
307     FIREqualizerContext *s = ctx->priv;
308     AVFilterLink *inlink = ctx->inputs[0];
309     const char *gain_entry_func_names[] = { "entry", NULL };
310     const char *gain_func_names[] = { "gain_interpolate", NULL };
311     double (*gain_entry_funcs[])(void *, double, double) = { entry_func, NULL };
312     double (*gain_funcs[])(void *, double) = { gain_interpolate_func, NULL };
313     double vars[VAR_NB];
314     AVExpr *gain_expr;
315     int ret, k, center, ch;
316
317     s->nb_gain_entry = 0;
318     s->gain_entry_err = 0;
319     if (gain_entry) {
320         double result = 0.0;
321         ret = av_expr_parse_and_eval(&result, gain_entry, NULL, NULL, NULL, NULL,
322                                      gain_entry_func_names, gain_entry_funcs, ctx, 0, ctx);
323         if (ret < 0)
324             return ret;
325         if (s->gain_entry_err < 0)
326             return s->gain_entry_err;
327     }
328
329     av_log(ctx, AV_LOG_DEBUG, "nb_gain_entry = %d.\n", s->nb_gain_entry);
330
331     ret = av_expr_parse(&gain_expr, gain, var_names,
332                         gain_func_names, gain_funcs, NULL, NULL, 0, ctx);
333     if (ret < 0)
334         return ret;
335
336     vars[VAR_CHS] = inlink->channels;
337     vars[VAR_CHLAYOUT] = inlink->channel_layout;
338     vars[VAR_SR] = inlink->sample_rate;
339     for (ch = 0; ch < inlink->channels; ch++) {
340         vars[VAR_CH] = ch;
341         vars[VAR_CHID] = av_channel_layout_extract_channel(inlink->channel_layout, ch);
342         vars[VAR_F] = 0.0;
343         s->analysis_buf[0] = pow(10.0, 0.05 * av_expr_eval(gain_expr, vars, ctx));
344         vars[VAR_F] = 0.5 * inlink->sample_rate;
345         s->analysis_buf[1] = pow(10.0, 0.05 * av_expr_eval(gain_expr, vars, ctx));
346
347         for (k = 1; k < s->analysis_rdft_len/2; k++) {
348             vars[VAR_F] = k * ((double)inlink->sample_rate /(double)s->analysis_rdft_len);
349             s->analysis_buf[2*k] = pow(10.0, 0.05 * av_expr_eval(gain_expr, vars, ctx));
350             s->analysis_buf[2*k+1] = 0.0;
351         }
352
353         av_rdft_calc(s->analysis_irdft, s->analysis_buf);
354         center = s->fir_len / 2;
355
356         for (k = 0; k <= center; k++) {
357             double u = k * (M_PI/center);
358             double win;
359             switch (s->wfunc) {
360             case WFUNC_RECTANGULAR:
361                 win = 1.0;
362                 break;
363             case WFUNC_HANN:
364                 win = 0.5 + 0.5 * cos(u);
365                 break;
366             case WFUNC_HAMMING:
367                 win = 0.53836 + 0.46164 * cos(u);
368                 break;
369             case WFUNC_BLACKMAN:
370                 win = 0.48 + 0.5 * cos(u) + 0.02 * cos(2*u);
371                 break;
372             case WFUNC_NUTTALL3:
373                 win = 0.40897 + 0.5 * cos(u) + 0.09103 * cos(2*u);
374                 break;
375             case WFUNC_MNUTTALL3:
376                 win = 0.4243801 + 0.4973406 * cos(u) + 0.0782793 * cos(2*u);
377                 break;
378             case WFUNC_NUTTALL:
379                 win = 0.355768 + 0.487396 * cos(u) + 0.144232 * cos(2*u) + 0.012604 * cos(3*u);
380                 break;
381             case WFUNC_BNUTTALL:
382                 win = 0.3635819 + 0.4891775 * cos(u) + 0.1365995 * cos(2*u) + 0.0106411 * cos(3*u);
383                 break;
384             case WFUNC_BHARRIS:
385                 win = 0.35875 + 0.48829 * cos(u) + 0.14128 * cos(2*u) + 0.01168 * cos(3*u);
386                 break;
387             default:
388                 av_assert0(0);
389             }
390             s->analysis_buf[k] *= (2.0/s->analysis_rdft_len) * (2.0/s->rdft_len) * win;
391         }
392
393         for (k = 0; k < center - k; k++) {
394             float tmp = s->analysis_buf[k];
395             s->analysis_buf[k] = s->analysis_buf[center - k];
396             s->analysis_buf[center - k] = tmp;
397         }
398
399         for (k = 1; k <= center; k++)
400             s->analysis_buf[center + k] = s->analysis_buf[center - k];
401
402         memset(s->analysis_buf + s->fir_len, 0, (s->rdft_len - s->fir_len) * sizeof(*s->analysis_buf));
403         av_rdft_calc(s->rdft, s->analysis_buf);
404
405         for (k = 0; k < s->rdft_len; k++) {
406             if (isnan(s->analysis_buf[k]) || isinf(s->analysis_buf[k])) {
407                 av_log(ctx, AV_LOG_ERROR, "filter kernel contains nan or infinity.\n");
408                 av_expr_free(gain_expr);
409                 return AVERROR(EINVAL);
410             }
411         }
412
413         memcpy(s->kernel_tmp_buf + ch * s->rdft_len, s->analysis_buf, s->rdft_len * sizeof(*s->analysis_buf));
414         if (!s->multi)
415             break;
416     }
417
418     memcpy(s->kernel_buf, s->kernel_tmp_buf, (s->multi ? inlink->channels : 1) * s->rdft_len * sizeof(*s->kernel_buf));
419     av_expr_free(gain_expr);
420     return 0;
421 }
422
423 static int config_input(AVFilterLink *inlink)
424 {
425     AVFilterContext *ctx = inlink->dst;
426     FIREqualizerContext *s = ctx->priv;
427     int rdft_bits;
428
429     common_uninit(s);
430
431     s->next_pts = 0;
432     s->frame_nsamples_max = 0;
433
434     s->fir_len = FFMAX(2 * (int)(inlink->sample_rate * s->delay) + 1, 3);
435     s->remaining = s->fir_len - 1;
436
437     for (rdft_bits = RDFT_BITS_MIN; rdft_bits <= RDFT_BITS_MAX; rdft_bits++) {
438         s->rdft_len = 1 << rdft_bits;
439         s->nsamples_max = s->rdft_len - s->fir_len + 1;
440         if (s->nsamples_max * 2 >= s->fir_len)
441             break;
442     }
443
444     if (rdft_bits > RDFT_BITS_MAX) {
445         av_log(ctx, AV_LOG_ERROR, "too large delay, please decrease it.\n");
446         return AVERROR(EINVAL);
447     }
448
449     if (!(s->rdft = av_rdft_init(rdft_bits, DFT_R2C)) || !(s->irdft = av_rdft_init(rdft_bits, IDFT_C2R)))
450         return AVERROR(ENOMEM);
451
452     for ( ; rdft_bits <= RDFT_BITS_MAX; rdft_bits++) {
453         s->analysis_rdft_len = 1 << rdft_bits;
454         if (inlink->sample_rate <= s->accuracy * s->analysis_rdft_len)
455             break;
456     }
457
458     if (rdft_bits > RDFT_BITS_MAX) {
459         av_log(ctx, AV_LOG_ERROR, "too small accuracy, please increase it.\n");
460         return AVERROR(EINVAL);
461     }
462
463     if (!(s->analysis_irdft = av_rdft_init(rdft_bits, IDFT_C2R)))
464         return AVERROR(ENOMEM);
465
466     s->analysis_buf = av_malloc_array(s->analysis_rdft_len, sizeof(*s->analysis_buf));
467     s->kernel_tmp_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->channels : 1), sizeof(*s->kernel_tmp_buf));
468     s->kernel_buf = av_malloc_array(s->rdft_len * (s->multi ? inlink->channels : 1), sizeof(*s->kernel_buf));
469     s->conv_buf   = av_calloc(2 * s->rdft_len * inlink->channels, sizeof(*s->conv_buf));
470     s->conv_idx   = av_calloc(inlink->channels, sizeof(*s->conv_idx));
471     if (!s->analysis_buf || !s->kernel_tmp_buf || !s->kernel_buf || !s->conv_buf || !s->conv_idx)
472         return AVERROR(ENOMEM);
473
474     av_log(ctx, AV_LOG_DEBUG, "sample_rate = %d, channels = %d, analysis_rdft_len = %d, rdft_len = %d, fir_len = %d, nsamples_max = %d.\n",
475            inlink->sample_rate, inlink->channels, s->analysis_rdft_len, s->rdft_len, s->fir_len, s->nsamples_max);
476
477     if (s->fixed)
478         inlink->min_samples = inlink->max_samples = inlink->partial_buf_size = s->nsamples_max;
479
480     return generate_kernel(ctx, s->gain_cmd ? s->gain_cmd : s->gain,
481                            s->gain_entry_cmd ? s->gain_entry_cmd : s->gain_entry);
482 }
483
484 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
485 {
486     AVFilterContext *ctx = inlink->dst;
487     FIREqualizerContext *s = ctx->priv;
488     int ch;
489
490     for (ch = 0; ch < inlink->channels; ch++) {
491         fast_convolute(s, s->kernel_buf + (s->multi ? ch * s->rdft_len : 0),
492                        s->conv_buf + 2 * ch * s->rdft_len, s->conv_idx + ch,
493                        (float *) frame->extended_data[ch], frame->nb_samples);
494     }
495
496     s->next_pts = frame->pts + av_rescale_q(frame->nb_samples, av_make_q(1, inlink->sample_rate), inlink->time_base);
497     s->frame_nsamples_max = FFMAX(s->frame_nsamples_max, frame->nb_samples);
498     return ff_filter_frame(ctx->outputs[0], frame);
499 }
500
501 static int request_frame(AVFilterLink *outlink)
502 {
503     AVFilterContext *ctx = outlink->src;
504     FIREqualizerContext *s= ctx->priv;
505     int ret;
506
507     ret = ff_request_frame(ctx->inputs[0]);
508     if (ret == AVERROR_EOF && s->remaining > 0 && s->frame_nsamples_max > 0) {
509         AVFrame *frame = ff_get_audio_buffer(outlink, FFMIN(s->remaining, s->frame_nsamples_max));
510
511         if (!frame)
512             return AVERROR(ENOMEM);
513
514         av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, outlink->channels, frame->format);
515         frame->pts = s->next_pts;
516         s->remaining -= frame->nb_samples;
517         ret = filter_frame(ctx->inputs[0], frame);
518     }
519
520     return ret;
521 }
522
523 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
524                            char *res, int res_len, int flags)
525 {
526     FIREqualizerContext *s = ctx->priv;
527     int ret = AVERROR(ENOSYS);
528
529     if (!strcmp(cmd, "gain")) {
530         char *gain_cmd;
531
532         gain_cmd = av_strdup(args);
533         if (!gain_cmd)
534             return AVERROR(ENOMEM);
535
536         ret = generate_kernel(ctx, gain_cmd, s->gain_entry_cmd ? s->gain_entry_cmd : s->gain_entry);
537         if (ret >= 0) {
538             av_freep(&s->gain_cmd);
539             s->gain_cmd = gain_cmd;
540         } else {
541             av_freep(&gain_cmd);
542         }
543     } else if (!strcmp(cmd, "gain_entry")) {
544         char *gain_entry_cmd;
545
546         gain_entry_cmd = av_strdup(args);
547         if (!gain_entry_cmd)
548             return AVERROR(ENOMEM);
549
550         ret = generate_kernel(ctx, s->gain_cmd ? s->gain_cmd : s->gain, gain_entry_cmd);
551         if (ret >= 0) {
552             av_freep(&s->gain_entry_cmd);
553             s->gain_entry_cmd = gain_entry_cmd;
554         } else {
555             av_freep(&gain_entry_cmd);
556         }
557     }
558
559     return ret;
560 }
561
562 static const AVFilterPad firequalizer_inputs[] = {
563     {
564         .name           = "default",
565         .config_props   = config_input,
566         .filter_frame   = filter_frame,
567         .type           = AVMEDIA_TYPE_AUDIO,
568         .needs_writable = 1,
569     },
570     { NULL }
571 };
572
573 static const AVFilterPad firequalizer_outputs[] = {
574     {
575         .name           = "default",
576         .request_frame  = request_frame,
577         .type           = AVMEDIA_TYPE_AUDIO,
578     },
579     { NULL }
580 };
581
582 AVFilter ff_af_firequalizer = {
583     .name               = "firequalizer",
584     .description        = NULL_IF_CONFIG_SMALL("Finite Impulse Response Equalizer"),
585     .uninit             = uninit,
586     .query_formats      = query_formats,
587     .process_command    = process_command,
588     .priv_size          = sizeof(FIREqualizerContext),
589     .inputs             = firequalizer_inputs,
590     .outputs            = firequalizer_outputs,
591     .priv_class         = &firequalizer_class,
592 };