FFmpeg
avf_showcqt.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015 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 "config.h"
22 #include "libavutil/tx.h"
24 #include "libavutil/opt.h"
26 #include "libavutil/eval.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/time.h"
29 #include "avfilter.h"
30 #include "filters.h"
31 #include "internal.h"
32 #include "lavfutils.h"
33 #include "lswsutils.h"
34 
35 #if CONFIG_LIBFREETYPE
36 #include <ft2build.h>
37 #include FT_FREETYPE_H
38 #endif
39 
40 #if CONFIG_LIBFONTCONFIG
41 #include <fontconfig/fontconfig.h>
42 #endif
43 
44 #include "avf_showcqt.h"
45 
46 #define BASEFREQ 20.01523126408007475
47 #define ENDFREQ 20495.59681441799654
48 #define TLENGTH "384*tc/(384+tc*f)"
49 #define TLENGTH_MIN 0.001
50 #define VOLUME_MAX 100.0
51 #define FONTCOLOR "st(0, (midi(f)-59.5)/12);" \
52  "st(1, if(between(ld(0),0,1), 0.5-0.5*cos(2*PI*ld(0)), 0));" \
53  "r(1-ld(1)) + b(ld(1))"
54 #define CSCHEME "1|0.5|0|0|0.5|1"
55 
56 #define OFFSET(x) offsetof(ShowCQTContext, x)
57 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
58 
59 static const AVOption showcqt_options[] = {
60  { "size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, { .str = "1920x1080" }, 0, 0, FLAGS },
61  { "s", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, { .str = "1920x1080" }, 0, 0, FLAGS },
62  { "fps", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 1, 1000, FLAGS },
63  { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 1, 1000, FLAGS },
64  { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 1, 1000, FLAGS },
65  { "bar_h", "set bargraph height", OFFSET(bar_h), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
66  { "axis_h", "set axis height", OFFSET(axis_h), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
67  { "sono_h", "set sonogram height", OFFSET(sono_h), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
68  { "fullhd", "set fullhd size", OFFSET(fullhd), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
69  { "sono_v", "set sonogram volume", OFFSET(sono_v), AV_OPT_TYPE_STRING, { .str = "16" }, 0, 0, FLAGS },
70  { "volume", "set sonogram volume", OFFSET(sono_v), AV_OPT_TYPE_STRING, { .str = "16" }, 0, 0, FLAGS },
71  { "bar_v", "set bargraph volume", OFFSET(bar_v), AV_OPT_TYPE_STRING, { .str = "sono_v" }, 0, 0, FLAGS },
72  { "volume2", "set bargraph volume", OFFSET(bar_v), AV_OPT_TYPE_STRING, { .str = "sono_v" }, 0, 0, FLAGS },
73  { "sono_g", "set sonogram gamma", OFFSET(sono_g), AV_OPT_TYPE_FLOAT, { .dbl = 3.0 }, 1.0, 7.0, FLAGS },
74  { "gamma", "set sonogram gamma", OFFSET(sono_g), AV_OPT_TYPE_FLOAT, { .dbl = 3.0 }, 1.0, 7.0, FLAGS },
75  { "bar_g", "set bargraph gamma", OFFSET(bar_g), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 1.0, 7.0, FLAGS },
76  { "gamma2", "set bargraph gamma", OFFSET(bar_g), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 1.0, 7.0, FLAGS },
77  { "bar_t", "set bar transparency", OFFSET(bar_t), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.0, 1.0, FLAGS },
78  { "timeclamp", "set timeclamp", OFFSET(timeclamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.17 }, 0.002, 1.0, FLAGS },
79  { "tc", "set timeclamp", OFFSET(timeclamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.17 }, 0.002, 1.0, FLAGS },
80  { "attack", "set attack time", OFFSET(attack), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0.0, 1.0, FLAGS },
81  { "basefreq", "set base frequency", OFFSET(basefreq), AV_OPT_TYPE_DOUBLE, { .dbl = BASEFREQ }, 10.0, 100000.0, FLAGS },
82  { "endfreq", "set end frequency", OFFSET(endfreq), AV_OPT_TYPE_DOUBLE, { .dbl = ENDFREQ }, 10.0, 100000.0, FLAGS },
83  { "coeffclamp", "set coeffclamp", OFFSET(coeffclamp), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.1, 10.0, FLAGS },
84  { "tlength", "set tlength", OFFSET(tlength), AV_OPT_TYPE_STRING, { .str = TLENGTH }, 0, 0, FLAGS },
85  { "count", "set transform count", OFFSET(count), AV_OPT_TYPE_INT, { .i64 = 6 }, 1, 30, FLAGS },
86  { "fcount", "set frequency count", OFFSET(fcount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 10, FLAGS },
87  { "fontfile", "set axis font file", OFFSET(fontfile), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
88  { "font", "set axis font", OFFSET(font), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
89  { "fontcolor", "set font color", OFFSET(fontcolor), AV_OPT_TYPE_STRING, { .str = FONTCOLOR }, 0, 0, FLAGS },
90  { "axisfile", "set axis image", OFFSET(axisfile), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
91  { "axis", "draw axis", OFFSET(axis), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
92  { "text", "draw axis", OFFSET(axis), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
93  { "csp", "set color space", OFFSET(csp), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, INT_MAX, FLAGS, "csp" },
94  { "unspecified", "unspecified", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, 0, FLAGS, "csp" },
95  { "bt709", "bt709", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT709 }, 0, 0, FLAGS, "csp" },
96  { "fcc", "fcc", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_FCC }, 0, 0, FLAGS, "csp" },
97  { "bt470bg", "bt470bg", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "csp" },
98  { "smpte170m", "smpte170m", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_SMPTE170M }, 0, 0, FLAGS, "csp" },
99  { "smpte240m", "smpte240m", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_SMPTE240M }, 0, 0, FLAGS, "csp" },
100  { "bt2020ncl", "bt2020ncl", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT2020_NCL }, 0, 0, FLAGS, "csp" },
101  { "cscheme", "set color scheme", OFFSET(cscheme), AV_OPT_TYPE_STRING, { .str = CSCHEME }, 0, 0, FLAGS },
102  { NULL }
103 };
104 
105 AVFILTER_DEFINE_CLASS(showcqt);
106 
108 {
109  int k;
110  int level = AV_LOG_DEBUG;
111  int64_t plot_time;
112 
113  if (s->fft_time)
114  av_log(s->ctx, level, "fft_time = %16.3f s.\n", s->fft_time * 1e-6);
115  if (s->cqt_time)
116  av_log(s->ctx, level, "cqt_time = %16.3f s.\n", s->cqt_time * 1e-6);
117  if (s->process_cqt_time)
118  av_log(s->ctx, level, "process_cqt_time = %16.3f s.\n", s->process_cqt_time * 1e-6);
119  if (s->update_sono_time)
120  av_log(s->ctx, level, "update_sono_time = %16.3f s.\n", s->update_sono_time * 1e-6);
121  if (s->alloc_time)
122  av_log(s->ctx, level, "alloc_time = %16.3f s.\n", s->alloc_time * 1e-6);
123  if (s->bar_time)
124  av_log(s->ctx, level, "bar_time = %16.3f s.\n", s->bar_time * 1e-6);
125  if (s->axis_time)
126  av_log(s->ctx, level, "axis_time = %16.3f s.\n", s->axis_time * 1e-6);
127  if (s->sono_time)
128  av_log(s->ctx, level, "sono_time = %16.3f s.\n", s->sono_time * 1e-6);
129 
130  plot_time = s->fft_time + s->cqt_time + s->process_cqt_time + s->update_sono_time
131  + s->alloc_time + s->bar_time + s->axis_time + s->sono_time;
132  if (plot_time)
133  av_log(s->ctx, level, "plot_time = %16.3f s.\n", plot_time * 1e-6);
134 
135  s->fft_time = s->cqt_time = s->process_cqt_time = s->update_sono_time
136  = s->alloc_time = s->bar_time = s->axis_time = s->sono_time = 0;
137  /* axis_frame may be non reference counted frame */
138  if (s->axis_frame && !s->axis_frame->buf[0]) {
139  av_freep(s->axis_frame->data);
140  for (k = 0; k < 4; k++)
141  s->axis_frame->data[k] = NULL;
142  }
143 
144  av_frame_free(&s->axis_frame);
145  av_frame_free(&s->sono_frame);
146  av_tx_uninit(&s->fft_ctx);
147  if (s->coeffs)
148  for (k = 0; k < s->cqt_len; k++)
149  av_freep(&s->coeffs[k].val);
150  av_freep(&s->coeffs);
151  av_freep(&s->fft_data);
152  av_freep(&s->fft_input);
153  av_freep(&s->fft_result);
154  av_freep(&s->cqt_result);
155  av_freep(&s->attack_data);
156  av_freep(&s->c_buf);
157  av_freep(&s->h_buf);
158  av_freep(&s->rcp_h_buf);
159  av_freep(&s->freq);
160  av_freep(&s->sono_v_buf);
161  av_freep(&s->bar_v_buf);
162 }
163 
164 static double *create_freq_table(double base, double end, int n)
165 {
166  double log_base, log_end;
167  double rcp_n = 1.0 / n;
168  double *freq;
169  int x;
170 
171  freq = av_malloc_array(n, sizeof(*freq));
172  if (!freq)
173  return NULL;
174 
175  log_base = log(base);
176  log_end = log(end);
177  for (x = 0; x < n; x++) {
178  double log_freq = log_base + (x + 0.5) * (log_end - log_base) * rcp_n;
179  freq[x] = exp(log_freq);
180  }
181  return freq;
182 }
183 
184 static double clip_with_log(void *log_ctx, const char *name,
185  double val, double min, double max,
186  double nan_replace, int idx)
187 {
188  int level = AV_LOG_WARNING;
189  if (isnan(val)) {
190  av_log(log_ctx, level, "[%d] %s is nan, setting it to %g.\n",
191  idx, name, nan_replace);
192  val = nan_replace;
193  } else if (val < min) {
194  av_log(log_ctx, level, "[%d] %s is too low (%g), setting it to %g.\n",
195  idx, name, val, min);
196  val = min;
197  } else if (val > max) {
198  av_log(log_ctx, level, "[%d] %s it too high (%g), setting it to %g.\n",
199  idx, name, val, max);
200  val = max;
201  }
202  return val;
203 }
204 
205 static double a_weighting(void *p, double f)
206 {
207  double ret = 12200.0*12200.0 * (f*f*f*f);
208  ret /= (f*f + 20.6*20.6) * (f*f + 12200.0*12200.0) *
209  sqrt((f*f + 107.7*107.7) * (f*f + 737.9*737.9));
210  return ret;
211 }
212 
213 static double b_weighting(void *p, double f)
214 {
215  double ret = 12200.0*12200.0 * (f*f*f);
216  ret /= (f*f + 20.6*20.6) * (f*f + 12200.0*12200.0) * sqrt(f*f + 158.5*158.5);
217  return ret;
218 }
219 
220 static double c_weighting(void *p, double f)
221 {
222  double ret = 12200.0*12200.0 * (f*f);
223  ret /= (f*f + 20.6*20.6) * (f*f + 12200.0*12200.0);
224  return ret;
225 }
226 
228 {
229  const char *func_names[] = { "a_weighting", "b_weighting", "c_weighting", NULL };
230  const char *sono_names[] = { "timeclamp", "tc", "frequency", "freq", "f", "bar_v", NULL };
231  const char *bar_names[] = { "timeclamp", "tc", "frequency", "freq", "f", "sono_v", NULL };
232  double (*funcs[])(void *, double) = { a_weighting, b_weighting, c_weighting };
233  AVExpr *sono = NULL, *bar = NULL;
234  int x, ret = AVERROR(ENOMEM);
235 
236  s->sono_v_buf = av_malloc_array(s->cqt_len, sizeof(*s->sono_v_buf));
237  s->bar_v_buf = av_malloc_array(s->cqt_len, sizeof(*s->bar_v_buf));
238  if (!s->sono_v_buf || !s->bar_v_buf)
239  goto error;
240 
241  if ((ret = av_expr_parse(&sono, s->sono_v, sono_names, func_names, funcs, NULL, NULL, 0, s->ctx)) < 0)
242  goto error;
243 
244  if ((ret = av_expr_parse(&bar, s->bar_v, bar_names, func_names, funcs, NULL, NULL, 0, s->ctx)) < 0)
245  goto error;
246 
247  for (x = 0; x < s->cqt_len; x++) {
248  double vars[] = { s->timeclamp, s->timeclamp, s->freq[x], s->freq[x], s->freq[x], 0.0 };
249  double vol = clip_with_log(s->ctx, "sono_v", av_expr_eval(sono, vars, NULL), 0.0, VOLUME_MAX, 0.0, x);
250  vars[5] = vol;
251  vol = clip_with_log(s->ctx, "bar_v", av_expr_eval(bar, vars, NULL), 0.0, VOLUME_MAX, 0.0, x);
252  s->bar_v_buf[x] = vol * vol;
253  vars[5] = vol;
254  vol = clip_with_log(s->ctx, "sono_v", av_expr_eval(sono, vars, NULL), 0.0, VOLUME_MAX, 0.0, x);
255  s->sono_v_buf[x] = vol * vol;
256  }
257  av_expr_free(sono);
258  av_expr_free(bar);
259  return 0;
260 
261 error:
262  av_freep(&s->sono_v_buf);
263  av_freep(&s->bar_v_buf);
264  av_expr_free(sono);
265  av_expr_free(bar);
266  return ret;
267 }
268 
269 static void cqt_calc(AVComplexFloat *dst, const AVComplexFloat *src, const Coeffs *coeffs,
270  int len, int fft_len)
271 {
272  int k, x, i, j;
273  for (k = 0; k < len; k++) {
274  AVComplexFloat l, r, a = {0,0}, b = {0,0};
275 
276  for (x = 0; x < coeffs[k].len; x++) {
277  float u = coeffs[k].val[x];
278  i = coeffs[k].start + x;
279  j = fft_len - i;
280  a.re += u * src[i].re;
281  a.im += u * src[i].im;
282  b.re += u * src[j].re;
283  b.im += u * src[j].im;
284  }
285 
286  /* separate left and right, (and multiply by 2.0) */
287  l.re = a.re + b.re;
288  l.im = a.im - b.im;
289  r.re = b.im + a.im;
290  r.im = b.re - a.re;
291  dst[k].re = l.re * l.re + l.im * l.im;
292  dst[k].im = r.re * r.re + r.im * r.im;
293  }
294 }
295 
297 {
298  const char *var_names[] = { "timeclamp", "tc", "frequency", "freq", "f", NULL };
299  AVExpr *expr = NULL;
300  int rate = s->ctx->inputs[0]->sample_rate;
301  int nb_cqt_coeffs = 0;
302  int k, x, ret;
303 
304  if ((ret = av_expr_parse(&expr, s->tlength, var_names, NULL, NULL, NULL, NULL, 0, s->ctx)) < 0)
305  goto error;
306 
307  ret = AVERROR(ENOMEM);
308  if (!(s->coeffs = av_calloc(s->cqt_len, sizeof(*s->coeffs))))
309  goto error;
310 
311  for (k = 0; k < s->cqt_len; k++) {
312  double vars[] = { s->timeclamp, s->timeclamp, s->freq[k], s->freq[k], s->freq[k] };
313  double flen, center, tlength;
314  int start, end, m = k;
315 
316  if (s->freq[k] > 0.5 * rate)
317  continue;
318  tlength = clip_with_log(s->ctx, "tlength", av_expr_eval(expr, vars, NULL),
319  TLENGTH_MIN, s->timeclamp, s->timeclamp, k);
320 
321  flen = 8.0 * s->fft_len / (tlength * rate);
322  center = s->freq[k] * s->fft_len / rate;
323  start = FFMAX(0, ceil(center - 0.5 * flen));
324  end = FFMIN(s->fft_len, floor(center + 0.5 * flen));
325 
326  s->coeffs[m].start = start & ~(s->cqt_align - 1);
327  s->coeffs[m].len = (end | (s->cqt_align - 1)) + 1 - s->coeffs[m].start;
328  nb_cqt_coeffs += s->coeffs[m].len;
329  if (!(s->coeffs[m].val = av_calloc(s->coeffs[m].len, sizeof(*s->coeffs[m].val))))
330  goto error;
331 
332  for (x = start; x <= end; x++) {
333  int sign = (x & 1) ? (-1) : 1;
334  double y = 2.0 * M_PI * (x - center) * (1.0 / flen);
335  /* nuttall window */
336  double w = 0.355768 + 0.487396 * cos(y) + 0.144232 * cos(2*y) + 0.012604 * cos(3*y);
337  w *= sign * (1.0 / s->fft_len);
338  s->coeffs[m].val[x - s->coeffs[m].start] = w;
339  }
340 
341  if (s->permute_coeffs)
342  s->permute_coeffs(s->coeffs[m].val, s->coeffs[m].len);
343  }
344 
345  av_expr_free(expr);
346  av_log(s->ctx, AV_LOG_VERBOSE, "nb_cqt_coeffs = %d.\n", nb_cqt_coeffs);
347  return 0;
348 
349 error:
350  av_expr_free(expr);
351  if (s->coeffs)
352  for (k = 0; k < s->cqt_len; k++)
353  av_freep(&s->coeffs[k].val);
354  av_freep(&s->coeffs);
355  return ret;
356 }
357 
359 {
360  AVFrame *out;
361  out = av_frame_alloc();
362  if (!out)
363  return NULL;
364  out->format = format;
365  out->width = w;
366  out->height = h;
367  if (av_frame_get_buffer(out, 0) < 0) {
368  av_frame_free(&out);
369  return NULL;
370  }
372  memset(out->data[0], 0, out->linesize[0] * h);
373  } else {
374  int hh = (format == AV_PIX_FMT_YUV420P || format == AV_PIX_FMT_YUVA420P) ? h / 2 : h;
375  memset(out->data[0], 16, out->linesize[0] * h);
376  memset(out->data[1], 128, out->linesize[1] * hh);
377  memset(out->data[2], 128, out->linesize[2] * hh);
378  if (out->data[3])
379  memset(out->data[3], 0, out->linesize[3] * h);
380  }
381  return out;
382 }
383 
385 {
386  switch (format) {
387  case AV_PIX_FMT_RGB24: format = AV_PIX_FMT_RGBA; break;
388  case AV_PIX_FMT_YUV444P:
389  case AV_PIX_FMT_YUV422P:
391  }
392  return format;
393 }
394 
396 {
397  if (!(s->axis_frame = alloc_frame_empty(convert_axis_pixel_format(s->format), s->width, s->axis_h)))
398  return AVERROR(ENOMEM);
399  return 0;
400 }
401 
403 {
404  uint8_t *tmp_data[4] = { NULL };
405  int tmp_linesize[4];
406  enum AVPixelFormat tmp_format;
407  int tmp_w, tmp_h, ret;
408 
409  if ((ret = ff_load_image(tmp_data, tmp_linesize, &tmp_w, &tmp_h, &tmp_format,
410  s->axisfile, s->ctx)) < 0)
411  goto error;
412 
413  ret = AVERROR(ENOMEM);
414  if (!(s->axis_frame = av_frame_alloc()))
415  goto error;
416 
417  if ((ret = ff_scale_image(s->axis_frame->data, s->axis_frame->linesize, s->width, s->axis_h,
418  convert_axis_pixel_format(s->format), tmp_data, tmp_linesize, tmp_w, tmp_h,
419  tmp_format, s->ctx)) < 0)
420  goto error;
421 
422  s->axis_frame->width = s->width;
423  s->axis_frame->height = s->axis_h;
424  s->axis_frame->format = convert_axis_pixel_format(s->format);
425  av_freep(tmp_data);
426  return 0;
427 
428 error:
429  av_frame_free(&s->axis_frame);
430  av_freep(tmp_data);
431  return ret;
432 }
433 
434 static double midi(void *p, double f)
435 {
436  return log2(f/440.0) * 12.0 + 69.0;
437 }
438 
439 static double r_func(void *p, double x)
440 {
441  x = av_clipd(x, 0.0, 1.0);
442  return lrint(x*255.0) << 16;
443 }
444 
445 static double g_func(void *p, double x)
446 {
447  x = av_clipd(x, 0.0, 1.0);
448  return lrint(x*255.0) << 8;
449 }
450 
451 static double b_func(void *p, double x)
452 {
453  x = av_clipd(x, 0.0, 1.0);
454  return lrint(x*255.0);
455 }
456 
458 {
459  const char *var_names[] = { "timeclamp", "tc", "frequency", "freq", "f", NULL };
460  const char *func_names[] = { "midi", "r", "g", "b", NULL };
461  double (*funcs[])(void *, double) = { midi, r_func, g_func, b_func };
462  AVExpr *expr = NULL;
463  double *freq = NULL;
464  int x, xs, y, ret;
465  int width = half ? 1920/2 : 1920, height = half ? 16 : 32;
466  int step = half ? 2 : 1;
467 
468  if (s->basefreq != (double) BASEFREQ || s->endfreq != (double) ENDFREQ) {
469  av_log(s->ctx, AV_LOG_WARNING, "font axis rendering is not implemented in non-default frequency range,"
470  " please use axisfile option instead.\n");
471  return AVERROR(EINVAL);
472  }
473 
474  if (s->cqt_len == 1920)
475  freq = s->freq;
476  else if (!(freq = create_freq_table(s->basefreq, s->endfreq, 1920)))
477  return AVERROR(ENOMEM);
478 
479  if ((ret = av_expr_parse(&expr, s->fontcolor, var_names, func_names, funcs, NULL, NULL, 0, s->ctx)) < 0) {
480  if (freq != s->freq)
481  av_freep(&freq);
482  return ret;
483  }
484 
485  for (x = 0, xs = 0; x < width; x++, xs += step) {
486  double vars[] = { s->timeclamp, s->timeclamp, freq[xs], freq[xs], freq[xs] };
487  int color = (int) av_expr_eval(expr, vars, NULL);
488  uint8_t r = (color >> 16) & 0xFF, g = (color >> 8) & 0xFF, b = color & 0xFF;
489  uint8_t *data = tmp->data[0];
490  int linesize = tmp->linesize[0];
491  for (y = 0; y < height; y++) {
492  data[linesize * y + 4 * x] = r;
493  data[linesize * y + 4 * x + 1] = g;
494  data[linesize * y + 4 * x + 2] = b;
495  }
496  }
497 
498  av_expr_free(expr);
499  if (freq != s->freq)
500  av_freep(&freq);
501  return 0;
502 }
503 
504 static int render_freetype(ShowCQTContext *s, AVFrame *tmp, char *fontfile)
505 {
506 #if CONFIG_LIBFREETYPE
507  const char *str = "EF G A BC D ";
508  uint8_t *data = tmp->data[0];
509  int linesize = tmp->linesize[0];
510  FT_Library lib = NULL;
511  FT_Face face = NULL;
512  int font_width = 16, font_height = 32;
513  int font_repeat = font_width * 12;
514  int linear_hori_advance = font_width * 65536;
515  int non_monospace_warning = 0;
516  int x;
517 
518  if (!fontfile)
519  return AVERROR(EINVAL);
520 
521  if (FT_Init_FreeType(&lib))
522  goto fail;
523 
524  if (FT_New_Face(lib, fontfile, 0, &face))
525  goto fail;
526 
527  if (FT_Set_Char_Size(face, 16*64, 0, 0, 0))
528  goto fail;
529 
530  if (FT_Load_Char(face, 'A', FT_LOAD_RENDER))
531  goto fail;
532 
533  if (FT_Set_Char_Size(face, 16*64 * linear_hori_advance / face->glyph->linearHoriAdvance, 0, 0, 0))
534  goto fail;
535 
536  for (x = 0; x < 12; x++) {
537  int sx, sy, rx, bx, by, dx, dy;
538 
539  if (str[x] == ' ')
540  continue;
541 
542  if (FT_Load_Char(face, str[x], FT_LOAD_RENDER))
543  goto fail;
544 
545  if (face->glyph->advance.x != font_width*64 && !non_monospace_warning) {
546  av_log(s->ctx, AV_LOG_WARNING, "font is not monospace.\n");
547  non_monospace_warning = 1;
548  }
549 
550  sy = font_height - 8 - face->glyph->bitmap_top;
551  for (rx = 0; rx < 10; rx++) {
552  sx = rx * font_repeat + x * font_width + face->glyph->bitmap_left;
553  for (by = 0; by < face->glyph->bitmap.rows; by++) {
554  dy = by + sy;
555  if (dy < 0)
556  continue;
557  if (dy >= font_height)
558  break;
559 
560  for (bx = 0; bx < face->glyph->bitmap.width; bx++) {
561  dx = bx + sx;
562  if (dx < 0)
563  continue;
564  if (dx >= 1920)
565  break;
566  data[dy*linesize+4*dx+3] = face->glyph->bitmap.buffer[by*face->glyph->bitmap.width+bx];
567  }
568  }
569  }
570  }
571 
572  FT_Done_Face(face);
573  FT_Done_FreeType(lib);
574  return 0;
575 
576 fail:
577  av_log(s->ctx, AV_LOG_WARNING, "error while loading freetype font.\n");
578  FT_Done_Face(face);
579  FT_Done_FreeType(lib);
580  return AVERROR(EINVAL);
581 #else
582  if (fontfile)
583  av_log(s->ctx, AV_LOG_WARNING, "freetype is not available, ignoring fontfile option.\n");
584  return AVERROR(EINVAL);
585 #endif
586 }
587 
588 static int render_fontconfig(ShowCQTContext *s, AVFrame *tmp, char* font)
589 {
590 #if CONFIG_LIBFONTCONFIG
591  FcConfig *fontconfig;
592  FcPattern *pat, *best;
593  FcResult result = FcResultMatch;
594  char *filename;
595  int i, ret;
596 
597  if (!font)
598  return AVERROR(EINVAL);
599 
600  for (i = 0; font[i]; i++) {
601  if (font[i] == '|')
602  font[i] = ':';
603  }
604 
605  if (!(fontconfig = FcInitLoadConfigAndFonts())) {
606  av_log(s->ctx, AV_LOG_ERROR, "impossible to init fontconfig.\n");
607  return AVERROR_UNKNOWN;
608  }
609 
610  if (!(pat = FcNameParse((uint8_t *)font))) {
611  av_log(s->ctx, AV_LOG_ERROR, "could not parse fontconfig pat.\n");
612  FcConfigDestroy(fontconfig);
613  return AVERROR(EINVAL);
614  }
615 
616  FcDefaultSubstitute(pat);
617 
618  if (!FcConfigSubstitute(fontconfig, pat, FcMatchPattern)) {
619  av_log(s->ctx, AV_LOG_ERROR, "could not substitue fontconfig options.\n");
620  FcPatternDestroy(pat);
621  FcConfigDestroy(fontconfig);
622  return AVERROR(ENOMEM);
623  }
624 
625  best = FcFontMatch(fontconfig, pat, &result);
626  FcPatternDestroy(pat);
627 
628  ret = AVERROR(EINVAL);
629  if (!best || result != FcResultMatch) {
630  av_log(s->ctx, AV_LOG_ERROR, "cannot find a valid font for %s.\n", font);
631  goto fail;
632  }
633 
634  if (FcPatternGetString(best, FC_FILE, 0, (FcChar8 **)&filename) != FcResultMatch) {
635  av_log(s->ctx, AV_LOG_ERROR, "no file path for %s\n", font);
636  goto fail;
637  }
638 
639  ret = render_freetype(s, tmp, filename);
640 
641 fail:
642  FcPatternDestroy(best);
643  FcConfigDestroy(fontconfig);
644  return ret;
645 #else
646  if (font)
647  av_log(s->ctx, AV_LOG_WARNING, "fontconfig is not available, ignoring font option.\n");
648  return AVERROR(EINVAL);
649 #endif
650 }
651 
653 {
654  const char *str = "EF G A BC D ";
655  int x, u, v, mask;
656  uint8_t *data = tmp->data[0];
657  int linesize = tmp->linesize[0];
658  int width = 1920/2, height = 16;
659 
660  for (x = 0; x < width; x += width/10) {
661  uint8_t *startptr = data + 4 * x;
662  for (u = 0; u < 12; u++) {
663  for (v = 0; v < height; v++) {
664  uint8_t *p = startptr + v * linesize + height/2 * 4 * u;
665  for (mask = 0x80; mask; mask >>= 1, p += 4) {
666  if (mask & avpriv_vga16_font[str[u] * 16 + v])
667  p[3] = 255;
668  else
669  p[3] = 0;
670  }
671  }
672  }
673  }
674 
675  return 0;
676 }
677 
679 {
680  AVFrame *tmp = NULL;
681  int ret = AVERROR(ENOMEM);
682  int width = 1920, height = 32;
683  int default_font = 0;
684 
686  goto fail;
687 
688  if (!(s->axis_frame = av_frame_alloc()))
689  goto fail;
690 
691  if (render_freetype(s, tmp, s->fontfile) < 0 &&
692  render_fontconfig(s, tmp, s->font) < 0 &&
693  (default_font = 1, ret = render_default_font(tmp)) < 0)
694  goto fail;
695 
696  if (default_font)
697  width /= 2, height /= 2;
698 
699  if ((ret = init_axis_color(s, tmp, default_font)) < 0)
700  goto fail;
701 
702  if ((ret = ff_scale_image(s->axis_frame->data, s->axis_frame->linesize, s->width, s->axis_h,
703  convert_axis_pixel_format(s->format), tmp->data, tmp->linesize,
704  width, height, AV_PIX_FMT_RGBA, s->ctx)) < 0)
705  goto fail;
706 
707  av_frame_free(&tmp);
708  s->axis_frame->width = s->width;
709  s->axis_frame->height = s->axis_h;
710  s->axis_frame->format = convert_axis_pixel_format(s->format);
711  return 0;
712 
713 fail:
714  av_frame_free(&tmp);
715  av_frame_free(&s->axis_frame);
716  return ret;
717 }
718 
719 static float calculate_gamma(float v, float g)
720 {
721  if (g == 1.0f)
722  return v;
723  if (g == 2.0f)
724  return sqrtf(v);
725  if (g == 3.0f)
726  return cbrtf(v);
727  if (g == 4.0f)
728  return sqrtf(sqrtf(v));
729  return expf(logf(v) / g);
730 }
731 
732 static void rgb_from_cqt(ColorFloat *c, const AVComplexFloat *v, float g, int len, float cscheme[6])
733 {
734  int x;
735  for (x = 0; x < len; x++) {
736  c[x].rgb.r = 255.0f * calculate_gamma(FFMIN(1.0f, cscheme[0] * v[x].re + cscheme[3] * v[x].im), g);
737  c[x].rgb.g = 255.0f * calculate_gamma(FFMIN(1.0f, cscheme[1] * v[x].re + cscheme[4] * v[x].im), g);
738  c[x].rgb.b = 255.0f * calculate_gamma(FFMIN(1.0f, cscheme[2] * v[x].re + cscheme[5] * v[x].im), g);
739  }
740 }
741 
742 static void yuv_from_cqt(ColorFloat *c, const AVComplexFloat *v, float gamma, int len, float cm[3][3], float cscheme[6])
743 {
744  int x;
745  for (x = 0; x < len; x++) {
746  float r, g, b;
747  r = calculate_gamma(FFMIN(1.0f, cscheme[0] * v[x].re + cscheme[3] * v[x].im), gamma);
748  g = calculate_gamma(FFMIN(1.0f, cscheme[1] * v[x].re + cscheme[4] * v[x].im), gamma);
749  b = calculate_gamma(FFMIN(1.0f, cscheme[2] * v[x].re + cscheme[5] * v[x].im), gamma);
750  c[x].yuv.y = cm[0][0] * r + cm[0][1] * g + cm[0][2] * b;
751  c[x].yuv.u = cm[1][0] * r + cm[1][1] * g + cm[1][2] * b;
752  c[x].yuv.v = cm[2][0] * r + cm[2][1] * g + cm[2][2] * b;
753  }
754 }
755 
756 static void draw_bar_rgb(AVFrame *out, const float *h, const float *rcp_h,
757  const ColorFloat *c, int bar_h, float bar_t)
758 {
759  int x, y, w = out->width;
760  float mul, ht, rcp_bar_h = 1.0f / bar_h, rcp_bar_t = 1.0f / bar_t;
761  uint8_t *v = out->data[0], *lp;
762  int ls = out->linesize[0];
763 
764  for (y = 0; y < bar_h; y++) {
765  ht = (bar_h - y) * rcp_bar_h;
766  lp = v + y * ls;
767  for (x = 0; x < w; x++) {
768  if (h[x] <= ht) {
769  *lp++ = 0;
770  *lp++ = 0;
771  *lp++ = 0;
772  } else {
773  mul = (h[x] - ht) * rcp_h[x];
774  mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f;
775  *lp++ = lrintf(mul * c[x].rgb.r);
776  *lp++ = lrintf(mul * c[x].rgb.g);
777  *lp++ = lrintf(mul * c[x].rgb.b);
778  }
779  }
780  }
781 }
782 
783 #define DRAW_BAR_WITH_CHROMA(x) \
784 do { \
785  if (h[x] <= ht) { \
786  *lpy++ = 16; \
787  *lpu++ = 128; \
788  *lpv++ = 128; \
789  } else { \
790  mul = (h[x] - ht) * rcp_h[x]; \
791  mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f; \
792  *lpy++ = lrintf(mul * c[x].yuv.y + 16.0f); \
793  *lpu++ = lrintf(mul * c[x].yuv.u + 128.0f); \
794  *lpv++ = lrintf(mul * c[x].yuv.v + 128.0f); \
795  } \
796 } while (0)
797 
798 #define DRAW_BAR_WITHOUT_CHROMA(x) \
799 do { \
800  if (h[x] <= ht) { \
801  *lpy++ = 16; \
802  } else { \
803  mul = (h[x] - ht) * rcp_h[x]; \
804  mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f; \
805  *lpy++ = lrintf(mul * c[x].yuv.y + 16.0f); \
806  } \
807 } while (0)
808 
809 static void draw_bar_yuv(AVFrame *out, const float *h, const float *rcp_h,
810  const ColorFloat *c, int bar_h, float bar_t)
811 {
812  int x, y, yh, w = out->width;
813  float mul, ht, rcp_bar_h = 1.0f / bar_h, rcp_bar_t = 1.0f / bar_t;
814  uint8_t *vy = out->data[0], *vu = out->data[1], *vv = out->data[2];
815  uint8_t *lpy, *lpu, *lpv;
816  int lsy = out->linesize[0], lsu = out->linesize[1], lsv = out->linesize[2];
817  int fmt = out->format;
818 
819  for (y = 0; y < bar_h; y += 2) {
820  yh = (fmt == AV_PIX_FMT_YUV420P) ? y / 2 : y;
821  ht = (bar_h - y) * rcp_bar_h;
822  lpy = vy + y * lsy;
823  lpu = vu + yh * lsu;
824  lpv = vv + yh * lsv;
825  if (fmt == AV_PIX_FMT_YUV444P) {
826  for (x = 0; x < w; x += 2) {
829  }
830  } else {
831  for (x = 0; x < w; x += 2) {
834  }
835  }
836 
837  ht = (bar_h - (y+1)) * rcp_bar_h;
838  lpy = vy + (y+1) * lsy;
839  lpu = vu + (y+1) * lsu;
840  lpv = vv + (y+1) * lsv;
841  if (fmt == AV_PIX_FMT_YUV444P) {
842  for (x = 0; x < w; x += 2) {
845  }
846  } else if (fmt == AV_PIX_FMT_YUV422P) {
847  for (x = 0; x < w; x += 2) {
850  }
851  } else {
852  for (x = 0; x < w; x += 2) {
855  }
856  }
857  }
858 }
859 
860 static void draw_axis_rgb(AVFrame *out, AVFrame *axis, const ColorFloat *c, int off)
861 {
862  int x, y, w = axis->width, h = axis->height;
863  float a, rcp_255 = 1.0f / 255.0f;
864  uint8_t *lp, *lpa;
865 
866  for (y = 0; y < h; y++) {
867  lp = out->data[0] + (off + y) * out->linesize[0];
868  lpa = axis->data[0] + y * axis->linesize[0];
869  for (x = 0; x < w; x++) {
870  if (!lpa[3]) {
871  *lp++ = lrintf(c[x].rgb.r);
872  *lp++ = lrintf(c[x].rgb.g);
873  *lp++ = lrintf(c[x].rgb.b);
874  } else if (lpa[3] == 255) {
875  *lp++ = lpa[0];
876  *lp++ = lpa[1];
877  *lp++ = lpa[2];
878  } else {
879  a = rcp_255 * lpa[3];
880  *lp++ = lrintf(a * lpa[0] + (1.0f - a) * c[x].rgb.r);
881  *lp++ = lrintf(a * lpa[1] + (1.0f - a) * c[x].rgb.g);
882  *lp++ = lrintf(a * lpa[2] + (1.0f - a) * c[x].rgb.b);
883  }
884  lpa += 4;
885  }
886  }
887 }
888 
889 #define BLEND_WITH_CHROMA(c) \
890 do { \
891  if (!*lpaa) { \
892  *lpy = lrintf(c.yuv.y + 16.0f); \
893  *lpu = lrintf(c.yuv.u + 128.0f); \
894  *lpv = lrintf(c.yuv.v + 128.0f); \
895  } else if (255 == *lpaa) { \
896  *lpy = *lpay; \
897  *lpu = *lpau; \
898  *lpv = *lpav; \
899  } else { \
900  float a = (1.0f/255.0f) * (*lpaa); \
901  *lpy = lrintf(a * (*lpay) + (1.0f - a) * (c.yuv.y + 16.0f)); \
902  *lpu = lrintf(a * (*lpau) + (1.0f - a) * (c.yuv.u + 128.0f)); \
903  *lpv = lrintf(a * (*lpav) + (1.0f - a) * (c.yuv.v + 128.0f)); \
904  } \
905  lpy++; lpu++; lpv++; \
906  lpay++; lpau++; lpav++; lpaa++; \
907 } while (0)
908 
909 #define BLEND_WITHOUT_CHROMA(c, alpha_inc) \
910 do { \
911  if (!*lpaa) { \
912  *lpy = lrintf(c.yuv.y + 16.0f); \
913  } else if (255 == *lpaa) { \
914  *lpy = *lpay; \
915  } else { \
916  float a = (1.0f/255.0f) * (*lpaa); \
917  *lpy = lrintf(a * (*lpay) + (1.0f - a) * (c.yuv.y + 16.0f)); \
918  } \
919  lpy++; \
920  lpay++; lpaa += alpha_inc; \
921 } while (0)
922 
923 #define BLEND_CHROMA2(c) \
924 do { \
925  if (!lpaa[0] && !lpaa[1]) { \
926  *lpu = lrintf(c.yuv.u + 128.0f); \
927  *lpv = lrintf(c.yuv.v + 128.0f); \
928  } else if (255 == lpaa[0] && 255 == lpaa[1]) { \
929  *lpu = *lpau; *lpv = *lpav; \
930  } else { \
931  float a0 = (0.5f/255.0f) * lpaa[0]; \
932  float a1 = (0.5f/255.0f) * lpaa[1]; \
933  float b = 1.0f - a0 - a1; \
934  *lpu = lrintf(a0 * lpau[0] + a1 * lpau[1] + b * (c.yuv.u + 128.0f)); \
935  *lpv = lrintf(a0 * lpav[0] + a1 * lpav[1] + b * (c.yuv.v + 128.0f)); \
936  } \
937  lpau += 2; lpav += 2; lpaa++; lpu++; lpv++; \
938 } while (0)
939 
940 #define BLEND_CHROMA2x2(c) \
941 do { \
942  if (!lpaa[0] && !lpaa[1] && !lpaa[lsaa] && !lpaa[lsaa+1]) { \
943  *lpu = lrintf(c.yuv.u + 128.0f); \
944  *lpv = lrintf(c.yuv.v + 128.0f); \
945  } else if (255 == lpaa[0] && 255 == lpaa[1] && \
946  255 == lpaa[lsaa] && 255 == lpaa[lsaa+1]) { \
947  *lpu = *lpau; *lpv = *lpav; \
948  } else { \
949  float a0 = (0.25f/255.0f) * lpaa[0]; \
950  float a1 = (0.25f/255.0f) * lpaa[1]; \
951  float a2 = (0.25f/255.0f) * lpaa[lsaa]; \
952  float a3 = (0.25f/255.0f) * lpaa[lsaa+1]; \
953  float b = 1.0f - a0 - a1 - a2 - a3; \
954  *lpu = lrintf(a0 * lpau[0] + a1 * lpau[1] + a2 * lpau[lsau] + a3 * lpau[lsau+1] \
955  + b * (c.yuv.u + 128.0f)); \
956  *lpv = lrintf(a0 * lpav[0] + a1 * lpav[1] + a2 * lpav[lsav] + a3 * lpav[lsav+1] \
957  + b * (c.yuv.v + 128.0f)); \
958  } \
959  lpau += 2; lpav += 2; lpaa++; lpu++; lpv++; \
960 } while (0)
961 
962 static void draw_axis_yuv(AVFrame *out, AVFrame *axis, const ColorFloat *c, int off)
963 {
964  int fmt = out->format, x, y, yh, w = axis->width, h = axis->height;
965  int offh = (fmt == AV_PIX_FMT_YUV420P) ? off / 2 : off;
966  uint8_t *vy = out->data[0], *vu = out->data[1], *vv = out->data[2];
967  uint8_t *vay = axis->data[0], *vau = axis->data[1], *vav = axis->data[2], *vaa = axis->data[3];
968  int lsy = out->linesize[0], lsu = out->linesize[1], lsv = out->linesize[2];
969  int lsay = axis->linesize[0], lsau = axis->linesize[1], lsav = axis->linesize[2], lsaa = axis->linesize[3];
970  uint8_t *lpy, *lpu, *lpv, *lpay, *lpau, *lpav, *lpaa;
971 
972  for (y = 0; y < h; y += 2) {
973  yh = (fmt == AV_PIX_FMT_YUV420P) ? y / 2 : y;
974  lpy = vy + (off + y) * lsy;
975  lpu = vu + (offh + yh) * lsu;
976  lpv = vv + (offh + yh) * lsv;
977  lpay = vay + y * lsay;
978  lpau = vau + y * lsau;
979  lpav = vav + y * lsav;
980  lpaa = vaa + y * lsaa;
981  if (fmt == AV_PIX_FMT_YUV444P) {
982  for (x = 0; x < w; x += 2) {
983  BLEND_WITH_CHROMA(c[x]);
984  BLEND_WITH_CHROMA(c[x+1]);
985  }
986  } else if (fmt == AV_PIX_FMT_YUV422P) {
987  for (x = 0; x < w; x += 2) {
988  BLEND_WITHOUT_CHROMA(c[x], 0);
989  BLEND_CHROMA2(c[x]);
990  BLEND_WITHOUT_CHROMA(c[x+1], 1);
991  }
992  } else {
993  for (x = 0; x < w; x += 2) {
994  BLEND_WITHOUT_CHROMA(c[x], 0);
995  BLEND_CHROMA2x2(c[x]);
996  BLEND_WITHOUT_CHROMA(c[x+1], 1);
997  }
998  }
999 
1000  lpy = vy + (off + y + 1) * lsy;
1001  lpu = vu + (off + y + 1) * lsu;
1002  lpv = vv + (off + y + 1) * lsv;
1003  lpay = vay + (y + 1) * lsay;
1004  lpau = vau + (y + 1) * lsau;
1005  lpav = vav + (y + 1) * lsav;
1006  lpaa = vaa + (y + 1) * lsaa;
1007  if (fmt == AV_PIX_FMT_YUV444P) {
1008  for (x = 0; x < w; x += 2) {
1009  BLEND_WITH_CHROMA(c[x]);
1010  BLEND_WITH_CHROMA(c[x+1]);
1011  }
1012  } else if (fmt == AV_PIX_FMT_YUV422P) {
1013  for (x = 0; x < w; x += 2) {
1014  BLEND_WITHOUT_CHROMA(c[x], 0);
1015  BLEND_CHROMA2(c[x]);
1016  BLEND_WITHOUT_CHROMA(c[x+1], 1);
1017  }
1018  } else {
1019  for (x = 0; x < w; x += 2) {
1020  BLEND_WITHOUT_CHROMA(c[x], 1);
1021  BLEND_WITHOUT_CHROMA(c[x+1], 1);
1022  }
1023  }
1024  }
1025 }
1026 
1027 static void draw_sono(AVFrame *out, AVFrame *sono, int off, int idx)
1028 {
1029  int fmt = out->format, h = sono->height;
1030  int nb_planes = (fmt == AV_PIX_FMT_RGB24) ? 1 : 3;
1031  int offh = (fmt == AV_PIX_FMT_YUV420P) ? off / 2 : off;
1032  int inc = (fmt == AV_PIX_FMT_YUV420P) ? 2 : 1;
1033  ptrdiff_t ls;
1034  int i, y, yh;
1035 
1036  ls = FFABS(FFMIN(out->linesize[0], sono->linesize[0]));
1037  for (y = 0; y < h; y++) {
1038  memcpy(out->data[0] + (off + y) * out->linesize[0],
1039  sono->data[0] + (idx + y) % h * sono->linesize[0], ls);
1040  }
1041 
1042  for (i = 1; i < nb_planes; i++) {
1043  ls = FFABS(FFMIN(out->linesize[i], sono->linesize[i]));
1044  for (y = 0; y < h; y += inc) {
1045  yh = (fmt == AV_PIX_FMT_YUV420P) ? y / 2 : y;
1046  memcpy(out->data[i] + (offh + yh) * out->linesize[i],
1047  sono->data[i] + (idx + y) % h * sono->linesize[i], ls);
1048  }
1049  }
1050 }
1051 
1052 static void update_sono_rgb(AVFrame *sono, const ColorFloat *c, int idx)
1053 {
1054  int x, w = sono->width;
1055  uint8_t *lp = sono->data[0] + idx * sono->linesize[0];
1056 
1057  for (x = 0; x < w; x++) {
1058  *lp++ = lrintf(c[x].rgb.r);
1059  *lp++ = lrintf(c[x].rgb.g);
1060  *lp++ = lrintf(c[x].rgb.b);
1061  }
1062 }
1063 
1064 static void update_sono_yuv(AVFrame *sono, const ColorFloat *c, int idx)
1065 {
1066  int x, fmt = sono->format, w = sono->width;
1067  uint8_t *lpy = sono->data[0] + idx * sono->linesize[0];
1068  uint8_t *lpu = sono->data[1] + idx * sono->linesize[1];
1069  uint8_t *lpv = sono->data[2] + idx * sono->linesize[2];
1070 
1071  for (x = 0; x < w; x += 2) {
1072  *lpy++ = lrintf(c[x].yuv.y + 16.0f);
1073  *lpu++ = lrintf(c[x].yuv.u + 128.0f);
1074  *lpv++ = lrintf(c[x].yuv.v + 128.0f);
1075  *lpy++ = lrintf(c[x+1].yuv.y + 16.0f);
1076  if (fmt == AV_PIX_FMT_YUV444P) {
1077  *lpu++ = lrintf(c[x+1].yuv.u + 128.0f);
1078  *lpv++ = lrintf(c[x+1].yuv.v + 128.0f);
1079  }
1080  }
1081 }
1082 
1084 {
1085  int x, i;
1086  if (!s->sono_count) {
1087  for (x = 0; x < s->cqt_len; x++) {
1088  s->h_buf[x] = s->bar_v_buf[x] * 0.5f * (s->cqt_result[x].re + s->cqt_result[x].im);
1089  }
1090  if (s->fcount > 1) {
1091  float rcp_fcount = 1.0f / s->fcount;
1092  for (x = 0; x < s->width; x++) {
1093  float h = 0.0f;
1094  for (i = 0; i < s->fcount; i++)
1095  h += s->h_buf[s->fcount * x + i];
1096  s->h_buf[x] = rcp_fcount * h;
1097  }
1098  }
1099  for (x = 0; x < s->width; x++) {
1100  s->h_buf[x] = calculate_gamma(s->h_buf[x], s->bar_g);
1101  s->rcp_h_buf[x] = 1.0f / (s->h_buf[x] + 0.0001f);
1102  }
1103  }
1104 
1105  for (x = 0; x < s->cqt_len; x++) {
1106  s->cqt_result[x].re *= s->sono_v_buf[x];
1107  s->cqt_result[x].im *= s->sono_v_buf[x];
1108  }
1109 
1110  if (s->fcount > 1) {
1111  float rcp_fcount = 1.0f / s->fcount;
1112  for (x = 0; x < s->width; x++) {
1113  AVComplexFloat result = {0.0f, 0.0f};
1114  for (i = 0; i < s->fcount; i++) {
1115  result.re += s->cqt_result[s->fcount * x + i].re;
1116  result.im += s->cqt_result[s->fcount * x + i].im;
1117  }
1118  s->cqt_result[x].re = rcp_fcount * result.re;
1119  s->cqt_result[x].im = rcp_fcount * result.im;
1120  }
1121  }
1122 
1123  if (s->format == AV_PIX_FMT_RGB24)
1124  rgb_from_cqt(s->c_buf, s->cqt_result, s->sono_g, s->width, s->cscheme_v);
1125  else
1126  yuv_from_cqt(s->c_buf, s->cqt_result, s->sono_g, s->width, s->cmatrix, s->cscheme_v);
1127 }
1128 
1129 static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout)
1130 {
1131  AVFilterLink *outlink = ctx->outputs[0];
1132  ShowCQTContext *s = ctx->priv;
1133  int64_t last_time, cur_time;
1134 
1135 #define UPDATE_TIME(t) \
1136  cur_time = av_gettime_relative(); \
1137  t += cur_time - last_time; \
1138  last_time = cur_time
1139 
1140  last_time = av_gettime_relative();
1141 
1142  memcpy(s->fft_input, s->fft_data, s->fft_len * sizeof(*s->fft_data));
1143  if (s->attack_data) {
1144  int k;
1145  for (k = 0; k < s->remaining_fill_max; k++) {
1146  s->fft_input[s->fft_len/2+k].re *= s->attack_data[k];
1147  s->fft_input[s->fft_len/2+k].im *= s->attack_data[k];
1148  }
1149  }
1150 
1151  s->tx_fn(s->fft_ctx, s->fft_result, s->fft_input, sizeof(AVComplexFloat));
1152  UPDATE_TIME(s->fft_time);
1153 
1154  s->cqt_calc(s->cqt_result, s->fft_result, s->coeffs, s->cqt_len, s->fft_len);
1155  UPDATE_TIME(s->cqt_time);
1156 
1157  process_cqt(s);
1158  UPDATE_TIME(s->process_cqt_time);
1159 
1160  if (s->sono_h) {
1161  s->update_sono(s->sono_frame, s->c_buf, s->sono_idx);
1162  UPDATE_TIME(s->update_sono_time);
1163  }
1164 
1165  if (!s->sono_count) {
1166  AVFrame *out = *frameout = ff_get_video_buffer(outlink, outlink->w, outlink->h);
1167  if (!out)
1168  return AVERROR(ENOMEM);
1169  out->sample_aspect_ratio = av_make_q(1, 1);
1170  out->color_range = AVCOL_RANGE_MPEG;
1171  out->colorspace = s->csp;
1172  UPDATE_TIME(s->alloc_time);
1173 
1174  if (s->bar_h) {
1175  s->draw_bar(out, s->h_buf, s->rcp_h_buf, s->c_buf, s->bar_h, s->bar_t);
1176  UPDATE_TIME(s->bar_time);
1177  }
1178 
1179  if (s->axis_h) {
1180  s->draw_axis(out, s->axis_frame, s->c_buf, s->bar_h);
1181  UPDATE_TIME(s->axis_time);
1182  }
1183 
1184  if (s->sono_h) {
1185  s->draw_sono(out, s->sono_frame, s->bar_h + s->axis_h, s->sono_idx);
1186  UPDATE_TIME(s->sono_time);
1187  }
1188  }
1189  s->sono_count = (s->sono_count + 1) % s->count;
1190  if (s->sono_h)
1191  s->sono_idx = (s->sono_idx + s->sono_h - 1) % s->sono_h;
1192  return 0;
1193 }
1194 
1196 {
1197  double kr, kg, kb;
1198 
1199  /* from vf_colorspace.c */
1200  switch (s->csp) {
1201  default:
1202  av_log(s->ctx, AV_LOG_WARNING, "unsupported colorspace, setting it to unspecified.\n");
1203  s->csp = AVCOL_SPC_UNSPECIFIED;
1204  case AVCOL_SPC_UNSPECIFIED:
1205  case AVCOL_SPC_BT470BG:
1206  case AVCOL_SPC_SMPTE170M:
1207  kr = 0.299; kb = 0.114; break;
1208  case AVCOL_SPC_BT709:
1209  kr = 0.2126; kb = 0.0722; break;
1210  case AVCOL_SPC_FCC:
1211  kr = 0.30; kb = 0.11; break;
1212  case AVCOL_SPC_SMPTE240M:
1213  kr = 0.212; kb = 0.087; break;
1214  case AVCOL_SPC_BT2020_NCL:
1215  kr = 0.2627; kb = 0.0593; break;
1216  }
1217 
1218  kg = 1.0 - kr - kb;
1219  s->cmatrix[0][0] = 219.0 * kr;
1220  s->cmatrix[0][1] = 219.0 * kg;
1221  s->cmatrix[0][2] = 219.0 * kb;
1222  s->cmatrix[1][0] = -112.0 * kr / (1.0 - kb);
1223  s->cmatrix[1][1] = -112.0 * kg / (1.0 - kb);
1224  s->cmatrix[1][2] = 112.0;
1225  s->cmatrix[2][0] = 112.0;
1226  s->cmatrix[2][1] = -112.0 * kg / (1.0 - kr);
1227  s->cmatrix[2][2] = -112.0 * kb / (1.0 - kr);
1228 }
1229 
1231 {
1232  char tail[2];
1233  int k;
1234 
1235  if (sscanf(s->cscheme, " %f | %f | %f | %f | %f | %f %1s", &s->cscheme_v[0],
1236  &s->cscheme_v[1], &s->cscheme_v[2], &s->cscheme_v[3], &s->cscheme_v[4],
1237  &s->cscheme_v[5], tail) != 6)
1238  goto fail;
1239 
1240  for (k = 0; k < 6; k++)
1241  if (isnan(s->cscheme_v[k]) || s->cscheme_v[k] < 0.0f || s->cscheme_v[k] > 1.0f)
1242  goto fail;
1243 
1244  return 0;
1245 
1246 fail:
1247  av_log(s->ctx, AV_LOG_ERROR, "invalid cscheme.\n");
1248  return AVERROR(EINVAL);
1249 }
1250 
1251 /* main filter control */
1253 {
1254  ShowCQTContext *s = ctx->priv;
1255  s->ctx = ctx;
1256 
1257  if (!s->fullhd) {
1258  av_log(ctx, AV_LOG_WARNING, "fullhd option is deprecated, use size/s option instead.\n");
1259  if (s->width != 1920 || s->height != 1080) {
1260  av_log(ctx, AV_LOG_ERROR, "fullhd set to 0 but with custom dimension.\n");
1261  return AVERROR(EINVAL);
1262  }
1263  s->width /= 2;
1264  s->height /= 2;
1265  s->fullhd = 1;
1266  }
1267 
1268  if (s->axis_h < 0) {
1269  s->axis_h = s->width / 60;
1270  if (s->axis_h & 1)
1271  s->axis_h++;
1272  if (s->bar_h >= 0 && s->sono_h >= 0)
1273  s->axis_h = s->height - s->bar_h - s->sono_h;
1274  if (s->bar_h >= 0 && s->sono_h < 0)
1275  s->axis_h = FFMIN(s->axis_h, s->height - s->bar_h);
1276  if (s->bar_h < 0 && s->sono_h >= 0)
1277  s->axis_h = FFMIN(s->axis_h, s->height - s->sono_h);
1278  }
1279 
1280  if (s->bar_h < 0) {
1281  s->bar_h = (s->height - s->axis_h) / 2;
1282  if (s->bar_h & 1)
1283  s->bar_h--;
1284  if (s->sono_h >= 0)
1285  s->bar_h = s->height - s->sono_h - s->axis_h;
1286  }
1287 
1288  if (s->sono_h < 0)
1289  s->sono_h = s->height - s->axis_h - s->bar_h;
1290 
1291  if ((s->width & 1) || (s->height & 1) || (s->bar_h & 1) || (s->axis_h & 1) || (s->sono_h & 1) ||
1292  (s->bar_h < 0) || (s->axis_h < 0) || (s->sono_h < 0) || (s->bar_h > s->height) ||
1293  (s->axis_h > s->height) || (s->sono_h > s->height) || (s->bar_h + s->axis_h + s->sono_h != s->height)) {
1294  av_log(ctx, AV_LOG_ERROR, "invalid dimension.\n");
1295  return AVERROR(EINVAL);
1296  }
1297 
1298  if (!s->fcount) {
1299  do {
1300  s->fcount++;
1301  } while(s->fcount * s->width < 1920 && s->fcount < 10);
1302  }
1303 
1305 
1306  return init_cscheme(s);
1307 }
1308 
1310 {
1311  common_uninit(ctx->priv);
1312 }
1313 
1315 {
1318  AVFilterLink *inlink = ctx->inputs[0];
1319  AVFilterLink *outlink = ctx->outputs[0];
1321  static const enum AVPixelFormat pix_fmts[] = {
1324  };
1327  int ret;
1328 
1329  /* set input audio formats */
1331  if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) < 0)
1332  return ret;
1333 
1335  if ((ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts)) < 0)
1336  return ret;
1337 
1339  if ((ret = ff_formats_ref(formats, &inlink->outcfg.samplerates)) < 0)
1340  return ret;
1341 
1342  /* set output video format */
1344  if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) < 0)
1345  return ret;
1346 
1347  return 0;
1348 }
1349 
1350 static int config_output(AVFilterLink *outlink)
1351 {
1352  AVFilterContext *ctx = outlink->src;
1353  AVFilterLink *inlink = ctx->inputs[0];
1354  ShowCQTContext *s = ctx->priv;
1355  float scale = 1.f;
1356  int ret;
1357 
1358  common_uninit(s);
1359 
1360  outlink->w = s->width;
1361  outlink->h = s->height;
1362  s->format = outlink->format;
1363  outlink->sample_aspect_ratio = av_make_q(1, 1);
1364  outlink->frame_rate = s->rate;
1365  outlink->time_base = av_inv_q(s->rate);
1366  av_log(ctx, AV_LOG_VERBOSE, "video: %dx%d %s %d/%d fps, bar_h = %d, axis_h = %d, sono_h = %d.\n",
1367  s->width, s->height, av_get_pix_fmt_name(s->format), s->rate.num, s->rate.den,
1368  s->bar_h, s->axis_h, s->sono_h);
1369 
1370  s->cqt_len = s->width * s->fcount;
1371  if (!(s->freq = create_freq_table(s->basefreq, s->endfreq, s->cqt_len)))
1372  return AVERROR(ENOMEM);
1373 
1374  if ((ret = init_volume(s)) < 0)
1375  return ret;
1376 
1377  s->fft_bits = FFMAX(ceil(log2(inlink->sample_rate * s->timeclamp)), 4);
1378  s->fft_len = 1 << s->fft_bits;
1379  av_log(ctx, AV_LOG_VERBOSE, "fft_len = %d, cqt_len = %d.\n", s->fft_len, s->cqt_len);
1380 
1381  ret = av_tx_init(&s->fft_ctx, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_len, &scale, 0);
1382  s->fft_data = av_calloc(s->fft_len, sizeof(*s->fft_data));
1383  s->fft_input = av_calloc(FFALIGN(s->fft_len + 64, 256), sizeof(*s->fft_input));
1384  s->fft_result = av_calloc(FFALIGN(s->fft_len + 64, 256), sizeof(*s->fft_result));
1385  s->cqt_result = av_malloc_array(s->cqt_len, sizeof(*s->cqt_result));
1386  if (!s->fft_ctx || !s->fft_data || !s->fft_result || !s->cqt_result)
1387  return AVERROR(ENOMEM);
1388 
1389  s->remaining_fill_max = s->fft_len / 2;
1390  if (s->attack > 0.0) {
1391  int k;
1392 
1393  s->remaining_fill_max = FFMIN(s->remaining_fill_max, ceil(inlink->sample_rate * s->attack));
1394  s->attack_data = av_malloc_array(s->remaining_fill_max, sizeof(*s->attack_data));
1395  if (!s->attack_data)
1396  return AVERROR(ENOMEM);
1397 
1398  for (k = 0; k < s->remaining_fill_max; k++) {
1399  double y = M_PI * k / (inlink->sample_rate * s->attack);
1400  s->attack_data[k] = 0.355768 + 0.487396 * cos(y) + 0.144232 * cos(2*y) + 0.012604 * cos(3*y);
1401  }
1402  }
1403 
1404  s->cqt_align = 1;
1405  s->cqt_calc = cqt_calc;
1406  s->permute_coeffs = NULL;
1407  s->draw_sono = draw_sono;
1408  if (s->format == AV_PIX_FMT_RGB24) {
1409  s->draw_bar = draw_bar_rgb;
1410  s->draw_axis = draw_axis_rgb;
1411  s->update_sono = update_sono_rgb;
1412  } else {
1413  s->draw_bar = draw_bar_yuv;
1414  s->draw_axis = draw_axis_yuv;
1415  s->update_sono = update_sono_yuv;
1416  }
1417 
1418 #if ARCH_X86
1420 #endif
1421 
1422  if ((ret = init_cqt(s)) < 0)
1423  return ret;
1424 
1425  if (s->axis_h) {
1426  if (!s->axis) {
1427  if ((ret = init_axis_empty(s)) < 0)
1428  return ret;
1429  } else if (s->axisfile) {
1430  if (init_axis_from_file(s) < 0) {
1431  av_log(ctx, AV_LOG_WARNING, "loading axis image failed, fallback to font rendering.\n");
1432  if (init_axis_from_font(s) < 0) {
1433  av_log(ctx, AV_LOG_WARNING, "loading axis font failed, disable text drawing.\n");
1434  if ((ret = init_axis_empty(s)) < 0)
1435  return ret;
1436  }
1437  }
1438  } else {
1439  if (init_axis_from_font(s) < 0) {
1440  av_log(ctx, AV_LOG_WARNING, "loading axis font failed, disable text drawing.\n");
1441  if ((ret = init_axis_empty(s)) < 0)
1442  return ret;
1443  }
1444  }
1445  }
1446 
1447  if (s->sono_h) {
1448  s->sono_frame = alloc_frame_empty((outlink->format == AV_PIX_FMT_YUV420P) ?
1449  AV_PIX_FMT_YUV422P : outlink->format, s->width, s->sono_h);
1450  if (!s->sono_frame)
1451  return AVERROR(ENOMEM);
1452  }
1453 
1454  s->h_buf = av_malloc_array(s->cqt_len, sizeof (*s->h_buf));
1455  s->rcp_h_buf = av_malloc_array(s->width, sizeof(*s->rcp_h_buf));
1456  s->c_buf = av_malloc_array(s->width, sizeof(*s->c_buf));
1457  if (!s->h_buf || !s->rcp_h_buf || !s->c_buf)
1458  return AVERROR(ENOMEM);
1459 
1460  s->sono_count = 0;
1461  s->next_pts = 0;
1462  s->sono_idx = 0;
1463  s->remaining_fill = s->remaining_fill_max;
1464  s->remaining_frac = 0;
1465  s->step_frac = av_div_q(av_make_q(inlink->sample_rate, s->count) , s->rate);
1466  s->step = (int)(s->step_frac.num / s->step_frac.den);
1467  s->step_frac.num %= s->step_frac.den;
1468  if (s->step_frac.num) {
1469  av_log(ctx, AV_LOG_VERBOSE, "audio: %d Hz, step = %d + %d/%d.\n",
1470  inlink->sample_rate, s->step, s->step_frac.num, s->step_frac.den);
1471  } else {
1472  av_log(ctx, AV_LOG_VERBOSE, "audio: %d Hz, step = %d.\n",
1473  inlink->sample_rate, s->step);
1474  }
1475 
1476  return 0;
1477 }
1478 
1479 
1480 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
1481 {
1482  AVFilterContext *ctx = inlink->dst;
1483  AVFilterLink *outlink = ctx->outputs[0];
1484  ShowCQTContext *s = ctx->priv;
1485  int remaining, step, ret, x, i, j, m, got_frame = 0;
1486  float *audio_data;
1487  AVFrame *out = NULL;
1488 
1489  if (!insamples) {
1490  while (s->remaining_fill < s->remaining_fill_max) {
1491  memset(&s->fft_data[s->fft_len/2 + s->remaining_fill_max - s->remaining_fill], 0, sizeof(*s->fft_data) * s->remaining_fill);
1492  ret = plot_cqt(ctx, &out);
1493  if (ret < 0)
1494  return ret;
1495 
1496  step = s->step + (s->step_frac.num + s->remaining_frac) / s->step_frac.den;
1497  s->remaining_frac = (s->step_frac.num + s->remaining_frac) % s->step_frac.den;
1498  for (x = 0; x < (s->fft_len/2 + s->remaining_fill_max - step); x++)
1499  s->fft_data[x] = s->fft_data[x+step];
1500  s->remaining_fill += step;
1501  s->next_pts++;
1502 
1503  if (out) {
1504  out->pts = s->next_pts;
1505  out->duration = 1;
1506  return ff_filter_frame(outlink, out);
1507  }
1508  }
1509  return 0;
1510  }
1511 
1512  remaining = insamples->nb_samples;
1513  audio_data = (float*) insamples->data[0];
1514 
1515  while (remaining) {
1516  i = insamples->nb_samples - remaining;
1517  j = s->fft_len/2 + s->remaining_fill_max - s->remaining_fill;
1518  if (remaining >= s->remaining_fill) {
1519  for (m = 0; m < s->remaining_fill; m++) {
1520  s->fft_data[j+m].re = audio_data[2*(i+m)];
1521  s->fft_data[j+m].im = audio_data[2*(i+m)+1];
1522  }
1523  ret = plot_cqt(ctx, &out);
1524  if (ret < 0) {
1525  av_frame_free(&insamples);
1526  return ret;
1527  }
1528  remaining -= s->remaining_fill;
1529  if (out) {
1530  int64_t pts = av_rescale_q(insamples->nb_samples - remaining - s->remaining_fill_max,
1531  av_make_q(1, inlink->sample_rate), inlink->time_base);
1532  out->pts = av_rescale_q(insamples->pts + pts, inlink->time_base, outlink->time_base);
1533  out->duration = 1;
1534  got_frame = 1;
1535  ret = ff_filter_frame(outlink, out);
1536  if (ret < 0) {
1537  av_frame_free(&insamples);
1538  return ret;
1539  }
1540  out = NULL;
1541  }
1542  step = s->step + (s->step_frac.num + s->remaining_frac) / s->step_frac.den;
1543  s->remaining_frac = (s->step_frac.num + s->remaining_frac) % s->step_frac.den;
1544  for (m = 0; m < s->fft_len/2 + s->remaining_fill_max - step; m++)
1545  s->fft_data[m] = s->fft_data[m+step];
1546  s->remaining_fill = step;
1547  } else {
1548  for (m = 0; m < remaining; m++) {
1549  s->fft_data[j+m].re = audio_data[2*(i+m)];
1550  s->fft_data[j+m].im = audio_data[2*(i+m)+1];
1551  }
1552  s->remaining_fill -= remaining;
1553  remaining = 0;
1554  }
1555  }
1556  if (!got_frame)
1557  ff_filter_set_ready(ctx, 100);
1558  av_frame_free(&insamples);
1559  return 0;
1560 }
1561 
1563 {
1564  AVFilterLink *inlink = ctx->inputs[0];
1565  AVFilterLink *outlink = ctx->outputs[0];
1566  ShowCQTContext *s = ctx->priv;
1567  int nb_samples, ret, status;
1568  int64_t pts;
1569  AVFrame *in;
1570 
1572 
1573  nb_samples = s->step + (s->step_frac.num + s->remaining_frac) / s->step_frac.den;
1574  ret = ff_inlink_consume_samples(inlink, nb_samples, nb_samples, &in);
1575  if (ret < 0)
1576  return ret;
1577  if (ret > 0)
1578  return filter_frame(inlink, in);
1579 
1581  if (status == AVERROR_EOF) {
1582  s->next_pts = av_rescale_q(pts, inlink->time_base, outlink->time_base);
1584  ff_outlink_set_status(outlink, AVERROR_EOF, s->next_pts);
1585  return ret;
1586  }
1587  }
1588 
1589  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1590 
1591  return FFERROR_NOT_READY;
1592 }
1593 
1594 static const AVFilterPad showcqt_inputs[] = {
1595  {
1596  .name = "default",
1597  .type = AVMEDIA_TYPE_AUDIO,
1598  },
1599 };
1600 
1601 static const AVFilterPad showcqt_outputs[] = {
1602  {
1603  .name = "default",
1604  .type = AVMEDIA_TYPE_VIDEO,
1605  .config_props = config_output,
1606  },
1607 };
1608 
1610  .name = "showcqt",
1611  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a CQT (Constant/Clamped Q Transform) spectrum video output."),
1612  .init = init,
1613  .activate = activate,
1614  .uninit = uninit,
1615  .priv_size = sizeof(ShowCQTContext),
1619  .priv_class = &showcqt_class,
1620 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
formats
formats
Definition: signature.h:48
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:101
rgb::b
uint8_t b
Definition: rpzaenc.c:62
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_avf_showcqt
const AVFilter ff_avf_showcqt
Definition: avf_showcqt.c:1609
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
Definition: channel_layout.h:397
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
level
uint8_t level
Definition: svq3.c:204
draw_axis_yuv
static void draw_axis_yuv(AVFrame *out, AVFrame *axis, const ColorFloat *c, int off)
Definition: avf_showcqt.c:962
r
const char * r
Definition: vf_curves.c:126
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
draw_bar_yuv
static void draw_bar_yuv(AVFrame *out, const float *h, const float *rcp_h, const ColorFloat *c, int bar_h, float bar_t)
Definition: avf_showcqt.c:809
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:401
out
FILE * out
Definition: movenc.c:54
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:243
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:369
color
Definition: vf_paletteuse.c:509
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:971
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:947
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:612
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:326
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
ColorFloat
Definition: avf_showcqt.h:41
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:238
var_names
static const char *const var_names[]
Definition: noise_bsf.c:30
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
init_cscheme
static int init_cscheme(ShowCQTContext *s)
Definition: avf_showcqt.c:1230
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
normalize.log
log
Definition: normalize.py:21
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
im
float im
Definition: fft.c:79
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:442
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
AVFrame::width
int width
Definition: frame.h:402
w
uint8_t w
Definition: llviddspenc.c:38
AVOption
AVOption.
Definition: opt.h:251
b
#define b
Definition: input.c:41
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:171
data
const char data[16]
Definition: mxf.c:148
expf
#define expf(x)
Definition: libm.h:283
FLAGS
#define FLAGS
Definition: avf_showcqt.c:57
half
static uint8_t half(int a, int b)
Definition: mobiclip.c:541
BLEND_WITH_CHROMA
#define BLEND_WITH_CHROMA(c)
Definition: avf_showcqt.c:889
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
base
uint8_t base
Definition: vp3data.h:128
c_weighting
static double c_weighting(void *p, double f)
Definition: avf_showcqt.c:220
AVComplexFloat
Definition: tx.h:27
max
#define max(a, b)
Definition: cuda_runtime.h:33
CSCHEME
#define CSCHEME
Definition: avf_showcqt.c:54
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
render_default_font
static int render_default_font(AVFrame *tmp)
Definition: avf_showcqt.c:652
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
draw_axis_rgb
static void draw_axis_rgb(AVFrame *out, AVFrame *axis, const ColorFloat *c, int off)
Definition: avf_showcqt.c:860
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:883
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:601
rgb
Definition: rpzaenc.c:59
AVComplexFloat::im
float im
Definition: tx.h:28
a_weighting
static double a_weighting(void *p, double f)
Definition: avf_showcqt.c:205
fail
#define fail()
Definition: checkasm.h:137
val
static double val(void *priv, double ch)
Definition: aeval.c:77
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showcqt.c:1309
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
pts
static int64_t pts
Definition: transcode_aac.c:643
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
ceil
static __device__ float ceil(float a)
Definition: cuda_runtime.h:176
lrint
#define lrint
Definition: tablegen.h:53
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
mask
static const uint16_t mask[17]
Definition: lzw.c:38
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
width
#define width
BLEND_WITHOUT_CHROMA
#define BLEND_WITHOUT_CHROMA(c, alpha_inc)
Definition: avf_showcqt.c:909
s
#define s(width, name)
Definition: cbs_vp9.c:256
UPDATE_TIME
#define UPDATE_TIME(t)
DRAW_BAR_WITHOUT_CHROMA
#define DRAW_BAR_WITHOUT_CHROMA(x)
Definition: avf_showcqt.c:798
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
init_colormatrix
static void init_colormatrix(ShowCQTContext *s)
Definition: avf_showcqt.c:1195
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
g
const char * g
Definition: vf_curves.c:127
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:602
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:617
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:297
AV_TX_FLOAT_FFT
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
Definition: tx.h:47
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:766
BLEND_CHROMA2x2
#define BLEND_CHROMA2x2(c)
Definition: avf_showcqt.c:940
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVExpr
Definition: eval.c:157
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
ShowCQTContext
Definition: avf_showcqt.h:46
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
if
if(ret)
Definition: filter_design.txt:179
clip_with_log
static double clip_with_log(void *log_ctx, const char *name, double val, double min, double max, double nan_replace, int idx)
Definition: avf_showcqt.c:184
xs
#define xs(width, name, var, subs,...)
Definition: cbs_vp9.c:352
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1393
NULL
#define NULL
Definition: coverity.c:32
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showcqt.c:1252
vars
static const uint8_t vars[2][12]
Definition: camellia.c:183
render_freetype
static int render_freetype(ShowCQTContext *s, AVFrame *tmp, char *fontfile)
Definition: avf_showcqt.c:504
isnan
#define isnan(x)
Definition: libm.h:340
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
double
double
Definition: af_crystalizer.c:132
time.h
rgb_from_cqt
static void rgb_from_cqt(ColorFloat *c, const AVComplexFloat *v, float g, int len, float cscheme[6])
Definition: avf_showcqt.c:732
showcqt_inputs
static const AVFilterPad showcqt_inputs[]
Definition: avf_showcqt.c:1594
exp
int8_t exp
Definition: eval.c:72
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1328
alloc_frame_empty
static AVFrame * alloc_frame_empty(enum AVPixelFormat format, int w, int h)
Definition: avf_showcqt.c:358
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
init_axis_from_file
static int init_axis_from_file(ShowCQTContext *s)
Definition: avf_showcqt.c:402
eval.h
f
f
Definition: af_crystalizer.c:122
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:114
showcqt_outputs
static const AVFilterPad showcqt_outputs[]
Definition: avf_showcqt.c:1601
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
process_cqt
static void process_cqt(ShowCQTContext *s)
Definition: avf_showcqt.c:1083
calculate_gamma
static float calculate_gamma(float v, float g)
Definition: avf_showcqt.c:719
init_axis_color
static int init_axis_color(ShowCQTContext *s, AVFrame *tmp, int half)
Definition: avf_showcqt.c:457
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
init_axis_from_font
static int init_axis_from_font(ShowCQTContext *s)
Definition: avf_showcqt.c:678
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AVComplexFloat::re
float re
Definition: tx.h:28
update_sono_rgb
static void update_sono_rgb(AVFrame *sono, const ColorFloat *c, int idx)
Definition: avf_showcqt.c:1052
Coeffs::val
float * val
Definition: avf_showcqt.h:29
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_showcqt.c:1314
ff_load_image
int ff_load_image(uint8_t *data[4], int linesize[4], int *w, int *h, enum AVPixelFormat *pix_fmt, const char *filename, void *log_ctx)
Load image from filename and put the resulting image in data.
Definition: lavfutils.c:34
TLENGTH
#define TLENGTH
Definition: avf_showcqt.c:48
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:417
height
#define height
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
rgb::g
uint8_t g
Definition: rpzaenc.c:61
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
init_volume
static int init_volume(ShowCQTContext *s)
Definition: avf_showcqt.c:227
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
xga_font_data.h
ENDFREQ
#define ENDFREQ
Definition: avf_showcqt.c:47
M_PI
#define M_PI
Definition: mathematics.h:67
yuv_from_cqt
static void yuv_from_cqt(ColorFloat *c, const AVComplexFloat *v, float gamma, int len, float cm[3][3], float cscheme[6])
Definition: avf_showcqt.c:742
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
BLEND_CHROMA2
#define BLEND_CHROMA2(c)
Definition: avf_showcqt.c:923
Coeffs::len
int len
Definition: avf_showcqt.h:30
AVCOL_SPC_SMPTE240M
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
Definition: pixfmt.h:603
convert_axis_pixel_format
static enum AVPixelFormat convert_axis_pixel_format(enum AVPixelFormat format)
Definition: avf_showcqt.c:384
create_freq_table
static double * create_freq_table(double base, double end, int n)
Definition: avf_showcqt.c:164
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:410
b_weighting
static double b_weighting(void *p, double f)
Definition: avf_showcqt.c:213
avpriv_vga16_font
const uint8_t avpriv_vga16_font[4096]
Definition: xga_font_data.c:160
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
b_func
static double b_func(void *p, double x)
Definition: avf_showcqt.c:451
r_func
static double r_func(void *p, double x)
Definition: avf_showcqt.c:439
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:606
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
VOLUME_MAX
#define VOLUME_MAX
Definition: avf_showcqt.c:50
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
cbrtf
static av_always_inline float cbrtf(float x)
Definition: libm.h:61
TLENGTH_MIN
#define TLENGTH_MIN
Definition: avf_showcqt.c:49
rgb::r
uint8_t r
Definition: rpzaenc.c:60
OFFSET
#define OFFSET(x)
Definition: avf_showcqt.c:56
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
len
int len
Definition: vorbis_enc_data.h:426
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
draw_bar_rgb
static void draw_bar_rgb(AVFrame *out, const float *h, const float *rcp_h, const ColorFloat *c, int bar_h, float bar_t)
Definition: avf_showcqt.c:756
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:598
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:652
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
Coeffs::start
int start
Definition: avf_showcqt.h:30
log2
#define log2(x)
Definition: libm.h:404
cqt_calc
static void cqt_calc(AVComplexFloat *dst, const AVComplexFloat *src, const Coeffs *coeffs, int len, int fft_len)
Definition: avf_showcqt.c:269
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showcqt.c:1562
common_uninit
static void common_uninit(ShowCQTContext *s)
Definition: avf_showcqt.c:107
AVFilter
Filter definition.
Definition: avfilter.h:166
plot_cqt
static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout)
Definition: avf_showcqt.c:1129
ret
ret
Definition: filter_design.txt:187
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showcqt.c:1350
FONTCOLOR
#define FONTCOLOR
Definition: avf_showcqt.c:51
showcqt_options
static const AVOption showcqt_options[]
Definition: avf_showcqt.c:59
AVFrame::height
int height
Definition: frame.h:402
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:572
Coeffs
Definition: af_atilt.c:28
channel_layout.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVCOL_SPC_FCC
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:600
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
midi
static double midi(void *p, double f)
Definition: avf_showcqt.c:434
avf_showcqt.h
cm
#define cm
Definition: dvbsubdec.c:39
init_cqt
static int init_cqt(ShowCQTContext *s)
Definition: avf_showcqt.c:296
update_sono_yuv
static void update_sono_yuv(AVFrame *sono, const ColorFloat *c, int idx)
Definition: avf_showcqt.c:1064
ff_showcqt_init_x86
void ff_showcqt_init_x86(ShowCQTContext *s)
Definition: avf_showcqt_init.c:47
lavfutils.h
g_func
static double g_func(void *p, double x)
Definition: avf_showcqt.c:445
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
Definition: avf_showcqt.c:1480
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:505
BASEFREQ
#define BASEFREQ
Definition: avf_showcqt.c:46
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:111
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
ff_make_channel_layout_list
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition: formats.c:410
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:375
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(showcqt)
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:597
int
int
Definition: ffmpeg_filter.c:354
ff_scale_image
int ff_scale_image(uint8_t *dst_data[4], int dst_linesize[4], int dst_w, int dst_h, enum AVPixelFormat dst_pix_fmt, uint8_t *const src_data[4], int src_linesize[4], int src_w, int src_h, enum AVPixelFormat src_pix_fmt, void *log_ctx)
Scale image using libswscale.
Definition: lswsutils.c:22
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
lswsutils.h
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60
draw_sono
static void draw_sono(AVFrame *out, AVFrame *sono, int off, int idx)
Definition: avf_showcqt.c:1027
av_clipd
av_clipd
Definition: af_crystalizer.c:132
DRAW_BAR_WITH_CHROMA
#define DRAW_BAR_WITH_CHROMA(x)
Definition: avf_showcqt.c:783
init_axis_empty
static int init_axis_empty(ShowCQTContext *s)
Definition: avf_showcqt.c:395
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2856
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:204
tx.h
re
float re
Definition: fft.c:79
funcs
CheckasmFunc * funcs
Definition: checkasm.c:301
min
float min
Definition: vorbis_enc_data.h:429
render_fontconfig
static int render_fontconfig(ShowCQTContext *s, AVFrame *tmp, char *font)
Definition: avf_showcqt.c:588