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)
|
||||
|
||||
OUTPUT_API_SRC = \
|
||||
src/output/Defaults.cxx src/output/Defaults.hxx \
|
||||
src/output/Client.hxx \
|
||||
src/output/OutputAPI.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 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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user