2011-11-06 23:28:05 +03: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 20:28:55 +03:00
|
|
|
* GNU Lesser General Public License for more details.
|
2011-11-06 23:28:05 +03: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 07:41:55 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2012-06-03 22:32:22 +03:00
|
|
|
#include "libavutil/bprint.h"
|
2012-11-13 16:16:48 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2024-03-25 02:30:37 +02:00
|
|
|
#include "libavutil/mem.h"
|
2012-06-03 22:32:22 +03:00
|
|
|
#include "libavutil/opt.h"
|
2011-11-06 23:28:05 +03:00
|
|
|
#include "avfilter.h"
|
2018-05-04 11:48:35 +02:00
|
|
|
#include "filters.h"
|
2012-05-12 18:58:14 +03:00
|
|
|
#include "audio.h"
|
2023-08-03 23:44:07 +02:00
|
|
|
#include "formats.h"
|
2011-11-06 23:28:05 +03:00
|
|
|
|
2015-07-19 21:36:46 +02:00
|
|
|
#define SWR_CH_MAX 64
|
2014-08-10 02:07:56 +03:00
|
|
|
|
2017-05-12 20:00:49 +02:00
|
|
|
typedef struct AMergeContext {
|
2012-06-03 22:32:22 +03:00
|
|
|
const AVClass *class;
|
|
|
|
int nb_inputs;
|
2011-11-06 23:28:05 +03:00
|
|
|
int route[SWR_CH_MAX]; /**< channels routing, see copy_samples */
|
|
|
|
int bps;
|
2012-05-31 22:47:10 +03:00
|
|
|
struct amerge_input {
|
2012-06-01 00:55:33 +03:00
|
|
|
int nb_ch; /**< number of channels for the input */
|
2012-06-03 22:32:22 +03:00
|
|
|
} *in;
|
2011-11-06 23:28:05 +03:00
|
|
|
} AMergeContext;
|
|
|
|
|
2012-06-03 22:32:22 +03:00
|
|
|
#define OFFSET(x) offsetof(AMergeContext, x)
|
2012-08-13 14:40:01 +03:00
|
|
|
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
2012-06-03 22:32:22 +03:00
|
|
|
|
|
|
|
static const AVOption amerge_options[] = {
|
|
|
|
{ "inputs", "specify the number of inputs", OFFSET(nb_inputs),
|
2016-09-05 21:51:21 +02:00
|
|
|
AV_OPT_TYPE_INT, { .i64 = 2 }, 1, SWR_CH_MAX, FLAGS },
|
2013-09-07 15:13:50 +03:00
|
|
|
{ NULL }
|
2012-06-03 22:32:22 +03:00
|
|
|
};
|
|
|
|
|
2012-06-22 15:33:09 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(amerge);
|
2012-06-03 22:32:22 +03:00
|
|
|
|
2011-11-06 23:28:05 +03:00
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
2015-08-26 18:53:44 +02:00
|
|
|
AMergeContext *s = ctx->priv;
|
2011-11-06 23:28:05 +03:00
|
|
|
|
2015-08-26 18:53:44 +02:00
|
|
|
av_freep(&s->in);
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
2020-08-21 15:13:02 +02:00
|
|
|
static const enum AVSampleFormat packed_sample_fmts[] = {
|
|
|
|
AV_SAMPLE_FMT_U8,
|
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
AV_SAMPLE_FMT_S32,
|
|
|
|
AV_SAMPLE_FMT_FLT,
|
|
|
|
AV_SAMPLE_FMT_DBL,
|
|
|
|
AV_SAMPLE_FMT_NONE
|
|
|
|
};
|
2015-08-26 18:53:44 +02:00
|
|
|
AMergeContext *s = ctx->priv;
|
2021-08-31 16:03:14 +02:00
|
|
|
AVChannelLayout *inlayout[SWR_CH_MAX] = { NULL }, outlayout = { 0 };
|
|
|
|
uint64_t outmask = 0;
|
2012-05-16 03:27:31 +03:00
|
|
|
AVFilterChannelLayouts *layouts;
|
2015-10-05 05:39:25 +02:00
|
|
|
int i, ret, overlap = 0, nb_ch = 0;
|
2011-11-06 23:28:05 +03:00
|
|
|
|
2015-08-26 18:53:44 +02:00
|
|
|
for (i = 0; i < s->nb_inputs; i++) {
|
2020-08-24 12:16:34 +02:00
|
|
|
if (!ctx->inputs[i]->incfg.channel_layouts ||
|
|
|
|
!ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts) {
|
2013-02-21 22:15:32 +03:00
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
2011-11-06 23:28:05 +03:00
|
|
|
"No channel layout for input %d\n", i + 1);
|
2013-02-21 22:15:32 +03:00
|
|
|
return AVERROR(EAGAIN);
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
2021-08-31 16:03:14 +02:00
|
|
|
inlayout[i] = &ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0];
|
2020-08-24 12:16:34 +02:00
|
|
|
if (ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts > 1) {
|
2011-11-06 23:28:05 +03:00
|
|
|
char buf[256];
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_describe(inlayout[i], buf, sizeof(buf));
|
2011-11-06 23:28:05 +03:00
|
|
|
av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1);
|
|
|
|
}
|
2016-12-15 04:28:20 +02:00
|
|
|
s->in[i].nb_ch = FF_LAYOUT2COUNT(inlayout[i]);
|
|
|
|
if (s->in[i].nb_ch) {
|
2012-06-03 22:32:22 +03:00
|
|
|
overlap++;
|
2016-12-15 04:28:20 +02:00
|
|
|
} else {
|
2021-08-31 16:03:14 +02:00
|
|
|
s->in[i].nb_ch = inlayout[i]->nb_channels;
|
|
|
|
if (av_channel_layout_subset(inlayout[i], outmask))
|
2016-12-15 04:28:20 +02:00
|
|
|
overlap++;
|
2021-08-31 16:03:14 +02:00
|
|
|
outmask |= inlayout[i]->order == AV_CHANNEL_ORDER_NATIVE ?
|
|
|
|
inlayout[i]->u.mask : 0;
|
2016-12-15 04:28:20 +02:00
|
|
|
}
|
2015-08-26 18:53:44 +02:00
|
|
|
nb_ch += s->in[i].nb_ch;
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
2012-06-03 22:32:22 +03:00
|
|
|
if (nb_ch > SWR_CH_MAX) {
|
2011-11-06 23:28:05 +03:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Too many channels (max %d)\n", SWR_CH_MAX);
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2012-06-03 22:32:22 +03:00
|
|
|
if (overlap) {
|
2011-11-06 23:28:05 +03:00
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
2012-09-11 11:32:13 +03:00
|
|
|
"Input channel layouts overlap: "
|
|
|
|
"output layout will be determined by the number of distinct input channels\n");
|
2012-06-03 22:32:22 +03:00
|
|
|
for (i = 0; i < nb_ch; i++)
|
2015-08-26 18:53:44 +02:00
|
|
|
s->route[i] = i;
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_default(&outlayout, nb_ch);
|
|
|
|
if (!KNOWN(&outlayout) && nb_ch)
|
|
|
|
av_channel_layout_from_mask(&outlayout, 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch));
|
2011-11-06 23:28:05 +03:00
|
|
|
} else {
|
2012-06-03 22:32:22 +03:00
|
|
|
int *route[SWR_CH_MAX];
|
2011-11-06 23:28:05 +03:00
|
|
|
int c, out_ch_number = 0;
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_from_mask(&outlayout, outmask);
|
2015-08-26 18:53:44 +02:00
|
|
|
route[0] = s->route;
|
|
|
|
for (i = 1; i < s->nb_inputs; i++)
|
|
|
|
route[i] = route[i - 1] + s->in[i - 1].nb_ch;
|
2011-11-06 23:28:05 +03:00
|
|
|
for (c = 0; c < 64; c++)
|
2015-08-26 18:53:44 +02:00
|
|
|
for (i = 0; i < s->nb_inputs; i++)
|
2021-08-31 16:03:14 +02:00
|
|
|
if (av_channel_layout_index_from_channel(inlayout[i], c) >= 0)
|
2011-11-06 23:28:05 +03:00
|
|
|
*(route[i]++) = out_ch_number++;
|
|
|
|
}
|
2021-08-10 01:25:31 +02:00
|
|
|
if ((ret = ff_set_common_formats_from_list(ctx, packed_sample_fmts)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2015-08-26 18:53:44 +02:00
|
|
|
for (i = 0; i < s->nb_inputs; i++) {
|
2012-05-16 03:27:31 +03:00
|
|
|
layouts = NULL;
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_channel_layout(&layouts, inlayout[i])) < 0)
|
|
|
|
return ret;
|
2020-08-24 12:16:34 +02:00
|
|
|
if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->outcfg.channel_layouts)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
2012-05-16 03:27:31 +03:00
|
|
|
layouts = NULL;
|
2021-08-31 16:03:14 +02:00
|
|
|
if ((ret = ff_add_channel_layout(&layouts, &outlayout)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2020-08-24 12:16:34 +02:00
|
|
|
if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
|
|
|
|
2021-08-10 01:25:31 +02:00
|
|
|
return ff_set_common_all_samplerates(ctx);
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int config_output(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
2015-08-26 18:53:44 +02:00
|
|
|
AMergeContext *s = ctx->priv;
|
2012-06-03 22:32:22 +03:00
|
|
|
AVBPrint bp;
|
2011-11-06 23:28:05 +03:00
|
|
|
int i;
|
|
|
|
|
2023-11-28 13:50:10 +02:00
|
|
|
s->bps = av_get_bytes_per_sample(outlink->format);
|
2011-11-06 23:28:05 +03:00
|
|
|
outlink->time_base = ctx->inputs[0]->time_base;
|
2012-06-03 22:32:22 +03:00
|
|
|
|
2018-06-10 10:00:49 +02:00
|
|
|
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
|
2015-08-26 18:53:44 +02:00
|
|
|
for (i = 0; i < s->nb_inputs; i++) {
|
2012-06-03 22:32:22 +03:00
|
|
|
av_bprintf(&bp, "%sin%d:", i ? " + " : "", i);
|
2023-12-29 14:41:42 +02:00
|
|
|
av_channel_layout_describe_bprint(&ctx->inputs[i]->ch_layout, &bp);
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
2012-06-03 22:32:22 +03:00
|
|
|
av_bprintf(&bp, " -> out:");
|
2023-12-29 14:41:42 +02:00
|
|
|
av_channel_layout_describe_bprint(&outlink->ch_layout, &bp);
|
2012-07-14 19:26:04 +03:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "%s\n", bp.str);
|
2012-06-03 22:32:22 +03:00
|
|
|
|
2011-11-06 23:28:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-03 22:32:22 +03:00
|
|
|
* Copy samples from several input streams to one output stream.
|
|
|
|
* @param nb_inputs number of inputs
|
2012-06-01 00:55:33 +03:00
|
|
|
* @param in inputs; used only for the nb_ch field;
|
2011-11-06 23:28:05 +03:00
|
|
|
* @param route routing values;
|
|
|
|
* input channel i goes to output channel route[i];
|
2012-06-01 00:55:33 +03: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 23:28:05 +03: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 22:32:22 +03:00
|
|
|
static inline void copy_samples(int nb_inputs, struct amerge_input in[],
|
|
|
|
int *route, uint8_t *ins[],
|
2011-11-06 23:28:05 +03:00
|
|
|
uint8_t **outs, int ns, int bps)
|
|
|
|
{
|
|
|
|
int *route_cur;
|
2012-06-03 22:32:22 +03:00
|
|
|
int i, c, nb_ch = 0;
|
2011-11-06 23:28:05 +03:00
|
|
|
|
2012-06-03 22:32:22 +03:00
|
|
|
for (i = 0; i < nb_inputs; i++)
|
|
|
|
nb_ch += in[i].nb_ch;
|
2011-11-06 23:28:05 +03:00
|
|
|
while (ns--) {
|
|
|
|
route_cur = route;
|
2012-06-03 22:32:22 +03:00
|
|
|
for (i = 0; i < nb_inputs; i++) {
|
2012-06-01 00:55:33 +03:00
|
|
|
for (c = 0; c < in[i].nb_ch; c++) {
|
2011-11-06 23:28:05 +03:00
|
|
|
memcpy((*outs) + bps * *(route_cur++), ins[i], bps);
|
|
|
|
ins[i] += bps;
|
|
|
|
}
|
|
|
|
}
|
2012-06-03 22:32:22 +03:00
|
|
|
*outs += nb_ch * bps;
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-04 11:48:35 +02:00
|
|
|
static void free_frames(int nb_inputs, AVFrame **input_frames)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < nb_inputs; i++)
|
|
|
|
av_frame_free(&input_frames[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int try_push_frame(AVFilterContext *ctx, int nb_samples)
|
2011-11-06 23:28:05 +03:00
|
|
|
{
|
2015-08-26 18:53:44 +02:00
|
|
|
AMergeContext *s = ctx->priv;
|
2018-05-04 11:48:35 +02:00
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
int i, ret;
|
|
|
|
AVFrame *outbuf, *inbuf[SWR_CH_MAX] = { NULL };
|
|
|
|
uint8_t *outs, *ins[SWR_CH_MAX];
|
|
|
|
|
|
|
|
for (i = 0; i < ctx->nb_inputs; i++) {
|
|
|
|
ret = ff_inlink_consume_samples(ctx->inputs[i], nb_samples, nb_samples, &inbuf[i]);
|
|
|
|
if (ret < 0) {
|
|
|
|
free_frames(i, inbuf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ins[i] = inbuf[i]->data[0];
|
2013-01-31 16:24:57 +03:00
|
|
|
}
|
2011-11-06 23:28:05 +03:00
|
|
|
|
2023-11-28 13:50:10 +02:00
|
|
|
outbuf = ff_get_audio_buffer(outlink, nb_samples);
|
2018-05-04 11:48:35 +02:00
|
|
|
if (!outbuf) {
|
|
|
|
free_frames(s->nb_inputs, inbuf);
|
2013-04-08 21:48:16 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
2018-05-04 11:48:35 +02:00
|
|
|
|
|
|
|
outs = outbuf->data[0];
|
|
|
|
outbuf->pts = inbuf[0]->pts;
|
2012-02-01 17:53:54 +03:00
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
outbuf->nb_samples = nb_samples;
|
2023-05-05 16:04:49 +02:00
|
|
|
outbuf->duration = av_rescale_q(outbuf->nb_samples,
|
|
|
|
av_make_q(1, outlink->sample_rate),
|
|
|
|
outlink->time_base);
|
|
|
|
|
2024-06-10 15:18:07 +02:00
|
|
|
if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0) {
|
|
|
|
free_frames(s->nb_inputs, inbuf);
|
|
|
|
av_frame_free(&outbuf);
|
2021-08-31 16:03:14 +02:00
|
|
|
return ret;
|
2024-06-10 15:18:07 +02:00
|
|
|
}
|
2012-02-01 17:53:54 +03:00
|
|
|
|
2011-11-06 23:28:05 +03:00
|
|
|
while (nb_samples) {
|
|
|
|
/* Unroll the most common sample formats: speed +~350% for the loop,
|
|
|
|
+~13% overall (including two common decoders) */
|
2015-08-26 18:53:44 +02:00
|
|
|
switch (s->bps) {
|
2011-11-06 23:28:05 +03:00
|
|
|
case 1:
|
2018-05-04 11:48:35 +02:00
|
|
|
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, 1);
|
2011-11-06 23:28:05 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-05-04 11:48:35 +02:00
|
|
|
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, 2);
|
2011-11-06 23:28:05 +03:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-05-04 11:48:35 +02:00
|
|
|
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, 4);
|
2011-11-06 23:28:05 +03:00
|
|
|
break;
|
|
|
|
default:
|
2018-05-04 11:48:35 +02:00
|
|
|
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, s->bps);
|
2011-11-06 23:28:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-04 11:48:35 +02:00
|
|
|
nb_samples = 0;
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
2018-05-04 11:48:35 +02:00
|
|
|
|
|
|
|
free_frames(s->nb_inputs, inbuf);
|
2023-11-28 13:50:10 +02:00
|
|
|
return ff_filter_frame(outlink, outbuf);
|
2011-11-06 23:28:05 +03:00
|
|
|
}
|
|
|
|
|
2018-05-04 11:48:35 +02:00
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
int i, status;
|
|
|
|
int ret, nb_samples;
|
|
|
|
int64_t pts;
|
|
|
|
|
|
|
|
FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
|
|
|
|
|
2018-11-03 19:08:50 +02:00
|
|
|
nb_samples = ff_inlink_queued_samples(ctx->inputs[0]);
|
2018-05-04 11:48:35 +02:00
|
|
|
for (i = 1; i < ctx->nb_inputs && nb_samples > 0; i++) {
|
2018-11-03 19:08:50 +02:00
|
|
|
nb_samples = FFMIN(ff_inlink_queued_samples(ctx->inputs[i]), nb_samples);
|
2018-05-04 11:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nb_samples) {
|
|
|
|
ret = try_push_frame(ctx, nb_samples);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ctx->nb_inputs; i++) {
|
2018-11-03 19:08:50 +02:00
|
|
|
if (ff_inlink_queued_samples(ctx->inputs[i]))
|
2018-05-04 11:48:35 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts)) {
|
|
|
|
ff_outlink_set_status(ctx->outputs[0], status, pts);
|
|
|
|
return 0;
|
|
|
|
} else if (ff_outlink_frame_wanted(ctx->outputs[0])) {
|
|
|
|
ff_inlink_request_frame(ctx->inputs[i]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-12 12:13:33 +03:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2012-06-03 22:32:22 +03:00
|
|
|
{
|
2015-08-26 18:53:44 +02:00
|
|
|
AMergeContext *s = ctx->priv;
|
2017-08-25 09:50:57 +02:00
|
|
|
int i, ret;
|
2012-06-03 22:32:22 +03:00
|
|
|
|
2015-08-26 18:53:44 +02:00
|
|
|
s->in = av_calloc(s->nb_inputs, sizeof(*s->in));
|
|
|
|
if (!s->in)
|
2012-06-03 22:32:22 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2015-08-26 18:53:44 +02:00
|
|
|
for (i = 0; i < s->nb_inputs; i++) {
|
2012-09-11 07:41:55 +03:00
|
|
|
char *name = av_asprintf("in%d", i);
|
2012-06-03 22:32:22 +03:00
|
|
|
AVFilterPad pad = {
|
|
|
|
.name = name,
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
};
|
2012-09-11 19:36:09 +03:00
|
|
|
if (!name)
|
|
|
|
return AVERROR(ENOMEM);
|
2021-08-11 22:02:44 +02:00
|
|
|
if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0)
|
2017-08-25 09:50:57 +02:00
|
|
|
return ret;
|
2012-06-03 22:32:22 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 22:01:59 +03:00
|
|
|
static const AVFilterPad amerge_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_output,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_af_amerge = {
|
2011-11-06 23:28:05 +03:00
|
|
|
.name = "amerge",
|
2013-02-11 15:47:02 +03:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Merge two or more audio streams into "
|
2011-11-06 23:28:05 +03:00
|
|
|
"a single multi-channel stream."),
|
|
|
|
.priv_size = sizeof(AMergeContext),
|
2012-06-03 22:32:22 +03:00
|
|
|
.init = init,
|
2011-11-06 23:28:05 +03:00
|
|
|
.uninit = uninit,
|
2018-05-04 11:48:35 +02:00
|
|
|
.activate = activate,
|
2012-11-28 22:01:59 +03:00
|
|
|
.inputs = NULL,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_OUTPUTS(amerge_outputs),
|
2021-09-27 12:07:35 +02:00
|
|
|
FILTER_QUERY_FUNC(query_formats),
|
2012-11-28 22:01:59 +03:00
|
|
|
.priv_class = &amerge_class,
|
2013-04-13 20:43:17 +03:00
|
|
|
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
|
2011-11-06 23:28:05 +03:00
|
|
|
};
|