Go to the documentation of this file.
51 const uint8_t *
src, uint8_t *dst);
55 #define OFFSET(x) offsetof(AudioDelayContext, x)
56 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
66 #define DELAY(name, type, fill) \
67 static void delay_channel_## name ##p(ChanDelay *d, int nb_samples, \
68 const uint8_t *ssrc, uint8_t *ddst) \
70 const type *src = (type *)ssrc; \
71 type *dst = (type *)ddst; \
72 type *samples = (type *)d->samples; \
74 while (nb_samples) { \
75 if (d->delay_index < d->delay) { \
76 const int len = FFMIN(nb_samples, d->delay - d->delay_index); \
78 memcpy(&samples[d->delay_index], src, len * sizeof(type)); \
79 memset(dst, fill, len * sizeof(type)); \
80 d->delay_index += len; \
85 *dst = samples[d->index]; \
86 samples[d->index] = *src; \
90 d->index = d->index >= d->delay ? 0 : d->index; \
95 DELAY(u8, uint8_t, 0x80)
96 DELAY(s16, int16_t, 0)
101 #define CHANGE_DELAY(name, type, fill) \
102 static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay) \
106 if (new_delay == d->delay) { \
110 if (new_delay == 0) { \
111 av_freep(&d->samples); \
112 d->samples_size = 0; \
115 d->delay_index = 0; \
119 samples = (type *) av_fast_realloc(d->samples, &d->samples_size, new_delay * sizeof(type)); \
121 return AVERROR(ENOMEM); \
124 if (new_delay < d->delay) { \
125 if (d->index > new_delay) { \
126 d->index -= new_delay; \
127 memmove(samples, &samples[new_delay], d->index * sizeof(type)); \
128 d->delay_index = new_delay; \
129 } else if (d->delay_index > d->index) { \
130 memmove(&samples[d->index], &samples[d->index+(d->delay-new_delay)], \
131 (new_delay - d->index) * sizeof(type)); \
132 d->delay_index -= d->delay - new_delay; \
136 if (d->delay_index >= d->delay) { \
137 block_size = (d->delay - d->index) * sizeof(type); \
138 memmove(&samples[d->index+(new_delay - d->delay)], &samples[d->index], block_size); \
139 d->delay_index = new_delay; \
141 d->delay_index += new_delay - d->delay; \
143 block_size = (new_delay - d->delay) * sizeof(type); \
144 memset(&samples[d->index], fill, block_size); \
146 d->delay = new_delay; \
147 d->samples = (void *) samples; \
168 div =
type ==
's' ? 1.0 : 1000.0;
187 char *p, *saveptr =
NULL;
193 s->nb_delays =
inlink->ch_layout.nb_channels;
197 for (
i = 0;
i <
s->nb_delays;
i++) {
210 for (
int j =
i; j <
s->nb_delays; j++)
211 s->chandelay[j].delay =
s->chandelay[
i-1].delay;
214 s->padding =
s->chandelay[0].delay;
215 for (
i = 1;
i <
s->nb_delays;
i++) {
218 s->padding =
FFMIN(
s->padding,
d->delay);
222 for (
i = 0;
i <
s->nb_delays;
i++) {
225 d->delay -=
s->padding;
229 for (
i = 0;
i <
s->nb_delays;
i++) {
235 if (
d->delay > SIZE_MAX) {
243 d->samples_size =
d->delay *
s->block_align;
245 s->max_delay =
FFMAX(
s->max_delay,
d->delay);
250 s->resize_channel_samples = resize_samples_u8p;
break;
252 s->resize_channel_samples = resize_samples_s16p;
break;
254 s->resize_channel_samples = resize_samples_s32p;
break;
256 s->resize_channel_samples = resize_samples_fltp;
break;
258 s->resize_channel_samples = resize_samples_dblp;
break;
265 char *res,
int res_len,
int flags)
271 if (!strcmp(cmd,
"delays")) {
273 char *p, *saveptr =
NULL;
274 int64_t all_delay = -1;
275 int64_t max_delay = 0;
277 if (args_cpy ==
NULL) {
284 if (!strncmp(args,
"all:", 4)) {
294 for (
int i = 0;
i <
s->nb_delays;
i++) {
306 ret =
s->resize_channel_samples(
d, delay);
309 max_delay =
FFMAX(max_delay,
d->delay);
311 s->max_delay =
FFMAX(
s->max_delay, max_delay);
326 if (
ctx->is_disabled || !
s->delays)
336 for (
i = 0;
i <
s->nb_delays;
i++) {
338 const uint8_t *
src =
frame->extended_data[
i];
342 memcpy(dst,
src,
frame->nb_samples *
s->block_align);
344 s->delay_channel(
d,
frame->nb_samples,
src, dst);
347 out_frame->
pts =
s->next_pts;
365 int nb_samples =
FFMIN(
s->padding, 2048);
370 s->padding -= nb_samples;
396 if (
s->eof &&
s->max_delay) {
397 int nb_samples =
FFMIN(
s->max_delay, 2048);
402 s->max_delay -= nb_samples;
413 if (
s->eof &&
s->max_delay == 0) {
429 for (
int i = 0;
i <
s->nb_delays;
i++)
454 .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
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
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.
#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.
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).
AVFILTER_DEFINE_CLASS(adelay)
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
#define AV_OPT_FLAG_RUNTIME_PARAM
a generic parameter which can be set by the user at runtime
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)
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_INPUTS(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.
static const AVFilterPad adelay_outputs[]
Rational number (pair of numerator and denominator).
static int parse_delays(char *p, char **saveptr, int64_t *result, AVFilterContext *ctx, int sample_rate)
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)
#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 sample_rate
samples per second
#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)
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
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[]
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)
#define FILTER_OUTPUTS(array)
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
#define FILTER_SAMPLEFMTS(...)