2013-05-09 10:09:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/m_option.h"
|
2013-05-09 10:09:23 +00:00
|
|
|
|
|
|
|
#include "audio/format.h"
|
|
|
|
#include "af.h"
|
|
|
|
|
|
|
|
struct priv {
|
|
|
|
struct m_config *config;
|
|
|
|
|
|
|
|
int in_format;
|
|
|
|
int in_srate;
|
|
|
|
struct mp_chmap in_channels;
|
|
|
|
int out_format;
|
|
|
|
int out_srate;
|
|
|
|
struct mp_chmap out_channels;
|
|
|
|
|
2013-07-22 12:43:34 +00:00
|
|
|
int fail;
|
2013-05-09 10:09:23 +00:00
|
|
|
};
|
|
|
|
|
2013-10-23 16:14:30 +00:00
|
|
|
static void force_in_params(struct af_instance *af, struct mp_audio *in)
|
|
|
|
{
|
|
|
|
struct priv *priv = af->priv;
|
|
|
|
|
|
|
|
if (priv->in_format != AF_FORMAT_UNKNOWN)
|
|
|
|
mp_audio_set_format(in, priv->in_format);
|
|
|
|
|
|
|
|
if (priv->in_channels.num)
|
|
|
|
mp_audio_set_channels(in, &priv->in_channels);
|
|
|
|
|
|
|
|
if (priv->in_srate)
|
|
|
|
in->rate = priv->in_srate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void force_out_params(struct af_instance *af, struct mp_audio *out)
|
|
|
|
{
|
|
|
|
struct priv *priv = af->priv;
|
|
|
|
|
|
|
|
if (priv->out_format != AF_FORMAT_UNKNOWN)
|
|
|
|
mp_audio_set_format(out, priv->out_format);
|
|
|
|
|
|
|
|
if (priv->out_channels.num)
|
|
|
|
mp_audio_set_channels(out, &priv->out_channels);
|
|
|
|
|
|
|
|
if (priv->out_srate)
|
|
|
|
out->rate = priv->out_srate;
|
|
|
|
}
|
|
|
|
|
2013-05-09 10:09:23 +00:00
|
|
|
static int control(struct af_instance *af, int cmd, void *arg)
|
|
|
|
{
|
2013-07-22 12:45:12 +00:00
|
|
|
struct priv *priv = af->priv;
|
2013-05-09 10:09:23 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case AF_CONTROL_REINIT: {
|
|
|
|
struct mp_audio *in = arg;
|
|
|
|
struct mp_audio orig_in = *in;
|
|
|
|
struct mp_audio *out = af->data;
|
|
|
|
|
2013-10-23 16:14:30 +00:00
|
|
|
force_in_params(af, in);
|
2013-05-09 10:09:23 +00:00
|
|
|
mp_audio_copy_config(out, in);
|
2013-10-23 16:14:30 +00:00
|
|
|
force_out_params(af, out);
|
2013-05-09 10:09:23 +00:00
|
|
|
|
|
|
|
if (in->nch != out->nch || in->bps != out->bps) {
|
|
|
|
mp_msg(MSGT_AFILTER, MSGL_ERR,
|
audio/filter: split af_format into separate filters, rename af_force
af_format is the old audio conversion filter. It could do all possible
conversions supported by the audio chain. However, ever since the
addition of af_lavrresample, most conversions are done by
libav/swresample, and af_format is used as fallback.
Separate out the fallback cases and remove af_format. af_convert24 does
24 bit <-> 32 bit conversions, while af_convertsignendian does sign and
endian conversions. Maybe the way the conversions are split sounds a bit
odd. But the former changes the size of the audio data, while the latter
is fully in-place, so there's at least different buffer management.
This requires a quite complicated algorithm to make sure all these
"partial" conversion filters can actually get from one format to
another. E.g. s24le->s32be always requires convertsignendian and
convert24, but af.c has no idea what the intermediate format should
be. So I added a graph search (trying every possible format and
filter) to determine required format and filter. When I wrote this,
it seemed this was still better than messing everything into
af_lavrresample, but maybe this is overkill and I'll change my
opinion. For now, it seems nice to get rid of af_format though.
The AC3->IEC61937 conversion isn't supported anymore, but I don't think
this is needed anywhere. Most AOs test all formats explicitly, or use
the AF_FORMAT_IS_IEC61937() macro (which includes AC3).
One positive consequence of this change is that conversions always
include dithering (done by libav/swresample), instead of possibly going
through af_format, which doesn't do anything fancy.
Rename af_force to af_format. It's essentially compatible with command
line uses of af_format. We retain a compatibility alias for af_force.
2013-10-21 23:20:43 +00:00
|
|
|
"[af_format] Forced input/output formats are incompatible.\n");
|
2013-07-22 12:43:34 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->fail) {
|
audio/filter: split af_format into separate filters, rename af_force
af_format is the old audio conversion filter. It could do all possible
conversions supported by the audio chain. However, ever since the
addition of af_lavrresample, most conversions are done by
libav/swresample, and af_format is used as fallback.
Separate out the fallback cases and remove af_format. af_convert24 does
24 bit <-> 32 bit conversions, while af_convertsignendian does sign and
endian conversions. Maybe the way the conversions are split sounds a bit
odd. But the former changes the size of the audio data, while the latter
is fully in-place, so there's at least different buffer management.
This requires a quite complicated algorithm to make sure all these
"partial" conversion filters can actually get from one format to
another. E.g. s24le->s32be always requires convertsignendian and
convert24, but af.c has no idea what the intermediate format should
be. So I added a graph search (trying every possible format and
filter) to determine required format and filter. When I wrote this,
it seemed this was still better than messing everything into
af_lavrresample, but maybe this is overkill and I'll change my
opinion. For now, it seems nice to get rid of af_format though.
The AC3->IEC61937 conversion isn't supported anymore, but I don't think
this is needed anywhere. Most AOs test all formats explicitly, or use
the AF_FORMAT_IS_IEC61937() macro (which includes AC3).
One positive consequence of this change is that conversions always
include dithering (done by libav/swresample), instead of possibly going
through af_format, which doesn't do anything fancy.
Rename af_force to af_format. It's essentially compatible with command
line uses of af_format. We retain a compatibility alias for af_force.
2013-10-21 23:20:43 +00:00
|
|
|
mp_msg(MSGT_AFILTER, MSGL_ERR, "[af_format] Failing on purpose.\n");
|
2013-05-09 10:09:23 +00:00
|
|
|
return AF_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mp_audio_config_equals(in, &orig_in) ? AF_OK : AF_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AF_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mp_audio *play(struct af_instance *af, struct mp_audio *data)
|
|
|
|
{
|
2013-11-10 22:20:06 +00:00
|
|
|
mp_audio_copy_config(data, af->data);
|
|
|
|
return data;
|
2013-05-09 10:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int af_open(struct af_instance *af)
|
|
|
|
{
|
|
|
|
af->control = control;
|
|
|
|
af->play = play;
|
2013-10-23 16:14:30 +00:00
|
|
|
|
|
|
|
force_in_params(af, af->data);
|
|
|
|
force_out_params(af, af->data);
|
|
|
|
|
2013-05-09 10:09:23 +00:00
|
|
|
return AF_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-22 12:45:12 +00:00
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
audio/filter: split af_format into separate filters, rename af_force
af_format is the old audio conversion filter. It could do all possible
conversions supported by the audio chain. However, ever since the
addition of af_lavrresample, most conversions are done by
libav/swresample, and af_format is used as fallback.
Separate out the fallback cases and remove af_format. af_convert24 does
24 bit <-> 32 bit conversions, while af_convertsignendian does sign and
endian conversions. Maybe the way the conversions are split sounds a bit
odd. But the former changes the size of the audio data, while the latter
is fully in-place, so there's at least different buffer management.
This requires a quite complicated algorithm to make sure all these
"partial" conversion filters can actually get from one format to
another. E.g. s24le->s32be always requires convertsignendian and
convert24, but af.c has no idea what the intermediate format should
be. So I added a graph search (trying every possible format and
filter) to determine required format and filter. When I wrote this,
it seemed this was still better than messing everything into
af_lavrresample, but maybe this is overkill and I'll change my
opinion. For now, it seems nice to get rid of af_format though.
The AC3->IEC61937 conversion isn't supported anymore, but I don't think
this is needed anywhere. Most AOs test all formats explicitly, or use
the AF_FORMAT_IS_IEC61937() macro (which includes AC3).
One positive consequence of this change is that conversions always
include dithering (done by libav/swresample), instead of possibly going
through af_format, which doesn't do anything fancy.
Rename af_force to af_format. It's essentially compatible with command
line uses of af_format. We retain a compatibility alias for af_force.
2013-10-21 23:20:43 +00:00
|
|
|
struct af_info af_info_format = {
|
2013-10-23 17:05:47 +00:00
|
|
|
.info = "Force audio format",
|
|
|
|
.name = "format",
|
|
|
|
.open = af_open,
|
2013-07-22 12:45:12 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.options = (const struct m_option[]) {
|
|
|
|
OPT_AUDIOFORMAT("format", in_format, 0),
|
|
|
|
OPT_INTRANGE("srate", in_srate, 0, 1000, 8*48000),
|
|
|
|
OPT_CHMAP("channels", in_channels, CONF_MIN, .min = 0),
|
|
|
|
OPT_AUDIOFORMAT("out-format", out_format, 0),
|
|
|
|
OPT_INTRANGE("out-srate", out_srate, 0, 1000, 8*48000),
|
|
|
|
OPT_CHMAP("out-channels", out_channels, CONF_MIN, .min = 0),
|
|
|
|
OPT_FLAG("fail", fail, 0),
|
|
|
|
{0}
|
|
|
|
},
|
2013-05-09 10:09:23 +00:00
|
|
|
};
|