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) \
69static 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; \
97DELAY(u8, uint8_t, 0x80)
103#define CHANGE_DELAY(name, type, fill) \
104static 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; \
169 if (ret != 2 ||
type !=
'S') {
170 div =
type ==
's' ? 1.0 : 1000.0;
175 *result = delay * sample_rate / div;
189 char *p, *saveptr =
NULL;
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++) {
225 for (
i = 0;
i <
s->nb_delays;
i++) {
236 for (
i = 0;
i <
s->nb_delays;
i++) {
242 if (d->
delay > SIZE_MAX) {
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);
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];
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++)
471 .p.priv_class = &adelay_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define DELAY(name, type, fill)
static const AVOption adelay_options[]
static const AVFilterPad adelay_inputs[]
const FFFilter ff_af_adelay
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
#define CHANGE_DELAY(name, type, fill)
static int parse_delays(char *p, char **saveptr, int64_t *result, AVFilterContext *ctx, int sample_rate)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Main libavfilter public API header.
int av_sscanf(const char *string, const char *format,...)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVERROR_EOF
End of file.
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_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
@ AV_SAMPLE_FMT_DBLP
double, planar
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.
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_NOPTS_VALUE
Undefined timestamp value.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_SAMPLEFMTS(...)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
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
AVChannelLayout ch_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.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int64_t duration
Duration of the frame, in the same units as pts.
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
int(* resize_channel_samples)(ChanDelay *d, int64_t new_delay)
void(* delay_channel)(ChanDelay *d, int nb_samples, const uint8_t *src, uint8_t *dst)
unsigned int samples_size
#define av_malloc_array(a, b)
static AVFormatContext * ctx