summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-18 20:57:02 +0200
committerMax Kellermann <max@musicpd.org>2018-08-18 20:57:02 +0200
commit4531e4cc55fa57964a3014fd65877ead3c23fa5d (patch)
tree7ee3cb6f3a25452739635a39bf4ede97825ea677
parent1ba35e1fd4871f2430d7f3bf5a799f2ad39f73ab (diff)
filter/LoadChain: move code to class FilterFactory
Eliminate a use of GetGlobalConfig().
-rw-r--r--Makefile.am1
-rw-r--r--src/filter/Factory.cxx40
-rw-r--r--src/filter/Factory.hxx40
-rw-r--r--src/filter/LoadChain.cxx31
-rw-r--r--src/filter/LoadChain.hxx4
-rw-r--r--src/output/Filtered.hxx8
-rw-r--r--src/output/Init.cxx17
-rw-r--r--src/output/MultipleOutputs.cxx19
8 files changed, 120 insertions, 40 deletions
diff --git a/Makefile.am b/Makefile.am
index e403da342..c3e39b549 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1834,6 +1834,7 @@ libfilter_plugins_a_SOURCES = \
libfilter_glue_a_SOURCES = \
src/filter/FilterRegistry.cxx src/filter/FilterRegistry.hxx \
+ src/filter/Factory.cxx src/filter/Factory.hxx \
src/filter/LoadOne.cxx src/filter/LoadOne.hxx \
src/filter/LoadChain.cxx src/filter/LoadChain.hxx
diff --git a/src/filter/Factory.cxx b/src/filter/Factory.cxx
new file mode 100644
index 000000000..baa4cd09e
--- /dev/null
+++ b/src/filter/Factory.cxx
@@ -0,0 +1,40 @@
+/*
+ * 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 "Factory.hxx"
+#include "LoadOne.hxx"
+#include "Prepared.hxx"
+#include "config/Data.hxx"
+#include "config/Block.hxx"
+#include "util/RuntimeError.hxx"
+
+std::unique_ptr<PreparedFilter>
+FilterFactory::MakeFilter(const char *name)
+{
+ const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER,
+ "name", name);
+ if (cfg == nullptr)
+ throw FormatRuntimeError("Filter template not found: %s",
+ name);
+
+ cfg->SetUsed();
+
+ return filter_configured_new(*cfg);
+}
diff --git a/src/filter/Factory.hxx b/src/filter/Factory.hxx
new file mode 100644
index 000000000..350cc2941
--- /dev/null
+++ b/src/filter/Factory.hxx
@@ -0,0 +1,40 @@
+/*
+ * 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_FILTER_FACTORY_HXX
+#define MPD_FILTER_FACTORY_HXX
+
+#include "check.h"
+
+#include <memory>
+
+struct ConfigData;
+class PreparedFilter;
+
+class FilterFactory {
+ const ConfigData &config;
+
+public:
+ explicit FilterFactory(const ConfigData &_config) noexcept
+ :config(_config) {}
+
+ std::unique_ptr<PreparedFilter> MakeFilter(const char *name);
+};
+
+#endif
diff --git a/src/filter/LoadChain.cxx b/src/filter/LoadChain.cxx
index e400dcebf..df5708cff 100644
--- a/src/filter/LoadChain.cxx
+++ b/src/filter/LoadChain.cxx
@@ -19,43 +19,26 @@
#include "config.h"
#include "LoadChain.hxx"
-#include "LoadOne.hxx"
+#include "Factory.hxx"
#include "Prepared.hxx"
#include "plugins/ChainFilterPlugin.hxx"
-#include "config/Param.hxx"
-#include "config/Option.hxx"
-#include "config/Data.hxx"
-#include "config/Domain.hxx"
-#include "config/Block.hxx"
-#include "util/RuntimeError.hxx"
#include <algorithm>
+#include <string>
#include <string.h>
static void
-filter_chain_append_new(PreparedFilter &chain, const ConfigData &config,
+filter_chain_append_new(PreparedFilter &chain, FilterFactory &factory,
const char *template_name)
{
- const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER,
- "name", template_name);
- if (cfg == nullptr)
- throw FormatRuntimeError("Filter template not found: %s",
- template_name);
-
- cfg->SetUsed();
-
- // Instantiate one of those filter plugins with the template name as a hint
- auto f = filter_configured_new(*cfg);
-
- const char *plugin_name = cfg->GetBlockValue("plugin",
- "unknown");
- filter_chain_append(chain, plugin_name, std::move(f));
+ filter_chain_append(chain, template_name,
+ factory.MakeFilter(template_name));
}
void
filter_chain_parse(PreparedFilter &chain,
- const ConfigData &config,
+ FilterFactory &factory,
const char *spec)
{
const char *const end = spec + strlen(spec);
@@ -64,7 +47,7 @@ filter_chain_parse(PreparedFilter &chain,
const char *comma = std::find(spec, end, ',');
if (comma > spec) {
const std::string name(spec, comma);
- filter_chain_append_new(chain, config, name.c_str());
+ filter_chain_append_new(chain, factory, name.c_str());
}
if (comma == end)
diff --git a/src/filter/LoadChain.hxx b/src/filter/LoadChain.hxx
index cfe4ae8b2..adbcc82b4 100644
--- a/src/filter/LoadChain.hxx
+++ b/src/filter/LoadChain.hxx
@@ -20,7 +20,7 @@
#ifndef MPD_FILTER_LOAD_CHAIN_HXX
#define MPD_FILTER_LOAD_CHAIN_HXX
-struct ConfigData;
+class FilterFactory;
class PreparedFilter;
/**
@@ -36,7 +36,7 @@ class PreparedFilter;
*/
void
filter_chain_parse(PreparedFilter &chain,
- const ConfigData &config,
+ FilterFactory &factory,
const char *spec);
#endif
diff --git a/src/output/Filtered.hxx b/src/output/Filtered.hxx
index ed9d51e71..4068763d6 100644
--- a/src/output/Filtered.hxx
+++ b/src/output/Filtered.hxx
@@ -28,6 +28,7 @@
#include <map>
#include <chrono>
+class FilterFactory;
class PreparedFilter;
class MusicPipe;
class EventLoop;
@@ -127,12 +128,14 @@ public:
*/
FilteredAudioOutput(const char *_plugin_name,
std::unique_ptr<AudioOutput> &&_output,
- const ConfigBlock &block);
+ const ConfigBlock &block,
+ FilterFactory *filter_factory);
~FilteredAudioOutput();
private:
- void Configure(const ConfigBlock &block);
+ void Configure(const ConfigBlock &block,
+ FilterFactory *filter_factory);
public:
void Setup(EventLoop &event_loop,
@@ -235,6 +238,7 @@ std::unique_ptr<FilteredAudioOutput>
audio_output_new(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config,
const ConfigBlock &block,
+ FilterFactory *filter_factory,
MixerListener &mixer_listener);
#endif
diff --git a/src/output/Init.cxx b/src/output/Init.cxx
index 784a605c8..0924a0f00 100644
--- a/src/output/Init.cxx
+++ b/src/output/Init.cxx
@@ -54,10 +54,11 @@
FilteredAudioOutput::FilteredAudioOutput(const char *_plugin_name,
std::unique_ptr<AudioOutput> &&_output,
- const ConfigBlock &block)
+ const ConfigBlock &block,
+ FilterFactory *filter_factory)
:plugin_name(_plugin_name), output(std::move(_output))
{
- Configure(block);
+ Configure(block, filter_factory);
}
static const AudioOutputPlugin *
@@ -148,7 +149,8 @@ audio_output_load_mixer(EventLoop &event_loop, FilteredAudioOutput &ao,
}
void
-FilteredAudioOutput::Configure(const ConfigBlock &block)
+FilteredAudioOutput::Configure(const ConfigBlock &block,
+ FilterFactory *filter_factory)
{
if (!block.IsNull()) {
name = block.GetBlockValue(AUDIO_OUTPUT_NAME);
@@ -181,8 +183,9 @@ FilteredAudioOutput::Configure(const ConfigBlock &block)
}
try {
- filter_chain_parse(*prepared_filter, GetGlobalConfig(),
- block.GetBlockValue(AUDIO_FILTERS, ""));
+ if (filter_factory != nullptr)
+ filter_chain_parse(*prepared_filter, *filter_factory,
+ block.GetBlockValue(AUDIO_FILTERS, ""));
} catch (...) {
/* It's not really fatal - Part of the filter chain
has been set up already and even an empty one will
@@ -256,6 +259,7 @@ std::unique_ptr<FilteredAudioOutput>
audio_output_new(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config,
const ConfigBlock &block,
+ FilterFactory *filter_factory,
MixerListener &mixer_listener)
{
const AudioOutputPlugin *plugin;
@@ -286,7 +290,8 @@ audio_output_new(EventLoop &event_loop,
assert(ao != nullptr);
auto f = std::make_unique<FilteredAudioOutput>(plugin->name,
- std::move(ao), block);
+ std::move(ao), block,
+ filter_factory);
f->Setup(event_loop, replay_gain_config,
plugin->mixer_plugin,
mixer_listener, block);
diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx
index af21d2e33..6c9acee9e 100644
--- a/src/output/MultipleOutputs.cxx
+++ b/src/output/MultipleOutputs.cxx
@@ -23,6 +23,7 @@
#include "Domain.hxx"
#include "MusicPipe.hxx"
#include "MusicChunk.hxx"
+#include "filter/Factory.hxx"
#include "config/Block.hxx"
#include "config/Data.hxx"
#include "config/Option.hxx"
@@ -51,9 +52,11 @@ static std::unique_ptr<FilteredAudioOutput>
LoadOutput(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config,
MixerListener &mixer_listener,
- const ConfigBlock &block)
+ const ConfigBlock &block,
+ FilterFactory *filter_factory)
try {
return audio_output_new(event_loop, replay_gain_config, block,
+ filter_factory,
mixer_listener);
} catch (...) {
if (block.line > 0)
@@ -67,11 +70,12 @@ static AudioOutputControl *
LoadOutputControl(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config,
MixerListener &mixer_listener,
- AudioOutputClient &client, const ConfigBlock &block)
+ AudioOutputClient &client, const ConfigBlock &block,
+ FilterFactory *filter_factory)
{
auto output = LoadOutput(event_loop, replay_gain_config,
mixer_listener,
- block);
+ block, filter_factory);
auto *control = new AudioOutputControl(std::move(output), client);
try {
@@ -91,12 +95,14 @@ MultipleOutputs::Configure(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config,
AudioOutputClient &client)
{
+ FilterFactory filter_factory(config);
+
for (const auto &block : config.GetBlockList(ConfigBlockOption::AUDIO_OUTPUT)) {
block.SetUsed();
auto *output = LoadOutputControl(event_loop,
replay_gain_config,
mixer_listener,
- client, block);
+ client, block, &filter_factory);
if (FindByName(output->GetName()) != nullptr)
throw FormatRuntimeError("output devices with identical "
"names: %s", output->GetName());
@@ -110,7 +116,8 @@ MultipleOutputs::Configure(EventLoop &event_loop,
auto *output = LoadOutputControl(event_loop,
replay_gain_config,
mixer_listener,
- client, empty);
+ client, empty,
+ nullptr);
outputs.push_back(output);
}
}
@@ -125,7 +132,7 @@ MultipleOutputs::AddNullOutput(EventLoop &event_loop,
auto *output = LoadOutputControl(event_loop, replay_gain_config,
mixer_listener,
- client, block);
+ client, block, nullptr);
outputs.push_back(output);
}