Go to the documentation of this file.
54 const uint8_t *
src, uint8_t *dst);
58 #define OFFSET(x) offsetof(AudioDelayContext, x)
59 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
69 #define DELAY(name, type, fill) \
70 static void delay_channel_## name ##p(ChanDelay *d, int nb_samples, \
71 const uint8_t *ssrc, uint8_t *ddst) \
73 const type *src = (type *)ssrc; \
74 type *dst = (type *)ddst; \
75 type *samples = (type *)d->samples; \
77 while (nb_samples) { \
78 if (d->delay_index < d->delay) { \
79 const int len = FFMIN(nb_samples, d->delay - d->delay_index); \
81 memcpy(&samples[d->delay_index], src, len * sizeof(type)); \
82 memset(dst, fill, len * sizeof(type)); \
83 d->delay_index += len; \
88 *dst = samples[d->index]; \
89 samples[d->index] = *src; \
93 d->index = d->index >= d->delay ? 0 : d->index; \
98 DELAY(u8, uint8_t, 0x80)
99 DELAY(s16, int16_t, 0)
102 DELAY(dbl,
double, 0)
104 #define CHANGE_DELAY(name, type, fill) \
105 static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay) \
109 if (new_delay == d->delay) { \
113 if (new_delay == 0) { \
114 av_freep(&d->samples); \
115 d->samples_size = 0; \
118 d->delay_index = 0; \
122 samples = (type *) av_fast_realloc(d->samples, &d->samples_size, new_delay * sizeof(type)); \
124 return AVERROR(ENOMEM); \
127 if (new_delay < d->delay) { \
128 if (d->index > new_delay) { \
129 d->index -= new_delay; \
130 memmove(samples, &samples[new_delay], d->index * sizeof(type)); \
131 d->delay_index = new_delay; \
132 } else if (d->delay_index > d->index) { \
133 memmove(&samples[d->index], &samples[d->index+(d->delay-new_delay)], \
134 (new_delay - d->index) * sizeof(type)); \
135 d->delay_index -= d->delay - new_delay; \
139 if (d->delay_index >= d->delay) { \
140 block_size = (d->delay - d->index) * sizeof(type); \
141 memmove(&samples[d->index+(new_delay - d->delay)], &samples[d->index], block_size); \
142 d->delay_index = new_delay; \
144 d->delay_index += new_delay - d->delay; \
146 block_size = (new_delay - d->delay) * sizeof(type); \
147 memset(&samples[d->index], fill, block_size); \
149 d->delay = new_delay; \
150 d->samples = (void *) samples; \
171 div =
type ==
's' ? 1.0 : 1000.0;
190 char *p, *saveptr =
NULL;
197 s->nb_delays =
inlink->ch_layout.nb_channels;
201 for (
i = 0;
i <
s->nb_delays;
i++) {
214 for (
int j =
i; j <
s->nb_delays; j++)
215 s->chandelay[j].delay =
s->chandelay[
i-1].delay;
218 s->padding =
s->chandelay[0].delay;
219 for (
i = 1;
i <
s->nb_delays;
i++) {
222 s->padding =
FFMIN(
s->padding,
d->delay);
226 for (
i = 0;
i <
s->nb_delays;
i++) {
229 d->delay -=
s->padding;
237 for (
i = 0;
i <
s->nb_delays;
i++) {
243 if (
d->delay > SIZE_MAX) {
251 d->samples_size =
d->delay *
s->block_align;
253 s->max_delay =
FFMAX(
s->max_delay,
d->delay);
258 s->resize_channel_samples = resize_samples_u8p;
break;
260 s->resize_channel_samples = resize_samples_s16p;
break;
262 s->resize_channel_samples = resize_samples_s32p;
break;
264 s->resize_channel_samples = resize_samples_fltp;
break;
266 s->resize_channel_samples = resize_samples_dblp;
break;
273 char *res,
int res_len,
int flags)
279 if (!strcmp(cmd,
"delays")) {
281 char *p, *saveptr =
NULL;
285 if (args_cpy ==
NULL) {
292 if (!strncmp(args,
"all:", 4)) {
302 for (
int i = 0;
i <
s->nb_delays;
i++) {
314 ret =
s->resize_channel_samples(
d, delay);
317 max_delay =
FFMAX(max_delay,
d->delay);
319 s->max_delay =
FFMAX(
s->max_delay, max_delay);
334 if (
ctx->is_disabled || !
s->delays) {
349 for (
i = 0;
i <
s->nb_delays;
i++) {
360 out_frame->
pts =
s->next_pts +
s->offset;
394 int nb_samples =
FFMIN(
s->padding, 2048);
399 s->padding -= nb_samples;
418 if (
s->eof &&
s->max_delay) {
419 int nb_samples =
FFMIN(
s->max_delay, 2048);
424 s->max_delay -= nb_samples;
439 if (
s->eof &&
s->max_delay == 0) {
455 for (
int i = 0;
i <
s->nb_delays;
i++)
473 .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.
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)
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.
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)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
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)
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)
#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(...)