Go to the documentation of this file.
51 #define DURATION_LONGEST 0
52 #define DURATION_SHORTEST 1
53 #define DURATION_FIRST 2
80 while (frame_list->
list) {
93 if (!frame_list->
list)
100 if (!frame_list->
list)
117 if (!frame_list->
list)
137 info->nb_samples = nb_samples;
141 if (!frame_list->
list) {
180 #define OFFSET(x) offsetof(MixContext, x)
181 #define A AV_OPT_FLAG_AUDIO_PARAM
182 #define F AV_OPT_FLAG_FILTERING_PARAM
184 {
"inputs",
"Number of inputs.",
186 {
"duration",
"How to determine the end-of-stream.",
191 {
"dropout_transition",
"Transition time, in seconds, for volume "
192 "renormalization when an input stream ends.",
194 {
"weights",
"Set weight for each input.",
210 float weight_sum = 0.f;
213 for (
i = 0;
i <
s->nb_inputs;
i++)
215 weight_sum +=
s->weights[
i];
217 for (
i = 0;
i <
s->nb_inputs;
i++) {
219 if (
s->scale_norm[
i] > weight_sum /
s->weights[
i]) {
220 s->scale_norm[
i] -= ((
s->weight_sum /
s->weights[
i]) /
s->nb_inputs) *
221 nb_samples / (
s->dropout_transition *
s->sample_rate);
222 s->scale_norm[
i] =
FFMAX(
s->scale_norm[
i], weight_sum /
s->weights[
i]);
227 for (
i = 0;
i <
s->nb_inputs;
i++) {
229 s->input_scale[
i] = 1.0f /
s->scale_norm[
i];
231 s->input_scale[
i] = 0.0f;
256 for (
i = 0;
i <
s->nb_inputs;
i++) {
265 memset(
s->input_state,
INPUT_ON,
s->nb_inputs);
266 s->active_inputs =
s->nb_inputs;
270 if (!
s->input_scale || !
s->scale_norm)
272 for (
i = 0;
i <
s->nb_inputs;
i++)
273 s->scale_norm[
i] =
s->weight_sum /
s->weights[
i];
279 "inputs:%d fmt:%s srate:%d cl:%s\n",
s->nb_inputs,
293 int nb_samples,
ns,
i;
298 for (
i = 1;
i <
s->nb_inputs;
i++) {
301 if (
ns < nb_samples) {
312 nb_samples = INT_MAX;
313 for (
i = 1;
i <
s->nb_inputs;
i++) {
316 nb_samples =
FFMIN(nb_samples,
ns);
319 if (nb_samples == INT_MAX) {
343 for (
i = 0;
i <
s->nb_inputs;
i++) {
345 int planes, plane_size, p;
350 planes =
s->planar ?
s->nb_channels : 1;
351 plane_size = nb_samples * (
s->planar ? 1 :
s->nb_channels);
352 plane_size =
FFALIGN(plane_size, 16);
356 for (p = 0; p <
planes; p++) {
359 s->input_scale[
i], plane_size);
362 for (p = 0; p <
planes; p++) {
365 s->input_scale[
i], plane_size);
372 out_buf->
pts =
s->next_pts;
374 s->next_pts += nb_samples;
389 for (
i = 1;
i <
s->nb_inputs;
i++) {
409 int active_inputs = 0;
410 for (
i = 0;
i <
s->nb_inputs;
i++)
411 active_inputs += !!(
s->input_state[
i] &
INPUT_ON);
412 s->active_inputs = active_inputs;
414 if (!active_inputs ||
430 for (
i = 0;
i <
s->nb_inputs;
i++) {
459 for (
i = 0;
i <
s->nb_inputs;
i++) {
466 s->input_state[
i] = 0;
467 if (
s->nb_inputs == 1) {
474 s->input_state[
i] = 0;
492 if (
s->frame_list->nb_frames == 0) {
509 char *p, *
arg, *saveptr =
NULL;
510 float last_weight = 1.f;
513 for (
i = 0;
i <
s->nb_inputs;
i++) {
536 for (
i = 0;
i <
s->nb_inputs;
i++) {
541 sscanf(
arg,
"%f", &last_weight);
542 s->weights[
i] = last_weight;
543 s->weight_sum += last_weight;
546 for (;
i <
s->nb_inputs;
i++) {
547 s->weights[
i] = last_weight;
548 s->weight_sum += last_weight;
560 for (
i = 0;
i <
s->nb_inputs;
i++)
572 for (
i = 0;
i <
ctx->nb_inputs;
i++)
617 .priv_class = &amix_class,
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
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
A list of supported channel layouts.
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
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.
enum MovChannelLayoutTag * layouts
#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
char * av_asprintf(const char *fmt,...)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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.
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).
void * av_mallocz_array(size_t nmemb, size_t size)
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
A link between two filters.
int channels
Number of channels.
#define INPUT_ON
input is active
float * input_scale
mixing scale factor for each input
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define INPUT_EOF
input has reached EOF (may still be active)
int sample_rate
sample rate
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Context for an Audio FIFO Buffer.
FrameList * frame_list
list of frame info for the first input
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
A filter pad used for either input or output.
static const AVFilterPad avfilter_af_amix_outputs[]
static const AVOption amix_options[]
static void calculate_scales(MixContext *s, int nb_samples)
Update the scaling factors to apply to each input during mixing.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
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_assert0(cond)
assert() equivalent, that is always enabled.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
static const AVFilterPad outputs[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int active_inputs
number of input currently active
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.
int duration_mode
mode for determining duration
Describe the class of an AVClass context structure.
int nb_channels
number of channels
float dropout_transition
transition time when an input drops out
Rational number (pair of numerator and denominator).
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVAudioFifo ** fifos
audio fifo for each input
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 inputs
Linked list used to store timestamps and frame sizes of all frames in the FIFO for the first input.
uint8_t * input_state
current state of each input
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
static int frame_list_add_frame(FrameList *frame_list, int nb_samples, int64_t pts)
static const struct @314 planes[]
static int config_output(AVFilterLink *outlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold void uninit(AVFilterContext *ctx)
int format
agreed upon media format
#define AV_NOPTS_VALUE
Undefined timestamp value.
float * scale_norm
normalization factor for every input
char * weights_str
string for custom weights for every input
static int output_frame(AVFilterLink *outlink)
Read samples from the input FIFOs, mix, and write to the output link.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
static int activate(AVFilterContext *ctx)
AVFilterContext * src
source filter
static int64_t frame_list_next_pts(FrameList *frame_list)
#define ns(max_value, name, subs,...)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
float weight_sum
sum of custom weights for every input
int64_t next_pts
calculated pts for next output frame
int sample_rate
samples per second
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
static int frame_list_next_frame_size(FrameList *frame_list)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Pad name.
enum AVMediaType type
AVFilterPad type.
float * weights
custom weights for every input
static int calc_active_inputs(MixContext *s)
Calculates the number of active inputs and determines EOF based on the duration option.
AVFILTER_DEFINE_CLASS(amix)
@ AV_SAMPLE_FMT_DBLP
double, planar
Filter the word “frame” indicates either a video frame or a group of audio samples
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static int request_samples(AVFilterContext *ctx, int min_samples)
Requests a frame, if needed, from each input link other than the first.
#define DURATION_SHORTEST
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static av_cold int init(AVFilterContext *ctx)
static void frame_list_clear(FrameList *frame_list)
#define flags(name, subs,...)
static int query_formats(AVFilterContext *ctx)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
@ AV_SAMPLE_FMT_DBL
double
static void frame_list_remove_samples(FrameList *frame_list, int nb_samples)
int nb_inputs
number of inputs