output/Init: pass global configuration in struct AudioOutputDefaults
This commit is contained in:
parent
aaa438e745
commit
1a9659ef45
@ -1551,6 +1551,7 @@ OUTPUT_LIBS = \
|
|||||||
$(SHOUT_LIBS)
|
$(SHOUT_LIBS)
|
||||||
|
|
||||||
OUTPUT_API_SRC = \
|
OUTPUT_API_SRC = \
|
||||||
|
src/output/Defaults.cxx src/output/Defaults.hxx \
|
||||||
src/output/Client.hxx \
|
src/output/Client.hxx \
|
||||||
src/output/OutputAPI.hxx \
|
src/output/OutputAPI.hxx \
|
||||||
src/output/Filtered.cxx src/output/Filtered.hxx \
|
src/output/Filtered.cxx src/output/Filtered.hxx \
|
||||||
|
31
src/output/Defaults.cxx
Normal file
31
src/output/Defaults.cxx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2018 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "Defaults.hxx"
|
||||||
|
#include "config/Data.hxx"
|
||||||
|
#include "mixer/MixerType.hxx"
|
||||||
|
|
||||||
|
AudioOutputDefaults::AudioOutputDefaults(const ConfigData &config)
|
||||||
|
:normalize(config.GetBool(ConfigOption::VOLUME_NORMALIZATION, false)),
|
||||||
|
mixer_type(mixer_type_parse(config.GetString(ConfigOption::MIXER_TYPE,
|
||||||
|
"hardware")))
|
||||||
|
|
||||||
|
{
|
||||||
|
}
|
47
src/output/Defaults.hxx
Normal file
47
src/output/Defaults.hxx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2018 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MPD_AUDIO_OUTPUT_DEFAULTS_HXX
|
||||||
|
#define MPD_AUDIO_OUTPUT_DEFAULTS_HXX
|
||||||
|
|
||||||
|
#include "check.h"
|
||||||
|
#include "mixer/MixerType.hxx"
|
||||||
|
|
||||||
|
struct ConfigData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This struct contains global AudioOutput configuration settings
|
||||||
|
* which may provide defaults for per-output settings.
|
||||||
|
*/
|
||||||
|
struct AudioOutputDefaults {
|
||||||
|
bool normalize = false;
|
||||||
|
|
||||||
|
MixerType mixer_type = MixerType::HARDWARE;
|
||||||
|
|
||||||
|
constexpr AudioOutputDefaults() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load defaults from configuration file.
|
||||||
|
*
|
||||||
|
* Throws on error.
|
||||||
|
*/
|
||||||
|
explicit AudioOutputDefaults(const ConfigData &config);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -38,6 +38,7 @@ struct MixerPlugin;
|
|||||||
struct MusicChunk;
|
struct MusicChunk;
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
class AudioOutput;
|
class AudioOutput;
|
||||||
|
struct AudioOutputDefaults;
|
||||||
struct ReplayGainConfig;
|
struct ReplayGainConfig;
|
||||||
struct Tag;
|
struct Tag;
|
||||||
|
|
||||||
@ -129,12 +130,14 @@ public:
|
|||||||
FilteredAudioOutput(const char *_plugin_name,
|
FilteredAudioOutput(const char *_plugin_name,
|
||||||
std::unique_ptr<AudioOutput> &&_output,
|
std::unique_ptr<AudioOutput> &&_output,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory);
|
FilterFactory *filter_factory);
|
||||||
|
|
||||||
~FilteredAudioOutput();
|
~FilteredAudioOutput();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Configure(const ConfigBlock &block,
|
void Configure(const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory);
|
FilterFactory *filter_factory);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -142,7 +145,8 @@ public:
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
const MixerPlugin *mixer_plugin,
|
const MixerPlugin *mixer_plugin,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
const ConfigBlock &block);
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults);
|
||||||
|
|
||||||
const char *GetName() const {
|
const char *GetName() const {
|
||||||
return name;
|
return name;
|
||||||
@ -238,6 +242,7 @@ std::unique_ptr<FilteredAudioOutput>
|
|||||||
audio_output_new(EventLoop &event_loop,
|
audio_output_new(EventLoop &event_loop,
|
||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory,
|
FilterFactory *filter_factory,
|
||||||
MixerListener &mixer_listener);
|
MixerListener &mixer_listener);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "Registry.hxx"
|
#include "Registry.hxx"
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "OutputAPI.hxx"
|
#include "OutputAPI.hxx"
|
||||||
|
#include "Defaults.hxx"
|
||||||
#include "AudioParser.hxx"
|
#include "AudioParser.hxx"
|
||||||
#include "mixer/MixerList.hxx"
|
#include "mixer/MixerList.hxx"
|
||||||
#include "mixer/MixerType.hxx"
|
#include "mixer/MixerType.hxx"
|
||||||
@ -36,7 +37,7 @@
|
|||||||
#include "filter/plugins/VolumeFilterPlugin.hxx"
|
#include "filter/plugins/VolumeFilterPlugin.hxx"
|
||||||
#include "filter/plugins/NormalizeFilterPlugin.hxx"
|
#include "filter/plugins/NormalizeFilterPlugin.hxx"
|
||||||
#include "config/Domain.hxx"
|
#include "config/Domain.hxx"
|
||||||
#include "config/Global.hxx"
|
#include "config/Option.hxx"
|
||||||
#include "config/Block.hxx"
|
#include "config/Block.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/StringFormat.hxx"
|
#include "util/StringFormat.hxx"
|
||||||
@ -55,10 +56,11 @@
|
|||||||
FilteredAudioOutput::FilteredAudioOutput(const char *_plugin_name,
|
FilteredAudioOutput::FilteredAudioOutput(const char *_plugin_name,
|
||||||
std::unique_ptr<AudioOutput> &&_output,
|
std::unique_ptr<AudioOutput> &&_output,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory)
|
FilterFactory *filter_factory)
|
||||||
:plugin_name(_plugin_name), output(std::move(_output))
|
:plugin_name(_plugin_name), output(std::move(_output))
|
||||||
{
|
{
|
||||||
Configure(block, filter_factory);
|
Configure(block, defaults, filter_factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AudioOutputPlugin *
|
static const AudioOutputPlugin *
|
||||||
@ -88,7 +90,8 @@ audio_output_detect()
|
|||||||
* mixer_enabled, if the mixer_type setting is not configured.
|
* mixer_enabled, if the mixer_type setting is not configured.
|
||||||
*/
|
*/
|
||||||
static MixerType
|
static MixerType
|
||||||
audio_output_mixer_type(const ConfigBlock &block)
|
audio_output_mixer_type(const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults)
|
||||||
{
|
{
|
||||||
/* read the local "mixer_type" setting */
|
/* read the local "mixer_type" setting */
|
||||||
const char *p = block.GetBlockValue("mixer_type");
|
const char *p = block.GetBlockValue("mixer_type");
|
||||||
@ -101,20 +104,20 @@ audio_output_mixer_type(const ConfigBlock &block)
|
|||||||
|
|
||||||
/* fall back to the global "mixer_type" setting (also
|
/* fall back to the global "mixer_type" setting (also
|
||||||
deprecated) */
|
deprecated) */
|
||||||
return mixer_type_parse(config_get_string(ConfigOption::MIXER_TYPE,
|
return defaults.mixer_type;
|
||||||
"hardware"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mixer *
|
static Mixer *
|
||||||
audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao,
|
audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
const MixerPlugin *plugin,
|
const MixerPlugin *plugin,
|
||||||
PreparedFilter &filter_chain,
|
PreparedFilter &filter_chain,
|
||||||
MixerListener &listener)
|
MixerListener &listener)
|
||||||
{
|
{
|
||||||
Mixer *mixer;
|
Mixer *mixer;
|
||||||
|
|
||||||
switch (audio_output_mixer_type(block)) {
|
switch (audio_output_mixer_type(block, defaults)) {
|
||||||
case MixerType::NONE:
|
case MixerType::NONE:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
@ -148,6 +151,7 @@ audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao,
|
|||||||
|
|
||||||
void
|
void
|
||||||
FilteredAudioOutput::Configure(const ConfigBlock &block,
|
FilteredAudioOutput::Configure(const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory)
|
FilterFactory *filter_factory)
|
||||||
{
|
{
|
||||||
if (!block.IsNull()) {
|
if (!block.IsNull()) {
|
||||||
@ -175,7 +179,7 @@ FilteredAudioOutput::Configure(const ConfigBlock &block,
|
|||||||
|
|
||||||
/* create the normalization filter (if configured) */
|
/* create the normalization filter (if configured) */
|
||||||
|
|
||||||
if (config_get_bool(ConfigOption::VOLUME_NORMALIZATION, false)) {
|
if (defaults.normalize) {
|
||||||
filter_chain_append(*prepared_filter, "normalize",
|
filter_chain_append(*prepared_filter, "normalize",
|
||||||
autoconvert_filter_new(normalize_filter_prepare()));
|
autoconvert_filter_new(normalize_filter_prepare()));
|
||||||
}
|
}
|
||||||
@ -199,7 +203,8 @@ FilteredAudioOutput::Setup(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
const MixerPlugin *mixer_plugin,
|
const MixerPlugin *mixer_plugin,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
const ConfigBlock &block)
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults)
|
||||||
{
|
{
|
||||||
if (output->GetNeedFullyDefinedAudioFormat() &&
|
if (output->GetNeedFullyDefinedAudioFormat() &&
|
||||||
!config_audio_format.IsFullyDefined())
|
!config_audio_format.IsFullyDefined())
|
||||||
@ -224,6 +229,7 @@ FilteredAudioOutput::Setup(EventLoop &event_loop,
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
mixer = audio_output_load_mixer(event_loop, *this, block,
|
mixer = audio_output_load_mixer(event_loop, *this, block,
|
||||||
|
defaults,
|
||||||
mixer_plugin,
|
mixer_plugin,
|
||||||
*prepared_filter,
|
*prepared_filter,
|
||||||
mixer_listener);
|
mixer_listener);
|
||||||
@ -257,6 +263,7 @@ std::unique_ptr<FilteredAudioOutput>
|
|||||||
audio_output_new(EventLoop &event_loop,
|
audio_output_new(EventLoop &event_loop,
|
||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory,
|
FilterFactory *filter_factory,
|
||||||
MixerListener &mixer_listener)
|
MixerListener &mixer_listener)
|
||||||
{
|
{
|
||||||
@ -289,9 +296,10 @@ audio_output_new(EventLoop &event_loop,
|
|||||||
|
|
||||||
auto f = std::make_unique<FilteredAudioOutput>(plugin->name,
|
auto f = std::make_unique<FilteredAudioOutput>(plugin->name,
|
||||||
std::move(ao), block,
|
std::move(ao), block,
|
||||||
|
defaults,
|
||||||
filter_factory);
|
filter_factory);
|
||||||
f->Setup(event_loop, replay_gain_config,
|
f->Setup(event_loop, replay_gain_config,
|
||||||
plugin->mixer_plugin,
|
plugin->mixer_plugin,
|
||||||
mixer_listener, block);
|
mixer_listener, block, defaults);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "MultipleOutputs.hxx"
|
#include "MultipleOutputs.hxx"
|
||||||
#include "Filtered.hxx"
|
#include "Filtered.hxx"
|
||||||
|
#include "Defaults.hxx"
|
||||||
#include "Domain.hxx"
|
#include "Domain.hxx"
|
||||||
#include "MusicPipe.hxx"
|
#include "MusicPipe.hxx"
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
@ -53,9 +54,11 @@ LoadOutput(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
const ConfigBlock &block,
|
const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory)
|
FilterFactory *filter_factory)
|
||||||
try {
|
try {
|
||||||
return audio_output_new(event_loop, replay_gain_config, block,
|
return audio_output_new(event_loop, replay_gain_config, block,
|
||||||
|
defaults,
|
||||||
filter_factory,
|
filter_factory,
|
||||||
mixer_listener);
|
mixer_listener);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -71,11 +74,12 @@ LoadOutputControl(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
MixerListener &mixer_listener,
|
MixerListener &mixer_listener,
|
||||||
AudioOutputClient &client, const ConfigBlock &block,
|
AudioOutputClient &client, const ConfigBlock &block,
|
||||||
|
const AudioOutputDefaults &defaults,
|
||||||
FilterFactory *filter_factory)
|
FilterFactory *filter_factory)
|
||||||
{
|
{
|
||||||
auto output = LoadOutput(event_loop, replay_gain_config,
|
auto output = LoadOutput(event_loop, replay_gain_config,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
block, filter_factory);
|
block, defaults, filter_factory);
|
||||||
auto *control = new AudioOutputControl(std::move(output), client);
|
auto *control = new AudioOutputControl(std::move(output), client);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -95,6 +99,7 @@ MultipleOutputs::Configure(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
AudioOutputClient &client)
|
AudioOutputClient &client)
|
||||||
{
|
{
|
||||||
|
const AudioOutputDefaults defaults(config);
|
||||||
FilterFactory filter_factory(config);
|
FilterFactory filter_factory(config);
|
||||||
|
|
||||||
for (const auto &block : config.GetBlockList(ConfigBlockOption::AUDIO_OUTPUT)) {
|
for (const auto &block : config.GetBlockList(ConfigBlockOption::AUDIO_OUTPUT)) {
|
||||||
@ -102,7 +107,8 @@ MultipleOutputs::Configure(EventLoop &event_loop,
|
|||||||
auto *output = LoadOutputControl(event_loop,
|
auto *output = LoadOutputControl(event_loop,
|
||||||
replay_gain_config,
|
replay_gain_config,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
client, block, &filter_factory);
|
client, block, defaults,
|
||||||
|
&filter_factory);
|
||||||
if (FindByName(output->GetName()) != nullptr)
|
if (FindByName(output->GetName()) != nullptr)
|
||||||
throw FormatRuntimeError("output devices with identical "
|
throw FormatRuntimeError("output devices with identical "
|
||||||
"names: %s", output->GetName());
|
"names: %s", output->GetName());
|
||||||
@ -116,7 +122,7 @@ MultipleOutputs::Configure(EventLoop &event_loop,
|
|||||||
auto *output = LoadOutputControl(event_loop,
|
auto *output = LoadOutputControl(event_loop,
|
||||||
replay_gain_config,
|
replay_gain_config,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
client, empty,
|
client, empty, defaults,
|
||||||
nullptr);
|
nullptr);
|
||||||
outputs.push_back(output);
|
outputs.push_back(output);
|
||||||
}
|
}
|
||||||
@ -127,12 +133,14 @@ MultipleOutputs::AddNullOutput(EventLoop &event_loop,
|
|||||||
const ReplayGainConfig &replay_gain_config,
|
const ReplayGainConfig &replay_gain_config,
|
||||||
AudioOutputClient &client)
|
AudioOutputClient &client)
|
||||||
{
|
{
|
||||||
|
const AudioOutputDefaults defaults;
|
||||||
|
|
||||||
ConfigBlock block;
|
ConfigBlock block;
|
||||||
block.AddBlockParam("type", "null");
|
block.AddBlockParam("type", "null");
|
||||||
|
|
||||||
auto *output = LoadOutputControl(event_loop, replay_gain_config,
|
auto *output = LoadOutputControl(event_loop, replay_gain_config,
|
||||||
mixer_listener,
|
mixer_listener,
|
||||||
client, block, nullptr);
|
client, block, defaults, nullptr);
|
||||||
outputs.push_back(output);
|
outputs.push_back(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user