2011-11-06 20:28:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Nicolas George <nicolas.george@normalesup.org>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-08-02 17:28:55 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2011-11-06 20:28:05 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Audio merging filter
|
|
|
|
*/
|
|
|
|
|
2012-09-11 04:41:55 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2012-06-03 19:32:22 +00:00
|
|
|
#include "libavutil/bprint.h"
|
2012-11-13 13:16:48 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-06-03 19:32:22 +00:00
|
|
|
#include "libavutil/opt.h"
|
2011-11-06 20:28:05 +00:00
|
|
|
#include "libswresample/swresample.h" // only for SWR_CH_MAX
|
|
|
|
#include "avfilter.h"
|
2012-05-12 15:58:14 +00:00
|
|
|
#include "audio.h"
|
2012-05-31 19:47:10 +00:00
|
|
|
#include "bufferqueue.h"
|
2011-11-06 20:28:05 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
typedef struct {
|
2012-06-03 19:32:22 +00:00
|
|
|
const AVClass *class;
|
|
|
|
int nb_inputs;
|
2011-11-06 20:28:05 +00:00
|
|
|
int route[SWR_CH_MAX]; /**< channels routing, see copy_samples */
|
|
|
|
int bps;
|
2012-05-31 19:47:10 +00:00
|
|
|
struct amerge_input {
|
|
|
|
struct FFBufQueue queue;
|
2012-05-31 21:55:33 +00:00
|
|
|
int nb_ch; /**< number of channels for the input */
|
2012-05-31 19:47:10 +00:00
|
|
|
int nb_samples;
|
|
|
|
int pos;
|
2012-06-03 19:32:22 +00:00
|
|
|
} *in;
|
2011-11-06 20:28:05 +00:00
|
|
|
} AMergeContext;
|
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
#define OFFSET(x) offsetof(AMergeContext, x)
|
2012-08-13 11:40:01 +00:00
|
|
|
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
2012-06-03 19:32:22 +00:00
|
|
|
|
|
|
|
static const AVOption amerge_options[] = {
|
|
|
|
{ "inputs", "specify the number of inputs", OFFSET(nb_inputs),
|
2012-09-05 12:26:01 +00:00
|
|
|
AV_OPT_TYPE_INT, { .i64 = 2 }, 2, SWR_CH_MAX, FLAGS },
|
2012-06-15 07:46:13 +00:00
|
|
|
{0}
|
2012-06-03 19:32:22 +00:00
|
|
|
};
|
|
|
|
|
2012-06-22 12:33:09 +00:00
|
|
|
AVFILTER_DEFINE_CLASS(amerge);
|
2012-06-03 19:32:22 +00:00
|
|
|
|
2011-11-06 20:28:05 +00:00
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AMergeContext *am = ctx->priv;
|
2012-05-31 19:47:10 +00:00
|
|
|
int i;
|
2011-11-06 20:28:05 +00:00
|
|
|
|
2012-09-11 04:41:55 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
2013-02-21 19:15:08 +00:00
|
|
|
if (am->in)
|
|
|
|
ff_bufqueue_discard_all(&am->in[i].queue);
|
|
|
|
if (ctx->input_pads)
|
|
|
|
av_freep(&ctx->input_pads[i].name);
|
2012-09-11 04:41:55 +00:00
|
|
|
}
|
2012-06-03 19:32:22 +00:00
|
|
|
av_freep(&am->in);
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AMergeContext *am = ctx->priv;
|
2012-06-03 19:32:22 +00:00
|
|
|
int64_t inlayout[SWR_CH_MAX], outlayout = 0;
|
2011-11-06 20:28:05 +00:00
|
|
|
AVFilterFormats *formats;
|
2012-05-16 00:27:31 +00:00
|
|
|
AVFilterChannelLayouts *layouts;
|
2012-06-03 19:32:22 +00:00
|
|
|
int i, overlap = 0, nb_ch = 0;
|
2011-11-06 20:28:05 +00:00
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
2012-05-16 00:27:31 +00:00
|
|
|
if (!ctx->inputs[i]->in_channel_layouts ||
|
|
|
|
!ctx->inputs[i]->in_channel_layouts->nb_channel_layouts) {
|
2011-11-06 20:28:05 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"No channel layout for input %d\n", i + 1);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2012-05-16 00:27:31 +00:00
|
|
|
inlayout[i] = ctx->inputs[i]->in_channel_layouts->channel_layouts[0];
|
|
|
|
if (ctx->inputs[i]->in_channel_layouts->nb_channel_layouts > 1) {
|
2011-11-06 20:28:05 +00:00
|
|
|
char buf[256];
|
|
|
|
av_get_channel_layout_string(buf, sizeof(buf), 0, inlayout[i]);
|
|
|
|
av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1);
|
|
|
|
}
|
2012-05-31 21:55:33 +00:00
|
|
|
am->in[i].nb_ch = av_get_channel_layout_nb_channels(inlayout[i]);
|
2012-06-03 19:32:22 +00:00
|
|
|
if (outlayout & inlayout[i])
|
|
|
|
overlap++;
|
|
|
|
outlayout |= inlayout[i];
|
|
|
|
nb_ch += am->in[i].nb_ch;
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
2012-06-03 19:32:22 +00:00
|
|
|
if (nb_ch > SWR_CH_MAX) {
|
2011-11-06 20:28:05 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Too many channels (max %d)\n", SWR_CH_MAX);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2012-06-03 19:32:22 +00:00
|
|
|
if (overlap) {
|
2011-11-06 20:28:05 +00:00
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
2012-09-11 08:32:13 +00:00
|
|
|
"Input channel layouts overlap: "
|
|
|
|
"output layout will be determined by the number of distinct input channels\n");
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < nb_ch; i++)
|
2011-11-06 20:28:05 +00:00
|
|
|
am->route[i] = i;
|
2012-06-03 19:32:22 +00:00
|
|
|
outlayout = av_get_default_channel_layout(nb_ch);
|
2011-11-06 20:28:05 +00:00
|
|
|
if (!outlayout)
|
2012-06-03 19:32:22 +00:00
|
|
|
outlayout = ((int64_t)1 << nb_ch) - 1;
|
2011-11-06 20:28:05 +00:00
|
|
|
} else {
|
2012-06-03 19:32:22 +00:00
|
|
|
int *route[SWR_CH_MAX];
|
2011-11-06 20:28:05 +00:00
|
|
|
int c, out_ch_number = 0;
|
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
route[0] = am->route;
|
|
|
|
for (i = 1; i < am->nb_inputs; i++)
|
|
|
|
route[i] = route[i - 1] + am->in[i - 1].nb_ch;
|
2011-11-06 20:28:05 +00:00
|
|
|
for (c = 0; c < 64; c++)
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++)
|
2011-11-06 20:28:05 +00:00
|
|
|
if ((inlayout[i] >> c) & 1)
|
|
|
|
*(route[i]++) = out_ch_number++;
|
|
|
|
}
|
2012-06-16 09:47:46 +00:00
|
|
|
formats = ff_make_format_list(ff_packed_sample_fmts_array);
|
|
|
|
ff_set_common_formats(ctx, formats);
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
2012-05-16 00:27:31 +00:00
|
|
|
layouts = NULL;
|
|
|
|
ff_add_channel_layout(&layouts, inlayout[i]);
|
|
|
|
ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
2012-05-16 00:27:31 +00:00
|
|
|
layouts = NULL;
|
|
|
|
ff_add_channel_layout(&layouts, outlayout);
|
|
|
|
ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
|
2012-05-23 10:58:15 +00:00
|
|
|
ff_set_common_samplerates(ctx, ff_all_samplerates());
|
2011-11-06 20:28:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_output(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AMergeContext *am = ctx->priv;
|
2012-06-03 19:32:22 +00:00
|
|
|
AVBPrint bp;
|
2011-11-06 20:28:05 +00:00
|
|
|
int i;
|
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 1; i < am->nb_inputs; i++) {
|
|
|
|
if (ctx->inputs[i]->sample_rate != ctx->inputs[0]->sample_rate) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Inputs must have the same sample rate "
|
2012-06-28 16:51:17 +00:00
|
|
|
"%d for in%d vs %d\n",
|
2012-06-03 19:32:22 +00:00
|
|
|
ctx->inputs[i]->sample_rate, i, ctx->inputs[0]->sample_rate);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
|
|
|
am->bps = av_get_bytes_per_sample(ctx->outputs[0]->format);
|
|
|
|
outlink->sample_rate = ctx->inputs[0]->sample_rate;
|
|
|
|
outlink->time_base = ctx->inputs[0]->time_base;
|
2012-06-03 19:32:22 +00:00
|
|
|
|
|
|
|
av_bprint_init(&bp, 0, 1);
|
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
|
|
|
av_bprintf(&bp, "%sin%d:", i ? " + " : "", i);
|
|
|
|
av_bprint_channel_layout(&bp, -1, ctx->inputs[i]->channel_layout);
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
2012-06-03 19:32:22 +00:00
|
|
|
av_bprintf(&bp, " -> out:");
|
|
|
|
av_bprint_channel_layout(&bp, -1, ctx->outputs[0]->channel_layout);
|
2012-07-14 16:26:04 +00:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "%s\n", bp.str);
|
2012-06-03 19:32:22 +00:00
|
|
|
|
2011-11-06 20:28:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AMergeContext *am = ctx->priv;
|
2012-04-26 15:43:00 +00:00
|
|
|
int i, ret;
|
2011-11-06 20:28:05 +00:00
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++)
|
2012-05-31 19:47:10 +00:00
|
|
|
if (!am->in[i].nb_samples)
|
2012-06-24 00:09:53 +00:00
|
|
|
if ((ret = ff_request_frame(ctx->inputs[i])) < 0)
|
2012-04-26 15:43:00 +00:00
|
|
|
return ret;
|
2011-11-06 20:28:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-03 19:32:22 +00:00
|
|
|
* Copy samples from several input streams to one output stream.
|
|
|
|
* @param nb_inputs number of inputs
|
2012-05-31 21:55:33 +00:00
|
|
|
* @param in inputs; used only for the nb_ch field;
|
2011-11-06 20:28:05 +00:00
|
|
|
* @param route routing values;
|
|
|
|
* input channel i goes to output channel route[i];
|
2012-05-31 21:55:33 +00:00
|
|
|
* i < in[0].nb_ch are the channels from the first output;
|
|
|
|
* i >= in[0].nb_ch are the channels from the second output
|
2011-11-06 20:28:05 +00:00
|
|
|
* @param ins pointer to the samples of each inputs, in packed format;
|
|
|
|
* will be left at the end of the copied samples
|
|
|
|
* @param outs pointer to the samples of the output, in packet format;
|
|
|
|
* must point to a buffer big enough;
|
|
|
|
* will be left at the end of the copied samples
|
|
|
|
* @param ns number of samples to copy
|
|
|
|
* @param bps bytes per sample
|
|
|
|
*/
|
2012-06-03 19:32:22 +00:00
|
|
|
static inline void copy_samples(int nb_inputs, struct amerge_input in[],
|
|
|
|
int *route, uint8_t *ins[],
|
2011-11-06 20:28:05 +00:00
|
|
|
uint8_t **outs, int ns, int bps)
|
|
|
|
{
|
|
|
|
int *route_cur;
|
2012-06-03 19:32:22 +00:00
|
|
|
int i, c, nb_ch = 0;
|
2011-11-06 20:28:05 +00:00
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < nb_inputs; i++)
|
|
|
|
nb_ch += in[i].nb_ch;
|
2011-11-06 20:28:05 +00:00
|
|
|
while (ns--) {
|
|
|
|
route_cur = route;
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < nb_inputs; i++) {
|
2012-05-31 21:55:33 +00:00
|
|
|
for (c = 0; c < in[i].nb_ch; c++) {
|
2011-11-06 20:28:05 +00:00
|
|
|
memcpy((*outs) + bps * *(route_cur++), ins[i], bps);
|
|
|
|
ins[i] += bps;
|
|
|
|
}
|
|
|
|
}
|
2012-06-03 19:32:22 +00:00
|
|
|
*outs += nb_ch * bps;
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-10 00:30:30 +00:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
|
2011-11-06 20:28:05 +00:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AMergeContext *am = ctx->priv;
|
2012-02-01 14:53:54 +00:00
|
|
|
AVFilterLink *const outlink = ctx->outputs[0];
|
2012-06-03 19:32:22 +00:00
|
|
|
int input_number;
|
2011-11-06 20:28:05 +00:00
|
|
|
int nb_samples, ns, i;
|
2013-03-10 00:30:30 +00:00
|
|
|
AVFrame *outbuf, *inbuf[SWR_CH_MAX];
|
2012-06-03 19:32:22 +00:00
|
|
|
uint8_t *ins[SWR_CH_MAX], *outs;
|
2011-11-06 20:28:05 +00:00
|
|
|
|
2012-06-03 19:32:22 +00:00
|
|
|
for (input_number = 0; input_number < am->nb_inputs; input_number++)
|
|
|
|
if (inlink == ctx->inputs[input_number])
|
|
|
|
break;
|
|
|
|
av_assert1(input_number < am->nb_inputs);
|
2013-01-31 13:24:57 +00:00
|
|
|
if (ff_bufqueue_is_full(&am->in[input_number].queue)) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Buffer queue overflow\n");
|
2013-03-10 00:30:30 +00:00
|
|
|
av_frame_free(&insamples);
|
2013-01-31 13:24:57 +00:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2013-03-10 00:30:30 +00:00
|
|
|
ff_bufqueue_add(ctx, &am->in[input_number].queue, av_frame_clone(insamples));
|
|
|
|
am->in[input_number].nb_samples += insamples->nb_samples;
|
|
|
|
av_frame_free(&insamples);
|
2012-06-03 19:32:22 +00:00
|
|
|
nb_samples = am->in[0].nb_samples;
|
|
|
|
for (i = 1; i < am->nb_inputs; i++)
|
|
|
|
nb_samples = FFMIN(nb_samples, am->in[i].nb_samples);
|
|
|
|
if (!nb_samples)
|
2012-07-09 20:10:38 +00:00
|
|
|
return 0;
|
2011-11-06 20:28:05 +00:00
|
|
|
|
2013-03-10 00:30:30 +00:00
|
|
|
outbuf = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
|
2011-11-06 20:28:05 +00:00
|
|
|
outs = outbuf->data[0];
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
2012-05-31 19:47:10 +00:00
|
|
|
inbuf[i] = ff_bufqueue_peek(&am->in[i].queue, 0);
|
|
|
|
ins[i] = inbuf[i]->data[0] +
|
2012-05-31 21:55:33 +00:00
|
|
|
am->in[i].pos * am->in[i].nb_ch * am->bps;
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
2013-03-10 00:30:30 +00:00
|
|
|
av_frame_copy_props(outbuf, inbuf[0]);
|
2012-05-31 19:47:10 +00:00
|
|
|
outbuf->pts = inbuf[0]->pts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE :
|
|
|
|
inbuf[0]->pts +
|
|
|
|
av_rescale_q(am->in[0].pos,
|
2012-05-23 11:14:27 +00:00
|
|
|
(AVRational){ 1, ctx->inputs[0]->sample_rate },
|
|
|
|
ctx->outputs[0]->time_base);
|
2012-02-01 14:53:54 +00:00
|
|
|
|
2013-03-10 00:30:30 +00:00
|
|
|
outbuf->nb_samples = nb_samples;
|
|
|
|
outbuf->channel_layout = outlink->channel_layout;
|
2013-03-15 15:13:53 +00:00
|
|
|
av_frame_set_channels(outbuf, outlink->channels);
|
2012-02-01 14:53:54 +00:00
|
|
|
|
2011-11-06 20:28:05 +00:00
|
|
|
while (nb_samples) {
|
|
|
|
ns = nb_samples;
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++)
|
2013-03-10 00:30:30 +00:00
|
|
|
ns = FFMIN(ns, inbuf[i]->nb_samples - am->in[i].pos);
|
2011-11-06 20:28:05 +00:00
|
|
|
/* Unroll the most common sample formats: speed +~350% for the loop,
|
|
|
|
+~13% overall (including two common decoders) */
|
|
|
|
switch (am->bps) {
|
|
|
|
case 1:
|
2012-06-03 19:32:22 +00:00
|
|
|
copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, 1);
|
2011-11-06 20:28:05 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2012-06-03 19:32:22 +00:00
|
|
|
copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, 2);
|
2011-11-06 20:28:05 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2012-06-03 19:32:22 +00:00
|
|
|
copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, 4);
|
2011-11-06 20:28:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-06-03 19:32:22 +00:00
|
|
|
copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, am->bps);
|
2011-11-06 20:28:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nb_samples -= ns;
|
2012-06-03 19:32:22 +00:00
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
2012-05-31 19:47:10 +00:00
|
|
|
am->in[i].nb_samples -= ns;
|
|
|
|
am->in[i].pos += ns;
|
2013-03-10 00:30:30 +00:00
|
|
|
if (am->in[i].pos == inbuf[i]->nb_samples) {
|
2012-05-31 19:47:10 +00:00
|
|
|
am->in[i].pos = 0;
|
2013-03-10 00:30:30 +00:00
|
|
|
av_frame_free(&inbuf[i]);
|
2012-05-31 19:47:10 +00:00
|
|
|
ff_bufqueue_get(&am->in[i].queue);
|
|
|
|
inbuf[i] = ff_bufqueue_peek(&am->in[i].queue, 0);
|
|
|
|
ins[i] = inbuf[i] ? inbuf[i]->data[0] : NULL;
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 12:53:48 +00:00
|
|
|
return ff_filter_frame(ctx->outputs[0], outbuf);
|
2011-11-06 20:28:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-26 21:27:59 +00:00
|
|
|
static av_cold int init(AVFilterContext *ctx, const char *args)
|
2012-06-03 19:32:22 +00:00
|
|
|
{
|
|
|
|
AMergeContext *am = ctx->priv;
|
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
am->class = &amerge_class;
|
|
|
|
av_opt_set_defaults(am);
|
|
|
|
ret = av_set_options_string(am, args, "=", ":");
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Error parsing options: '%s'\n", args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
am->in = av_calloc(am->nb_inputs, sizeof(*am->in));
|
|
|
|
if (!am->in)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
for (i = 0; i < am->nb_inputs; i++) {
|
2012-09-11 04:41:55 +00:00
|
|
|
char *name = av_asprintf("in%d", i);
|
2012-06-03 19:32:22 +00:00
|
|
|
AVFilterPad pad = {
|
|
|
|
.name = name,
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-11-28 12:53:48 +00:00
|
|
|
.filter_frame = filter_frame,
|
2012-06-03 19:32:22 +00:00
|
|
|
};
|
2012-09-11 16:36:09 +00:00
|
|
|
if (!name)
|
|
|
|
return AVERROR(ENOMEM);
|
2012-06-16 09:47:46 +00:00
|
|
|
ff_insert_inpad(ctx, i, &pad);
|
2012-06-03 19:32:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 19:01:59 +00:00
|
|
|
static const AVFilterPad amerge_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_output,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2011-11-06 20:28:05 +00:00
|
|
|
AVFilter avfilter_af_amerge = {
|
|
|
|
.name = "amerge",
|
2013-02-11 12:47:02 +00:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Merge two or more audio streams into "
|
2011-11-06 20:28:05 +00:00
|
|
|
"a single multi-channel stream."),
|
|
|
|
.priv_size = sizeof(AMergeContext),
|
2012-06-03 19:32:22 +00:00
|
|
|
.init = init,
|
2011-11-06 20:28:05 +00:00
|
|
|
.uninit = uninit,
|
|
|
|
.query_formats = query_formats,
|
2012-11-28 19:01:59 +00:00
|
|
|
.inputs = NULL,
|
|
|
|
.outputs = amerge_outputs,
|
|
|
|
.priv_class = &amerge_class,
|
2011-11-06 20:28:05 +00:00
|
|
|
};
|