Go to the documentation of this file.
65 const LADSPA_Descriptor *
desc;
83 #define OFFSET(x) offsetof(LADSPAContext, x)
84 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
94 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
109 for (
int ctl = 0; ctl <
s->nb_outputcontrols; ctl++) {
113 latency =
lrintf(
s->octlv[ctl]);
124 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
128 if (LADSPA_IS_HINT_TOGGLED(
h->HintDescriptor)) {
131 if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
134 if (LADSPA_IS_HINT_INTEGER(
h->HintDescriptor)) {
137 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
140 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
145 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
150 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
153 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
158 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
162 if (LADSPA_IS_HINT_SAMPLE_RATE(
h->HintDescriptor))
165 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
177 int i,
h, p, new_out_samples;
178 int64_t out_duration;
185 if (!
s->nb_outputs ||
187 s->in_trim == 0 &&
s->out_pad == 0 &&
188 !(
s->desc->Properties & LADSPA_PROPERTY_INPLACE_BROKEN))) {
199 av_assert0(!
s->nb_outputs ||
out->ch_layout.nb_channels == (
s->nb_outputs *
s->nb_handles));
201 for (
h = 0;
h <
s->nb_handles;
h++) {
202 for (
i = 0;
i <
s->nb_inputs;
i++) {
203 p =
s->nb_handles > 1 ?
h :
i;
204 s->desc->connect_port(
s->handles[
h],
s->ipmap[
i],
208 for (
i = 0;
i <
s->nb_outputs;
i++) {
209 p =
s->nb_handles > 1 ?
h :
i;
210 s->desc->connect_port(
s->handles[
h],
s->opmap[
i],
211 (LADSPA_Data*)
out->extended_data[p]);
220 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
229 new_out_samples =
out->nb_samples;
230 if (
s->in_trim > 0) {
231 int trim =
FFMIN(new_out_samples,
s->in_trim);
233 new_out_samples -= trim;
237 if (new_out_samples <= 0) {
240 }
else if (new_out_samples < out->nb_samples) {
241 int offset =
out->nb_samples - new_out_samples;
242 for (
int ch = 0; ch <
out->ch_layout.nb_channels; ch++)
243 memmove(
out->extended_data[ch],
out->extended_data[ch] +
sizeof(
float) *
offset,
244 sizeof(
float) * new_out_samples);
245 out->nb_samples = new_out_samples;
256 out->pts =
s->next_out_pts;
260 s->next_in_pts = in_pts + in_duration;
261 s->next_out_pts =
out->pts + out_duration;
274 if (
ctx->nb_inputs) {
290 if (
s->duration >= 0 && t >=
s->duration)
297 for (
i = 0;
i <
s->nb_outputs;
i++)
298 s->desc->connect_port(
s->handles[0],
s->opmap[
i],
299 (LADSPA_Data*)
out->extended_data[
i]);
301 s->desc->run(
s->handles[0],
s->nb_samples);
303 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
306 out->sample_rate =
s->sample_rate;
308 s->pts +=
s->nb_samples;
316 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
317 const LADSPA_Data lower =
h->LowerBound;
318 const LADSPA_Data upper =
h->UpperBound;
320 if (LADSPA_IS_HINT_DEFAULT_MINIMUM(
h->HintDescriptor)) {
322 }
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(
h->HintDescriptor)) {
324 }
else if (LADSPA_IS_HINT_DEFAULT_0(
h->HintDescriptor)) {
326 }
else if (LADSPA_IS_HINT_DEFAULT_1(
h->HintDescriptor)) {
328 }
else if (LADSPA_IS_HINT_DEFAULT_100(
h->HintDescriptor)) {
330 }
else if (LADSPA_IS_HINT_DEFAULT_440(
h->HintDescriptor)) {
332 }
else if (LADSPA_IS_HINT_DEFAULT_LOW(
h->HintDescriptor)) {
333 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
336 values[ctl] = lower * 0.75 + upper * 0.25;
337 }
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(
h->HintDescriptor)) {
338 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
341 values[ctl] = lower * 0.5 + upper * 0.5;
342 }
else if (LADSPA_IS_HINT_DEFAULT_HIGH(
h->HintDescriptor)) {
343 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
346 values[ctl] = lower * 0.25 + upper * 0.75;
356 s->handles =
av_calloc(
s->nb_handles,
sizeof(*
s->handles));
360 for (
i = 0;
i <
s->nb_handles;
i++) {
362 if (!
s->handles[
i]) {
368 for (j = 0; j <
s->nb_inputcontrols; j++)
369 s->desc->connect_port(
s->handles[
i],
s->icmap[j],
s->ictlv + j);
372 for (j = 0; j <
s->nb_outputcontrols; j++)
373 s->desc->connect_port(
s->handles[
i],
s->ocmap[j], &
s->octlv[j]);
375 if (
s->desc->activate)
376 s->desc->activate(
s->handles[
i]);
397 if (
ctx->nb_inputs) {
402 if (
s->nb_inputs ==
s->nb_outputs) {
405 #if FF_API_OLD_CHANNEL_LAYOUT
407 outlink->channel_layout =
inlink->channel_layout;
424 unsigned long *nb_inputs,
unsigned long *nb_outputs)
426 LADSPA_PortDescriptor pd;
429 for (
i = 0;
i <
desc->PortCount;
i++) {
430 pd =
desc->PortDescriptors[
i];
432 if (LADSPA_IS_PORT_AUDIO(pd)) {
433 if (LADSPA_IS_PORT_INPUT(pd)) {
435 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
442 static void *
try_load(
const char *dir,
const char *soname)
448 ret = dlopen(path, RTLD_LOCAL|RTLD_NOW);
458 const char *label =
s->desc->Label;
459 LADSPA_PortRangeHint *
h = (LADSPA_PortRangeHint *)
s->desc->PortRangeHints +
462 if (port >=
s->nb_inputcontrols) {
464 port,
s->nb_inputcontrols);
468 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor) &&
469 value < h->LowerBound) {
471 "%s: input control c%ld is below lower boundary of %0.4f.\n",
472 label, port,
h->LowerBound);
476 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor) &&
479 "%s: input control c%ld is above upper boundary of %0.4f.\n",
480 label, port,
h->UpperBound);
492 LADSPA_Descriptor_Function descriptor_fn;
493 const LADSPA_Descriptor *
desc;
494 LADSPA_PortDescriptor pd;
496 char *p, *
arg, *saveptr =
NULL;
497 unsigned long nb_ports;
505 if (
s->dl_name[0] ==
'/' ||
s->dl_name[0] ==
'.') {
507 s->dl_handle = dlopen(
s->dl_name, RTLD_LOCAL|RTLD_NOW);
510 char *paths =
av_strdup(getenv(
"LADSPA_PATH"));
511 const char *home_path = getenv(
"HOME");
512 const char *separator =
":";
516 while ((
arg =
av_strtok(p, separator, &saveptr)) && !
s->dl_handle) {
523 if (!
s->dl_handle && home_path && (paths =
av_asprintf(
"%s/.ladspa", home_path))) {
528 if (!
s->dl_handle && home_path && (paths =
av_asprintf(
"%s/.ladspa/lib", home_path))) {
534 s->dl_handle =
try_load(
"/usr/local/lib/ladspa",
s->dl_name);
537 s->dl_handle =
try_load(
"/usr/lib/ladspa",
s->dl_name);
544 descriptor_fn = dlsym(
s->dl_handle,
"ladspa_descriptor");
545 if (!descriptor_fn) {
557 for (
i = 0;
desc = descriptor_fn(
i);
i++) {
571 desc = descriptor_fn(
i);
577 if (
desc->Label && !strcmp(
desc->Label,
s->plugin))
583 nb_ports =
desc->PortCount;
591 s->ctl_needs_value =
av_calloc(nb_ports,
sizeof(*
s->ctl_needs_value));
592 if (!
s->ipmap || !
s->opmap || !
s->icmap ||
593 !
s->ocmap || !
s->ictlv || !
s->octlv || !
s->ctl_needs_value)
596 for (
i = 0;
i < nb_ports;
i++) {
597 pd =
desc->PortDescriptors[
i];
599 if (LADSPA_IS_PORT_AUDIO(pd)) {
600 if (LADSPA_IS_PORT_INPUT(pd)) {
601 s->ipmap[
s->nb_inputs] =
i;
603 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
604 s->opmap[
s->nb_outputs] =
i;
607 }
else if (LADSPA_IS_PORT_CONTROL(pd)) {
608 if (LADSPA_IS_PORT_INPUT(pd)) {
609 s->icmap[
s->nb_inputcontrols] =
i;
611 if (LADSPA_IS_HINT_HAS_DEFAULT(
desc->PortRangeHints[
i].HintDescriptor))
614 s->ctl_needs_value[
s->nb_inputcontrols] = 1;
616 s->nb_inputcontrols++;
617 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
618 s->ocmap[
s->nb_outputcontrols] =
i;
619 s->nb_outputcontrols++;
625 if (
s->options && !strcmp(
s->options,
"help")) {
626 if (!
s->nb_inputcontrols) {
628 "The '%s' plugin does not have any input controls.\n",
632 "The '%s' plugin has the following input controls:\n",
634 for (
i = 0;
i <
s->nb_inputcontrols;
i++)
660 s->ctl_needs_value[
i] = 0;
664 for (
i = 0;
i <
s->nb_inputcontrols;
i++) {
665 if (
s->ctl_needs_value[
i]) {
687 s->nb_inputs,
s->nb_outputs);
689 s->nb_inputcontrols,
s->nb_outputcontrols);
723 if (
s->nb_inputs == 1 &&
s->nb_outputs == 1) {
728 }
else if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
739 if (
s->nb_inputs >= 1) {
751 if (!
s->nb_outputs) {
758 if (
s->nb_outputs >= 1) {
779 for (
i = 0;
i <
s->nb_handles;
i++) {
780 if (
s->desc->deactivate)
781 s->desc->deactivate(
s->handles[
i]);
782 if (
s->desc->cleanup)
783 s->desc->cleanup(
s->handles[
i]);
787 dlclose(
s->dl_handle);
802 char *res,
int res_len,
int flags)
826 .priv_class = &ladspa_class,
static void * try_load(const char *dir, const char *soname)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define FF_ENABLE_DEPRECATION_WARNINGS
@ AV_SAMPLE_FMT_FLTP
float, planar
A list of supported channel layouts.
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,...)
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
AVFILTER_DEFINE_CLASS(ladspa)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define FILTER_QUERY_FUNC(func)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
#define AV_LOG_VERBOSE
Detailed information.
static int config_output(AVFilterLink *outlink)
const char * name
Filter name.
static av_cold void uninit(AVFilterContext *ctx)
int nb_channels
Number of channels in this layout.
A link between two filters.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int connect_ports(AVFilterContext *ctx, AVFilterLink *link)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
const LADSPA_Descriptor * desc
static double val(void *priv, double ch)
static int request_frame(AVFilterLink *outlink)
AVChannelLayout ch_layout
Channel layout of the audio data.
#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.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
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_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Describe the class of an AVClass context structure.
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)
static void count_ports(const LADSPA_Descriptor *desc, unsigned long *nb_inputs, unsigned long *nb_outputs)
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
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
static int config_input(AVFilterLink *inlink)
static void print_ctl_info(AVFilterContext *ctx, int level, LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values, int print)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
const OptionDef options[]
#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.
unsigned long nb_inputcontrols
static int set_control(AVFilterContext *ctx, unsigned long port, LADSPA_Data value)
int sample_rate
Sample rate of the audio data.
static void print(AVTreeNode *t, int depth)
int format
agreed upon media format
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
#define AVERROR_EXTERNAL
Generic error in an external library.
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
#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
static int query_formats(AVFilterContext *ctx)
#define i(width, name, range_min, range_max)
#define AV_TIME_BASE
Internal time base represented as integer.
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
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
const char * name
Pad name.
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.
const AVFilter ff_af_ladspa
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.
static const AVFilterPad outputs[]
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
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
static int find_latency(AVFilterContext *ctx, LADSPAContext *s)
#define FF_DISABLE_DEPRECATION_WARNINGS
char * av_strdup(const char *s)
Duplicate a string.
static void set_default_ctl_value(LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values)
const VDPAUPixFmtMap * map
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static const AVOption ladspa_options[]
#define FILTER_OUTPUTS(array)
static const AVFilterPad ladspa_outputs[]
#define flags(name, subs,...)
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static av_cold int init(AVFilterContext *ctx)
unsigned long nb_outputcontrols
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.