You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

539 lines
19KB

  1. /*
  2. * Copyright (c) 2015 Paul B Mahol
  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. #include <float.h>
  21. #include <math.h>
  22. #include "libavcodec/avfft.h"
  23. #include "libavutil/audio_fifo.h"
  24. #include "libavutil/avassert.h"
  25. #include "libavutil/avstring.h"
  26. #include "libavutil/channel_layout.h"
  27. #include "libavutil/intreadwrite.h"
  28. #include "libavutil/opt.h"
  29. #include "libavutil/parseutils.h"
  30. #include "audio.h"
  31. #include "filters.h"
  32. #include "video.h"
  33. #include "avfilter.h"
  34. #include "internal.h"
  35. #include "window_func.h"
  36. enum DisplayMode { LINE, BAR, DOT, NB_MODES };
  37. enum ChannelMode { COMBINED, SEPARATE, NB_CMODES };
  38. enum FrequencyScale { FS_LINEAR, FS_LOG, FS_RLOG, NB_FSCALES };
  39. enum AmplitudeScale { AS_LINEAR, AS_SQRT, AS_CBRT, AS_LOG, NB_ASCALES };
  40. typedef struct ShowFreqsContext {
  41. const AVClass *class;
  42. int w, h;
  43. int mode;
  44. int cmode;
  45. int fft_size;
  46. int fft_bits;
  47. int ascale, fscale;
  48. int avg;
  49. int win_func;
  50. FFTContext *fft;
  51. FFTComplex **fft_data;
  52. float **avg_data;
  53. float *window_func_lut;
  54. float overlap;
  55. float minamp;
  56. int hop_size;
  57. int nb_channels;
  58. int nb_freq;
  59. int win_size;
  60. float scale;
  61. char *colors;
  62. AVAudioFifo *fifo;
  63. int64_t pts;
  64. } ShowFreqsContext;
  65. #define OFFSET(x) offsetof(ShowFreqsContext, x)
  66. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  67. static const AVOption showfreqs_options[] = {
  68. { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
  69. { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
  70. { "mode", "set display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BAR}, 0, NB_MODES-1, FLAGS, "mode" },
  71. { "line", "show lines", 0, AV_OPT_TYPE_CONST, {.i64=LINE}, 0, 0, FLAGS, "mode" },
  72. { "bar", "show bars", 0, AV_OPT_TYPE_CONST, {.i64=BAR}, 0, 0, FLAGS, "mode" },
  73. { "dot", "show dots", 0, AV_OPT_TYPE_CONST, {.i64=DOT}, 0, 0, FLAGS, "mode" },
  74. { "ascale", "set amplitude scale", OFFSET(ascale), AV_OPT_TYPE_INT, {.i64=AS_LOG}, 0, NB_ASCALES-1, FLAGS, "ascale" },
  75. { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=AS_LINEAR}, 0, 0, FLAGS, "ascale" },
  76. { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=AS_SQRT}, 0, 0, FLAGS, "ascale" },
  77. { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=AS_CBRT}, 0, 0, FLAGS, "ascale" },
  78. { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=AS_LOG}, 0, 0, FLAGS, "ascale" },
  79. { "fscale", "set frequency scale", OFFSET(fscale), AV_OPT_TYPE_INT, {.i64=FS_LINEAR}, 0, NB_FSCALES-1, FLAGS, "fscale" },
  80. { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=FS_LINEAR}, 0, 0, FLAGS, "fscale" },
  81. { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_LOG}, 0, 0, FLAGS, "fscale" },
  82. { "rlog", "reverse logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_RLOG}, 0, 0, FLAGS, "fscale" },
  83. { "win_size", "set window size", OFFSET(fft_size), AV_OPT_TYPE_INT, {.i64=2048}, 16, 65536, FLAGS },
  84. { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64=WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
  85. { "rect", "Rectangular", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT}, 0, 0, FLAGS, "win_func" },
  86. { "bartlett", "Bartlett", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
  87. { "hanning", "Hanning", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
  88. { "hamming", "Hamming", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
  89. { "blackman", "Blackman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
  90. { "welch", "Welch", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH}, 0, 0, FLAGS, "win_func" },
  91. { "flattop", "Flat-top", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP}, 0, 0, FLAGS, "win_func" },
  92. { "bharris", "Blackman-Harris", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS}, 0, 0, FLAGS, "win_func" },
  93. { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
  94. { "bhann", "Bartlett-Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN}, 0, 0, FLAGS, "win_func" },
  95. { "sine", "Sine", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE}, 0, 0, FLAGS, "win_func" },
  96. { "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
  97. { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
  98. { "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
  99. { "tukey", "Tukey", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY}, 0, 0, FLAGS, "win_func" },
  100. { "dolph", "Dolph-Chebyshev", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_DOLPH}, 0, 0, FLAGS, "win_func" },
  101. { "cauchy", "Cauchy", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_CAUCHY}, 0, 0, FLAGS, "win_func" },
  102. { "parzen", "Parzen", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_PARZEN}, 0, 0, FLAGS, "win_func" },
  103. { "poisson", "Poisson", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_POISSON}, 0, 0, FLAGS, "win_func" },
  104. { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN} , 0, 0, FLAGS, "win_func" },
  105. { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
  106. { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
  107. { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
  108. { "cmode", "set channel mode", OFFSET(cmode), AV_OPT_TYPE_INT, {.i64=COMBINED}, 0, NB_CMODES-1, FLAGS, "cmode" },
  109. { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },
  110. { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },
  111. { "minamp", "set minimum amplitude", OFFSET(minamp), AV_OPT_TYPE_FLOAT, {.dbl=1e-6}, FLT_MIN, 1e-6, FLAGS },
  112. { NULL }
  113. };
  114. AVFILTER_DEFINE_CLASS(showfreqs);
  115. static int query_formats(AVFilterContext *ctx)
  116. {
  117. AVFilterFormats *formats = NULL;
  118. AVFilterChannelLayouts *layouts = NULL;
  119. AVFilterLink *inlink = ctx->inputs[0];
  120. AVFilterLink *outlink = ctx->outputs[0];
  121. static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
  122. static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
  123. int ret;
  124. /* set input audio formats */
  125. formats = ff_make_format_list(sample_fmts);
  126. if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
  127. return ret;
  128. layouts = ff_all_channel_layouts();
  129. if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
  130. return ret;
  131. formats = ff_all_samplerates();
  132. if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
  133. return ret;
  134. /* set output video format */
  135. formats = ff_make_format_list(pix_fmts);
  136. if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
  137. return ret;
  138. return 0;
  139. }
  140. static av_cold int init(AVFilterContext *ctx)
  141. {
  142. ShowFreqsContext *s = ctx->priv;
  143. s->pts = AV_NOPTS_VALUE;
  144. return 0;
  145. }
  146. static int config_output(AVFilterLink *outlink)
  147. {
  148. AVFilterContext *ctx = outlink->src;
  149. AVFilterLink *inlink = ctx->inputs[0];
  150. ShowFreqsContext *s = ctx->priv;
  151. float overlap;
  152. int i;
  153. s->fft_bits = av_log2(s->fft_size);
  154. s->nb_freq = 1 << (s->fft_bits - 1);
  155. s->win_size = s->nb_freq << 1;
  156. av_audio_fifo_free(s->fifo);
  157. av_fft_end(s->fft);
  158. s->fft = av_fft_init(s->fft_bits, 0);
  159. if (!s->fft) {
  160. av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
  161. "The window size might be too high.\n");
  162. return AVERROR(ENOMEM);
  163. }
  164. /* FFT buffers: x2 for each (display) channel buffer.
  165. * Note: we use free and malloc instead of a realloc-like function to
  166. * make sure the buffer is aligned in memory for the FFT functions. */
  167. for (i = 0; i < s->nb_channels; i++) {
  168. av_freep(&s->fft_data[i]);
  169. av_freep(&s->avg_data[i]);
  170. }
  171. av_freep(&s->fft_data);
  172. av_freep(&s->avg_data);
  173. s->nb_channels = inlink->channels;
  174. s->fft_data = av_calloc(s->nb_channels, sizeof(*s->fft_data));
  175. if (!s->fft_data)
  176. return AVERROR(ENOMEM);
  177. s->avg_data = av_calloc(s->nb_channels, sizeof(*s->avg_data));
  178. if (!s->avg_data)
  179. return AVERROR(ENOMEM);
  180. for (i = 0; i < s->nb_channels; i++) {
  181. s->fft_data[i] = av_calloc(s->win_size, sizeof(**s->fft_data));
  182. s->avg_data[i] = av_calloc(s->nb_freq, sizeof(**s->avg_data));
  183. if (!s->fft_data[i] || !s->avg_data[i])
  184. return AVERROR(ENOMEM);
  185. }
  186. /* pre-calc windowing function */
  187. s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
  188. sizeof(*s->window_func_lut));
  189. if (!s->window_func_lut)
  190. return AVERROR(ENOMEM);
  191. generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
  192. if (s->overlap == 1.)
  193. s->overlap = overlap;
  194. s->hop_size = (1. - s->overlap) * s->win_size;
  195. if (s->hop_size < 1) {
  196. av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
  197. return AVERROR(EINVAL);
  198. }
  199. for (s->scale = 0, i = 0; i < s->win_size; i++) {
  200. s->scale += s->window_func_lut[i] * s->window_func_lut[i];
  201. }
  202. outlink->frame_rate = av_make_q(inlink->sample_rate, s->win_size * (1.-s->overlap));
  203. outlink->sample_aspect_ratio = (AVRational){1,1};
  204. outlink->w = s->w;
  205. outlink->h = s->h;
  206. s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
  207. if (!s->fifo)
  208. return AVERROR(ENOMEM);
  209. return 0;
  210. }
  211. static inline void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
  212. {
  213. uint32_t color = AV_RL32(out->data[0] + y * out->linesize[0] + x * 4);
  214. if ((color & 0xffffff) != 0)
  215. AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg) | color);
  216. else
  217. AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg));
  218. }
  219. static int get_sx(ShowFreqsContext *s, int f)
  220. {
  221. switch (s->fscale) {
  222. case FS_LINEAR:
  223. return (s->w/(float)s->nb_freq)*f;
  224. case FS_LOG:
  225. return s->w-pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.));
  226. case FS_RLOG:
  227. return pow(s->w, f/(s->nb_freq-1.));
  228. }
  229. return 0;
  230. }
  231. static float get_bsize(ShowFreqsContext *s, int f)
  232. {
  233. switch (s->fscale) {
  234. case FS_LINEAR:
  235. return s->w/(float)s->nb_freq;
  236. case FS_LOG:
  237. return pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.))-
  238. pow(s->w, (s->nb_freq-f-2)/(s->nb_freq-1.));
  239. case FS_RLOG:
  240. return pow(s->w, (f+1)/(s->nb_freq-1.))-
  241. pow(s->w, f /(s->nb_freq-1.));
  242. }
  243. return 1.;
  244. }
  245. static inline void plot_freq(ShowFreqsContext *s, int ch,
  246. double a, int f, uint8_t fg[4], int *prev_y,
  247. AVFrame *out, AVFilterLink *outlink)
  248. {
  249. const int w = s->w;
  250. const float min = s->minamp;
  251. const float avg = s->avg_data[ch][f];
  252. const float bsize = get_bsize(s, f);
  253. const int sx = get_sx(s, f);
  254. int end = outlink->h;
  255. int x, y, i;
  256. switch(s->ascale) {
  257. case AS_SQRT:
  258. a = 1.0 - sqrt(a);
  259. break;
  260. case AS_CBRT:
  261. a = 1.0 - cbrt(a);
  262. break;
  263. case AS_LOG:
  264. a = log(av_clipd(a, min, 1)) / log(min);
  265. break;
  266. case AS_LINEAR:
  267. a = 1.0 - a;
  268. break;
  269. }
  270. switch (s->cmode) {
  271. case COMBINED:
  272. y = a * outlink->h - 1;
  273. break;
  274. case SEPARATE:
  275. end = (outlink->h / s->nb_channels) * (ch + 1);
  276. y = (outlink->h / s->nb_channels) * ch + a * (outlink->h / s->nb_channels) - 1;
  277. break;
  278. default:
  279. av_assert0(0);
  280. }
  281. if (y < 0)
  282. return;
  283. switch (s->avg) {
  284. case 0:
  285. y = s->avg_data[ch][f] = !outlink->frame_count_in ? y : FFMIN(avg, y);
  286. break;
  287. case 1:
  288. break;
  289. default:
  290. s->avg_data[ch][f] = avg + y * (y - avg) / (FFMIN(outlink->frame_count_in + 1, s->avg) * y);
  291. y = s->avg_data[ch][f];
  292. break;
  293. }
  294. switch(s->mode) {
  295. case LINE:
  296. if (*prev_y == -1) {
  297. *prev_y = y;
  298. }
  299. if (y <= *prev_y) {
  300. for (x = sx + 1; x < sx + bsize && x < w; x++)
  301. draw_dot(out, x, y, fg);
  302. for (i = y; i <= *prev_y; i++)
  303. draw_dot(out, sx, i, fg);
  304. } else {
  305. for (i = *prev_y; i <= y; i++)
  306. draw_dot(out, sx, i, fg);
  307. for (x = sx + 1; x < sx + bsize && x < w; x++)
  308. draw_dot(out, x, i - 1, fg);
  309. }
  310. *prev_y = y;
  311. break;
  312. case BAR:
  313. for (x = sx; x < sx + bsize && x < w; x++)
  314. for (i = y; i < end; i++)
  315. draw_dot(out, x, i, fg);
  316. break;
  317. case DOT:
  318. for (x = sx; x < sx + bsize && x < w; x++)
  319. draw_dot(out, x, y, fg);
  320. break;
  321. }
  322. }
  323. static int plot_freqs(AVFilterLink *inlink, AVFrame *in)
  324. {
  325. AVFilterContext *ctx = inlink->dst;
  326. AVFilterLink *outlink = ctx->outputs[0];
  327. ShowFreqsContext *s = ctx->priv;
  328. const int win_size = s->win_size;
  329. char *colors, *color, *saveptr = NULL;
  330. AVFrame *out;
  331. int ch, n;
  332. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  333. if (!out)
  334. return AVERROR(ENOMEM);
  335. for (n = 0; n < outlink->h; n++)
  336. memset(out->data[0] + out->linesize[0] * n, 0, outlink->w * 4);
  337. /* fill FFT input with the number of samples available */
  338. for (ch = 0; ch < s->nb_channels; ch++) {
  339. const float *p = (float *)in->extended_data[ch];
  340. for (n = 0; n < in->nb_samples; n++) {
  341. s->fft_data[ch][n].re = p[n] * s->window_func_lut[n];
  342. s->fft_data[ch][n].im = 0;
  343. }
  344. for (; n < win_size; n++) {
  345. s->fft_data[ch][n].re = 0;
  346. s->fft_data[ch][n].im = 0;
  347. }
  348. }
  349. /* run FFT on each samples set */
  350. for (ch = 0; ch < s->nb_channels; ch++) {
  351. av_fft_permute(s->fft, s->fft_data[ch]);
  352. av_fft_calc(s->fft, s->fft_data[ch]);
  353. }
  354. #define RE(x, ch) s->fft_data[ch][x].re
  355. #define IM(x, ch) s->fft_data[ch][x].im
  356. #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
  357. colors = av_strdup(s->colors);
  358. if (!colors) {
  359. av_frame_free(&out);
  360. return AVERROR(ENOMEM);
  361. }
  362. for (ch = 0; ch < s->nb_channels; ch++) {
  363. uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
  364. int prev_y = -1, f;
  365. double a;
  366. color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr);
  367. if (color)
  368. av_parse_color(fg, color, -1, ctx);
  369. a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1);
  370. plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
  371. for (f = 1; f < s->nb_freq; f++) {
  372. a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
  373. plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
  374. }
  375. }
  376. av_free(colors);
  377. out->pts = in->pts;
  378. out->sample_aspect_ratio = (AVRational){1,1};
  379. return ff_filter_frame(outlink, out);
  380. }
  381. static int filter_frame(AVFilterLink *inlink)
  382. {
  383. AVFilterContext *ctx = inlink->dst;
  384. ShowFreqsContext *s = ctx->priv;
  385. AVFrame *fin = NULL;
  386. int ret = 0;
  387. fin = ff_get_audio_buffer(inlink, s->win_size);
  388. if (!fin) {
  389. ret = AVERROR(ENOMEM);
  390. goto fail;
  391. }
  392. fin->pts = s->pts;
  393. s->pts += s->hop_size;
  394. ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
  395. if (ret < 0)
  396. goto fail;
  397. ret = plot_freqs(inlink, fin);
  398. av_frame_free(&fin);
  399. av_audio_fifo_drain(s->fifo, s->hop_size);
  400. fail:
  401. av_frame_free(&fin);
  402. return ret;
  403. }
  404. static int activate(AVFilterContext *ctx)
  405. {
  406. AVFilterLink *inlink = ctx->inputs[0];
  407. AVFilterLink *outlink = ctx->outputs[0];
  408. ShowFreqsContext *s = ctx->priv;
  409. AVFrame *in = NULL;
  410. int ret = 0;
  411. FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
  412. if (av_audio_fifo_size(s->fifo) < s->win_size)
  413. ret = ff_inlink_consume_samples(inlink, s->win_size, s->win_size, &in);
  414. if (ret < 0)
  415. return ret;
  416. if (ret > 0) {
  417. av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
  418. if (s->pts == AV_NOPTS_VALUE)
  419. s->pts = in->pts;
  420. }
  421. if (av_audio_fifo_size(s->fifo) >= s->win_size) {
  422. ret = filter_frame(inlink);
  423. if (ret <= 0)
  424. return ret;
  425. }
  426. FF_FILTER_FORWARD_STATUS(inlink, outlink);
  427. FF_FILTER_FORWARD_WANTED(outlink, inlink);
  428. return FFERROR_NOT_READY;
  429. }
  430. static av_cold void uninit(AVFilterContext *ctx)
  431. {
  432. ShowFreqsContext *s = ctx->priv;
  433. int i;
  434. av_fft_end(s->fft);
  435. for (i = 0; i < s->nb_channels; i++) {
  436. if (s->fft_data)
  437. av_freep(&s->fft_data[i]);
  438. if (s->avg_data)
  439. av_freep(&s->avg_data[i]);
  440. }
  441. av_freep(&s->fft_data);
  442. av_freep(&s->avg_data);
  443. av_freep(&s->window_func_lut);
  444. av_audio_fifo_free(s->fifo);
  445. }
  446. static const AVFilterPad showfreqs_inputs[] = {
  447. {
  448. .name = "default",
  449. .type = AVMEDIA_TYPE_AUDIO,
  450. },
  451. { NULL }
  452. };
  453. static const AVFilterPad showfreqs_outputs[] = {
  454. {
  455. .name = "default",
  456. .type = AVMEDIA_TYPE_VIDEO,
  457. .config_props = config_output,
  458. },
  459. { NULL }
  460. };
  461. AVFilter ff_avf_showfreqs = {
  462. .name = "showfreqs",
  463. .description = NULL_IF_CONFIG_SMALL("Convert input audio to a frequencies video output."),
  464. .init = init,
  465. .uninit = uninit,
  466. .query_formats = query_formats,
  467. .priv_size = sizeof(ShowFreqsContext),
  468. .activate = activate,
  469. .inputs = showfreqs_inputs,
  470. .outputs = showfreqs_outputs,
  471. .priv_class = &showfreqs_class,
  472. };