2013-05-09 10:09:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
af_format: change license to LGPL
This case is a bit weird, because MPlayer certainly also has a file
named af_format.c. Both appear to have the function of converting audio
data between sample formats.
However, mpv's af_format.c is a rewrite, and doesn't actually do
conversion by itself. It's similar to vf_format.c, and forces the
generic filter chain code to insert conversion filters, instead of doing
conversion explicitly.
mpv's current af_format.c started out as af_force.c in d9582ad0a41. It
was renamed to af_format.c in e60b8f181d, while the old af_format.c was
split into two new filters. In 943c785619 the filename was changed to
af_format.c as well.
The new af_format.c does not contain any libaf code, except for some
potentially copy & pasted skeleton and boilerplate code. (We don't
account for this in per-filter file licenses, as the old libaf code
has to be removed fully, at which point the filters will have to be
ported to another framework, which will removed that boilerplate code.)
The old filters based on af_format.c were progressively replaced and
removed. Support for non-native endian and formats with signedness
different from native FFmpeg was completely removed in 831d7c3c400b.
The old 24 bit conversion code was removed in 552dc0d564 (made
unnecessary by 5a9f817bfde8).
Also list hwdec_vaglx.c as GPL-only, which doesn't have anything to do
with this commit.
2017-05-11 09:00:15 +00:00
|
|
|
* mpv 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.
|
2013-05-09 10:09:23 +00:00
|
|
|
*
|
|
|
|
* 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
|
af_format: change license to LGPL
This case is a bit weird, because MPlayer certainly also has a file
named af_format.c. Both appear to have the function of converting audio
data between sample formats.
However, mpv's af_format.c is a rewrite, and doesn't actually do
conversion by itself. It's similar to vf_format.c, and forces the
generic filter chain code to insert conversion filters, instead of doing
conversion explicitly.
mpv's current af_format.c started out as af_force.c in d9582ad0a41. It
was renamed to af_format.c in e60b8f181d, while the old af_format.c was
split into two new filters. In 943c785619 the filename was changed to
af_format.c as well.
The new af_format.c does not contain any libaf code, except for some
potentially copy & pasted skeleton and boilerplate code. (We don't
account for this in per-filter file licenses, as the old libaf code
has to be removed fully, at which point the filters will have to be
ported to another framework, which will removed that boilerplate code.)
The old filters based on af_format.c were progressively replaced and
removed. Support for non-native endian and formats with signedness
different from native FFmpeg was completely removed in 831d7c3c400b.
The old 24 bit conversion code was removed in 552dc0d564 (made
unnecessary by 5a9f817bfde8).
Also list hwdec_vaglx.c as GPL-only, which doesn't have anything to do
with this commit.
2017-05-11 09:00:15 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-05-09 10:09:23 +00:00
|
|
|
*
|
af_format: change license to LGPL
This case is a bit weird, because MPlayer certainly also has a file
named af_format.c. Both appear to have the function of converting audio
data between sample formats.
However, mpv's af_format.c is a rewrite, and doesn't actually do
conversion by itself. It's similar to vf_format.c, and forces the
generic filter chain code to insert conversion filters, instead of doing
conversion explicitly.
mpv's current af_format.c started out as af_force.c in d9582ad0a41. It
was renamed to af_format.c in e60b8f181d, while the old af_format.c was
split into two new filters. In 943c785619 the filename was changed to
af_format.c as well.
The new af_format.c does not contain any libaf code, except for some
potentially copy & pasted skeleton and boilerplate code. (We don't
account for this in per-filter file licenses, as the old libaf code
has to be removed fully, at which point the filters will have to be
ported to another framework, which will removed that boilerplate code.)
The old filters based on af_format.c were progressively replaced and
removed. Support for non-native endian and formats with signedness
different from native FFmpeg was completely removed in 831d7c3c400b.
The old 24 bit conversion code was removed in 552dc0d564 (made
unnecessary by 5a9f817bfde8).
Also list hwdec_vaglx.c as GPL-only, which doesn't have anything to do
with this commit.
2017-05-11 09:00:15 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-05-09 10:09:23 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
#include "audio/aframe.h"
|
2013-05-09 10:09:23 +00:00
|
|
|
#include "audio/format.h"
|
2018-01-18 13:44:20 +00:00
|
|
|
#include "filters/f_autoconvert.h"
|
|
|
|
#include "filters/filter_internal.h"
|
|
|
|
#include "filters/user_filters.h"
|
|
|
|
#include "options/m_option.h"
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
struct f_opts {
|
2013-05-09 10:09:23 +00:00
|
|
|
int in_format;
|
|
|
|
int in_srate;
|
2016-08-04 18:49:20 +00:00
|
|
|
struct m_channels in_channels;
|
2013-05-09 10:09:23 +00:00
|
|
|
int out_format;
|
|
|
|
int out_srate;
|
2016-08-04 18:49:20 +00:00
|
|
|
struct m_channels out_channels;
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2023-02-20 03:32:50 +00:00
|
|
|
bool fail;
|
2013-05-09 10:09:23 +00:00
|
|
|
};
|
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
struct priv {
|
|
|
|
struct f_opts *opts;
|
|
|
|
struct mp_pin *in_pin;
|
|
|
|
};
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
static void process(struct mp_filter *f)
|
2013-10-23 16:14:30 +00:00
|
|
|
{
|
2018-01-18 13:44:20 +00:00
|
|
|
struct priv *p = f->priv;
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (!mp_pin_can_transfer_data(f->ppins[1], p->in_pin))
|
|
|
|
return;
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
struct mp_frame frame = mp_pin_out_read(p->in_pin);
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (p->opts->fail) {
|
|
|
|
MP_ERR(f, "Failing on purpose.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (frame.type == MP_FRAME_EOF) {
|
|
|
|
mp_pin_in_write(f->ppins[1], frame);
|
|
|
|
return;
|
|
|
|
}
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (frame.type != MP_FRAME_AUDIO) {
|
|
|
|
MP_ERR(f, "audio frame expected\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
struct mp_aframe *in = frame.data;
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (p->opts->out_channels.num_chmaps > 0) {
|
|
|
|
if (!mp_aframe_set_chmap(in, &p->opts->out_channels.chmaps[0])) {
|
|
|
|
MP_ERR(f, "could not force output channels\n");
|
|
|
|
goto error;
|
2013-07-22 12:43:34 +00:00
|
|
|
}
|
2018-01-18 13:44:20 +00:00
|
|
|
}
|
2013-07-22 12:43:34 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (p->opts->out_srate)
|
|
|
|
mp_aframe_set_rate(in, p->opts->out_srate);
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
mp_pin_in_write(f->ppins[1], frame);
|
|
|
|
return;
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
error:
|
|
|
|
mp_frame_unref(&frame);
|
|
|
|
mp_filter_internal_mark_failed(f);
|
2013-05-09 10:09:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
static const struct mp_filter_info af_format_filter = {
|
|
|
|
.name = "format",
|
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.process = process,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mp_filter *af_format_create(struct mp_filter *parent,
|
|
|
|
void *options)
|
2013-05-09 10:09:23 +00:00
|
|
|
{
|
2018-01-18 13:44:20 +00:00
|
|
|
struct mp_filter *f = mp_filter_create(parent, &af_format_filter);
|
|
|
|
if (!f) {
|
|
|
|
talloc_free(options);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
struct priv *p = f->priv;
|
|
|
|
p->opts = talloc_steal(p, options);
|
2013-10-23 16:14:30 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
mp_filter_add_pin(f, MP_PIN_IN, "in");
|
|
|
|
mp_filter_add_pin(f, MP_PIN_OUT, "out");
|
2013-05-09 10:09:23 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
struct mp_autoconvert *conv = mp_autoconvert_create(f);
|
|
|
|
if (!conv)
|
|
|
|
abort();
|
2013-07-22 12:45:12 +00:00
|
|
|
|
2018-01-18 13:44:20 +00:00
|
|
|
if (p->opts->in_format)
|
|
|
|
mp_autoconvert_add_afmt(conv, p->opts->in_format);
|
|
|
|
if (p->opts->in_srate)
|
|
|
|
mp_autoconvert_add_srate(conv, p->opts->in_srate);
|
|
|
|
if (p->opts->in_channels.num_chmaps > 0)
|
|
|
|
mp_autoconvert_add_chmap(conv, &p->opts->in_channels.chmaps[0]);
|
|
|
|
|
|
|
|
mp_pin_connect(conv->f->pins[0], f->ppins[0]);
|
|
|
|
p->in_pin = conv->f->pins[1];
|
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OPT_BASE_STRUCT struct f_opts
|
|
|
|
|
|
|
|
const struct mp_user_filter_entry af_format = {
|
|
|
|
.desc = {
|
|
|
|
.name = "format",
|
|
|
|
.description = "Force audio format",
|
|
|
|
.priv_size = sizeof(struct f_opts),
|
|
|
|
.options = (const struct m_option[]) {
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
{"format", OPT_AUDIOFORMAT(in_format)},
|
|
|
|
{"srate", OPT_INT(in_srate), M_RANGE(1000, 8*48000)},
|
2020-04-09 09:27:38 +00:00
|
|
|
{"channels", OPT_CHANNELS(in_channels),
|
|
|
|
.flags = M_OPT_CHANNELS_LIMITED},
|
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
2020-03-14 20:28:01 +00:00
|
|
|
{"out-srate", OPT_INT(out_srate), M_RANGE(1000, 8*48000)},
|
2020-04-09 09:27:38 +00:00
|
|
|
{"out-channels", OPT_CHANNELS(out_channels),
|
|
|
|
.flags = M_OPT_CHANNELS_LIMITED},
|
2023-02-20 03:32:50 +00:00
|
|
|
{"fail", OPT_BOOL(fail)},
|
2018-01-18 13:44:20 +00:00
|
|
|
{0}
|
|
|
|
},
|
2013-07-22 12:45:12 +00:00
|
|
|
},
|
2018-01-18 13:44:20 +00:00
|
|
|
.create = af_format_create,
|
2013-05-09 10:09:23 +00:00
|
|
|
};
|