diff options
author | Max Kellermann <max@musicpd.org> | 2018-08-19 07:43:47 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-08-19 07:52:23 +0200 |
commit | 1a9659ef455773adddecd92295c73bfc1f8d401b (patch) | |
tree | 2ec44d7a374e1f0a2c9782a181c8e7db74c30efb /src | |
parent | aaa438e745dbab22f77aff9db00ce9038a07df08 (diff) |
output/Init: pass global configuration in struct AudioOutputDefaults
Diffstat (limited to 'src')
-rw-r--r-- | src/output/Defaults.cxx | 31 | ||||
-rw-r--r-- | src/output/Defaults.hxx | 47 | ||||
-rw-r--r-- | src/output/Filtered.hxx | 7 | ||||
-rw-r--r-- | src/output/Init.cxx | 26 | ||||
-rw-r--r-- | src/output/MultipleOutputs.cxx | 16 |
5 files changed, 113 insertions, 14 deletions
diff --git a/src/output/Defaults.cxx b/src/output/Defaults.cxx new file mode 100644 index 000000000..53db168f0 --- /dev/null +++ b/src/output/Defaults.cxx @@ -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"))) + +{ +} diff --git a/src/output/Defaults.hxx b/src/output/Defaults.hxx new file mode 100644 index 000000000..3c839b450 --- /dev/null +++ b/src/output/Defaults.hxx @@ -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 diff --git a/src/output/Filtered.hxx b/src/output/Filtered.hxx index 4068763d6..543e3c863 100644 --- a/src/output/Filtered.hxx +++ b/src/output/Filtered.hxx @@ -38,6 +38,7 @@ struct MixerPlugin; struct MusicChunk; struct ConfigBlock; class AudioOutput; +struct AudioOutputDefaults; struct ReplayGainConfig; struct Tag; @@ -129,12 +130,14 @@ public: FilteredAudioOutput(const char *_plugin_name, std::unique_ptr<AudioOutput> &&_output, const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory); ~FilteredAudioOutput(); private: void Configure(const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory); public: @@ -142,7 +145,8 @@ public: const ReplayGainConfig &replay_gain_config, const MixerPlugin *mixer_plugin, MixerListener &mixer_listener, - const ConfigBlock &block); + const ConfigBlock &block, + const AudioOutputDefaults &defaults); const char *GetName() const { return name; @@ -238,6 +242,7 @@ std::unique_ptr<FilteredAudioOutput> audio_output_new(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory, MixerListener &mixer_listener); diff --git a/src/output/Init.cxx b/src/output/Init.cxx index 9cac298fe..bf9aebe6e 100644 --- a/src/output/Init.cxx +++ b/src/output/Init.cxx @@ -22,6 +22,7 @@ #include "Registry.hxx" #include "Domain.hxx" #include "OutputAPI.hxx" +#include "Defaults.hxx" #include "AudioParser.hxx" #include "mixer/MixerList.hxx" #include "mixer/MixerType.hxx" @@ -36,7 +37,7 @@ #include "filter/plugins/VolumeFilterPlugin.hxx" #include "filter/plugins/NormalizeFilterPlugin.hxx" #include "config/Domain.hxx" -#include "config/Global.hxx" +#include "config/Option.hxx" #include "config/Block.hxx" #include "util/RuntimeError.hxx" #include "util/StringFormat.hxx" @@ -55,10 +56,11 @@ FilteredAudioOutput::FilteredAudioOutput(const char *_plugin_name, std::unique_ptr<AudioOutput> &&_output, const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory) :plugin_name(_plugin_name), output(std::move(_output)) { - Configure(block, filter_factory); + Configure(block, defaults, filter_factory); } static const AudioOutputPlugin * @@ -88,7 +90,8 @@ audio_output_detect() * mixer_enabled, if the mixer_type setting is not configured. */ 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 */ 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 deprecated) */ - return mixer_type_parse(config_get_string(ConfigOption::MIXER_TYPE, - "hardware")); + return defaults.mixer_type; } static Mixer * audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao, const ConfigBlock &block, + const AudioOutputDefaults &defaults, const MixerPlugin *plugin, PreparedFilter &filter_chain, MixerListener &listener) { Mixer *mixer; - switch (audio_output_mixer_type(block)) { + switch (audio_output_mixer_type(block, defaults)) { case MixerType::NONE: return nullptr; @@ -148,6 +151,7 @@ audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao, void FilteredAudioOutput::Configure(const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory) { if (!block.IsNull()) { @@ -175,7 +179,7 @@ FilteredAudioOutput::Configure(const ConfigBlock &block, /* create the normalization filter (if configured) */ - if (config_get_bool(ConfigOption::VOLUME_NORMALIZATION, false)) { + if (defaults.normalize) { filter_chain_append(*prepared_filter, "normalize", autoconvert_filter_new(normalize_filter_prepare())); } @@ -199,7 +203,8 @@ FilteredAudioOutput::Setup(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, const MixerPlugin *mixer_plugin, MixerListener &mixer_listener, - const ConfigBlock &block) + const ConfigBlock &block, + const AudioOutputDefaults &defaults) { if (output->GetNeedFullyDefinedAudioFormat() && !config_audio_format.IsFullyDefined()) @@ -224,6 +229,7 @@ FilteredAudioOutput::Setup(EventLoop &event_loop, try { mixer = audio_output_load_mixer(event_loop, *this, block, + defaults, mixer_plugin, *prepared_filter, mixer_listener); @@ -257,6 +263,7 @@ std::unique_ptr<FilteredAudioOutput> audio_output_new(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory, MixerListener &mixer_listener) { @@ -289,9 +296,10 @@ audio_output_new(EventLoop &event_loop, auto f = std::make_unique<FilteredAudioOutput>(plugin->name, std::move(ao), block, + defaults, filter_factory); f->Setup(event_loop, replay_gain_config, plugin->mixer_plugin, - mixer_listener, block); + mixer_listener, block, defaults); return f; } diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index 6c9acee9e..edaa0c9f4 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "MultipleOutputs.hxx" #include "Filtered.hxx" +#include "Defaults.hxx" #include "Domain.hxx" #include "MusicPipe.hxx" #include "MusicChunk.hxx" @@ -53,9 +54,11 @@ LoadOutput(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, MixerListener &mixer_listener, const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory) try { return audio_output_new(event_loop, replay_gain_config, block, + defaults, filter_factory, mixer_listener); } catch (...) { @@ -71,11 +74,12 @@ LoadOutputControl(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, MixerListener &mixer_listener, AudioOutputClient &client, const ConfigBlock &block, + const AudioOutputDefaults &defaults, FilterFactory *filter_factory) { auto output = LoadOutput(event_loop, replay_gain_config, mixer_listener, - block, filter_factory); + block, defaults, filter_factory); auto *control = new AudioOutputControl(std::move(output), client); try { @@ -95,6 +99,7 @@ MultipleOutputs::Configure(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, AudioOutputClient &client) { + const AudioOutputDefaults defaults(config); FilterFactory filter_factory(config); for (const auto &block : config.GetBlockList(ConfigBlockOption::AUDIO_OUTPUT)) { @@ -102,7 +107,8 @@ MultipleOutputs::Configure(EventLoop &event_loop, auto *output = LoadOutputControl(event_loop, replay_gain_config, mixer_listener, - client, block, &filter_factory); + client, block, defaults, + &filter_factory); if (FindByName(output->GetName()) != nullptr) throw FormatRuntimeError("output devices with identical " "names: %s", output->GetName()); @@ -116,7 +122,7 @@ MultipleOutputs::Configure(EventLoop &event_loop, auto *output = LoadOutputControl(event_loop, replay_gain_config, mixer_listener, - client, empty, + client, empty, defaults, nullptr); outputs.push_back(output); } @@ -127,12 +133,14 @@ MultipleOutputs::AddNullOutput(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, AudioOutputClient &client) { + const AudioOutputDefaults defaults; + ConfigBlock block; block.AddBlockParam("type", "null"); auto *output = LoadOutputControl(event_loop, replay_gain_config, mixer_listener, - client, block, nullptr); + client, block, defaults, nullptr); outputs.push_back(output); } |