66 const LADSPA_Descriptor *
desc;
84#define OFFSET(x) offsetof(LADSPAContext, x)
85#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
95 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
110 for (
int ctl = 0; ctl <
s->nb_outputcontrols; ctl++) {
114 latency =
lrintf(
s->octlv[ctl]);
123 LADSPA_Data *values,
int print)
125 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
129 if (LADSPA_IS_HINT_TOGGLED(
h->HintDescriptor)) {
132 if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
135 if (LADSPA_IS_HINT_INTEGER(
h->HintDescriptor)) {
138 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
141 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
146 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
151 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
154 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
159 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
163 if (LADSPA_IS_HINT_SAMPLE_RATE(
h->HintDescriptor))
166 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
178 int i,
h, p, new_out_samples;
186 if (!
s->nb_outputs ||
188 s->in_trim == 0 &&
s->out_pad == 0 &&
189 !(
s->desc->Properties & LADSPA_PROPERTY_INPLACE_BROKEN))) {
200 av_assert0(!
s->nb_outputs ||
out->ch_layout.nb_channels == (
s->nb_outputs *
s->nb_handles));
202 for (
h = 0;
h <
s->nb_handles;
h++) {
203 for (
i = 0;
i <
s->nb_inputs;
i++) {
204 p =
s->nb_handles > 1 ?
h :
i;
205 s->desc->connect_port(
s->handles[
h],
s->ipmap[
i],
209 for (
i = 0;
i <
s->nb_outputs;
i++) {
210 p =
s->nb_handles > 1 ?
h :
i;
211 s->desc->connect_port(
s->handles[
h],
s->opmap[
i],
212 (LADSPA_Data*)
out->extended_data[p]);
221 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
230 new_out_samples =
out->nb_samples;
231 if (
s->in_trim > 0) {
232 int trim =
FFMIN(new_out_samples,
s->in_trim);
234 new_out_samples -= trim;
238 if (new_out_samples <= 0) {
241 }
else if (new_out_samples < out->nb_samples) {
242 int offset =
out->nb_samples - new_out_samples;
243 for (
int ch = 0; ch <
out->ch_layout.nb_channels; ch++)
244 memmove(
out->extended_data[ch],
out->extended_data[ch] +
sizeof(
float) *
offset,
245 sizeof(
float) * new_out_samples);
246 out->nb_samples = new_out_samples;
257 out->pts =
s->next_out_pts;
261 s->next_in_pts = in_pts + in_duration;
262 s->next_out_pts =
out->pts + out_duration;
275 if (
ctx->nb_inputs) {
283 s->out_pad -=
frame->nb_samples;
284 frame->pts =
s->next_in_pts;
291 if (
s->duration >= 0 && t >=
s->duration)
298 for (
i = 0;
i <
s->nb_outputs;
i++)
299 s->desc->connect_port(
s->handles[0],
s->opmap[
i],
300 (LADSPA_Data*)
out->extended_data[
i]);
302 s->desc->run(
s->handles[0],
s->nb_samples);
304 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
307 out->sample_rate =
s->sample_rate;
309 s->pts +=
s->nb_samples;
315 unsigned long *
map, LADSPA_Data *values)
317 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
318 const LADSPA_Data lower =
h->LowerBound;
319 const LADSPA_Data upper =
h->UpperBound;
321 if (LADSPA_IS_HINT_DEFAULT_MINIMUM(
h->HintDescriptor)) {
323 }
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(
h->HintDescriptor)) {
325 }
else if (LADSPA_IS_HINT_DEFAULT_0(
h->HintDescriptor)) {
327 }
else if (LADSPA_IS_HINT_DEFAULT_1(
h->HintDescriptor)) {
329 }
else if (LADSPA_IS_HINT_DEFAULT_100(
h->HintDescriptor)) {
331 }
else if (LADSPA_IS_HINT_DEFAULT_440(
h->HintDescriptor)) {
333 }
else if (LADSPA_IS_HINT_DEFAULT_LOW(
h->HintDescriptor)) {
334 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
335 values[ctl] =
exp(log(lower) * 0.75 + log(upper) * 0.25);
337 values[ctl] = lower * 0.75 + upper * 0.25;
338 }
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(
h->HintDescriptor)) {
339 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
340 values[ctl] =
exp(log(lower) * 0.5 + log(upper) * 0.5);
342 values[ctl] = lower * 0.5 + upper * 0.5;
343 }
else if (LADSPA_IS_HINT_DEFAULT_HIGH(
h->HintDescriptor)) {
344 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
345 values[ctl] =
exp(log(lower) * 0.25 + log(upper) * 0.75);
347 values[ctl] = lower * 0.25 + upper * 0.75;
357 s->handles =
av_calloc(
s->nb_handles,
sizeof(*
s->handles));
361 for (
i = 0;
i <
s->nb_handles;
i++) {
363 if (!
s->handles[
i]) {
369 for (j = 0; j <
s->nb_inputcontrols; j++)
370 s->desc->connect_port(
s->handles[
i],
s->icmap[j],
s->ictlv + j);
373 for (j = 0; j <
s->nb_outputcontrols; j++)
374 s->desc->connect_port(
s->handles[
i],
s->ocmap[j], &
s->octlv[j]);
376 if (
s->desc->activate)
377 s->desc->activate(
s->handles[
i]);
398 if (
ctx->nb_inputs) {
403 if (
s->nb_inputs ==
s->nb_outputs) {
420 unsigned long *nb_inputs,
unsigned long *nb_outputs)
422 LADSPA_PortDescriptor pd;
425 for (
i = 0;
i <
desc->PortCount;
i++) {
426 pd =
desc->PortDescriptors[
i];
428 if (LADSPA_IS_PORT_AUDIO(pd)) {
429 if (LADSPA_IS_PORT_INPUT(pd)) {
431 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
438static void *
try_load(
const char *dir,
const char *soname)
444 ret = dlopen(path, RTLD_LOCAL|RTLD_NOW);
454 const char *label =
s->desc->Label;
455 LADSPA_PortRangeHint *
h = (LADSPA_PortRangeHint *)
s->desc->PortRangeHints +
458 if (port >=
s->nb_inputcontrols) {
460 port,
s->nb_inputcontrols);
464 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor) &&
467 "%s: input control c%ld is below lower boundary of %0.4f.\n",
468 label, port,
h->LowerBound);
472 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor) &&
475 "%s: input control c%ld is above upper boundary of %0.4f.\n",
476 label, port,
h->UpperBound);
488 LADSPA_Descriptor_Function descriptor_fn;
489 const LADSPA_Descriptor *
desc;
490 LADSPA_PortDescriptor pd;
492 char *p, *
arg, *saveptr =
NULL;
493 unsigned long nb_ports;
501 if (
s->dl_name[0] ==
'/' ||
s->dl_name[0] ==
'.') {
503 s->dl_handle = dlopen(
s->dl_name, RTLD_LOCAL|RTLD_NOW);
506 char *paths =
av_strdup(getenv(
"LADSPA_PATH"));
507 const char *home_path = getenv(
"HOME");
519 if (!
s->dl_handle && home_path && (paths =
av_asprintf(
"%s/.ladspa", home_path))) {
524 if (!
s->dl_handle && home_path && (paths =
av_asprintf(
"%s/.ladspa/lib", home_path))) {
530 s->dl_handle =
try_load(
"/usr/local/lib/ladspa",
s->dl_name);
533 s->dl_handle =
try_load(
"/usr/lib/ladspa",
s->dl_name);
540 descriptor_fn = dlsym(
s->dl_handle,
"ladspa_descriptor");
541 if (!descriptor_fn) {
553 for (
i = 0;
desc = descriptor_fn(
i);
i++) {
567 desc = descriptor_fn(
i);
573 if (
desc->Label && !strcmp(
desc->Label,
s->plugin))
579 nb_ports =
desc->PortCount;
587 s->ctl_needs_value =
av_calloc(nb_ports,
sizeof(*
s->ctl_needs_value));
588 if (!
s->ipmap || !
s->opmap || !
s->icmap ||
589 !
s->ocmap || !
s->ictlv || !
s->octlv || !
s->ctl_needs_value)
592 for (
i = 0;
i < nb_ports;
i++) {
593 pd =
desc->PortDescriptors[
i];
595 if (LADSPA_IS_PORT_AUDIO(pd)) {
596 if (LADSPA_IS_PORT_INPUT(pd)) {
597 s->ipmap[
s->nb_inputs] =
i;
599 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
600 s->opmap[
s->nb_outputs] =
i;
603 }
else if (LADSPA_IS_PORT_CONTROL(pd)) {
604 if (LADSPA_IS_PORT_INPUT(pd)) {
605 s->icmap[
s->nb_inputcontrols] =
i;
607 if (LADSPA_IS_HINT_HAS_DEFAULT(
desc->PortRangeHints[
i].HintDescriptor))
610 s->ctl_needs_value[
s->nb_inputcontrols] = 1;
612 s->nb_inputcontrols++;
613 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
614 s->ocmap[
s->nb_outputcontrols] =
i;
615 s->nb_outputcontrols++;
621 if (
s->options && !strcmp(
s->options,
"help")) {
622 if (!
s->nb_inputcontrols) {
624 "The '%s' plugin does not have any input controls.\n",
628 "The '%s' plugin has the following input controls:\n",
630 for (
i = 0;
i <
s->nb_inputcontrols;
i++)
656 s->ctl_needs_value[
i] = 0;
660 for (
i = 0;
i <
s->nb_inputcontrols;
i++) {
661 if (
s->ctl_needs_value[
i]) {
683 s->nb_inputs,
s->nb_outputs);
685 s->nb_inputcontrols,
s->nb_outputcontrols);
717 if (
s->nb_inputs == 1 &&
s->nb_outputs == 1) {
722 }
else if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
731 if (
s->nb_inputs >= 1) {
742 if (!
s->nb_outputs) {
749 if (
s->nb_outputs >= 1) {
770 for (
i = 0;
i <
s->nb_handles;
i++) {
771 if (
s->desc->deactivate)
772 s->desc->deactivate(
s->handles[
i]);
773 if (
s->desc->cleanup)
774 s->desc->cleanup(
s->handles[
i]);
778 dlclose(
s->dl_handle);
793 char *res,
int res_len,
int flags)
816 .p.priv_class = &ladspa_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 const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static int config_input(AVFilterLink *inlink)
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 void set_default_ctl_value(LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values)
static void print_ctl_info(AVFilterContext *ctx, int level, LADSPAContext *s, int ctl, unsigned long *map, LADSPA_Data *values, int print)
static int connect_ports(AVFilterContext *ctx, AVFilterLink *link)
static int set_control(AVFilterContext *ctx, unsigned long port, LADSPA_Data value)
static int config_input(AVFilterLink *inlink)
static int find_latency(AVFilterContext *ctx, LADSPAContext *s)
static int request_frame(AVFilterLink *outlink)
static void count_ports(const LADSPA_Descriptor *desc, unsigned long *nb_inputs, unsigned long *nb_outputs)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
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 const AVOption ladspa_options[]
static av_cold void uninit(AVFilterContext *ctx)
static void * try_load(const char *dir, const char *soname)
const FFFilter ff_af_ladspa
static int config_output(AVFilterLink *outlink)
static const AVFilterPad ladspa_outputs[]
static AVFormatContext * ctx
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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.
int av_sscanf(const char *string, const char *format,...)
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)
static char separator(CheckasmFormat format)
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
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_EXTERNAL
Generic error in an external library.
#define AVERROR_EOF
End of file.
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.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
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_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
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().
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
const VDPAUPixFmtMap * map
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_OUTPUTS(array)
#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
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
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.
int(* config_props)(AVFilterLink *link)
Link configuration callback.
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
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVChannelLayout ch_layout
Channel layout of the audio data.
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
const LADSPA_Descriptor * desc
unsigned long nb_outputcontrols
unsigned long nb_inputcontrols
static void print(AVTreeNode *t, int depth)