FFmpeg  4.4.9
af_lv2.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Paul B Mahol
3  * Copyright (c) 2007-2016 David Robillard <http://drobilla.net>
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  * LV2 wrapper
25  */
26 
27 #include <lilv/lilv.h>
28 #include <lv2/lv2plug.in/ns/ext/atom/atom.h>
29 #include <lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
30 
31 #include "libavutil/avassert.h"
32 #include "libavutil/avstring.h"
34 #include "libavutil/opt.h"
35 #include "audio.h"
36 #include "avfilter.h"
37 #include "internal.h"
38 
39 typedef struct URITable {
40  char **uris;
41  size_t n_uris;
42 } URITable;
43 
44 typedef struct LV2Context {
45  const AVClass *class;
46  char *plugin_uri;
47  char *options;
48 
49  unsigned nb_inputs;
50  unsigned nb_inputcontrols;
51  unsigned nb_outputs;
52 
57 
58  LilvWorld *world;
59  const LilvPlugin *plugin;
60  uint32_t nb_ports;
61  float *values;
63  LV2_URID_Map map;
64  LV2_Feature map_feature;
65  LV2_URID_Unmap unmap;
66  LV2_Feature unmap_feature;
67  LV2_Atom_Sequence seq_in[2];
68  LV2_Atom_Sequence *seq_out;
69  const LV2_Feature *features[6];
70 
71  float *mins;
72  float *maxes;
73  float *controls;
74 
75  LilvInstance *instance;
77 
78  LilvNode *atom_AtomPort;
79  LilvNode *atom_Sequence;
80  LilvNode *lv2_AudioPort;
81  LilvNode *lv2_CVPort;
82  LilvNode *lv2_ControlPort;
83  LilvNode *lv2_Optional;
84  LilvNode *lv2_InputPort;
85  LilvNode *lv2_OutputPort;
86  LilvNode *urid_map;
88  LilvNode *fixedBlockLength;
89  LilvNode *boundedBlockLength;
90 } LV2Context;
91 
92 #define OFFSET(x) offsetof(LV2Context, x)
93 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
94 
95 static const AVOption lv2_options[] = {
96  { "plugin", "set plugin uri", OFFSET(plugin_uri), AV_OPT_TYPE_STRING, .flags = FLAGS },
97  { "p", "set plugin uri", OFFSET(plugin_uri), AV_OPT_TYPE_STRING, .flags = FLAGS },
98  { "controls", "set plugin options", OFFSET(options), AV_OPT_TYPE_STRING, .flags = FLAGS },
99  { "c", "set plugin options", OFFSET(options), AV_OPT_TYPE_STRING, .flags = FLAGS },
100  { "sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT32_MAX, FLAGS },
101  { "s", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT32_MAX, FLAGS },
102  { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, FLAGS },
103  { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, FLAGS },
104  { "duration", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
105  { "d", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64=-1}, -1, INT64_MAX, FLAGS },
106  { NULL }
107 };
108 
110 
112 {
113  table->uris = NULL;
114  table->n_uris = 0;
115 }
116 
118 {
119  int i;
120 
121  for (i = 0; i < table->n_uris; i++) {
122  av_freep(&table->uris[i]);
123  }
124 
125  av_freep(&table->uris);
126 }
127 
128 static LV2_URID uri_table_map(LV2_URID_Map_Handle handle, const char *uri)
129 {
130  URITable *table = (URITable*)handle;
131  const size_t len = strlen(uri);
132  size_t i;
133  char **tmp;
134 
135  for (i = 0; i < table->n_uris; i++) {
136  if (!strcmp(table->uris[i], uri)) {
137  return i + 1;
138  }
139  }
140 
141  tmp = av_calloc(table->n_uris + 1, sizeof(char*));
142  if (!tmp)
143  return table->n_uris;
144  memcpy(tmp, table->uris, table->n_uris * sizeof(char**));
145 
146  av_free(table->uris);
147  table->uris = tmp;
148  table->uris[table->n_uris] = av_malloc(len + 1);
149  if (!table->uris[table->n_uris])
150  return table->n_uris;
151 
152  memcpy(table->uris[table->n_uris], uri, len + 1);
153  table->n_uris++;
154 
155  return table->n_uris;
156 }
157 
158 static const char *uri_table_unmap(LV2_URID_Map_Handle handle, LV2_URID urid)
159 {
160  URITable *table = (URITable*)handle;
161 
162  if (urid > 0 && urid <= table->n_uris) {
163  return table->uris[urid - 1];
164  }
165 
166  return NULL;
167 }
168 
170 {
171  int ich = 0, och = 0, i;
172 
173  for (i = 0; i < s->nb_ports; i++) {
174  const LilvPort *port = lilv_plugin_get_port_by_index(s->plugin, i);
175 
176  if (lilv_port_is_a(s->plugin, port, s->lv2_AudioPort) ||
177  lilv_port_is_a(s->plugin, port, s->lv2_CVPort)) {
178  if (lilv_port_is_a(s->plugin, port, s->lv2_InputPort)) {
179  lilv_instance_connect_port(s->instance, i, in->extended_data[ich++]);
180  } else if (lilv_port_is_a(s->plugin, port, s->lv2_OutputPort)) {
181  lilv_instance_connect_port(s->instance, i, out->extended_data[och++]);
182  } else {
183  av_log(s, AV_LOG_WARNING, "port %d neither input nor output, skipping\n", i);
184  }
185  } else if (lilv_port_is_a(s->plugin, port, s->atom_AtomPort)) {
186  if (lilv_port_is_a(s->plugin, port, s->lv2_InputPort)) {
187  lilv_instance_connect_port(s->instance, i, &s->seq_in);
188  } else {
189  lilv_instance_connect_port(s->instance, i, s->seq_out);
190  }
191  } else if (lilv_port_is_a(s->plugin, port, s->lv2_ControlPort)) {
192  lilv_instance_connect_port(s->instance, i, &s->controls[i]);
193  }
194  }
195 
196  s->seq_in[0].atom.size = sizeof(LV2_Atom_Sequence_Body);
197  s->seq_in[0].atom.type = uri_table_map(&s->uri_table, LV2_ATOM__Sequence);
198  s->seq_out->atom.size = 9624;
199  s->seq_out->atom.type = uri_table_map(&s->uri_table, LV2_ATOM__Chunk);
200 }
201 
202 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
203 {
204  AVFilterContext *ctx = inlink->dst;
205  LV2Context *s = ctx->priv;
206  AVFrame *out;
207 
208  if (!s->nb_outputs ||
209  (av_frame_is_writable(in) && s->nb_inputs == s->nb_outputs)) {
210  out = in;
211  } else {
212  out = ff_get_audio_buffer(ctx->outputs[0], in->nb_samples);
213  if (!out) {
214  av_frame_free(&in);
215  return AVERROR(ENOMEM);
216  }
218  }
219 
220  connect_ports(s, in, out);
221 
222  lilv_instance_run(s->instance, in->nb_samples);
223 
224  if (out != in)
225  av_frame_free(&in);
226 
227  return ff_filter_frame(ctx->outputs[0], out);
228 }
229 
230 static int request_frame(AVFilterLink *outlink)
231 {
232  AVFilterContext *ctx = outlink->src;
233  LV2Context *s = ctx->priv;
234  AVFrame *out;
235  int64_t t;
236 
237  if (ctx->nb_inputs)
238  return ff_request_frame(ctx->inputs[0]);
239 
240  t = av_rescale(s->pts, AV_TIME_BASE, s->sample_rate);
241  if (s->duration >= 0 && t >= s->duration)
242  return AVERROR_EOF;
243 
244  out = ff_get_audio_buffer(outlink, s->nb_samples);
245  if (!out)
246  return AVERROR(ENOMEM);
247 
248  connect_ports(s, out, out);
249 
250  lilv_instance_run(s->instance, out->nb_samples);
251 
252  out->sample_rate = s->sample_rate;
253  out->pts = s->pts;
254  s->pts += s->nb_samples;
255 
256  return ff_filter_frame(outlink, out);
257 }
258 
259 static const LV2_Feature buf_size_features[3] = {
260  { LV2_BUF_SIZE__powerOf2BlockLength, NULL },
261  { LV2_BUF_SIZE__fixedBlockLength, NULL },
262  { LV2_BUF_SIZE__boundedBlockLength, NULL },
263 };
264 
265 static int config_output(AVFilterLink *outlink)
266 {
267  AVFilterContext *ctx = outlink->src;
268  LV2Context *s = ctx->priv;
269  char *p, *arg, *saveptr = NULL;
270  int i, sample_rate;
271 
272  uri_table_init(&s->uri_table);
273  s->map.handle = &s->uri_table;
274  s->map.map = uri_table_map;
275  s->map_feature.URI = LV2_URID_MAP_URI;
276  s->map_feature.data = &s->map;
277  s->unmap.handle = &s->uri_table;
278  s->unmap.unmap = uri_table_unmap;
279  s->unmap_feature.URI = LV2_URID_UNMAP_URI;
280  s->unmap_feature.data = &s->unmap;
281  s->features[0] = &s->map_feature;
282  s->features[1] = &s->unmap_feature;
283  s->features[2] = &buf_size_features[0];
284  s->features[3] = &buf_size_features[1];
285  s->features[4] = &buf_size_features[2];
286  s->features[5] = NULL;
287 
288  if (ctx->nb_inputs) {
289  AVFilterLink *inlink = ctx->inputs[0];
290 
291  outlink->format = inlink->format;
292  outlink->sample_rate = sample_rate = inlink->sample_rate;
293  if (s->nb_inputs == s->nb_outputs) {
294  outlink->channel_layout = inlink->channel_layout;
295  outlink->channels = inlink->channels;
296  }
297 
298  } else {
299  outlink->sample_rate = sample_rate = s->sample_rate;
300  outlink->time_base = (AVRational){1, s->sample_rate};
301  }
302 
303  s->instance = lilv_plugin_instantiate(s->plugin, sample_rate, s->features);
304  if (!s->instance) {
305  av_log(s, AV_LOG_ERROR, "Failed to instantiate <%s>\n", lilv_node_as_uri(lilv_plugin_get_uri(s->plugin)));
306  return AVERROR(EINVAL);
307  }
308 
309  s->mins = av_calloc(s->nb_ports, sizeof(float));
310  s->maxes = av_calloc(s->nb_ports, sizeof(float));
311  s->controls = av_calloc(s->nb_ports, sizeof(float));
312 
313  if (!s->mins || !s->maxes || !s->controls)
314  return AVERROR(ENOMEM);
315 
316  lilv_plugin_get_port_ranges_float(s->plugin, s->mins, s->maxes, s->controls);
317  s->seq_out = av_malloc(sizeof(LV2_Atom_Sequence) + 9624);
318  if (!s->seq_out)
319  return AVERROR(ENOMEM);
320 
321  if (s->options && !strcmp(s->options, "help")) {
322  if (!s->nb_inputcontrols) {
324  "The '%s' plugin does not have any input controls.\n",
325  s->plugin_uri);
326  } else {
328  "The '%s' plugin has the following input controls:\n",
329  s->plugin_uri);
330  for (i = 0; i < s->nb_ports; i++) {
331  const LilvPort *port = lilv_plugin_get_port_by_index(s->plugin, i);
332  const LilvNode *symbol = lilv_port_get_symbol(s->plugin, port);
333  LilvNode *name = lilv_port_get_name(s->plugin, port);
334 
335  if (lilv_port_is_a(s->plugin, port, s->lv2_InputPort) &&
336  lilv_port_is_a(s->plugin, port, s->lv2_ControlPort)) {
337  av_log(ctx, AV_LOG_INFO, "%s\t\t<float> (from %f to %f) (default %f)\t\t%s\n",
338  lilv_node_as_string(symbol), s->mins[i], s->maxes[i], s->controls[i],
339  lilv_node_as_string(name));
340  }
341 
342  lilv_node_free(name);
343  }
344  }
345  return AVERROR_EXIT;
346  }
347 
348  p = s->options;
349  while (s->options) {
350  const LilvPort *port;
351  LilvNode *sym;
352  float val;
353  char *str, *vstr;
354  int index;
355 
356  if (!(arg = av_strtok(p, " |", &saveptr)))
357  break;
358  p = NULL;
359 
360  vstr = strstr(arg, "=");
361  if (vstr == NULL) {
362  av_log(ctx, AV_LOG_ERROR, "Invalid syntax.\n");
363  return AVERROR(EINVAL);
364  }
365 
366  vstr[0] = 0;
367  str = arg;
368  val = atof(vstr+1);
369  sym = lilv_new_string(s->world, str);
370  port = lilv_plugin_get_port_by_symbol(s->plugin, sym);
371  lilv_node_free(sym);
372  if (!port) {
373  av_log(s, AV_LOG_WARNING, "Unknown option: <%s>\n", str);
374  } else {
375  index = lilv_port_get_index(s->plugin, port);
376  s->controls[index] = val;
377  }
378  }
379 
380  if (s->nb_inputs &&
381  (lilv_plugin_has_feature(s->plugin, s->powerOf2BlockLength) ||
382  lilv_plugin_has_feature(s->plugin, s->fixedBlockLength) ||
383  lilv_plugin_has_feature(s->plugin, s->boundedBlockLength))) {
384  AVFilterLink *inlink = ctx->inputs[0];
385 
386  inlink->partial_buf_size = inlink->min_samples = inlink->max_samples = 4096;
387  }
388 
389  lilv_instance_activate(s->instance);
390  s->instance_activated = 1;
391 
392  return 0;
393 }
394 
396 {
397  LV2Context *s = ctx->priv;
398  const LilvPlugins *plugins;
399  const LilvPlugin *plugin;
400  AVFilterPad pad = { NULL };
401  LilvNode *uri;
402  int i;
403 
404  s->world = lilv_world_new();
405  if (!s->world)
406  return AVERROR(ENOMEM);
407 
408  uri = lilv_new_uri(s->world, s->plugin_uri);
409  if (!uri) {
410  av_log(s, AV_LOG_ERROR, "Invalid plugin URI <%s>\n", s->plugin_uri);
411  return AVERROR(EINVAL);
412  }
413 
414  lilv_world_load_all(s->world);
415  plugins = lilv_world_get_all_plugins(s->world);
416  plugin = lilv_plugins_get_by_uri(plugins, uri);
417  lilv_node_free(uri);
418 
419  if (!plugin) {
420  av_log(s, AV_LOG_ERROR, "Plugin <%s> not found\n", s->plugin_uri);
421  return AVERROR(EINVAL);
422  }
423 
424  s->plugin = plugin;
425  s->nb_ports = lilv_plugin_get_num_ports(s->plugin);
426 
427  s->lv2_InputPort = lilv_new_uri(s->world, LV2_CORE__InputPort);
428  s->lv2_OutputPort = lilv_new_uri(s->world, LV2_CORE__OutputPort);
429  s->lv2_AudioPort = lilv_new_uri(s->world, LV2_CORE__AudioPort);
430  s->lv2_ControlPort = lilv_new_uri(s->world, LV2_CORE__ControlPort);
431  s->lv2_Optional = lilv_new_uri(s->world, LV2_CORE__connectionOptional);
432  s->atom_AtomPort = lilv_new_uri(s->world, LV2_ATOM__AtomPort);
433  s->atom_Sequence = lilv_new_uri(s->world, LV2_ATOM__Sequence);
434  s->urid_map = lilv_new_uri(s->world, LV2_URID__map);
435  s->powerOf2BlockLength = lilv_new_uri(s->world, LV2_BUF_SIZE__powerOf2BlockLength);
436  s->fixedBlockLength = lilv_new_uri(s->world, LV2_BUF_SIZE__fixedBlockLength);
437  s->boundedBlockLength = lilv_new_uri(s->world, LV2_BUF_SIZE__boundedBlockLength);
438 
439  for (i = 0; i < s->nb_ports; i++) {
440  const LilvPort *lport = lilv_plugin_get_port_by_index(s->plugin, i);
441  int is_input = 0;
442  int is_optional = 0;
443 
444  is_optional = lilv_port_has_property(s->plugin, lport, s->lv2_Optional);
445 
446  if (lilv_port_is_a(s->plugin, lport, s->lv2_InputPort)) {
447  is_input = 1;
448  } else if (!lilv_port_is_a(s->plugin, lport, s->lv2_OutputPort) && !is_optional) {
449  return AVERROR(EINVAL);
450  }
451 
452  if (lilv_port_is_a(s->plugin, lport, s->lv2_ControlPort)) {
453  if (is_input) {
454  s->nb_inputcontrols++;
455  }
456  } else if (lilv_port_is_a(s->plugin, lport, s->lv2_AudioPort)) {
457  if (is_input) {
458  s->nb_inputs++;
459  } else {
460  s->nb_outputs++;
461  }
462  }
463  }
464 
465  pad.type = AVMEDIA_TYPE_AUDIO;
466 
467  if (s->nb_inputs) {
468  pad.name = av_asprintf("in0:%s:%u", s->plugin_uri, s->nb_inputs);
469  if (!pad.name)
470  return AVERROR(ENOMEM);
471 
473  if (ff_insert_inpad(ctx, ctx->nb_inputs, &pad) < 0) {
474  av_freep(&pad.name);
475  return AVERROR(ENOMEM);
476  }
477  }
478 
479  return 0;
480 }
481 
483 {
484  LV2Context *s = ctx->priv;
487  AVFilterLink *outlink = ctx->outputs[0];
488  static const enum AVSampleFormat sample_fmts[] = {
490  int ret;
491 
493  if (!formats)
494  return AVERROR(ENOMEM);
496  if (ret < 0)
497  return ret;
498 
499  if (s->nb_inputs) {
501  if (!formats)
502  return AVERROR(ENOMEM);
503 
505  if (ret < 0)
506  return ret;
507  } else {
508  int sample_rates[] = { s->sample_rate, -1 };
509 
511  if (ret < 0)
512  return ret;
513  }
514 
515  if (s->nb_inputs == 2 && s->nb_outputs == 2) {
516  layouts = NULL;
518  if (ret < 0)
519  return ret;
521  if (ret < 0)
522  return ret;
523  } else {
524  if (s->nb_inputs >= 1) {
525  AVFilterLink *inlink = ctx->inputs[0];
526  uint64_t inlayout = FF_COUNT2LAYOUT(s->nb_inputs);
527 
528  layouts = NULL;
529  ret = ff_add_channel_layout(&layouts, inlayout);
530  if (ret < 0)
531  return ret;
533  if (ret < 0)
534  return ret;
535 
536  if (!s->nb_outputs) {
538  if (ret < 0)
539  return ret;
540  }
541  }
542 
543  if (s->nb_outputs >= 1) {
544  uint64_t outlayout = FF_COUNT2LAYOUT(s->nb_outputs);
545 
546  layouts = NULL;
547  ret = ff_add_channel_layout(&layouts, outlayout);
548  if (ret < 0)
549  return ret;
551  if (ret < 0)
552  return ret;
553  }
554  }
555 
556  return 0;
557 }
558 
560 {
561  LV2Context *s = ctx->priv;
562 
563  if (s->instance_activated)
564  lilv_instance_deactivate(s->instance);
565  lilv_node_free(s->powerOf2BlockLength);
566  lilv_node_free(s->fixedBlockLength);
567  lilv_node_free(s->boundedBlockLength);
568  lilv_node_free(s->urid_map);
569  lilv_node_free(s->atom_Sequence);
570  lilv_node_free(s->atom_AtomPort);
571  lilv_node_free(s->lv2_Optional);
572  lilv_node_free(s->lv2_ControlPort);
573  lilv_node_free(s->lv2_AudioPort);
574  lilv_node_free(s->lv2_OutputPort);
575  lilv_node_free(s->lv2_InputPort);
576  uri_table_destroy(&s->uri_table);
577  lilv_instance_free(s->instance);
578  lilv_world_free(s->world);
579  av_freep(&s->mins);
580  av_freep(&s->maxes);
581  av_freep(&s->controls);
582  av_freep(&s->seq_out);
583 
584  if (ctx->nb_inputs)
585  av_freep(&ctx->input_pads[0].name);
586 }
587 
588 static const AVFilterPad lv2_outputs[] = {
589  {
590  .name = "default",
591  .type = AVMEDIA_TYPE_AUDIO,
592  .config_props = config_output,
593  .request_frame = request_frame,
594  },
595  { NULL }
596 };
597 
599  .name = "lv2",
600  .description = NULL_IF_CONFIG_SMALL("Apply LV2 effect."),
601  .priv_size = sizeof(LV2Context),
602  .priv_class = &lv2_class,
603  .init = init,
604  .uninit = uninit,
606  .inputs = 0,
607  .outputs = lv2_outputs,
609 };
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:925
static double val(void *priv, double ch)
Definition: aeval.c:76
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AVFILTER_DEFINE_CLASS(lv2)
AVFilter ff_af_lv2
Definition: af_lv2.c:598
static const AVFilterPad lv2_outputs[]
Definition: af_lv2.c:588
static void uri_table_init(URITable *table)
Definition: af_lv2.c:111
static int query_formats(AVFilterContext *ctx)
Definition: af_lv2.c:482
#define FLAGS
Definition: af_lv2.c:93
static int request_frame(AVFilterLink *outlink)
Definition: af_lv2.c:230
static const AVOption lv2_options[]
Definition: af_lv2.c:95
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_lv2.c:202
static void uri_table_destroy(URITable *table)
Definition: af_lv2.c:117
static void connect_ports(LV2Context *s, AVFrame *in, AVFrame *out)
Definition: af_lv2.c:169
static av_cold int init(AVFilterContext *ctx)
Definition: af_lv2.c:395
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_lv2.c:559
#define OFFSET(x)
Definition: af_lv2.c:92
static int config_output(AVFilterLink *outlink)
Definition: af_lv2.c:265
static LV2_URID uri_table_map(LV2_URID_Map_Handle handle, const char *uri)
Definition: af_lv2.c:128
static const LV2_Feature buf_size_features[3]
Definition: af_lv2.c:259
static const char * uri_table_unmap(LV2_URID_Map_Handle handle, LV2_URID urid)
Definition: af_lv2.c:158
#define av_cold
Definition: attributes.h:88
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:411
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
audio channel layout utility functions
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
const OptionDef options[]
sample_rates
sample_rate
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:338
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:575
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:461
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
Definition: formats.c:568
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:421
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:103
@ AV_OPT_TYPE_DURATION
Definition: opt.h:239
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AV_CH_LAYOUT_STEREO
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:106
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AVERROR(e)
Definition: error.h:43
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
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:186
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
int index
Definition: gxfenc.c:89
int i
Definition: input.c:407
const char * arg
Definition: jacosubdec.c:67
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:240
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVOptions.
static const uint16_t table[]
Definition: prosumer.c:206
const char * name
Definition: qsvenc.c:46
formats
Definition: signature.h:48
Describe the class of an AVClass context structure.
Definition: log.h:67
A list of supported channel layouts.
Definition: formats.h:86
An instance of a filter.
Definition: avfilter.h:341
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:455
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: internal.h:93
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
Rational number (pair of numerator and denominator).
Definition: rational.h:58
const LV2_Feature * features[6]
Definition: af_lv2.c:69
float * mins
Definition: af_lv2.c:71
LilvNode * lv2_ControlPort
Definition: af_lv2.c:82
LV2_URID_Unmap unmap
Definition: af_lv2.c:65
LilvNode * lv2_InputPort
Definition: af_lv2.c:84
LV2_Atom_Sequence seq_in[2]
Definition: af_lv2.c:67
unsigned nb_outputs
Definition: af_lv2.c:51
float * maxes
Definition: af_lv2.c:72
LilvNode * atom_AtomPort
Definition: af_lv2.c:78
int nb_samples
Definition: af_lv2.c:54
float * values
Definition: af_lv2.c:61
char * options
Definition: af_lv2.c:47
int instance_activated
Definition: af_lv2.c:76
LilvNode * urid_map
Definition: af_lv2.c:86
LV2_Atom_Sequence * seq_out
Definition: af_lv2.c:68
uint32_t nb_ports
Definition: af_lv2.c:60
float * controls
Definition: af_lv2.c:73
LilvNode * boundedBlockLength
Definition: af_lv2.c:89
LilvInstance * instance
Definition: af_lv2.c:75
URITable uri_table
Definition: af_lv2.c:62
LV2_Feature unmap_feature
Definition: af_lv2.c:66
int64_t pts
Definition: af_lv2.c:55
int64_t duration
Definition: af_lv2.c:56
LilvNode * lv2_CVPort
Definition: af_lv2.c:81
LilvNode * powerOf2BlockLength
Definition: af_lv2.c:87
LilvNode * lv2_AudioPort
Definition: af_lv2.c:80
LilvNode * lv2_OutputPort
Definition: af_lv2.c:85
LV2_Feature map_feature
Definition: af_lv2.c:64
LilvNode * fixedBlockLength
Definition: af_lv2.c:88
int sample_rate
Definition: af_lv2.c:53
LilvNode * lv2_Optional
Definition: af_lv2.c:83
LV2_URID_Map map
Definition: af_lv2.c:63
LilvNode * atom_Sequence
Definition: af_lv2.c:79
unsigned nb_inputs
Definition: af_lv2.c:49
LilvWorld * world
Definition: af_lv2.c:58
char * plugin_uri
Definition: af_lv2.c:46
unsigned nb_inputcontrols
Definition: af_lv2.c:50
const LilvPlugin * plugin
Definition: af_lv2.c:59
size_t n_uris
Definition: af_lv2.c:41
char ** uris
Definition: af_lv2.c:40
#define av_free(p)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
FILE * out
Definition: movenc.c:54
int64_t duration
Definition: movenc.c:64
AVFormatContext * ctx
Definition: movenc.c:48
int len