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>
92 #define OFFSET(x) offsetof(LV2Context, x)
93 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
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 },
121 for (
i = 0;
i <
table->n_uris;
i++) {
131 const size_t len = strlen(uri);
135 for (
i = 0;
i <
table->n_uris;
i++) {
136 if (!strcmp(
table->uris[
i], uri)) {
143 return table->n_uris;
150 return table->n_uris;
155 return table->n_uris;
162 if (urid > 0 && urid <= table->n_uris) {
163 return table->uris[urid - 1];
171 int ich = 0, och = 0,
i;
173 for (
i = 0;
i <
s->nb_ports;
i++) {
174 const LilvPort *port = lilv_plugin_get_port_by_index(
s->plugin,
i);
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++]);
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);
189 lilv_instance_connect_port(
s->instance,
i,
s->seq_out);
191 }
else if (lilv_port_is_a(
s->plugin, port,
s->lv2_ControlPort)) {
192 lilv_instance_connect_port(
s->instance,
i, &
s->controls[
i]);
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;
208 if (!
s->nb_outputs ||
222 lilv_instance_run(
s->instance,
in->nb_samples);
241 if (
s->duration >= 0 && t >=
s->duration)
250 lilv_instance_run(
s->instance,
out->nb_samples);
252 out->sample_rate =
s->sample_rate;
254 s->pts +=
s->nb_samples;
260 { LV2_BUF_SIZE__powerOf2BlockLength,
NULL },
261 { LV2_BUF_SIZE__fixedBlockLength,
NULL },
262 { LV2_BUF_SIZE__boundedBlockLength,
NULL },
269 char *p, *
arg, *saveptr =
NULL;
273 s->map.handle = &
s->uri_table;
275 s->map_feature.URI = LV2_URID_MAP_URI;
276 s->map_feature.data = &
s->map;
277 s->unmap.handle = &
s->uri_table;
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;
287 if (
ctx->nb_inputs) {
292 if (
s->nb_inputs ==
s->nb_outputs) {
302 s->instance = lilv_plugin_instantiate(
s->plugin,
sample_rate,
s->features);
304 av_log(
s,
AV_LOG_ERROR,
"Failed to instantiate <%s>\n", lilv_node_as_uri(lilv_plugin_get_uri(
s->plugin)));
310 s->controls =
av_calloc(
s->nb_ports,
sizeof(
float));
312 if (!
s->mins || !
s->maxes || !
s->controls)
315 lilv_plugin_get_port_ranges_float(
s->plugin,
s->mins,
s->maxes,
s->controls);
316 s->seq_out =
av_malloc(
sizeof(LV2_Atom_Sequence) + 9624);
320 if (
s->options && !strcmp(
s->options,
"help")) {
321 if (!
s->nb_inputcontrols) {
323 "The '%s' plugin does not have any input controls.\n",
327 "The '%s' plugin has the following input controls:\n",
329 for (
i = 0;
i <
s->nb_ports;
i++) {
330 const LilvPort *port = lilv_plugin_get_port_by_index(
s->plugin,
i);
331 const LilvNode *symbol = lilv_port_get_symbol(
s->plugin, port);
332 LilvNode *
name = lilv_port_get_name(
s->plugin, port);
334 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort) &&
335 lilv_port_is_a(
s->plugin, port,
s->lv2_ControlPort)) {
337 lilv_node_as_string(symbol),
s->mins[
i],
s->maxes[
i],
s->controls[
i],
338 lilv_node_as_string(
name));
341 lilv_node_free(
name);
349 const LilvPort *port;
359 vstr = strstr(
arg,
"=");
368 sym = lilv_new_string(
s->world,
str);
369 port = lilv_plugin_get_port_by_symbol(
s->plugin, sym);
374 index = lilv_port_get_index(
s->plugin, port);
380 (lilv_plugin_has_feature(
s->plugin,
s->powerOf2BlockLength) ||
381 lilv_plugin_has_feature(
s->plugin,
s->fixedBlockLength) ||
382 lilv_plugin_has_feature(
s->plugin,
s->boundedBlockLength))) {
388 lilv_instance_activate(
s->instance);
389 s->instance_activated = 1;
397 const LilvPlugins *plugins;
398 const LilvPlugin *plugin;
403 s->world = lilv_world_new();
407 uri = lilv_new_uri(
s->world,
s->plugin_uri);
413 lilv_world_load_all(
s->world);
414 plugins = lilv_world_get_all_plugins(
s->world);
415 plugin = lilv_plugins_get_by_uri(plugins, uri);
424 s->nb_ports = lilv_plugin_get_num_ports(
s->plugin);
426 s->lv2_InputPort = lilv_new_uri(
s->world, LV2_CORE__InputPort);
427 s->lv2_OutputPort = lilv_new_uri(
s->world, LV2_CORE__OutputPort);
428 s->lv2_AudioPort = lilv_new_uri(
s->world, LV2_CORE__AudioPort);
429 s->lv2_ControlPort = lilv_new_uri(
s->world, LV2_CORE__ControlPort);
430 s->lv2_Optional = lilv_new_uri(
s->world, LV2_CORE__connectionOptional);
431 s->atom_AtomPort = lilv_new_uri(
s->world, LV2_ATOM__AtomPort);
432 s->atom_Sequence = lilv_new_uri(
s->world, LV2_ATOM__Sequence);
433 s->urid_map = lilv_new_uri(
s->world, LV2_URID__map);
434 s->powerOf2BlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__powerOf2BlockLength);
435 s->fixedBlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__fixedBlockLength);
436 s->boundedBlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__boundedBlockLength);
438 for (
i = 0;
i <
s->nb_ports;
i++) {
439 const LilvPort *lport = lilv_plugin_get_port_by_index(
s->plugin,
i);
443 is_optional = lilv_port_has_property(
s->plugin, lport,
s->lv2_Optional);
445 if (lilv_port_is_a(
s->plugin, lport,
s->lv2_InputPort)) {
447 }
else if (!lilv_port_is_a(
s->plugin, lport,
s->lv2_OutputPort) && !is_optional) {
451 if (lilv_port_is_a(
s->plugin, lport,
s->lv2_ControlPort)) {
453 s->nb_inputcontrols++;
455 }
else if (lilv_port_is_a(
s->plugin, lport,
s->lv2_AudioPort)) {
514 if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
523 if (
s->nb_inputs >= 1) {
535 if (!
s->nb_outputs) {
542 if (
s->nb_outputs >= 1) {
562 if (
s->instance_activated)
563 lilv_instance_deactivate(
s->instance);
564 lilv_node_free(
s->powerOf2BlockLength);
565 lilv_node_free(
s->fixedBlockLength);
566 lilv_node_free(
s->boundedBlockLength);
567 lilv_node_free(
s->urid_map);
568 lilv_node_free(
s->atom_Sequence);
569 lilv_node_free(
s->atom_AtomPort);
570 lilv_node_free(
s->lv2_Optional);
571 lilv_node_free(
s->lv2_ControlPort);
572 lilv_node_free(
s->lv2_AudioPort);
573 lilv_node_free(
s->lv2_OutputPort);
574 lilv_node_free(
s->lv2_InputPort);
576 lilv_instance_free(
s->instance);
577 lilv_world_free(
s->world);
601 .priv_class = &lv2_class,
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
AVFILTER_DEFINE_CLASS(lv2)
static const AVFilterPad lv2_outputs[]
static void uri_table_init(URITable *table)
static int query_formats(AVFilterContext *ctx)
static int request_frame(AVFilterLink *outlink)
static const AVOption lv2_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void uri_table_destroy(URITable *table)
static void connect_ports(LV2Context *s, AVFrame *in, AVFrame *out)
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static LV2_URID uri_table_map(LV2_URID_Map_Handle handle, const char *uri)
static const LV2_Feature buf_size_features[3]
static const char * uri_table_unmap(LV2_URID_Map_Handle handle, LV2_URID urid)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
#define flags(name, subs,...)
audio channel layout utility functions
const OptionDef options[]
#define AV_CH_LAYOUT_STEREO
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
#define AVERROR_EOF
End of file.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
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().
#define AV_TIME_BASE
Internal time base represented as integer.
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum MovChannelLayoutTag * layouts
static const uint16_t table[]
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
int max_samples
Maximum number of samples to filter at once.
int channels
Number of channels.
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
int partial_buf_size
Size of the partial buffer to allocate.
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
int format
agreed upon media format
int min_samples
Minimum number of samples to filter at once.
A filter pad used for either input or output.
enum AVMediaType type
AVFilterPad type.
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
Rational number (pair of numerator and denominator).
LilvNode * lv2_ControlPort
const LV2_Feature * features[5]
LV2_Atom_Sequence seq_in[2]
LV2_Atom_Sequence * seq_out
LilvNode * boundedBlockLength
LV2_Feature unmap_feature
LilvNode * powerOf2BlockLength
LilvNode * lv2_OutputPort
LilvNode * fixedBlockLength
unsigned nb_inputcontrols
const LilvPlugin * plugin