2009-12-14 21:09:28 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-12-14 21:09:28 +01:00
|
|
|
* 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"
|
2018-01-02 23:09:36 +01:00
|
|
|
#include "LoadChain.hxx"
|
2018-01-02 23:06:53 +01:00
|
|
|
#include "LoadOne.hxx"
|
2018-01-01 18:48:34 +01:00
|
|
|
#include "Prepared.hxx"
|
2017-12-27 09:17:15 +01:00
|
|
|
#include "plugins/ChainFilterPlugin.hxx"
|
2015-01-21 21:14:25 +01:00
|
|
|
#include "config/Param.hxx"
|
2018-07-16 19:50:07 +02:00
|
|
|
#include "config/Option.hxx"
|
|
|
|
#include "config/Global.hxx"
|
|
|
|
#include "config/Domain.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "config/Block.hxx"
|
2016-09-04 20:07:05 +02:00
|
|
|
#include "util/RuntimeError.hxx"
|
2009-12-14 21:09:28 +01:00
|
|
|
|
2013-10-19 16:34:11 +02:00
|
|
|
#include <algorithm>
|
2013-01-30 22:39:19 +01:00
|
|
|
|
2009-12-14 21:09:28 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-04 20:07:05 +02:00
|
|
|
static void
|
|
|
|
filter_chain_append_new(PreparedFilter &chain, const char *template_name)
|
2013-10-19 16:26:51 +02:00
|
|
|
{
|
2015-01-21 22:13:44 +01:00
|
|
|
const auto *cfg = config_find_block(ConfigBlockOption::AUDIO_FILTER,
|
|
|
|
"name", template_name);
|
2016-09-04 20:07:05 +02:00
|
|
|
if (cfg == nullptr)
|
|
|
|
throw FormatRuntimeError("Filter template not found: %s",
|
|
|
|
template_name);
|
2013-10-19 16:26:51 +02:00
|
|
|
|
|
|
|
// Instantiate one of those filter plugins with the template name as a hint
|
2017-12-27 09:17:15 +01:00
|
|
|
auto f = filter_configured_new(*cfg);
|
2013-10-19 16:26:51 +02:00
|
|
|
|
|
|
|
const char *plugin_name = cfg->GetBlockValue("plugin",
|
|
|
|
"unknown");
|
2017-12-27 09:17:15 +01:00
|
|
|
filter_chain_append(chain, plugin_name, std::move(f));
|
2013-10-19 16:26:51 +02:00
|
|
|
}
|
|
|
|
|
2016-09-04 20:07:05 +02:00
|
|
|
void
|
|
|
|
filter_chain_parse(PreparedFilter &chain, const char *spec)
|
2009-12-14 21:09:28 +01:00
|
|
|
{
|
2013-10-19 16:34:11 +02:00
|
|
|
const char *const end = spec + strlen(spec);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
const char *comma = std::find(spec, end, ',');
|
|
|
|
if (comma > spec) {
|
|
|
|
const std::string name(spec, comma);
|
2016-09-04 20:07:05 +02:00
|
|
|
filter_chain_append_new(chain, name.c_str());
|
2013-10-19 16:34:11 +02:00
|
|
|
}
|
2009-12-14 21:09:28 +01:00
|
|
|
|
2013-10-19 16:34:11 +02:00
|
|
|
if (comma == end)
|
|
|
|
break;
|
2009-12-14 21:09:28 +01:00
|
|
|
|
2013-10-19 16:34:11 +02:00
|
|
|
spec = comma + 1;
|
2009-12-14 21:09:28 +01:00
|
|
|
}
|
|
|
|
}
|