58 const LADSPA_Descriptor *
desc;
72 #define OFFSET(x) offsetof(LADSPAContext, x)
73 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
83 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX,
FLAGS },
98 for (
int ctl = 0; ctl <
s->nb_outputcontrols; ctl++) {
102 latency =
lrintf(
s->octlv[ctl]);
111 LADSPA_Data *values,
int print)
113 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
117 if (LADSPA_IS_HINT_TOGGLED(
h->HintDescriptor)) {
120 if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
123 if (LADSPA_IS_HINT_INTEGER(
h->HintDescriptor)) {
126 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
129 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
134 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
139 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor))
142 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor))
147 else if (LADSPA_IS_HINT_HAS_DEFAULT(
h->HintDescriptor))
151 if (LADSPA_IS_HINT_SAMPLE_RATE(
h->HintDescriptor))
154 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
166 int i,
h, p, new_out_samples;
170 if (!
s->nb_outputs ||
172 s->in_trim == 0 &&
s->out_pad == 0 &&
173 !(
s->desc->Properties & LADSPA_PROPERTY_INPLACE_BROKEN))) {
184 av_assert0(!
s->nb_outputs ||
out->channels == (
s->nb_outputs *
s->nb_handles));
186 for (
h = 0;
h <
s->nb_handles;
h++) {
187 for (
i = 0;
i <
s->nb_inputs;
i++) {
188 p =
s->nb_handles > 1 ?
h :
i;
189 s->desc->connect_port(
s->handles[
h],
s->ipmap[
i],
190 (LADSPA_Data*)
in->extended_data[p]);
193 for (
i = 0;
i <
s->nb_outputs;
i++) {
194 p =
s->nb_handles > 1 ?
h :
i;
195 s->desc->connect_port(
s->handles[
h],
s->opmap[
i],
196 (LADSPA_Data*)
out->extended_data[p]);
199 s->desc->run(
s->handles[
h],
in->nb_samples);
205 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
211 new_out_samples =
out->nb_samples;
212 if (
s->in_trim > 0) {
213 int trim =
FFMIN(new_out_samples,
s->in_trim);
215 new_out_samples -= trim;
219 if (new_out_samples <= 0) {
222 }
else if (new_out_samples < out->nb_samples) {
223 int offset =
out->nb_samples - new_out_samples;
224 for (
int ch = 0; ch <
out->channels; ch++)
225 memmove(
out->extended_data[ch],
out->extended_data[ch] +
sizeof(
float) *
offset,
226 sizeof(
float) * new_out_samples);
227 out->nb_samples = new_out_samples;
241 if (
ctx->nb_inputs) {
256 if (
s->duration >= 0 && t >=
s->duration)
263 for (
i = 0;
i <
s->nb_outputs;
i++)
264 s->desc->connect_port(
s->handles[0],
s->opmap[
i],
265 (LADSPA_Data*)
out->extended_data[
i]);
267 s->desc->run(
s->handles[0],
s->nb_samples);
269 for (
i = 0;
i <
s->nb_outputcontrols;
i++)
272 out->sample_rate =
s->sample_rate;
274 s->pts +=
s->nb_samples;
280 unsigned long *
map, LADSPA_Data *values)
282 const LADSPA_PortRangeHint *
h =
s->desc->PortRangeHints +
map[ctl];
283 const LADSPA_Data lower =
h->LowerBound;
284 const LADSPA_Data upper =
h->UpperBound;
286 if (LADSPA_IS_HINT_DEFAULT_MINIMUM(
h->HintDescriptor)) {
288 }
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(
h->HintDescriptor)) {
290 }
else if (LADSPA_IS_HINT_DEFAULT_0(
h->HintDescriptor)) {
292 }
else if (LADSPA_IS_HINT_DEFAULT_1(
h->HintDescriptor)) {
294 }
else if (LADSPA_IS_HINT_DEFAULT_100(
h->HintDescriptor)) {
296 }
else if (LADSPA_IS_HINT_DEFAULT_440(
h->HintDescriptor)) {
298 }
else if (LADSPA_IS_HINT_DEFAULT_LOW(
h->HintDescriptor)) {
299 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
300 values[ctl] =
exp(log(lower) * 0.75 + log(upper) * 0.25);
302 values[ctl] = lower * 0.75 + upper * 0.25;
303 }
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(
h->HintDescriptor)) {
304 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
305 values[ctl] =
exp(log(lower) * 0.5 + log(upper) * 0.5);
307 values[ctl] = lower * 0.5 + upper * 0.5;
308 }
else if (LADSPA_IS_HINT_DEFAULT_HIGH(
h->HintDescriptor)) {
309 if (LADSPA_IS_HINT_LOGARITHMIC(
h->HintDescriptor))
310 values[ctl] =
exp(log(lower) * 0.25 + log(upper) * 0.75);
312 values[ctl] = lower * 0.25 + upper * 0.75;
321 s->nb_handles =
s->nb_inputs == 1 &&
s->nb_outputs == 1 ? link->
channels : 1;
322 s->handles =
av_calloc(
s->nb_handles,
sizeof(*
s->handles));
326 for (
i = 0;
i <
s->nb_handles;
i++) {
328 if (!
s->handles[
i]) {
334 for (j = 0; j <
s->nb_inputcontrols; j++)
335 s->desc->connect_port(
s->handles[
i],
s->icmap[j],
s->ictlv + j);
338 for (j = 0; j <
s->nb_outputcontrols; j++)
339 s->desc->connect_port(
s->handles[
i],
s->ocmap[j], &
s->octlv[j]);
341 if (
s->desc->activate)
342 s->desc->activate(
s->handles[
i]);
363 if (
ctx->nb_inputs) {
368 if (
s->nb_inputs ==
s->nb_outputs) {
385 unsigned long *nb_inputs,
unsigned long *nb_outputs)
387 LADSPA_PortDescriptor pd;
390 for (
i = 0;
i <
desc->PortCount;
i++) {
391 pd =
desc->PortDescriptors[
i];
393 if (LADSPA_IS_PORT_AUDIO(pd)) {
394 if (LADSPA_IS_PORT_INPUT(pd)) {
396 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
403 static void *
try_load(
const char *dir,
const char *soname)
409 ret = dlopen(path, RTLD_LOCAL|RTLD_NOW);
419 const char *label =
s->desc->Label;
420 LADSPA_PortRangeHint *
h = (LADSPA_PortRangeHint *)
s->desc->PortRangeHints +
423 if (port >=
s->nb_inputcontrols) {
425 port,
s->nb_inputcontrols);
429 if (LADSPA_IS_HINT_BOUNDED_BELOW(
h->HintDescriptor) &&
430 value < h->LowerBound) {
432 "%s: input control c%ld is below lower boundary of %0.4f.\n",
433 label, port,
h->LowerBound);
437 if (LADSPA_IS_HINT_BOUNDED_ABOVE(
h->HintDescriptor) &&
440 "%s: input control c%ld is above upper boundary of %0.4f.\n",
441 label, port,
h->UpperBound);
453 LADSPA_Descriptor_Function descriptor_fn;
454 const LADSPA_Descriptor *
desc;
455 LADSPA_PortDescriptor pd;
457 char *p, *
arg, *saveptr =
NULL;
458 unsigned long nb_ports;
466 if (
s->dl_name[0] ==
'/' ||
s->dl_name[0] ==
'.') {
468 s->dl_handle = dlopen(
s->dl_name, RTLD_LOCAL|RTLD_NOW);
471 char *paths =
av_strdup(getenv(
"LADSPA_PATH"));
472 const char *home_path = getenv(
"HOME");
473 const char *separator =
":";
477 while ((
arg =
av_strtok(p, separator, &saveptr)) && !
s->dl_handle) {
484 if (!
s->dl_handle && home_path && (paths =
av_asprintf(
"%s/.ladspa", home_path))) {
489 if (!
s->dl_handle && home_path && (paths =
av_asprintf(
"%s/.ladspa/lib", home_path))) {
495 s->dl_handle =
try_load(
"/usr/local/lib/ladspa",
s->dl_name);
498 s->dl_handle =
try_load(
"/usr/lib/ladspa",
s->dl_name);
505 descriptor_fn = dlsym(
s->dl_handle,
"ladspa_descriptor");
506 if (!descriptor_fn) {
518 for (
i = 0;
desc = descriptor_fn(
i);
i++) {
532 desc = descriptor_fn(
i);
538 if (
desc->Label && !strcmp(
desc->Label,
s->plugin))
544 nb_ports =
desc->PortCount;
552 s->ctl_needs_value =
av_calloc(nb_ports,
sizeof(*
s->ctl_needs_value));
553 if (!
s->ipmap || !
s->opmap || !
s->icmap ||
554 !
s->ocmap || !
s->ictlv || !
s->octlv || !
s->ctl_needs_value)
557 for (
i = 0;
i < nb_ports;
i++) {
558 pd =
desc->PortDescriptors[
i];
560 if (LADSPA_IS_PORT_AUDIO(pd)) {
561 if (LADSPA_IS_PORT_INPUT(pd)) {
562 s->ipmap[
s->nb_inputs] =
i;
564 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
565 s->opmap[
s->nb_outputs] =
i;
568 }
else if (LADSPA_IS_PORT_CONTROL(pd)) {
569 if (LADSPA_IS_PORT_INPUT(pd)) {
570 s->icmap[
s->nb_inputcontrols] =
i;
572 if (LADSPA_IS_HINT_HAS_DEFAULT(
desc->PortRangeHints[
i].HintDescriptor))
575 s->ctl_needs_value[
s->nb_inputcontrols] = 1;
577 s->nb_inputcontrols++;
578 }
else if (LADSPA_IS_PORT_OUTPUT(pd)) {
579 s->ocmap[
s->nb_outputcontrols] =
i;
580 s->nb_outputcontrols++;
586 if (
s->options && !strcmp(
s->options,
"help")) {
587 if (!
s->nb_inputcontrols) {
589 "The '%s' plugin does not have any input controls.\n",
593 "The '%s' plugin has the following input controls:\n",
595 for (
i = 0;
i <
s->nb_inputcontrols;
i++)
621 s->ctl_needs_value[
i] = 0;
625 for (
i = 0;
i <
s->nb_inputcontrols;
i++) {
626 if (
s->ctl_needs_value[
i]) {
650 s->nb_inputs,
s->nb_outputs);
652 s->nb_inputcontrols,
s->nb_outputcontrols);
689 if (
s->nb_inputs == 1 &&
s->nb_outputs == 1) {
698 }
else if (
s->nb_inputs == 2 &&
s->nb_outputs == 2) {
709 if (
s->nb_inputs >= 1) {
721 if (!
s->nb_outputs) {
728 if (
s->nb_outputs >= 1) {
749 for (
i = 0;
i <
s->nb_handles;
i++) {
750 if (
s->desc->deactivate)
751 s->desc->deactivate(
s->handles[
i]);
752 if (
s->desc->cleanup)
753 s->desc->cleanup(
s->handles[
i]);
757 dlclose(
s->dl_handle);
773 char *res,
int res_len,
int flags)
798 .priv_class = &ladspa_class,
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
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 query_formats(AVFilterContext *ctx)
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 void * try_load(const char *dir, const char *soname)
AVFILTER_DEFINE_CLASS(ladspa)
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 int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static const AVFilterPad ladspa_outputs[]
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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
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_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,...)
audio channel layout utility functions
const OptionDef options[]
#define AV_CH_LAYOUT_STEREO
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#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.
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.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
char * av_strdup(const char *s)
Duplicate a string.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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.
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
#define AV_TIME_BASE
Internal time base represented as integer.
const VDPAUPixFmtMap * map
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum MovChannelLayoutTag * layouts
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
int channels
Number of channels.
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
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
uint64_t channel_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.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
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)
static const uint8_t offset[127][2]