2011-11-05 14:48:41 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Anders Johansson <ajh@atri.curtin.edu.au>
|
2013-09-03 20:42:24 +02:00
|
|
|
* Copyright (c) 2011 Clément Bœsch <u pkh me>
|
2011-11-05 14:48:41 +01: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 19:28:55 +02:00
|
|
|
* GNU Lesser General Public License for more details.
|
2011-11-05 14:48:41 +01: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 panning filter (channels mixing)
|
|
|
|
* Original code written by Anders Johansson for MPlayer,
|
|
|
|
* reimplemented for FFmpeg.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "libavutil/avstring.h"
|
2012-11-13 14:16:48 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-01-18 12:00:16 +01:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "libswresample/swresample.h"
|
2012-05-12 17:58:14 +02:00
|
|
|
#include "audio.h"
|
2011-11-05 14:48:41 +01:00
|
|
|
#include "avfilter.h"
|
2012-05-16 02:27:31 +02:00
|
|
|
#include "formats.h"
|
2012-05-17 19:32:17 +02:00
|
|
|
#include "internal.h"
|
2011-11-05 14:48:41 +01:00
|
|
|
|
2015-07-17 00:17:38 +02:00
|
|
|
#define MAX_CHANNELS 64
|
2011-11-05 14:48:41 +01:00
|
|
|
|
2012-01-18 12:00:16 +01:00
|
|
|
typedef struct PanContext {
|
2013-04-12 10:32:41 +02:00
|
|
|
const AVClass *class;
|
|
|
|
char *args;
|
2011-11-05 14:48:41 +01:00
|
|
|
int64_t out_channel_layout;
|
2012-02-20 21:25:12 +01:00
|
|
|
double gain[MAX_CHANNELS][MAX_CHANNELS];
|
2011-11-05 14:48:41 +01:00
|
|
|
int64_t need_renorm;
|
|
|
|
int need_renumber;
|
|
|
|
int nb_output_channels;
|
2012-01-18 12:00:16 +01:00
|
|
|
|
|
|
|
int pure_gains;
|
|
|
|
/* channel mapping specific */
|
2014-08-10 01:07:20 +02:00
|
|
|
int channel_map[MAX_CHANNELS];
|
2012-01-18 12:00:16 +01:00
|
|
|
struct SwrContext *swr;
|
2011-11-05 14:48:41 +01:00
|
|
|
} PanContext;
|
|
|
|
|
2013-04-12 10:45:11 +02:00
|
|
|
static void skip_spaces(char **arg)
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
sscanf(*arg, " %n", &len);
|
|
|
|
*arg += len;
|
|
|
|
}
|
|
|
|
|
2011-11-05 14:48:41 +01:00
|
|
|
static int parse_channel_name(char **arg, int *rchannel, int *rnamed)
|
|
|
|
{
|
|
|
|
char buf[8];
|
2012-02-14 13:46:40 +01:00
|
|
|
int len, i, channel_id = 0;
|
2011-11-05 14:48:41 +01:00
|
|
|
int64_t layout, layout0;
|
|
|
|
|
2013-04-12 10:45:11 +02:00
|
|
|
skip_spaces(arg);
|
2012-02-15 19:41:41 +01:00
|
|
|
/* try to parse a channel name, e.g. "FL" */
|
2013-04-12 10:45:11 +02:00
|
|
|
if (sscanf(*arg, "%7[A-Z]%n", buf, &len)) {
|
2011-11-05 14:48:41 +01:00
|
|
|
layout0 = layout = av_get_channel_layout(buf);
|
2012-02-15 19:41:41 +01:00
|
|
|
/* channel_id <- first set bit in layout */
|
2011-11-05 14:48:41 +01:00
|
|
|
for (i = 32; i > 0; i >>= 1) {
|
|
|
|
if (layout >= (int64_t)1 << i) {
|
|
|
|
channel_id += i;
|
|
|
|
layout >>= i;
|
|
|
|
}
|
|
|
|
}
|
2012-02-15 19:41:41 +01:00
|
|
|
/* reject layouts that are not a single channel */
|
2011-11-05 14:48:41 +01:00
|
|
|
if (channel_id >= MAX_CHANNELS || layout0 != (int64_t)1 << channel_id)
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
*rchannel = channel_id;
|
|
|
|
*rnamed = 1;
|
|
|
|
*arg += len;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-15 19:41:41 +01:00
|
|
|
/* try to parse a channel number, e.g. "c2" */
|
2012-09-14 18:45:34 +02:00
|
|
|
if (sscanf(*arg, "c%d%n", &channel_id, &len) &&
|
2011-11-05 14:48:41 +01:00
|
|
|
channel_id >= 0 && channel_id < MAX_CHANNELS) {
|
|
|
|
*rchannel = channel_id;
|
|
|
|
*rnamed = 0;
|
|
|
|
*arg += len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:13:33 +02:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2011-11-05 14:48:41 +01:00
|
|
|
{
|
|
|
|
PanContext *const pan = ctx->priv;
|
2013-04-12 10:32:41 +02:00
|
|
|
char *arg, *arg0, *tokenizer, *args = av_strdup(pan->args);
|
2012-05-17 19:32:17 +02:00
|
|
|
int out_ch_id, in_ch_id, len, named, ret;
|
2011-11-05 14:48:41 +01:00
|
|
|
int nb_in_channels[2] = { 0, 0 }; // number of unnamed and named input channels
|
|
|
|
double gain;
|
|
|
|
|
2013-04-12 10:32:41 +02:00
|
|
|
if (!pan->args) {
|
2012-01-17 11:01:37 +01:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"pan filter needs a channel layout and a set "
|
|
|
|
"of channels definitions as parameter\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2011-11-05 14:48:41 +01:00
|
|
|
if (!args)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-04-12 10:32:41 +02:00
|
|
|
arg = av_strtok(args, "|", &tokenizer);
|
2013-10-25 16:02:04 +02:00
|
|
|
ret = ff_parse_channel_layout(&pan->out_channel_layout,
|
|
|
|
&pan->nb_output_channels, arg, ctx);
|
2012-05-17 19:32:17 +02:00
|
|
|
if (ret < 0)
|
2012-10-13 01:32:50 +02:00
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
|
|
|
|
/* parse channel specifications */
|
2013-04-12 10:32:41 +02:00
|
|
|
while ((arg = arg0 = av_strtok(NULL, "|", &tokenizer))) {
|
2011-11-05 14:48:41 +01:00
|
|
|
/* channel name */
|
|
|
|
if (parse_channel_name(&arg, &out_ch_id, &named)) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Expected out channel name, got \"%.8s\"\n", arg);
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
if (named) {
|
|
|
|
if (!((pan->out_channel_layout >> out_ch_id) & 1)) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Channel \"%.8s\" does not exist in the chosen layout\n", arg0);
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
/* get the channel number in the output channel layout:
|
|
|
|
* out_channel_layout & ((1 << out_ch_id) - 1) are all the
|
|
|
|
* channels that come before out_ch_id,
|
|
|
|
* so their count is the index of out_ch_id */
|
|
|
|
out_ch_id = av_get_channel_layout_nb_channels(pan->out_channel_layout & (((int64_t)1 << out_ch_id) - 1));
|
|
|
|
}
|
|
|
|
if (out_ch_id < 0 || out_ch_id >= pan->nb_output_channels) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Invalid out channel name \"%.8s\"\n", arg0);
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
2012-09-14 18:45:34 +02:00
|
|
|
skip_spaces(&arg);
|
2011-11-05 14:48:41 +01:00
|
|
|
if (*arg == '=') {
|
|
|
|
arg++;
|
|
|
|
} else if (*arg == '<') {
|
|
|
|
pan->need_renorm |= (int64_t)1 << out_ch_id;
|
|
|
|
arg++;
|
|
|
|
} else {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Syntax error after channel name in \"%.8s\"\n", arg0);
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
/* gains */
|
|
|
|
while (1) {
|
|
|
|
gain = 1;
|
2012-09-14 18:45:34 +02:00
|
|
|
if (sscanf(arg, "%lf%n *%n", &gain, &len, &len))
|
2011-11-05 14:48:41 +01:00
|
|
|
arg += len;
|
|
|
|
if (parse_channel_name(&arg, &in_ch_id, &named)){
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Expected in channel name, got \"%.8s\"\n", arg);
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
nb_in_channels[named]++;
|
|
|
|
if (nb_in_channels[!named]) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Can not mix named and numbered channels\n");
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
2012-02-20 21:25:12 +01:00
|
|
|
pan->gain[out_ch_id][in_ch_id] = gain;
|
2012-09-14 18:45:34 +02:00
|
|
|
skip_spaces(&arg);
|
2011-11-05 14:48:41 +01:00
|
|
|
if (!*arg)
|
|
|
|
break;
|
|
|
|
if (*arg != '+') {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Syntax error near \"%.8s\"\n", arg);
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = AVERROR(EINVAL);
|
|
|
|
goto fail;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pan->need_renumber = !!nb_in_channels[1];
|
|
|
|
|
2012-10-13 01:32:50 +02:00
|
|
|
ret = 0;
|
|
|
|
fail:
|
2011-11-05 14:48:41 +01:00
|
|
|
av_free(args);
|
2012-10-13 01:32:50 +02:00
|
|
|
return ret;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-18 12:00:16 +01:00
|
|
|
static int are_gains_pure(const PanContext *pan)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CHANNELS; i++) {
|
|
|
|
int nb_gain = 0;
|
|
|
|
|
|
|
|
for (j = 0; j < MAX_CHANNELS; j++) {
|
2012-02-20 21:25:12 +01:00
|
|
|
double gain = pan->gain[i][j];
|
2012-01-18 12:00:16 +01:00
|
|
|
|
|
|
|
/* channel mapping is effective only if 0% or 100% of a channel is
|
|
|
|
* selected... */
|
|
|
|
if (gain != 0. && gain != 1.)
|
|
|
|
return 0;
|
|
|
|
/* ...and if the output channel is only composed of one input */
|
|
|
|
if (gain && nb_gain++)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-02-20 21:45:18 +01:00
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
PanContext *pan = ctx->priv;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
2012-05-17 16:31:52 +02:00
|
|
|
AVFilterFormats *formats = NULL;
|
2012-05-16 02:27:31 +02:00
|
|
|
AVFilterChannelLayouts *layouts;
|
2015-10-05 05:39:25 +02:00
|
|
|
int ret;
|
2012-02-20 21:45:18 +01:00
|
|
|
|
|
|
|
pan->pure_gains = are_gains_pure(pan);
|
|
|
|
/* libswr supports any sample and packing formats */
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)
|
|
|
|
return ret;
|
2012-02-20 21:45:18 +01:00
|
|
|
|
2012-05-17 16:31:52 +02:00
|
|
|
formats = ff_all_samplerates();
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_set_common_samplerates(ctx, formats)) < 0)
|
|
|
|
return ret;
|
2012-05-17 16:31:52 +02:00
|
|
|
|
2012-02-20 21:45:18 +01:00
|
|
|
// inlink supports any channel layout
|
2013-10-25 16:12:06 +02:00
|
|
|
layouts = ff_all_channel_counts();
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
|
|
|
|
return ret;
|
2012-02-20 21:45:18 +01:00
|
|
|
|
|
|
|
// outlink supports only requested output channel layout
|
2012-05-16 02:27:31 +02:00
|
|
|
layouts = NULL;
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_channel_layout(&layouts,
|
2013-10-25 16:02:04 +02:00
|
|
|
pan->out_channel_layout ? pan->out_channel_layout :
|
2015-10-05 05:39:25 +02:00
|
|
|
FF_COUNT2LAYOUT(pan->nb_output_channels))) < 0)
|
|
|
|
return ret;
|
|
|
|
return ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
|
2012-02-20 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
2011-11-05 14:48:41 +01:00
|
|
|
static int config_props(AVFilterLink *link)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = link->dst;
|
|
|
|
PanContext *pan = ctx->priv;
|
|
|
|
char buf[1024], *cur;
|
|
|
|
int i, j, k, r;
|
|
|
|
double t;
|
|
|
|
|
|
|
|
if (pan->need_renumber) {
|
|
|
|
// input channels were given by their name: renumber them
|
|
|
|
for (i = j = 0; i < MAX_CHANNELS; i++) {
|
|
|
|
if ((link->channel_layout >> i) & 1) {
|
|
|
|
for (k = 0; k < pan->nb_output_channels; k++)
|
2012-02-20 21:25:12 +01:00
|
|
|
pan->gain[k][j] = pan->gain[k][i];
|
2011-11-05 14:48:41 +01:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-18 12:00:16 +01:00
|
|
|
|
2012-02-20 20:15:09 +01:00
|
|
|
// sanity check; can't be done in query_formats since the inlink
|
|
|
|
// channel layout is unknown at that time
|
2014-08-10 01:07:20 +02:00
|
|
|
if (link->channels > MAX_CHANNELS ||
|
|
|
|
pan->nb_output_channels > MAX_CHANNELS) {
|
2012-02-20 20:15:09 +01:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
2014-08-10 01:07:20 +02:00
|
|
|
"af_pan support a maximum of %d channels. "
|
|
|
|
"Feel free to ask for a higher limit.\n", MAX_CHANNELS);
|
2012-02-20 20:15:09 +01:00
|
|
|
return AVERROR_PATCHWELCOME;
|
|
|
|
}
|
2012-01-18 12:00:16 +01:00
|
|
|
|
2012-02-20 20:15:09 +01:00
|
|
|
// init libswresample context
|
|
|
|
pan->swr = swr_alloc_set_opts(pan->swr,
|
|
|
|
pan->out_channel_layout, link->format, link->sample_rate,
|
|
|
|
link->channel_layout, link->format, link->sample_rate,
|
|
|
|
0, ctx);
|
|
|
|
if (!pan->swr)
|
|
|
|
return AVERROR(ENOMEM);
|
2014-08-10 01:06:52 +02:00
|
|
|
if (!link->channel_layout) {
|
|
|
|
if (av_opt_set_int(pan->swr, "ich", link->channels, 0) < 0)
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
if (!pan->out_channel_layout) {
|
|
|
|
if (av_opt_set_int(pan->swr, "och", pan->nb_output_channels, 0) < 0)
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2012-02-16 12:34:39 +01:00
|
|
|
|
|
|
|
// gains are pure, init the channel mapping
|
|
|
|
if (pan->pure_gains) {
|
|
|
|
|
2012-01-18 12:00:16 +01:00
|
|
|
// get channel map from the pure gains
|
|
|
|
for (i = 0; i < pan->nb_output_channels; i++) {
|
|
|
|
int ch_id = -1;
|
2013-10-25 16:12:06 +02:00
|
|
|
for (j = 0; j < link->channels; j++) {
|
2012-02-20 21:25:12 +01:00
|
|
|
if (pan->gain[i][j]) {
|
2012-01-18 12:00:16 +01:00
|
|
|
ch_id = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pan->channel_map[i] = ch_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_opt_set_int(pan->swr, "icl", pan->out_channel_layout, 0);
|
|
|
|
av_opt_set_int(pan->swr, "uch", pan->nb_output_channels, 0);
|
|
|
|
swr_set_channel_mapping(pan->swr, pan->channel_map);
|
|
|
|
} else {
|
2012-01-23 11:27:11 +01:00
|
|
|
// renormalize
|
|
|
|
for (i = 0; i < pan->nb_output_channels; i++) {
|
|
|
|
if (!((pan->need_renorm >> i) & 1))
|
|
|
|
continue;
|
|
|
|
t = 0;
|
2013-10-25 16:12:06 +02:00
|
|
|
for (j = 0; j < link->channels; j++)
|
2012-02-20 21:25:12 +01:00
|
|
|
t += pan->gain[i][j];
|
2012-01-23 11:27:11 +01:00
|
|
|
if (t > -1E-5 && t < 1E-5) {
|
|
|
|
// t is almost 0 but not exactly, this is probably a mistake
|
|
|
|
if (t)
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"Degenerate coefficients while renormalizing\n");
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-25 16:12:06 +02:00
|
|
|
for (j = 0; j < link->channels; j++)
|
2012-02-20 21:25:12 +01:00
|
|
|
pan->gain[i][j] /= t;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
2012-02-16 12:34:39 +01:00
|
|
|
av_opt_set_int(pan->swr, "icl", link->channel_layout, 0);
|
|
|
|
av_opt_set_int(pan->swr, "ocl", pan->out_channel_layout, 0);
|
2012-02-20 21:25:12 +01:00
|
|
|
swr_set_matrix(pan->swr, pan->gain[0], pan->gain[1] - pan->gain[0]);
|
2012-01-18 12:00:16 +01:00
|
|
|
}
|
2012-02-16 12:34:39 +01:00
|
|
|
|
|
|
|
r = swr_init(pan->swr);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2011-11-05 14:48:41 +01:00
|
|
|
// summary
|
|
|
|
for (i = 0; i < pan->nb_output_channels; i++) {
|
|
|
|
cur = buf;
|
2013-10-25 16:12:06 +02:00
|
|
|
for (j = 0; j < link->channels; j++) {
|
2011-11-05 14:48:41 +01:00
|
|
|
r = snprintf(cur, buf + sizeof(buf) - cur, "%s%.3g i%d",
|
2012-02-20 21:25:12 +01:00
|
|
|
j ? " + " : "", pan->gain[i][j], j);
|
2011-11-05 14:48:41 +01:00
|
|
|
cur += FFMIN(buf + sizeof(buf) - cur, r);
|
|
|
|
}
|
2012-07-14 18:26:04 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "o%d = %s\n", i, buf);
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
2012-01-18 12:00:16 +01:00
|
|
|
// add channel mapping summary if possible
|
|
|
|
if (pan->pure_gains) {
|
|
|
|
av_log(ctx, AV_LOG_INFO, "Pure channel mapping detected:");
|
|
|
|
for (i = 0; i < pan->nb_output_channels; i++)
|
|
|
|
if (pan->channel_map[i] < 0)
|
|
|
|
av_log(ctx, AV_LOG_INFO, " M");
|
|
|
|
else
|
|
|
|
av_log(ctx, AV_LOG_INFO, " %d", pan->channel_map[i]);
|
|
|
|
av_log(ctx, AV_LOG_INFO, "\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-05 14:48:41 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
|
2012-01-18 12:00:16 +01:00
|
|
|
{
|
2012-07-09 22:10:38 +02:00
|
|
|
int ret;
|
2013-03-10 01:30:30 +01:00
|
|
|
int n = insamples->nb_samples;
|
2012-01-18 12:00:16 +01:00
|
|
|
AVFilterLink *const outlink = inlink->dst->outputs[0];
|
2013-03-10 01:30:30 +01:00
|
|
|
AVFrame *outsamples = ff_get_audio_buffer(outlink, n);
|
2012-01-18 12:00:16 +01:00
|
|
|
PanContext *pan = inlink->dst->priv;
|
|
|
|
|
2013-04-08 20:48:16 +02:00
|
|
|
if (!outsamples)
|
|
|
|
return AVERROR(ENOMEM);
|
2014-02-11 15:15:58 +01:00
|
|
|
swr_convert(pan->swr, outsamples->extended_data, n,
|
|
|
|
(void *)insamples->extended_data, n);
|
2013-03-10 01:30:30 +01:00
|
|
|
av_frame_copy_props(outsamples, insamples);
|
|
|
|
outsamples->channel_layout = outlink->channel_layout;
|
2013-03-15 16:13:53 +01:00
|
|
|
av_frame_set_channels(outsamples, outlink->channels);
|
2012-01-31 08:20:42 +01:00
|
|
|
|
2012-11-28 13:53:48 +01:00
|
|
|
ret = ff_filter_frame(outlink, outsamples);
|
2013-03-10 01:30:30 +01:00
|
|
|
av_frame_free(&insamples);
|
2012-07-09 22:10:38 +02:00
|
|
|
return ret;
|
2011-11-05 14:48:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-18 12:00:16 +01:00
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
PanContext *pan = ctx->priv;
|
|
|
|
swr_free(&pan->swr);
|
|
|
|
}
|
|
|
|
|
2013-04-12 10:32:41 +02:00
|
|
|
#define OFFSET(x) offsetof(PanContext, x)
|
|
|
|
|
|
|
|
static const AVOption pan_options[] = {
|
|
|
|
{ "args", NULL, OFFSET(args), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(pan);
|
|
|
|
|
2012-11-28 20:01:59 +01:00
|
|
|
static const AVFilterPad pan_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.filter_frame = filter_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad pan_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2013-10-29 11:50:56 +01:00
|
|
|
AVFilter ff_af_pan = {
|
2011-11-05 14:48:41 +01:00
|
|
|
.name = "pan",
|
2012-01-20 00:16:27 +01:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Remix channels with coefficients (panning)."),
|
2011-11-05 14:48:41 +01:00
|
|
|
.priv_size = sizeof(PanContext),
|
2013-04-12 10:32:41 +02:00
|
|
|
.priv_class = &pan_class,
|
2011-11-05 14:48:41 +01:00
|
|
|
.init = init,
|
2012-01-18 12:00:16 +01:00
|
|
|
.uninit = uninit,
|
2011-11-05 14:48:41 +01:00
|
|
|
.query_formats = query_formats,
|
2012-11-28 20:01:59 +01:00
|
|
|
.inputs = pan_inputs,
|
|
|
|
.outputs = pan_outputs,
|
2011-11-05 14:48:41 +01:00
|
|
|
};
|