Go to the documentation of this file.
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>
93 #define OFFSET(x) offsetof(LV2Context, x)
94 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
103 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
104 {
"n",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
122 for (
i = 0;
i <
table->n_uris;
i++) {
132 const size_t len = strlen(uri);
136 for (
i = 0;
i <
table->n_uris;
i++) {
137 if (!strcmp(
table->uris[
i], uri)) {
144 return table->n_uris;
151 return table->n_uris;
156 return table->n_uris;
163 if (urid > 0 && urid <= table->n_uris) {
164 return table->uris[urid - 1];
173 int ich = 0, och = 0,
i;
175 for (
i = 0;
i <
s->nb_ports;
i++) {
176 const LilvPort *port = lilv_plugin_get_port_by_index(
s->plugin,
i);
178 if (lilv_port_is_a(
s->plugin, port,
s->lv2_AudioPort) ||
179 lilv_port_is_a(
s->plugin, port,
s->lv2_CVPort)) {
180 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort)) {
182 }
else if (lilv_port_is_a(
s->plugin, port,
s->lv2_OutputPort)) {
183 lilv_instance_connect_port(
s->instance,
i,
out->extended_data[och++]);
187 }
else if (lilv_port_is_a(
s->plugin, port,
s->atom_AtomPort)) {
188 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort)) {
189 lilv_instance_connect_port(
s->instance,
i, &
s->seq_in);
191 lilv_instance_connect_port(
s->instance,
i,
s->seq_out);
193 }
else if (lilv_port_is_a(
s->plugin, port,
s->lv2_ControlPort)) {
194 lilv_instance_connect_port(
s->instance,
i, &
s->controls[
i]);
198 s->seq_in[0].atom.size =
sizeof(LV2_Atom_Sequence_Body);
199 s->seq_in[0].atom.type =
uri_table_map(&
s->uri_table, LV2_ATOM__Sequence);
200 s->seq_out->atom.size = 9624;
210 if (!
s->nb_outputs ||
243 if (
s->duration >= 0 && t >=
s->duration)
252 lilv_instance_run(
s->instance,
out->nb_samples);
254 out->sample_rate =
s->sample_rate;
256 s->pts +=
s->nb_samples;
262 { LV2_BUF_SIZE__powerOf2BlockLength,
NULL },
263 { LV2_BUF_SIZE__fixedBlockLength,
NULL },
264 { LV2_BUF_SIZE__boundedBlockLength,
NULL },
275 s->map.handle = &
s->uri_table;
277 s->map_feature.URI = LV2_URID_MAP_URI;
278 s->map_feature.data = &
s->map;
279 s->unmap.handle = &
s->uri_table;
281 s->unmap_feature.URI = LV2_URID_UNMAP_URI;
282 s->unmap_feature.data = &
s->unmap;
283 s->features[0] = &
s->map_feature;
284 s->features[1] = &
s->unmap_feature;
289 if (
ctx->nb_inputs) {
294 if (
s->nb_inputs ==
s->nb_outputs) {
305 s->instance = lilv_plugin_instantiate(
s->plugin, sample_rate,
s->features);
307 av_log(
ctx,
AV_LOG_ERROR,
"Failed to instantiate <%s>\n", lilv_node_as_uri(lilv_plugin_get_uri(
s->plugin)));
313 s->controls =
av_calloc(
s->nb_ports,
sizeof(
float));
315 if (!
s->mins || !
s->maxes || !
s->controls)
318 lilv_plugin_get_port_ranges_float(
s->plugin,
s->mins,
s->maxes,
s->controls);
319 s->seq_out =
av_malloc(
sizeof(LV2_Atom_Sequence) + 9624);
323 if (
s->options && !strcmp(
s->options,
"help")) {
324 if (!
s->nb_inputcontrols) {
326 "The '%s' plugin does not have any input controls.\n",
330 "The '%s' plugin has the following input controls:\n",
332 for (
i = 0;
i <
s->nb_ports;
i++) {
333 const LilvPort *port = lilv_plugin_get_port_by_index(
s->plugin,
i);
334 const LilvNode *symbol = lilv_port_get_symbol(
s->plugin, port);
335 LilvNode *
name = lilv_port_get_name(
s->plugin, port);
337 if (lilv_port_is_a(
s->plugin, port,
s->lv2_InputPort) &&
338 lilv_port_is_a(
s->plugin, port,
s->lv2_ControlPort)) {
340 lilv_node_as_string(symbol),
s->mins[
i],
s->maxes[
i],
s->controls[
i],
341 lilv_node_as_string(
name));
344 lilv_node_free(
name);
352 const LilvPort *port;
362 vstr = strstr(
arg,
"=");
371 sym = lilv_new_string(
s->world, str);
372 port = lilv_plugin_get_port_by_symbol(
s->plugin, sym);
377 index = lilv_port_get_index(
s->plugin, port);
383 (lilv_plugin_has_feature(
s->plugin,
s->powerOf2BlockLength) ||
384 lilv_plugin_has_feature(
s->plugin,
s->fixedBlockLength) ||
385 lilv_plugin_has_feature(
s->plugin,
s->boundedBlockLength))) {
391 lilv_instance_activate(
s->instance);
392 s->instance_activated = 1;
400 const LilvPlugins *plugins;
401 const LilvPlugin *plugin;
406 s->world = lilv_world_new();
410 uri = lilv_new_uri(
s->world,
s->plugin_uri);
416 lilv_world_load_all(
s->world);
417 plugins = lilv_world_get_all_plugins(
s->world);
418 plugin = lilv_plugins_get_by_uri(plugins, uri);
427 s->nb_ports = lilv_plugin_get_num_ports(
s->plugin);
429 s->lv2_InputPort = lilv_new_uri(
s->world, LV2_CORE__InputPort);
430 s->lv2_OutputPort = lilv_new_uri(
s->world, LV2_CORE__OutputPort);
431 s->lv2_AudioPort = lilv_new_uri(
s->world, LV2_CORE__AudioPort);
432 s->lv2_ControlPort = lilv_new_uri(
s->world, LV2_CORE__ControlPort);
433 s->lv2_Optional = lilv_new_uri(
s->world, LV2_CORE__connectionOptional);
434 s->atom_AtomPort = lilv_new_uri(
s->world, LV2_ATOM__AtomPort);
435 s->atom_Sequence = lilv_new_uri(
s->world, LV2_ATOM__Sequence);
436 s->urid_map = lilv_new_uri(
s->world, LV2_URID__map);
437 s->powerOf2BlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__powerOf2BlockLength);
438 s->fixedBlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__fixedBlockLength);
439 s->boundedBlockLength = lilv_new_uri(
s->world, LV2_BUF_SIZE__boundedBlockLength);
441 for (
i = 0;
i <
s->nb_ports;
i++) {
442 const LilvPort *lport = lilv_plugin_get_port_by_index(
s->plugin,
i);
446 is_optional = lilv_port_has_property(
s->plugin, lport,
s->lv2_Optional);
448 if (lilv_port_is_a(
s->plugin, lport,
s->lv2_InputPort)) {
450 }
else if (!lilv_port_is_a(
s->plugin, lport,
s->lv2_OutputPort) && !is_optional) {
454 if (lilv_port_is_a(
s->plugin, lport,
s->lv2_ControlPort)) {
456 s->nb_inputcontrols++;
458 }
else if (lilv_port_is_a(
s->plugin, lport,
s->lv2_AudioPort)) {
502 if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
511 if (
s->nb_inputs >= 1) {
522 if (!
s->nb_outputs) {
529 if (
s->nb_outputs >= 1) {
546 char *res,
int res_len,
int flags)
549 const LilvPort *port;
553 sym = lilv_new_string(
s->world, cmd);
554 port = lilv_plugin_get_port_by_symbol(
s->plugin, sym);
559 index = lilv_port_get_index(
s->plugin, port);
560 s->controls[
index] = atof(args);
569 if (
s->instance_activated)
570 lilv_instance_deactivate(
s->instance);
571 lilv_node_free(
s->powerOf2BlockLength);
572 lilv_node_free(
s->fixedBlockLength);
573 lilv_node_free(
s->boundedBlockLength);
574 lilv_node_free(
s->urid_map);
575 lilv_node_free(
s->atom_Sequence);
576 lilv_node_free(
s->atom_AtomPort);
577 lilv_node_free(
s->lv2_Optional);
578 lilv_node_free(
s->lv2_ControlPort);
579 lilv_node_free(
s->lv2_AudioPort);
580 lilv_node_free(
s->lv2_OutputPort);
581 lilv_node_free(
s->lv2_InputPort);
583 lilv_instance_free(
s->instance);
584 lilv_world_free(
s->world);
603 .p.priv_class = &lv2_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
A list of supported channel layouts.
#define AV_LOG_WARNING
Something somehow does not look correct.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
LilvNode * lv2_OutputPort
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
#define AV_CHANNEL_LAYOUT_STEREO
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
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
char * av_asprintf(const char *fmt,...)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static const AVFilterPad lv2_outputs[]
static const int sample_rates[]
This structure describes decoded (raw) audio or video data.
static const uint16_t table[]
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
static av_cold int init(AVFilterContext *ctx)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
const char * name
Filter name.
static const AVOption lv2_options[]
A link between two filters.
Link properties exposed to filter code, but not external callers.
LilvNode * lv2_ControlPort
static double val(void *priv, double ch)
LilvNode * fixedBlockLength
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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().
const LV2_Feature * features[5]
static AVFormatContext * ctx
static av_cold void uninit(AVFilterContext *ctx)
#define FILTER_OUTPUTS(array)
Describe the class of an AVClass context structure.
LilvNode * boundedBlockLength
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
static void connect_ports(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
static void uri_table_init(URITable *table)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static FilterLink * ff_filter_link(AVFilterLink *link)
static void uri_table_destroy(URITable *table)
LV2_Atom_Sequence * seq_out
unsigned nb_inputcontrols
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
#define i(width, name, range_min, range_max)
int format
agreed upon media format
static LV2_URID uri_table_map(LV2_URID_Map_Handle handle, const char *uri)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
static int request_frame(AVFilterLink *outlink)
#define AV_LOG_INFO
Standard information.
int sample_rate
samples per second
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_TIME_BASE
Internal time base represented as integer.
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
const char * name
Pad name.
AVFILTER_DEFINE_CLASS(lv2)
LilvNode * powerOf2BlockLength
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)
enum AVMediaType type
AVFilterPad type.
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static int config_output(AVFilterLink *outlink)
static const LV2_Feature buf_size_features[3]
static const char * uri_table_unmap(LV2_URID_Map_Handle handle, LV2_URID urid)
@ AV_OPT_TYPE_INT
Underlying C type is int.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
AVFilter p
The public AVFilter.
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static const uint16_t channel_layouts[7]
LV2_Atom_Sequence seq_in[2]
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
@ 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...
const LilvPlugin * plugin
LV2_Feature unmap_feature