Go to the documentation of this file.
58 const LADSPA_Descriptor *
desc;
69 #define OFFSET(x) offsetof(LADSPAContext, x)
70 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
80 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
93 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
97 if (LADSPA_IS_HINT_TOGGLED(
h->HintDescriptor)) {
100 if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
103 if (LADSPA_IS_HINT_INTEGER(
h->HintDescriptor)) {
106 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
109 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
114 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
119 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
122 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
127 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
131 if (LADSPA_IS_HINT_SAMPLE_RATE(
h->HintDescriptor))
134 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
150 if (!
s->nb_outputs ||
152 !(
s->desc->Properties & LADSPA_PROPERTY_INPLACE_BROKEN))) {
163 av_assert0(!
s->nb_outputs ||
out->channels == (
s->nb_outputs *
s->nb_handles));
165 for (
h = 0;
h <
s->nb_handles;
h++) {
166 for (
i = 0;
i <
s->nb_inputs;
i++) {
167 p =
s->nb_handles > 1 ?
h :
i;
168 s->desc->connect_port(
s->handles[
h],
s->ipmap[
i],
169 (LADSPA_Data*)
in->extended_data[p]);
172 for (
i = 0;
i <
s->nb_outputs;
i++) {
173 p =
s->nb_handles > 1 ?
h :
i;
174 s->desc->connect_port(
s->handles[
h],
s->opmap[
i],
175 (LADSPA_Data*)
out->extended_data[p]);
178 s->desc->run(
s->handles[
h],
in->nb_samples);
181 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
202 if (
s->duration >= 0 && t >=
s->duration)
209 for (
i = 0;
i <
s->nb_outputs;
i++)
210 s->desc->connect_port(
s->handles[0],
s->opmap[
i],
211 (LADSPA_Data*)
out->extended_data[
i]);
213 s->desc->run(
s->handles[0],
s->nb_samples);
215 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
218 out->sample_rate =
s->sample_rate;
220 s->pts +=
s->nb_samples;
228 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
229 const LADSPA_Data lower =
h->LowerBound;
230 const LADSPA_Data upper =
h->UpperBound;
232 if (LADSPA_IS_HINT_DEFAULT_MINIMUM(
h->HintDescriptor)) {
234 }
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(
h->HintDescriptor)) {
236 }
else if (LADSPA_IS_HINT_DEFAULT_0(
h->HintDescriptor)) {
238 }
else if (LADSPA_IS_HINT_DEFAULT_1(
h->HintDescriptor)) {
240 }
else if (LADSPA_IS_HINT_DEFAULT_100(
h->HintDescriptor)) {
242 }
else if (LADSPA_IS_HINT_DEFAULT_440(
h->HintDescriptor)) {
244 }
else if (LADSPA_IS_HINT_DEFAULT_LOW(
h->HintDescriptor)) {
245 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
246 values[ctl] =
exp(log(lower) * 0.75 + log(upper) * 0.25);
248 values[ctl] = lower * 0.75 + upper * 0.25;
249 }
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(
h->HintDescriptor)) {
250 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
251 values[ctl] =
exp(log(lower) * 0.5 + log(upper) * 0.5);
253 values[ctl] = lower * 0.5 + upper * 0.5;
254 }
else if (LADSPA_IS_HINT_DEFAULT_HIGH(
h->HintDescriptor)) {
255 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
256 values[ctl] =
exp(log(lower) * 0.25 + log(upper) * 0.75);
258 values[ctl] = lower * 0.25 + upper * 0.75;
267 s->nb_handles =
s->nb_inputs == 1 &&
s->nb_outputs == 1 ?
link->
channels : 1;
268 s->handles =
av_calloc(
s->nb_handles,
sizeof(*
s->handles));
272 for (
i = 0;
i <
s->nb_handles;
i++) {
274 if (!
s->handles[
i]) {
280 for (j = 0; j <
s->nb_inputcontrols; j++)
281 s->desc->connect_port(
s->handles[
i],
s->icmap[j],
s->ictlv + j);
284 for (j = 0; j <
s->nb_outputcontrols; j++)
285 s->desc->connect_port(
s->handles[
i],
s->ocmap[j], &
s->octlv[j]);
287 if (
s->desc->activate)
288 s->desc->activate(
s->handles[
i]);
309 if (
ctx->nb_inputs) {
314 if (
s->nb_inputs ==
s->nb_outputs) {
331 unsigned long *nb_inputs,
unsigned long *nb_outputs)
333 LADSPA_PortDescriptor pd;
336 for (
i = 0;
i <
desc->PortCount;
i++) {
337 pd =
desc->PortDescriptors[
i];
339 if (LADSPA_IS_PORT_AUDIO(pd)) {
340 if (LADSPA_IS_PORT_INPUT(pd)) {
342 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
349 static void *
try_load(
const char *dir,
const char *soname)
355 ret = dlopen(path, RTLD_LOCAL|RTLD_NOW);
365 const char *label =
s->desc->Label;
366 LADSPA_PortRangeHint *
h = (LADSPA_PortRangeHint *)
s->desc->PortRangeHints +
369 if (port >=
s->nb_inputcontrols) {
371 port,
s->nb_inputcontrols);
375 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor) &&
376 value < h->LowerBound) {
378 "%s: input control c%ld is below lower boundary of %0.4f.\n",
379 label, port,
h->LowerBound);
383 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor) &&
386 "%s: input control c%ld is above upper boundary of %0.4f.\n",
387 label, port,
h->UpperBound);
399 LADSPA_Descriptor_Function descriptor_fn;
400 const LADSPA_Descriptor *
desc;
401 LADSPA_PortDescriptor pd;
403 char *p, *
arg, *saveptr =
NULL;
404 unsigned long nb_ports;
412 if (
s->dl_name[0] ==
'/' ||
s->dl_name[0] ==
'.') {
414 s->dl_handle = dlopen(
s->dl_name, RTLD_LOCAL|RTLD_NOW);
417 char *paths =
av_strdup(getenv(
"LADSPA_PATH"));
418 const char *separator =
":";
422 while ((
arg =
av_strtok(p, separator, &saveptr)) && !
s->dl_handle) {
429 if (!
s->dl_handle && (paths =
av_asprintf(
"%s/.ladspa/lib", getenv(
"HOME")))) {
435 s->dl_handle =
try_load(
"/usr/local/lib/ladspa",
s->dl_name);
438 s->dl_handle =
try_load(
"/usr/lib/ladspa",
s->dl_name);
445 descriptor_fn = dlsym(
s->dl_handle,
"ladspa_descriptor");
446 if (!descriptor_fn) {
458 for (
i = 0;
desc = descriptor_fn(
i);
i++) {
472 desc = descriptor_fn(
i);
478 if (
desc->Label && !strcmp(
desc->Label,
s->plugin))
484 nb_ports =
desc->PortCount;
492 s->ctl_needs_value =
av_calloc(nb_ports,
sizeof(*
s->ctl_needs_value));
493 if (!
s->ipmap || !
s->opmap || !
s->icmap ||
494 !
s->ocmap || !
s->ictlv || !
s->octlv || !
s->ctl_needs_value)
497 for (
i = 0;
i < nb_ports;
i++) {
498 pd =
desc->PortDescriptors[
i];
500 if (LADSPA_IS_PORT_AUDIO(pd)) {
501 if (LADSPA_IS_PORT_INPUT(pd)) {
502 s->ipmap[
s->nb_inputs] =
i;
504 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
505 s->opmap[
s->nb_outputs] =
i;
508 }
else if (LADSPA_IS_PORT_CONTROL(pd)) {
509 if (LADSPA_IS_PORT_INPUT(pd)) {
510 s->icmap[
s->nb_inputcontrols] =
i;
512 if (LADSPA_IS_HINT_HAS_DEFAULT(
desc->PortRangeHints[
i].HintDescriptor))
515 s->ctl_needs_value[
s->nb_inputcontrols] = 1;
517 s->nb_inputcontrols++;
518 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
519 s->ocmap[
s->nb_outputcontrols] =
i;
520 s->nb_outputcontrols++;
526 if (
s->options && !strcmp(
s->options,
"help")) {
527 if (!
s->nb_inputcontrols) {
529 "The '%s' plugin does not have any input controls.\n",
533 "The '%s' plugin has the following input controls:\n",
535 for (
i = 0;
i <
s->nb_inputcontrols;
i++)
561 s->ctl_needs_value[
i] = 0;
565 for (
i = 0;
i <
s->nb_inputcontrols;
i++) {
566 if (
s->ctl_needs_value[
i]) {
590 s->nb_inputs,
s->nb_outputs);
592 s->nb_inputcontrols,
s->nb_outputcontrols);
629 if (
s->nb_inputs == 1 &&
s->nb_outputs == 1) {
638 }
else if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
649 if (
s->nb_inputs >= 1) {
661 if (!
s->nb_outputs) {
668 if (
s->nb_outputs >= 1) {
689 for (
i = 0;
i <
s->nb_handles;
i++) {
690 if (
s->desc->deactivate)
691 s->desc->deactivate(
s->handles[
i]);
692 if (
s->desc->cleanup)
693 s->desc->cleanup(
s->handles[
i]);
697 dlclose(
s->dl_handle);
713 char *res,
int res_len,
int flags)
738 .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.
@ 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
struct AVFilterChannelLayouts * in_channel_layouts
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,...)
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.
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)
A link between two filters.
int channels
Number of channels.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
static int connect_ports(AVFilterContext *ctx, AVFilterLink *link)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const LADSPA_Descriptor * desc
static int request_frame(AVFilterLink *outlink)
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#define AV_CH_LAYOUT_STEREO
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int channels
number of audio channels, only used for audio.
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.
static const AVFilterPad outputs[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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).
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
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.
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
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
const char const char void * val
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_INFO
Standard information.
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
int sample_rate
samples per second
static int query_formats(AVFilterContext *ctx)
#define i(width, name, range_min, range_max)
#define AV_TIME_BASE
Internal time base represented as integer.
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 AVS_Value args
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.
enum AVMediaType type
AVFilterPad type.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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.
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
static const AVOption ladspa_options[]
static const AVFilterPad ladspa_outputs[]
#define flags(name, subs,...)
#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
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.