2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "filter_config.h"
23 #include "filter/chain_filter_plugin.h"
24 #include "filter_plugin.h"
25 #include "filter_internal.h"
26 #include "filter_registry.h"
34 return g_quark_from_static_string("filter");
38 * Find the "filter" configuration block for the specified name.
40 * @param filter_template_name the name of the filter template
41 * @param error_r space to return an error description
42 * @return the configuration block, or NULL if none was configured
44 static const struct config_param
*
45 filter_plugin_config(const char *filter_template_name
, GError
**error_r
)
47 const struct config_param
*param
= NULL
;
49 while ((param
= config_get_next_param(CONF_AUDIO_FILTER
, param
)) != NULL
) {
51 config_get_block_string(param
, "name", NULL
);
53 g_set_error(error_r
, filter_quark(), 1,
54 "filter configuration without 'name' name in line %d",
59 if (strcmp(name
, filter_template_name
) == 0)
63 g_set_error(error_r
, filter_quark(), 1,
64 "filter template not found: %s",
65 filter_template_name
);
71 * Builds a filter chain from a configuration string on the form
72 * "name1, name2, name3, ..." by looking up each name among the
73 * configured filter sections.
74 * @param chain the chain to append filters on
75 * @param spec the filter chain specification
76 * @param error_r space to return an error description
77 * @return the number of filters which were successfully added
80 filter_chain_parse(struct filter
*chain
, const char *spec
, GError
**error_r
)
84 gchar
** tokens
= g_strsplit_set(spec
, ",", 255);
86 int added_filters
= 0;
88 // Add each name to the filter chain by instantiating an actual filter
89 char **template_names
= tokens
;
90 while (*template_names
!= NULL
) {
92 const struct config_param
*cfg
;
95 g_strstrip(*template_names
);
97 cfg
= filter_plugin_config(*template_names
, error_r
);
99 // The error has already been set, just stop.
103 // Instantiate one of those filter plugins with the template name as a hint
104 f
= filter_configured_new(cfg
, error_r
);
106 // The error has already been set, just stop.
110 filter_chain_append(chain
, f
);
118 return added_filters
;