Go to the documentation of this file.
53 const uint8_t *
src, uint8_t *dst);
57 #define OFFSET(x) offsetof(AudioDelayContext, x)
58 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
68 #define DELAY(name, type, fill) \
69 static void delay_channel_## name ##p(ChanDelay *d, int nb_samples, \
70 const uint8_t *ssrc, uint8_t *ddst) \
72 const type *src = (type *)ssrc; \
73 type *dst = (type *)ddst; \
74 type *samples = (type *)d->samples; \
76 while (nb_samples) { \
77 if (d->delay_index < d->delay) { \
78 const int len = FFMIN(nb_samples, d->delay - d->delay_index); \
80 memcpy(&samples[d->delay_index], src, len * sizeof(type)); \
81 memset(dst, fill, len * sizeof(type)); \
82 d->delay_index += len; \
87 *dst = samples[d->index]; \
88 samples[d->index] = *src; \
92 d->index = d->index >= d->delay ? 0 : d->index; \
97 DELAY(u8, uint8_t, 0x80)
98 DELAY(s16, int16_t, 0)
101 DELAY(dbl,
double, 0)
103 #define CHANGE_DELAY(name, type, fill) \
104 static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay) \
108 if (new_delay == d->delay) { \
112 if (new_delay == 0) { \
113 av_freep(&d->samples); \
114 d->samples_size = 0; \
117 d->delay_index = 0; \
121 samples = (type *) av_fast_realloc(d->samples, &d->samples_size, new_delay * sizeof(type)); \
123 return AVERROR(ENOMEM); \
126 if (new_delay < d->delay) { \
127 if (d->index > new_delay) { \
128 d->index -= new_delay; \
129 memmove(samples, &samples[new_delay], d->index * sizeof(type)); \
130 d->delay_index = new_delay; \
131 } else if (d->delay_index > d->index) { \
132 memmove(&samples[d->index], &samples[d->index+(d->delay-new_delay)], \
133 (new_delay - d->index) * sizeof(type)); \
134 d->delay_index -= d->delay - new_delay; \
138 if (d->delay_index >= d->delay) { \
139 block_size = (d->delay - d->index) * sizeof(type); \
140 memmove(&samples[d->index+(new_delay - d->delay)], &samples[d->index], block_size); \
141 d->delay_index = new_delay; \
143 d->delay_index += new_delay - d->delay; \
145 block_size = (new_delay - d->delay) * sizeof(type); \
146 memset(&samples[d->index], fill, block_size); \
148 d->delay = new_delay; \
149 d->samples = (void *) samples; \
170 div =
type ==
's' ? 1.0 : 1000.0;
189 char *p, *saveptr =
NULL;
196 s->nb_delays =
inlink->ch_layout.nb_channels;
200 for (
i = 0;
i <
s->nb_delays;
i++) {
213 for (
int j =
i; j <
s->nb_delays; j++)
214 s->chandelay[j].delay =
s->chandelay[
i-1].delay;
217 s->padding =
s->chandelay[0].delay;
218 for (
i = 1;
i <
s->nb_delays;
i++) {
221 s->padding =
FFMIN(
s->padding,
d->delay);
225 for (
i = 0;
i <
s->nb_delays;
i++) {
228 d->delay -=
s->padding;
236 for (
i = 0;
i <
s->nb_delays;
i++) {
242 if (
d->delay > SIZE_MAX) {
250 d->samples_size =
d->delay *
s->block_align;
252 s->max_delay =
FFMAX(
s->max_delay,
d->delay);
257 s->resize_channel_samples = resize_samples_u8p;
break;
259 s->resize_channel_samples = resize_samples_s16p;
break;
261 s->resize_channel_samples = resize_samples_s32p;
break;
263 s->resize_channel_samples = resize_samples_fltp;
break;
265 s->resize_channel_samples = resize_samples_dblp;
break;
272 char *res,
int res_len,
int flags)
278 if (!strcmp(cmd,
"delays")) {
280 char *p, *saveptr =
NULL;
284 if (args_cpy ==
NULL) {
291 if (!strncmp(args,
"all:", 4)) {
301 for (
int i = 0;
i <
s->nb_delays;
i++) {
313 ret =
s->resize_channel_samples(
d, delay);
316 max_delay =
FFMAX(max_delay,
d->delay);
318 s->max_delay =
FFMAX(
s->max_delay, max_delay);
333 if (
ctx->is_disabled || !
s->delays) {
348 for (
i = 0;
i <
s->nb_delays;
i++) {
350 const uint8_t *
src =
frame->extended_data[
i];
354 memcpy(dst,
src,
frame->nb_samples *
s->block_align);
356 s->delay_channel(
d,
frame->nb_samples,
src, dst);
359 out_frame->
pts =
s->next_pts +
s->offset;
393 int nb_samples =
FFMIN(
s->padding, 2048);
398 s->padding -= nb_samples;
409 s->next_pts +=
frame->duration;
417 if (
s->eof &&
s->max_delay) {
418 int nb_samples =
FFMIN(
s->max_delay, 2048);
423 s->max_delay -= nb_samples;
434 s->next_pts +=
frame->duration;
438 if (
s->eof &&
s->max_delay == 0) {
454 for (
int i = 0;
i <
s->nb_delays;
i++)
472 .priv_class = &adelay_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
int(* resize_channel_samples)(ChanDelay *d, int64_t new_delay)
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t duration
Duration of the frame, in the same units as pts.
#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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
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).
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
AVFILTER_DEFINE_CLASS(adelay)
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
const AVFilter ff_af_adelay
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
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 type
A filter pad used for either input or output.
static int activate(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* delay_channel)(ChanDelay *d, int nb_samples, const uint8_t *src, uint8_t *dst)
#define FILTER_SAMPLEFMTS(...)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
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().
static const AVOption adelay_options[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_OUTPUTS(array)
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
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).
static int parse_delays(char *p, char **saveptr, int64_t *result, AVFilterContext *ctx, int sample_rate)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
#define DELAY(name, type, fill)
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
FF_FILTER_FORWARD_WANTED(outlink, inlink)
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
uint8_t ** extended_data
pointers to the data planes/channels.
#define av_malloc_array(a, b)
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
#define CHANGE_DELAY(name, type, fill)
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 or at least make progress towards producing a frame
static const AVFilterPad adelay_inputs[]
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
@ AV_SAMPLE_FMT_DBLP
double, planar
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.
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define flags(name, subs,...)
unsigned int samples_size
@ 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...