50 #define DURATION_LONGEST 0
51 #define DURATION_SHORTEST 1
52 #define DURATION_FIRST 2
79 while (frame_list->
list) {
92 if (!frame_list->
list)
99 if (!frame_list->
list)
109 int samples = nb_samples;
110 while (samples > 0) {
116 if (!frame_list->
list)
123 info->
pts += samples;
140 if (!frame_list->
list) {
141 frame_list->
list = info;
142 frame_list->
end = info;
146 frame_list->
end = info;
175 #define OFFSET(x) offsetof(MixContext, x)
176 #define A AV_OPT_FLAG_AUDIO_PARAM
177 #define F AV_OPT_FLAG_FILTERING_PARAM
179 {
"inputs",
"Number of inputs.",
181 {
"duration",
"How to determine the end-of-stream.",
186 {
"dropout_transition",
"Transition time, in seconds, for volume "
187 "renormalization when an input stream ends.",
260 "inputs:%d fmt:%s srate:%d cl:%s\n", s->
nb_inputs,
276 int nb_samples, ns, ret, i;
288 if (ns < nb_samples) {
299 nb_samples = INT_MAX;
303 nb_samples =
FFMIN(nb_samples, ns);
306 if (nb_samples == INT_MAX)
330 int planes, plane_size, p;
337 plane_size =
FFALIGN(plane_size, 16);
339 for (p = 0; p < planes; p++) {
393 int active_inputs = 0;
398 if (!active_inputs ||
444 if (ctx->
inputs[i] == inlink)
481 snprintf(name,
sizeof(name),
"input%d", i);
558 .priv_class = &amix_class,
563 .
outputs = avfilter_af_amix_outputs,
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
This structure describes decoded (raw) audio or video data.
Main libavfilter public API header.
static av_cold void uninit(AVFilterContext *ctx)
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
static enum AVSampleFormat formats[]
enum AVMediaType type
AVFilterPad type.
static int frame_list_next_frame_size(FrameList *frame_list)
Macro definitions for various function/variable attributes.
Linked list used to store timestamps and frame sizes of all frames in the FIFO for the first input...
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#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.
static int64_t frame_list_next_pts(FrameList *frame_list)
static int request_samples(AVFilterContext *ctx, int min_samples)
Requests a frame, if needed, from each input link other than the first.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static const AVFilterPad avfilter_af_amix_outputs[]
static int calc_active_inputs(MixContext *s)
Calculates the number of active inputs and determines EOF based on the duration option.
int sample_rate
sample rate
static int query_formats(AVFilterContext *ctx)
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
float dropout_transition
transition time when an input drops out
FrameList * frame_list
list of frame info for the first input
float * input_scale
mixing scale factor for each input
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
AVAudioFifo ** fifos
audio fifo for each input
AVFilterPad * input_pads
array of input pads
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
float scale_norm
normalization factor for all inputs
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
uint64_t * channel_layouts
list of channel layouts
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Context for an Audio FIFO Buffer.
int active_inputs
number of input currently active
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
audio channel layout utility functions
unsigned nb_inputs
number of input pads
static void frame_list_remove_samples(FrameList *frame_list, int nb_samples)
int duration_mode
mode for determining duration
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
int nb_channels
number of channels
int format
agreed upon media format
static int frame_list_add_frame(FrameList *frame_list, int nb_samples, int64_t pts)
A list of supported channel layouts.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
static const AVFilterPad inputs[]
char * av_strdup(const char *s)
Duplicate the string s.
uint8_t * input_state
current state of each input
Describe the class of an AVClass context structure.
rational number numerator/denominator
const char * name
Filter name.
static int output_frame(AVFilterLink *outlink)
Read samples from the input FIFOs, mix, and write to the output link.
#define INPUT_ON
input is active
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
int64_t next_pts
calculated pts for next output frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
#define DURATION_SHORTEST
static int64_t pts
Global timestamp for the audio frames.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
#define INPUT_EOF
input has reached EOF (may still be active)
static void calculate_scales(MixContext *s, int nb_samples)
Update the scaling factors to apply to each input during mixing.
common internal and external API header
AVFILTER_DEFINE_CLASS(amix)
static int request_frame(AVFilterLink *outlink)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static const AVOption amix_options[]
AVFilterContext * dst
dest filter
int nb_inputs
number of inputs
static void * av_mallocz_array(size_t nmemb, size_t size)
static av_cold int init(AVFilterContext *ctx)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static int config_output(AVFilterLink *outlink)
uint8_t ** extended_data
pointers to the data planes/channels.
int nb_samples
number of audio samples (per channel) described by this frame
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void frame_list_clear(FrameList *frame_list)
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.