28#include <lv2/lv2plug.in/ns/ext/atom/atom.h>
29#include <lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
30#include <lv2/lv2plug.in/ns/ext/options/options.h>
97#define OFFSET(x) offsetof(LV2Context, x)
98#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
107 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
108 {
"n",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
126 for (
i = 0;
i <
table->n_uris;
i++) {
136 const size_t len = strlen(uri);
140 for (
i = 0;
i <
table->n_uris;
i++) {
141 if (!strcmp(
table->uris[
i], uri)) {
148 return table->n_uris;
155 return table->n_uris;
160 return table->n_uris;
167 if (urid > 0 && urid <= table->n_uris) {
168 return table->uris[urid - 1];
177 int ich = 0, och = 0,
i;
179 for (
i = 0;
i <
s->nb_ports;
i++) {
180 const LilvPort *port = lilv_plugin_get_port_by_index(
s->plugin,
i);
182 if (lilv_port_is_a(
s->plugin, port,
s->lv2_AudioPort) ||
183 lilv_port_is_a(
s->plugin, port,
s->lv2_CVPort)) {
184 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort)) {
186 }
else if (lilv_port_is_a(
s->plugin, port,
s->lv2_OutputPort)) {
187 lilv_instance_connect_port(
s->instance,
i,
out->extended_data[och++]);
191 }
else if (lilv_port_is_a(
s->plugin, port,
s->atom_AtomPort)) {
192 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort)) {
193 lilv_instance_connect_port(
s->instance,
i, &
s->seq_in);
195 lilv_instance_connect_port(
s->instance,
i,
s->seq_out);
197 }
else if (lilv_port_is_a(
s->plugin, port,
s->lv2_ControlPort)) {
198 lilv_instance_connect_port(
s->instance,
i, &
s->controls[
i]);
202 s->seq_in[0].atom.size =
sizeof(LV2_Atom_Sequence_Body);
203 s->seq_in[0].atom.type =
uri_table_map(&
s->uri_table, LV2_ATOM__Sequence);
204 s->seq_out->atom.size = 9624;
214 if (!
s->nb_outputs ||
247 if (
s->duration >= 0 && t >=
s->duration)
256 lilv_instance_run(
s->instance,
out->nb_samples);
258 out->sample_rate =
s->sample_rate;
260 s->pts +=
s->nb_samples;
266 { LV2_BUF_SIZE__powerOf2BlockLength,
NULL },
267 { LV2_BUF_SIZE__fixedBlockLength,
NULL },
268 { LV2_BUF_SIZE__boundedBlockLength,
NULL },
275 char *p, *
arg, *saveptr =
NULL;
279 s->map.handle = &
s->uri_table;
281 s->map_feature.URI = LV2_URID_MAP_URI;
282 s->map_feature.data = &
s->map;
283 s->unmap.handle = &
s->uri_table;
285 s->unmap_feature.URI = LV2_URID_UNMAP_URI;
286 s->unmap_feature.data = &
s->unmap;
287 s->features[0] = &
s->map_feature;
288 s->features[1] = &
s->unmap_feature;
292 s->features[5] = &
s->options_feature;
293 s->features[6] =
NULL;
295 if (
ctx->nb_inputs) {
300 if (
s->nb_inputs ==
s->nb_outputs) {
306 if (lilv_plugin_has_feature(
s->plugin,
s->powerOf2BlockLength) ||
307 lilv_plugin_has_feature(
s->plugin,
s->fixedBlockLength) ||
308 lilv_plugin_has_feature(
s->plugin,
s->boundedBlockLength)) {
317 s->max_block_length =
s->nb_samples;
321 if (
s->max_block_length) {
322 s->host_options[nb_options++] = (LV2_Options_Option) {
323 LV2_OPTIONS_INSTANCE, 0,
325 sizeof(
s->max_block_length),
330 s->host_options[nb_options] = (LV2_Options_Option) {
331 LV2_OPTIONS_INSTANCE, 0, 0, 0, 0,
NULL
333 s->options_feature.URI = LV2_OPTIONS__options;
334 s->options_feature.data =
s->host_options;
336 s->instance = lilv_plugin_instantiate(
s->plugin, sample_rate,
s->features);
338 av_log(
ctx,
AV_LOG_ERROR,
"Failed to instantiate <%s>\n", lilv_node_as_uri(lilv_plugin_get_uri(
s->plugin)));
344 s->controls =
av_calloc(
s->nb_ports,
sizeof(
float));
346 if (!
s->mins || !
s->maxes || !
s->controls)
349 lilv_plugin_get_port_ranges_float(
s->plugin,
s->mins,
s->maxes,
s->controls);
350 s->seq_out =
av_malloc(
sizeof(LV2_Atom_Sequence) + 9624);
354 if (
s->options && !strcmp(
s->options,
"help")) {
355 if (!
s->nb_inputcontrols) {
357 "The '%s' plugin does not have any input controls.\n",
361 "The '%s' plugin has the following input controls:\n",
363 for (
i = 0;
i <
s->nb_ports;
i++) {
364 const LilvPort *port = lilv_plugin_get_port_by_index(
s->plugin,
i);
365 const LilvNode *symbol = lilv_port_get_symbol(
s->plugin, port);
366 LilvNode *
name = lilv_port_get_name(
s->plugin, port);
368 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort) &&
369 lilv_port_is_a(
s->plugin, port,
s->lv2_ControlPort)) {
371 lilv_node_as_string(symbol),
s->mins[
i],
s->maxes[
i],
s->controls[
i],
372 lilv_node_as_string(
name));
375 lilv_node_free(
name);
383 const LilvPort *port;
393 vstr = strstr(
arg,
"=");
402 sym = lilv_new_string(
s->world, str);
403 port = lilv_plugin_get_port_by_symbol(
s->plugin, sym);
408 index = lilv_port_get_index(
s->plugin, port);
413 lilv_instance_activate(
s->instance);
414 s->instance_activated = 1;
422 const LilvPlugins *plugins;
423 const LilvPlugin *plugin;
428 s->world = lilv_world_new();
432 uri = lilv_new_uri(
s->world,
s->plugin_uri);
438 lilv_world_load_all(
s->world);
439 plugins = lilv_world_get_all_plugins(
s->world);
440 plugin = lilv_plugins_get_by_uri(plugins, uri);
449 s->nb_ports = lilv_plugin_get_num_ports(
s->plugin);
451 s->lv2_InputPort = lilv_new_uri(
s->world, LV2_CORE__InputPort);
452 s->lv2_OutputPort = lilv_new_uri(
s->world, LV2_CORE__OutputPort);
453 s->lv2_AudioPort = lilv_new_uri(
s->world, LV2_CORE__AudioPort);
454 s->lv2_ControlPort = lilv_new_uri(
s->world, LV2_CORE__ControlPort);
455 s->lv2_Optional = lilv_new_uri(
s->world, LV2_CORE__connectionOptional);
456 s->atom_AtomPort = lilv_new_uri(
s->world, LV2_ATOM__AtomPort);
457 s->atom_Sequence = lilv_new_uri(
s->world, LV2_ATOM__Sequence);
458 s->urid_map = lilv_new_uri(
s->world, LV2_URID__map);
459 s->powerOf2BlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__powerOf2BlockLength);
460 s->fixedBlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__fixedBlockLength);
461 s->boundedBlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__boundedBlockLength);
463 for (
i = 0;
i <
s->nb_ports;
i++) {
464 const LilvPort *lport = lilv_plugin_get_port_by_index(
s->plugin,
i);
468 is_optional = lilv_port_has_property(
s->plugin, lport,
s->lv2_Optional);
470 if (lilv_port_is_a(
s->plugin, lport,
s->lv2_InputPort)) {
472 }
else if (!lilv_port_is_a(
s->plugin, lport,
s->lv2_OutputPort) && !is_optional) {
476 if (lilv_port_is_a(
s->plugin, lport,
s->lv2_ControlPort)) {
478 s->nb_inputcontrols++;
480 }
else if (lilv_port_is_a(
s->plugin, lport,
s->lv2_AudioPort)) {
524 if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
533 if (
s->nb_inputs >= 1) {
544 if (!
s->nb_outputs) {
551 if (
s->nb_outputs >= 1) {
568 char *res,
int res_len,
int flags)
571 const LilvPort *port;
575 sym = lilv_new_string(
s->world, cmd);
576 port = lilv_plugin_get_port_by_symbol(
s->plugin, sym);
581 index = lilv_port_get_index(
s->plugin, port);
582 s->controls[
index] = atof(args);
591 if (
s->instance_activated)
592 lilv_instance_deactivate(
s->instance);
593 lilv_node_free(
s->powerOf2BlockLength);
594 lilv_node_free(
s->fixedBlockLength);
595 lilv_node_free(
s->boundedBlockLength);
596 lilv_node_free(
s->urid_map);
597 lilv_node_free(
s->atom_Sequence);
598 lilv_node_free(
s->atom_AtomPort);
599 lilv_node_free(
s->lv2_Optional);
600 lilv_node_free(
s->lv2_ControlPort);
601 lilv_node_free(
s->lv2_AudioPort);
602 lilv_node_free(
s->lv2_OutputPort);
603 lilv_node_free(
s->lv2_InputPort);
605 lilv_instance_free(
s->instance);
606 lilv_world_free(
s->world);
625 .p.priv_class = &lv2_class,
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int request_frame(AVFilterLink *outlink)
static const AVFilterPad lv2_outputs[]
static const char * uri_table_unmap(LV2_URID_Map_Handle handle, LV2_URID urid)
static void uri_table_init(URITable *table)
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 int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static av_cold void uninit(AVFilterContext *ctx)
static void connect_ports(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
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 AVFormatContext * ctx
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
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,...)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
static const uint16_t channel_layouts[7]
static const int sample_rates[]
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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...
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#define AV_CHANNEL_LAYOUT_STEREO
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
#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.
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 av_cold void uninit(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_OUTPUTS(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
enum MovChannelLayoutTag * layouts
static const uint16_t table[]
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
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
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
int format
agreed upon media format
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.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
int min_samples
Minimum number of samples to filter at once.
int max_samples
Maximum number of samples to filter at once.
LilvNode * lv2_ControlPort
LV2_Atom_Sequence seq_in[2]
LV2_Atom_Sequence * seq_out
const LV2_Feature * features[7]
LilvNode * boundedBlockLength
LV2_Feature unmap_feature
LilvNode * powerOf2BlockLength
LilvNode * lv2_OutputPort
LV2_Options_Option host_options[2]
LilvNode * fixedBlockLength
LV2_Feature options_feature
unsigned nb_inputcontrols
const LilvPlugin * plugin