Commit 1a4a91f9 authored by Thomas Guillem's avatar Thomas Guillem Committed by Jean-Baptiste Kempf
Browse files

aout: use a new chan_mode for binaural

Instead of using a custom cfg with an extra "audio filter".

i_chan_mode is already used by "audio converter" for dolbystereo.

The spatialaudio "audio filter" is converted to an "audio converter".
Such type of modules are loaded automatically when a conversion is needed
(the chan_mode conversion). Since this module is now an "audio
converter", don't override in/out fmt, but test for in/out fmt
compatibility.
parent aa22f0f1
......@@ -170,6 +170,7 @@ static const uint16_t vlc_chan_maps[] =
/* Values available for i_chan_mode only */
#define AOUT_CHANMODE_DUALMONO 0x1
#define AOUT_CHANMODE_DOLBYSTEREO 0x2
#define AOUT_CHANMODE_BINAURAL 0x4
/**
* Picture orientation.
......
......@@ -74,7 +74,7 @@ vlc_module_begin()
add_submodule()
set_shortname(N_("Binauralizer"))
set_capability("audio filter", 0)
set_capability("audio converter", 30)
set_callback(OpenBinauralizer)
add_shortcut("binauralizer")
vlc_module_end()
......@@ -332,8 +332,18 @@ static const struct FilterOperationInitializer {
static int OpenBinauralizer(vlc_object_t *p_this)
{
filter_t *p_filter = (filter_t *)p_this;
audio_format_t *infmt = &p_filter->fmt_in.audio;
audio_format_t *outfmt = &p_filter->fmt_out.audio;
const audio_format_t *infmt = &p_filter->fmt_in.audio;
const audio_format_t *outfmt = &p_filter->fmt_out.audio;
if (infmt->i_format != VLC_CODEC_FL32 || outfmt->i_format != VLC_CODEC_FL32)
return VLC_EGENERIC;
if (infmt->i_rate != outfmt->i_rate)
return VLC_EGENERIC;
if (infmt->i_channels <= 2 || outfmt->i_channels != 2
|| outfmt->i_chan_mode != AOUT_CHANMODE_BINAURAL)
return VLC_EGENERIC;
filter_spatialaudio *p_sys = new(std::nothrow)filter_spatialaudio();
if (p_sys == NULL)
......@@ -395,12 +405,6 @@ static int OpenBinauralizer(vlc_object_t *p_this)
}
p_sys->binauralizer.Reset();
outfmt->i_format = infmt->i_format = VLC_CODEC_FL32;
outfmt->i_rate = infmt->i_rate;
outfmt->i_physical_channels = AOUT_CHANS_STEREO;
aout_FormatPrepare(infmt);
aout_FormatPrepare(outfmt);
p_filter->p_sys = p_sys;
p_filter->ops = &filter_ops.ops;
......@@ -463,12 +467,9 @@ static int Open(vlc_object_t *p_this)
msg_Dbg(p_filter, "Order: %d %d %d", p_sys->i_order, p_sys->i_nondiegetic, infmt->i_channels);
static const char *const options[] = { "headphones", NULL };
config_ChainParse(p_filter, CFG_PREFIX, options, p_filter->p_cfg);
unsigned i_tailLength = 0;
if (p_filter->fmt_out.audio.i_channels == 2
&& var_InheritBool(p_filter, CFG_PREFIX "headphones"))
&& p_filter->fmt_out.audio.i_chan_mode == AOUT_CHANMODE_BINAURAL)
{
p_sys->mode = filter_spatialaudio::AMBISONICS_BINAURAL_DECODER;
......
......@@ -152,8 +152,7 @@ static filter_t *TryFormat (vlc_object_t *obj, vlc_fourcc_t codec,
static int aout_FiltersPipelineCreate(vlc_object_t *obj, filter_t **filters,
unsigned *count, unsigned max,
const audio_sample_format_t *restrict infmt,
const audio_sample_format_t *restrict outfmt,
bool headphones)
const audio_sample_format_t *restrict outfmt)
{
aout_FormatsPrint (obj, "conversion:", infmt, outfmt);
max -= *count;
......@@ -207,13 +206,8 @@ static int aout_FiltersPipelineCreate(vlc_object_t *obj, filter_t **filters,
infmt->channel_type != outfmt->channel_type ?
"audio renderer" : "audio converter";
config_chain_t *cfg = NULL;
if (headphones)
config_ChainParseOptions(&cfg, "{headphones=true}");
filter_t *f = aout_filter_Create(obj, NULL, filter_type, NULL,
&input, &output, cfg, true);
if (cfg)
config_ChainDestroy(cfg);
&input, &output, NULL, true);
if (f == NULL)
{
......@@ -430,7 +424,7 @@ static int AppendFilter(vlc_object_t *obj, const char *type, const char *name,
/* convert to the filter input format if necessary */
if (aout_FiltersPipelineCreate (obj, filters->tab, &filters->count,
max - 1, infmt, &filter->fmt_in.audio, false))
max - 1, infmt, &filter->fmt_in.audio))
{
msg_Err (filter, "cannot add user %s \"%s\" (skipped)", type, name);
filter_Close( filter );
......@@ -552,8 +546,7 @@ aout_filters_t *aout_FiltersNewWithClock(vlc_object_t *obj, const vlc_clock_t *c
/* convert to the output format (minus resampling) if necessary */
output_format.i_rate = input_format.i_rate;
if (aout_FiltersPipelineCreate (obj, filters->tab, &filters->count,
AOUT_MAX_FILTERS, &input_format, &output_format,
cfg->headphones))
AOUT_MAX_FILTERS, &input_format, &output_format))
{
msg_Warn (obj, "cannot setup audio renderer pipeline");
/* Fallback to bitmap without any conversions */
......@@ -597,15 +590,9 @@ aout_filters_t *aout_FiltersNewWithClock(vlc_object_t *obj, const vlc_clock_t *c
}
if (cfg != NULL)
{
AppendRemapFilter(obj, filters, &input_format, &output_format,
cfg->remap);
if (input_format.i_channels > 2 && cfg->headphones)
AppendFilter(obj, "audio filter", "binauralizer", filters,
&input_format, &output_format, NULL);
}
/* Now add user filters */
char *str = var_InheritString (obj, "audio-filter");
if (str != NULL)
......@@ -628,7 +615,7 @@ aout_filters_t *aout_FiltersNewWithClock(vlc_object_t *obj, const vlc_clock_t *c
/* convert to the output format (minus resampling) if necessary */
output_format.i_rate = input_format.i_rate;
if (aout_FiltersPipelineCreate (obj, filters->tab, &filters->count,
AOUT_MAX_FILTERS, &input_format, &output_format, false))
AOUT_MAX_FILTERS, &input_format, &output_format))
{
msg_Err (obj, "cannot setup filtering pipeline");
goto error;
......
......@@ -618,8 +618,7 @@ static bool aout_HasMixModeChoice(audio_output_t *aout, int mode)
static void aout_UpdateMixMode(audio_output_t *aout, int mode,
audio_sample_format_t *restrict fmt,
aout_filters_cfg_t *filters_cfg)
audio_sample_format_t *restrict fmt)
{
/* The user may have selected a different channels configuration. */
switch (mode)
......@@ -628,7 +627,7 @@ static void aout_UpdateMixMode(audio_output_t *aout, int mode,
break;
case AOUT_MIX_MODE_BINAURAL:
fmt->i_physical_channels = AOUT_CHANS_STEREO;
filters_cfg->headphones = true;
fmt->i_chan_mode = AOUT_CHANMODE_BINAURAL;
break;
case AOUT_MIX_MODE_STEREO:
fmt->i_physical_channels = AOUT_CHANS_STEREO;
......@@ -702,7 +701,7 @@ int aout_OutputNew (audio_output_t *aout)
/* Prefer the user requested mode if available, otherwise, use the
* default one */
if (aout_HasMixModeChoice(aout, owner->requested_mix_mode))
aout_UpdateMixMode(aout, owner->requested_mix_mode, fmt, filters_cfg);
aout_UpdateMixMode(aout, owner->requested_mix_mode, fmt);
aout_FormatPrepare (fmt);
assert (aout_FormatNbChannels(fmt) > 0);
......@@ -769,7 +768,7 @@ int aout_OutputNew (audio_output_t *aout)
{
assert(fmt->i_physical_channels == AOUT_CHANS_STEREO);
assert(stereo_mode == AOUT_VAR_CHAN_UNSET);
aout_UpdateMixMode(aout, AOUT_MIX_MODE_BINAURAL, fmt, filters_cfg);
aout_UpdateMixMode(aout, AOUT_MIX_MODE_BINAURAL, fmt);
}
aout_FormatPrepare (fmt);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment