FFmpeg
af_ladspa.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Paul B Mahol
3  * Copyright (c) 2011 Mina Nagy Zaki
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * LADSPA wrapper
25  */
26 
27 #include <dlfcn.h>
28 #include <ladspa.h>
29 #include "libavutil/avassert.h"
30 #include "libavutil/avstring.h"
32 #include "libavutil/fifo.h"
33 #include "libavutil/mem.h"
34 #include "libavutil/opt.h"
35 #include "audio.h"
36 #include "avfilter.h"
37 #include "filters.h"
38 #include "formats.h"
39 
40 typedef struct MetaItem {
41  int64_t pts;
42  int nb_samples;
43 } MetaItem;
44 
45 typedef struct LADSPAContext {
46  const AVClass *class;
47  char *dl_name;
48  char *plugin;
49  char *options;
50  void *dl_handle;
51 
52  unsigned long nb_inputs;
53  unsigned long *ipmap; /* map input number to port number */
54 
55  unsigned long nb_inputcontrols;
56  unsigned long *icmap; /* map input control number to port number */
57  LADSPA_Data *ictlv; /* input controls values */
58 
59  unsigned long nb_outputs;
60  unsigned long *opmap; /* map output number to port number */
61 
62  unsigned long nb_outputcontrols;
63  unsigned long *ocmap; /* map output control number to port number */
64  LADSPA_Data *octlv; /* output controls values */
65 
66  const LADSPA_Descriptor *desc;
69  LADSPA_Handle *handles;
70 
77  int in_trim;
78  int out_pad;
79  int latency;
80 
83 
84 #define OFFSET(x) offsetof(LADSPAContext, x)
85 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
86 static const AVOption ladspa_options[] = {
87  { "file", "set library name or full path", OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
88  { "f", "set library name or full path", OFFSET(dl_name), AV_OPT_TYPE_STRING, .flags = FLAGS },
89  { "plugin", "set plugin name", OFFSET(plugin), AV_OPT_TYPE_STRING, .flags = FLAGS },
90  { "p", "set plugin name", OFFSET(plugin), AV_OPT_TYPE_STRING, .flags = FLAGS },
91  { "controls", "set plugin options", OFFSET(options), AV_OPT_TYPE_STRING, .flags = FLAGS },
92  { "c", "set plugin options", OFFSET(options), AV_OPT_TYPE_STRING, .flags = FLAGS },
93  { "sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT32_MAX, FLAGS },
94  { "s", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT32_MAX, FLAGS },
95  { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, FLAGS },
96  { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, FLAGS },
97  { "duration", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
98  { "d", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
99  { "latency", "enable latency compensation", OFFSET(latency), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
100  { "l", "enable latency compensation", OFFSET(latency), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
101  { NULL }
102 };
103 
104 AVFILTER_DEFINE_CLASS(ladspa);
105 
107 {
108  int latency = 0;
109 
110  for (int ctl = 0; ctl < s->nb_outputcontrols; ctl++) {
111  if (av_strcasecmp("latency", s->desc->PortNames[s->ocmap[ctl]]))
112  continue;
113 
114  latency = lrintf(s->octlv[ctl]);
115  break;
116  }
117 
118  return latency;
119 }
120 
122  LADSPAContext *s, int ctl, unsigned long *map,
123  LADSPA_Data *values, int print)
124 {
125  const LADSPA_PortRangeHint *h = s->desc->PortRangeHints + map[ctl];
126 
127  av_log(ctx, level, "c%i: %s [", ctl, s->desc->PortNames[map[ctl]]);
128 
129  if (LADSPA_IS_HINT_TOGGLED(h->HintDescriptor)) {
130  av_log(ctx, level, "toggled (1 or 0)");
131 
132  if (LADSPA_IS_HINT_HAS_DEFAULT(h->HintDescriptor))
133  av_log(ctx, level, " (default %i)", (int)values[ctl]);
134  } else {
135  if (LADSPA_IS_HINT_INTEGER(h->HintDescriptor)) {
136  av_log(ctx, level, "<int>");
137 
138  if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor))
139  av_log(ctx, level, ", min: %i", (int)h->LowerBound);
140 
141  if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor))
142  av_log(ctx, level, ", max: %i", (int)h->UpperBound);
143 
144  if (print)
145  av_log(ctx, level, " (value %d)", (int)values[ctl]);
146  else if (LADSPA_IS_HINT_HAS_DEFAULT(h->HintDescriptor))
147  av_log(ctx, level, " (default %d)", (int)values[ctl]);
148  } else {
149  av_log(ctx, level, "<float>");
150 
151  if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor))
152  av_log(ctx, level, ", min: %f", h->LowerBound);
153 
154  if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor))
155  av_log(ctx, level, ", max: %f", h->UpperBound);
156 
157  if (print)
158  av_log(ctx, level, " (value %f)", values[ctl]);
159  else if (LADSPA_IS_HINT_HAS_DEFAULT(h->HintDescriptor))
160  av_log(ctx, level, " (default %f)", values[ctl]);
161  }
162 
163  if (LADSPA_IS_HINT_SAMPLE_RATE(h->HintDescriptor))
164  av_log(ctx, level, ", multiple of sample rate");
165 
166  if (LADSPA_IS_HINT_LOGARITHMIC(h->HintDescriptor))
167  av_log(ctx, level, ", logarithmic scale");
168  }
169 
170  av_log(ctx, level, "]\n");
171 }
172 
174 {
175  AVFilterContext *ctx = inlink->dst;
176  LADSPAContext *s = ctx->priv;
177  AVFrame *out;
178  int i, h, p, new_out_samples;
179  int64_t out_duration;
180  int64_t in_duration;
181  int64_t in_pts;
182  MetaItem meta;
183 
184  av_assert0(in->ch_layout.nb_channels == (s->nb_inputs * s->nb_handles));
185 
186  if (!s->nb_outputs ||
187  (av_frame_is_writable(in) && s->nb_inputs == s->nb_outputs &&
188  s->in_trim == 0 && s->out_pad == 0 &&
189  !(s->desc->Properties & LADSPA_PROPERTY_INPLACE_BROKEN))) {
190  out = in;
191  } else {
192  out = ff_get_audio_buffer(ctx->outputs[0], in->nb_samples);
193  if (!out) {
194  av_frame_free(&in);
195  return AVERROR(ENOMEM);
196  }
198  }
199 
200  av_assert0(!s->nb_outputs || out->ch_layout.nb_channels == (s->nb_outputs * s->nb_handles));
201 
202  for (h = 0; h < s->nb_handles; h++) {
203  for (i = 0; i < s->nb_inputs; i++) {
204  p = s->nb_handles > 1 ? h : i;
205  s->desc->connect_port(s->handles[h], s->ipmap[i],
206  (LADSPA_Data*)in->extended_data[p]);
207  }
208 
209  for (i = 0; i < s->nb_outputs; i++) {
210  p = s->nb_handles > 1 ? h : i;
211  s->desc->connect_port(s->handles[h], s->opmap[i],
212  (LADSPA_Data*)out->extended_data[p]);
213  }
214 
215  s->desc->run(s->handles[h], in->nb_samples);
216  if (s->latency)
217  s->in_trim = s->out_pad = find_latency(ctx, s);
218  s->latency = 0;
219  }
220 
221  for (i = 0; i < s->nb_outputcontrols; i++)
222  print_ctl_info(ctx, AV_LOG_VERBOSE, s, i, s->ocmap, s->octlv, 1);
223 
224  meta = (MetaItem){ in->pts, in->nb_samples };
225  av_fifo_write(s->fifo, &meta, 1);
226 
227  if (out != in)
228  av_frame_free(&in);
229 
230  new_out_samples = out->nb_samples;
231  if (s->in_trim > 0) {
232  int trim = FFMIN(new_out_samples, s->in_trim);
233 
234  new_out_samples -= trim;
235  s->in_trim -= trim;
236  }
237 
238  if (new_out_samples <= 0) {
239  av_frame_free(&out);
240  return 0;
241  } else if (new_out_samples < out->nb_samples) {
242  int offset = out->nb_samples - new_out_samples;
243  for (int ch = 0; ch < out->ch_layout.nb_channels; ch++)
244  memmove(out->extended_data[ch], out->extended_data[ch] + sizeof(float) * offset,
245  sizeof(float) * new_out_samples);
246  out->nb_samples = new_out_samples;
247  }
248 
249  av_fifo_read(s->fifo, &meta, 1);
250 
251  out_duration = av_rescale_q(out->nb_samples, inlink->time_base, av_make_q(1, out->sample_rate));
252  in_duration = av_rescale_q(meta.nb_samples, inlink->time_base, av_make_q(1, out->sample_rate));
253  in_pts = meta.pts;
254 
255  if (s->next_out_pts != AV_NOPTS_VALUE && out->pts != s->next_out_pts &&
256  s->next_in_pts != AV_NOPTS_VALUE && in_pts == s->next_in_pts) {
257  out->pts = s->next_out_pts;
258  } else {
259  out->pts = in_pts;
260  }
261  s->next_in_pts = in_pts + in_duration;
262  s->next_out_pts = out->pts + out_duration;
263 
264  return ff_filter_frame(ctx->outputs[0], out);
265 }
266 
267 static int request_frame(AVFilterLink *outlink)
268 {
269  AVFilterContext *ctx = outlink->src;
270  LADSPAContext *s = ctx->priv;
271  AVFrame *out;
272  int64_t t;
273  int i;
274 
275  if (ctx->nb_inputs) {
276  int ret = ff_request_frame(ctx->inputs[0]);
277 
278  if (ret == AVERROR_EOF && s->out_pad > 0) {
279  AVFrame *frame = ff_get_audio_buffer(outlink, FFMIN(2048, s->out_pad));
280  if (!frame)
281  return AVERROR(ENOMEM);
282 
283  s->out_pad -= frame->nb_samples;
284  frame->pts = s->next_in_pts;
285  return filter_frame(ctx->inputs[0], frame);
286  }
287  return ret;
288  }
289 
290  t = av_rescale(s->pts, AV_TIME_BASE, s->sample_rate);
291  if (s->duration >= 0 && t >= s->duration)
292  return AVERROR_EOF;
293 
294  out = ff_get_audio_buffer(outlink, s->nb_samples);
295  if (!out)
296  return AVERROR(ENOMEM);
297 
298  for (i = 0; i < s->nb_outputs; i++)
299  s->desc->connect_port(s->handles[0], s->opmap[i],
300  (LADSPA_Data*)out->extended_data[i]);
301 
302  s->desc->run(s->handles[0], s->nb_samples);
303 
304  for (i = 0; i < s->nb_outputcontrols; i++)
305  print_ctl_info(ctx, AV_LOG_INFO, s, i, s->ocmap, s->octlv, 1);
306 
307  out->sample_rate = s->sample_rate;
308  out->pts = s->pts;
309  s->pts += s->nb_samples;
310 
311  return ff_filter_frame(outlink, out);
312 }
313 
314 static void set_default_ctl_value(LADSPAContext *s, int ctl,
315  unsigned long *map, LADSPA_Data *values)
316 {
317  const LADSPA_PortRangeHint *h = s->desc->PortRangeHints + map[ctl];
318  const LADSPA_Data lower = h->LowerBound;
319  const LADSPA_Data upper = h->UpperBound;
320 
321  if (LADSPA_IS_HINT_DEFAULT_MINIMUM(h->HintDescriptor)) {
322  values[ctl] = lower;
323  } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(h->HintDescriptor)) {
324  values[ctl] = upper;
325  } else if (LADSPA_IS_HINT_DEFAULT_0(h->HintDescriptor)) {
326  values[ctl] = 0.0;
327  } else if (LADSPA_IS_HINT_DEFAULT_1(h->HintDescriptor)) {
328  values[ctl] = 1.0;
329  } else if (LADSPA_IS_HINT_DEFAULT_100(h->HintDescriptor)) {
330  values[ctl] = 100.0;
331  } else if (LADSPA_IS_HINT_DEFAULT_440(h->HintDescriptor)) {
332  values[ctl] = 440.0;
333  } else if (LADSPA_IS_HINT_DEFAULT_LOW(h->HintDescriptor)) {
334  if (LADSPA_IS_HINT_LOGARITHMIC(h->HintDescriptor))
335  values[ctl] = exp(log(lower) * 0.75 + log(upper) * 0.25);
336  else
337  values[ctl] = lower * 0.75 + upper * 0.25;
338  } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(h->HintDescriptor)) {
339  if (LADSPA_IS_HINT_LOGARITHMIC(h->HintDescriptor))
340  values[ctl] = exp(log(lower) * 0.5 + log(upper) * 0.5);
341  else
342  values[ctl] = lower * 0.5 + upper * 0.5;
343  } else if (LADSPA_IS_HINT_DEFAULT_HIGH(h->HintDescriptor)) {
344  if (LADSPA_IS_HINT_LOGARITHMIC(h->HintDescriptor))
345  values[ctl] = exp(log(lower) * 0.25 + log(upper) * 0.75);
346  else
347  values[ctl] = lower * 0.25 + upper * 0.75;
348  }
349 }
350 
352 {
353  LADSPAContext *s = ctx->priv;
354  int i, j;
355 
356  s->nb_handles = s->nb_inputs == 1 && s->nb_outputs == 1 ? link->ch_layout.nb_channels : 1;
357  s->handles = av_calloc(s->nb_handles, sizeof(*s->handles));
358  if (!s->handles)
359  return AVERROR(ENOMEM);
360 
361  for (i = 0; i < s->nb_handles; i++) {
362  s->handles[i] = s->desc->instantiate(s->desc, link->sample_rate);
363  if (!s->handles[i]) {
364  av_log(ctx, AV_LOG_ERROR, "Could not instantiate plugin.\n");
365  return AVERROR_EXTERNAL;
366  }
367 
368  // Connect the input control ports
369  for (j = 0; j < s->nb_inputcontrols; j++)
370  s->desc->connect_port(s->handles[i], s->icmap[j], s->ictlv + j);
371 
372  // Connect the output control ports
373  for (j = 0; j < s->nb_outputcontrols; j++)
374  s->desc->connect_port(s->handles[i], s->ocmap[j], &s->octlv[j]);
375 
376  if (s->desc->activate)
377  s->desc->activate(s->handles[i]);
378  }
379 
380  av_log(ctx, AV_LOG_DEBUG, "handles: %d\n", s->nb_handles);
381 
382  return 0;
383 }
384 
386 {
387  AVFilterContext *ctx = inlink->dst;
388 
389  return connect_ports(ctx, inlink);
390 }
391 
392 static int config_output(AVFilterLink *outlink)
393 {
394  AVFilterContext *ctx = outlink->src;
395  LADSPAContext *s = ctx->priv;
396  int ret;
397 
398  if (ctx->nb_inputs) {
399  AVFilterLink *inlink = ctx->inputs[0];
400 
401  outlink->format = inlink->format;
402  outlink->sample_rate = inlink->sample_rate;
403  if (s->nb_inputs == s->nb_outputs) {
404  if ((ret = av_channel_layout_copy(&outlink->ch_layout, &inlink->ch_layout)) < 0)
405  return ret;
406  }
407 
408  ret = 0;
409  } else {
410  outlink->sample_rate = s->sample_rate;
411  outlink->time_base = (AVRational){1, s->sample_rate};
412 
413  ret = connect_ports(ctx, outlink);
414  }
415 
416  return ret;
417 }
418 
419 static void count_ports(const LADSPA_Descriptor *desc,
420  unsigned long *nb_inputs, unsigned long *nb_outputs)
421 {
422  LADSPA_PortDescriptor pd;
423  int i;
424 
425  for (i = 0; i < desc->PortCount; i++) {
426  pd = desc->PortDescriptors[i];
427 
428  if (LADSPA_IS_PORT_AUDIO(pd)) {
429  if (LADSPA_IS_PORT_INPUT(pd)) {
430  (*nb_inputs)++;
431  } else if (LADSPA_IS_PORT_OUTPUT(pd)) {
432  (*nb_outputs)++;
433  }
434  }
435  }
436 }
437 
438 static void *try_load(const char *dir, const char *soname)
439 {
440  char *path = av_asprintf("%s/%s.so", dir, soname);
441  void *ret = NULL;
442 
443  if (path) {
444  ret = dlopen(path, RTLD_LOCAL|RTLD_NOW);
445  av_free(path);
446  }
447 
448  return ret;
449 }
450 
451 static int set_control(AVFilterContext *ctx, unsigned long port, LADSPA_Data value)
452 {
453  LADSPAContext *s = ctx->priv;
454  const char *label = s->desc->Label;
455  LADSPA_PortRangeHint *h = (LADSPA_PortRangeHint *)s->desc->PortRangeHints +
456  s->icmap[port];
457 
458  if (port >= s->nb_inputcontrols) {
459  av_log(ctx, AV_LOG_ERROR, "Control c%ld is out of range [0 - %lu].\n",
460  port, s->nb_inputcontrols);
461  return AVERROR(EINVAL);
462  }
463 
464  if (LADSPA_IS_HINT_BOUNDED_BELOW(h->HintDescriptor) &&
465  value < h->LowerBound) {
467  "%s: input control c%ld is below lower boundary of %0.4f.\n",
468  label, port, h->LowerBound);
469  return AVERROR(EINVAL);
470  }
471 
472  if (LADSPA_IS_HINT_BOUNDED_ABOVE(h->HintDescriptor) &&
473  value > h->UpperBound) {
475  "%s: input control c%ld is above upper boundary of %0.4f.\n",
476  label, port, h->UpperBound);
477  return AVERROR(EINVAL);
478  }
479 
480  s->ictlv[port] = value;
481 
482  return 0;
483 }
484 
486 {
487  LADSPAContext *s = ctx->priv;
488  LADSPA_Descriptor_Function descriptor_fn;
489  const LADSPA_Descriptor *desc;
490  LADSPA_PortDescriptor pd;
491  AVFilterPad pad = { NULL };
492  char *p, *arg, *saveptr = NULL;
493  unsigned long nb_ports;
494  int i, j = 0, ret;
495 
496  if (!s->dl_name) {
497  av_log(ctx, AV_LOG_ERROR, "No plugin name provided\n");
498  return AVERROR(EINVAL);
499  }
500 
501  if (s->dl_name[0] == '/' || s->dl_name[0] == '.') {
502  // argument is a path
503  s->dl_handle = dlopen(s->dl_name, RTLD_LOCAL|RTLD_NOW);
504  } else {
505  // argument is a shared object name
506  char *paths = av_strdup(getenv("LADSPA_PATH"));
507  const char *home_path = getenv("HOME");
508  const char *separator = ":";
509 
510  if (paths) {
511  p = paths;
512  while ((arg = av_strtok(p, separator, &saveptr)) && !s->dl_handle) {
513  s->dl_handle = try_load(arg, s->dl_name);
514  p = NULL;
515  }
516  }
517 
518  av_free(paths);
519  if (!s->dl_handle && home_path && (paths = av_asprintf("%s/.ladspa", home_path))) {
520  s->dl_handle = try_load(paths, s->dl_name);
521  av_free(paths);
522  }
523 
524  if (!s->dl_handle && home_path && (paths = av_asprintf("%s/.ladspa/lib", home_path))) {
525  s->dl_handle = try_load(paths, s->dl_name);
526  av_free(paths);
527  }
528 
529  if (!s->dl_handle)
530  s->dl_handle = try_load("/usr/local/lib/ladspa", s->dl_name);
531 
532  if (!s->dl_handle)
533  s->dl_handle = try_load("/usr/lib/ladspa", s->dl_name);
534  }
535  if (!s->dl_handle) {
536  av_log(ctx, AV_LOG_ERROR, "Failed to load '%s'\n", s->dl_name);
537  return AVERROR(EINVAL);
538  }
539 
540  descriptor_fn = dlsym(s->dl_handle, "ladspa_descriptor");
541  if (!descriptor_fn) {
542  av_log(ctx, AV_LOG_ERROR, "Could not find ladspa_descriptor: %s\n", dlerror());
543  return AVERROR(EINVAL);
544  }
545 
546  // Find the requested plugin, or list plugins
547  if (!s->plugin) {
548  av_log(ctx, AV_LOG_INFO, "The '%s' library contains the following plugins:\n", s->dl_name);
549  av_log(ctx, AV_LOG_INFO, "I = Input Channels\n");
550  av_log(ctx, AV_LOG_INFO, "O = Output Channels\n");
551  av_log(ctx, AV_LOG_INFO, "I:O %-25s %s\n", "Plugin", "Description");
552  av_log(ctx, AV_LOG_INFO, "\n");
553  for (i = 0; desc = descriptor_fn(i); i++) {
554  unsigned long inputs = 0, outputs = 0;
555 
557  av_log(ctx, AV_LOG_INFO, "%lu:%lu %-25s %s\n", inputs, outputs, desc->Label,
558  (char *)av_x_if_null(desc->Name, "?"));
559  av_log(ctx, AV_LOG_VERBOSE, "Maker: %s\n",
560  (char *)av_x_if_null(desc->Maker, "?"));
561  av_log(ctx, AV_LOG_VERBOSE, "Copyright: %s\n",
562  (char *)av_x_if_null(desc->Copyright, "?"));
563  }
564  return AVERROR_EXIT;
565  } else {
566  for (i = 0;; i++) {
567  desc = descriptor_fn(i);
568  if (!desc) {
569  av_log(ctx, AV_LOG_ERROR, "Could not find plugin: %s\n", s->plugin);
570  return AVERROR(EINVAL);
571  }
572 
573  if (desc->Label && !strcmp(desc->Label, s->plugin))
574  break;
575  }
576  }
577 
578  s->desc = desc;
579  nb_ports = desc->PortCount;
580 
581  s->ipmap = av_calloc(nb_ports, sizeof(*s->ipmap));
582  s->opmap = av_calloc(nb_ports, sizeof(*s->opmap));
583  s->icmap = av_calloc(nb_ports, sizeof(*s->icmap));
584  s->ocmap = av_calloc(nb_ports, sizeof(*s->ocmap));
585  s->ictlv = av_calloc(nb_ports, sizeof(*s->ictlv));
586  s->octlv = av_calloc(nb_ports, sizeof(*s->octlv));
587  s->ctl_needs_value = av_calloc(nb_ports, sizeof(*s->ctl_needs_value));
588  if (!s->ipmap || !s->opmap || !s->icmap ||
589  !s->ocmap || !s->ictlv || !s->octlv || !s->ctl_needs_value)
590  return AVERROR(ENOMEM);
591 
592  for (i = 0; i < nb_ports; i++) {
593  pd = desc->PortDescriptors[i];
594 
595  if (LADSPA_IS_PORT_AUDIO(pd)) {
596  if (LADSPA_IS_PORT_INPUT(pd)) {
597  s->ipmap[s->nb_inputs] = i;
598  s->nb_inputs++;
599  } else if (LADSPA_IS_PORT_OUTPUT(pd)) {
600  s->opmap[s->nb_outputs] = i;
601  s->nb_outputs++;
602  }
603  } else if (LADSPA_IS_PORT_CONTROL(pd)) {
604  if (LADSPA_IS_PORT_INPUT(pd)) {
605  s->icmap[s->nb_inputcontrols] = i;
606 
607  if (LADSPA_IS_HINT_HAS_DEFAULT(desc->PortRangeHints[i].HintDescriptor))
608  set_default_ctl_value(s, s->nb_inputcontrols, s->icmap, s->ictlv);
609  else
610  s->ctl_needs_value[s->nb_inputcontrols] = 1;
611 
612  s->nb_inputcontrols++;
613  } else if (LADSPA_IS_PORT_OUTPUT(pd)) {
614  s->ocmap[s->nb_outputcontrols] = i;
615  s->nb_outputcontrols++;
616  }
617  }
618  }
619 
620  // List Control Ports if "help" is specified
621  if (s->options && !strcmp(s->options, "help")) {
622  if (!s->nb_inputcontrols) {
624  "The '%s' plugin does not have any input controls.\n",
625  desc->Label);
626  } else {
628  "The '%s' plugin has the following input controls:\n",
629  desc->Label);
630  for (i = 0; i < s->nb_inputcontrols; i++)
631  print_ctl_info(ctx, AV_LOG_INFO, s, i, s->icmap, s->ictlv, 0);
632  }
633  return AVERROR_EXIT;
634  }
635 
636  // Parse control parameters
637  p = s->options;
638  while (s->options) {
639  LADSPA_Data val;
640  int ret;
641 
642  if (!(arg = av_strtok(p, " |", &saveptr)))
643  break;
644  p = NULL;
645 
646  if (av_sscanf(arg, "c%d=%f", &i, &val) != 2) {
647  if (av_sscanf(arg, "%f", &val) != 1) {
648  av_log(ctx, AV_LOG_ERROR, "Invalid syntax.\n");
649  return AVERROR(EINVAL);
650  }
651  i = j++;
652  }
653 
654  if ((ret = set_control(ctx, i, val)) < 0)
655  return ret;
656  s->ctl_needs_value[i] = 0;
657  }
658 
659  // Check if any controls are not set
660  for (i = 0; i < s->nb_inputcontrols; i++) {
661  if (s->ctl_needs_value[i]) {
662  av_log(ctx, AV_LOG_ERROR, "Control c%d must be set.\n", i);
663  print_ctl_info(ctx, AV_LOG_ERROR, s, i, s->icmap, s->ictlv, 0);
664  return AVERROR(EINVAL);
665  }
666  }
667 
668  pad.type = AVMEDIA_TYPE_AUDIO;
669 
670  if (s->nb_inputs) {
671  pad.name = av_asprintf("in0:%s%lu", desc->Label, s->nb_inputs);
672  if (!pad.name)
673  return AVERROR(ENOMEM);
674 
677  if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0)
678  return ret;
679  }
680 
681  av_log(ctx, AV_LOG_DEBUG, "ports: %lu\n", nb_ports);
682  av_log(ctx, AV_LOG_DEBUG, "inputs: %lu outputs: %lu\n",
683  s->nb_inputs, s->nb_outputs);
684  av_log(ctx, AV_LOG_DEBUG, "input controls: %lu output controls: %lu\n",
685  s->nb_inputcontrols, s->nb_outputcontrols);
686 
687  s->next_out_pts = AV_NOPTS_VALUE;
688  s->next_in_pts = AV_NOPTS_VALUE;
689 
690  s->fifo = av_fifo_alloc2(8, sizeof(MetaItem), AV_FIFO_FLAG_AUTO_GROW);
691  if (!s->fifo)
692  return AVERROR(ENOMEM);
693 
694  return 0;
695 }
696 
698  AVFilterFormatsConfig **cfg_in,
699  AVFilterFormatsConfig **cfg_out)
700 {
701  const LADSPAContext *s = ctx->priv;
703  static const enum AVSampleFormat sample_fmts[] = {
705  int ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, sample_fmts);
706  if (ret < 0)
707  return ret;
708 
709  if (!s->nb_inputs) {
710  int sample_rates[] = { s->sample_rate, -1 };
711 
713  if (ret < 0)
714  return ret;
715  }
716 
717  if (s->nb_inputs == 1 && s->nb_outputs == 1) {
718  // We will instantiate multiple LADSPA_Handle, one over each channel
719  ret = ff_set_common_all_channel_counts2(ctx, cfg_in, cfg_out);
720  if (ret < 0)
721  return ret;
722  } else if (s->nb_inputs == 2 && s->nb_outputs == 2) {
723  layouts = NULL;
725  if (ret < 0)
726  return ret;
727  ret = ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, layouts);
728  if (ret < 0)
729  return ret;
730  } else {
731  if (s->nb_inputs >= 1) {
732  AVChannelLayout inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
733 
734  layouts = NULL;
735  ret = ff_add_channel_layout(&layouts, &inlayout);
736  if (ret < 0)
737  return ret;
739  if (ret < 0)
740  return ret;
741 
742  if (!s->nb_outputs) {
744  if (ret < 0)
745  return ret;
746  }
747  }
748 
749  if (s->nb_outputs >= 1) {
750  AVChannelLayout outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
751 
752  layouts = NULL;
753  ret = ff_add_channel_layout(&layouts, &outlayout);
754  if (ret < 0)
755  return ret;
757  if (ret < 0)
758  return ret;
759  }
760  }
761 
762  return 0;
763 }
764 
766 {
767  LADSPAContext *s = ctx->priv;
768  int i;
769 
770  for (i = 0; i < s->nb_handles; i++) {
771  if (s->desc->deactivate)
772  s->desc->deactivate(s->handles[i]);
773  if (s->desc->cleanup)
774  s->desc->cleanup(s->handles[i]);
775  }
776 
777  if (s->dl_handle)
778  dlclose(s->dl_handle);
779 
780  av_freep(&s->ipmap);
781  av_freep(&s->opmap);
782  av_freep(&s->icmap);
783  av_freep(&s->ocmap);
784  av_freep(&s->ictlv);
785  av_freep(&s->octlv);
786  av_freep(&s->handles);
787  av_freep(&s->ctl_needs_value);
788 
789  av_fifo_freep2(&s->fifo);
790 }
791 
792 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
793  char *res, int res_len, int flags)
794 {
795  LADSPA_Data value;
796  unsigned long port;
797 
798  if (av_sscanf(cmd, "c%ld", &port) + av_sscanf(args, "%f", &value) != 2)
799  return AVERROR(EINVAL);
800 
801  return set_control(ctx, port, value);
802 }
803 
804 static const AVFilterPad ladspa_outputs[] = {
805  {
806  .name = "default",
807  .type = AVMEDIA_TYPE_AUDIO,
808  .config_props = config_output,
809  .request_frame = request_frame,
810  },
811 };
812 
814  .name = "ladspa",
815  .description = NULL_IF_CONFIG_SMALL("Apply LADSPA effect."),
816  .priv_size = sizeof(LADSPAContext),
817  .priv_class = &ladspa_class,
818  .init = init,
819  .uninit = uninit,
821  .inputs = 0,
825 };
LADSPAContext::nb_inputs
unsigned long nb_inputs
Definition: af_ladspa.c:52
try_load
static void * try_load(const char *dir, const char *soname)
Definition: af_ladspa.c:438
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:98
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
level
uint8_t level
Definition: svq3.c:205
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
ff_set_common_channel_layouts2
int ff_set_common_channel_layouts2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterChannelLayouts *channel_layouts)
Helpers for query_formats2() which set all free audio links to the same list of channel layouts/sampl...
Definition: formats.c:911
out
FILE * out
Definition: movenc.c:55
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:387
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1025
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:673
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:335
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
ff_set_common_all_channel_counts2
int ff_set_common_all_channel_counts2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:928
int64_t
long long int64_t
Definition: coverity.c:34
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
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:115
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:207
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(ladspa)
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:162
sample_rates
static const int sample_rates[]
Definition: dcaenc.h:34
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:501
AVOption
AVOption.
Definition: opt.h:429
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition: opt.h:319
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:473
LADSPAContext::handles
LADSPA_Handle * handles
Definition: af_ladspa.c:69
LADSPAContext::ctl_needs_value
int * ctl_needs_value
Definition: af_ladspa.c:67
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
LADSPAContext
Definition: af_ladspa.c:45
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_ladspa.c:392
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_ladspa.c:765
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:321
LADSPAContext::options
char * options
Definition: af_ladspa.c:49
LADSPAContext::icmap
unsigned long * icmap
Definition: af_ladspa.c:56
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_ladspa.c:792
formats.h
LADSPAContext::nb_outputs
unsigned long nb_outputs
Definition: af_ladspa.c:59
connect_ports
static int connect_ports(AVFilterContext *ctx, AVFilterLink *link)
Definition: af_ladspa.c:351
LADSPAContext::next_in_pts
int64_t next_in_pts
Definition: af_ladspa.c:73
fifo.h
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_ladspa.c:173
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
LADSPAContext::nb_handles
int nb_handles
Definition: af_ladspa.c:68
LADSPAContext::desc
const LADSPA_Descriptor * desc
Definition: af_ladspa.c:66
val
static double val(void *priv, double ch)
Definition: aeval.c:77
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_ladspa.c:267
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:790
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:141
LADSPAContext::plugin
char * plugin
Definition: af_ladspa.c:48
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
LADSPAContext::out_pad
int out_pad
Definition: af_ladspa.c:78
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
duration
int64_t duration
Definition: movenc.c:65
s
#define s(width, name)
Definition: cbs_vp9.c:198
LADSPAContext::sample_rate
int sample_rate
Definition: af_ladspa.c:71
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_strtok
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:178
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
filters.h
LADSPAContext::dl_handle
void * dl_handle
Definition: af_ladspa.c:50
ff_set_common_samplerates_from_list2
int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *samplerates)
Definition: formats.c:944
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ctx
AVFormatContext * ctx
Definition: movenc.c:49
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
LADSPAContext::ipmap
unsigned long * ipmap
Definition: af_ladspa.c:53
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
LADSPAContext::next_out_pts
int64_t next_out_pts
Definition: af_ladspa.c:74
link
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 link
Definition: filter_design.txt:23
arg
const char * arg
Definition: jacosubdec.c:67
if
if(ret)
Definition: filter_design.txt:179
av_sscanf
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:961
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
LADSPAContext::ictlv
LADSPA_Data * ictlv
Definition: af_ladspa.c:57
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:713
LADSPAContext::in_trim
int in_trim
Definition: af_ladspa.c:77
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_append_inpad_free_name
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:131
OFFSET
#define OFFSET(x)
Definition: af_ladspa.c:84
count_ports
static void count_ports(const LADSPA_Descriptor *desc, unsigned long *nb_inputs, unsigned long *nb_outputs)
Definition: af_ladspa.c:419
AVFilterPad::filter_frame
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: filters.h:93
MetaItem::pts
int64_t pts
Definition: af_alimiter.c:38
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_ladspa.c:385
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:521
exp
int8_t exp
Definition: eval.c:73
LADSPAContext::ocmap
unsigned long * ocmap
Definition: af_ladspa.c:63
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:111
print_ctl_info
static void print_ctl_info(AVFilterContext *ctx, int level, LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values, int print)
Definition: af_ladspa.c:121
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: filters.h:118
options
const OptionDef options[]
AVFifo
Definition: fifo.c:35
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:94
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:311
LADSPAContext::nb_inputcontrols
unsigned long nb_inputcontrols
Definition: af_ladspa.c:55
set_control
static int set_control(AVFilterContext *ctx, unsigned long port, LADSPA_Data value)
Definition: af_ladspa.c:451
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:588
print
static void print(AVTreeNode *t, int depth)
Definition: tree.c:45
LADSPAContext::dl_name
char * dl_name
Definition: af_ladspa.c:47
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:649
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
offset
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 offset
Definition: writing_filters.txt:86
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:469
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
LADSPAContext::latency
int latency
Definition: af_ladspa.c:79
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:450
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:239
value
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 value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
outputs
static const AVFilterPad outputs[]
Definition: af_aap.c:310
AVFilter
Filter definition.
Definition: avfilter.h:201
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: filters.h:49
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
FF_COUNT2LAYOUT
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
ff_af_ladspa
const AVFilter ff_af_ladspa
Definition: af_ladspa.c:813
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
LADSPAContext::duration
int64_t duration
Definition: af_ladspa.c:76
ff_set_common_formats_from_list2
int ff_set_common_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *fmts)
Definition: formats.c:1016
channel_layout.h
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
values
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
Definition: filter_design.txt:263
MetaItem
Definition: af_alimiter.c:37
query_formats
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: af_ladspa.c:697
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
MetaItem::nb_samples
int nb_samples
Definition: af_alimiter.c:39
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:444
find_latency
static int find_latency(AVFilterContext *ctx, LADSPAContext *s)
Definition: af_ladspa.c:106
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
set_default_ctl_value
static void set_default_ctl_value(LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values)
Definition: af_ladspa.c:314
desc
const char * desc
Definition: libsvtav1.c:79
mem.h
audio.h
LADSPAContext::octlv
LADSPA_Data * octlv
Definition: af_ladspa.c:64
LADSPAContext::opmap
unsigned long * opmap
Definition: af_ladspa.c:60
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ladspa_options
static const AVOption ladspa_options[]
Definition: af_ladspa.c:86
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:112
ladspa_outputs
static const AVFilterPad ladspa_outputs[]
Definition: af_ladspa.c:804
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
FLAGS
#define FLAGS
Definition: af_ladspa.c:85
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
h
h
Definition: vp9dsp_template.c:2070
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
LADSPAContext::fifo
AVFifo * fifo
Definition: af_ladspa.c:81
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_ladspa.c:485
LADSPAContext::pts
int64_t pts
Definition: af_ladspa.c:75
LADSPAContext::nb_outputcontrols
unsigned long nb_outputcontrols
Definition: af_ladspa.c:62
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:63
av_x_if_null
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:312
LADSPAContext::nb_samples
int nb_samples
Definition: af_ladspa.c:72