libOggFLAC.m4: Remove libOggFLAC.m4 as it's buggy.
[mpd-mk.git] / src / filter_config.c
blob90de199b79e3cfa973feb9582ef58678f4cd7b23
1 /*
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"
21 #include "config.h"
22 #include "conf.h"
23 #include "filter/chain_filter_plugin.h"
24 #include "filter_plugin.h"
25 #include "filter_internal.h"
26 #include "filter_registry.h"
28 #include <string.h>
31 static GQuark
32 filter_quark(void)
34 return g_quark_from_static_string("filter");
37 /**
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) {
50 const char *name =
51 config_get_block_string(param, "name", NULL);
52 if (name == NULL) {
53 g_set_error(error_r, filter_quark(), 1,
54 "filter configuration without 'name' name in line %d",
55 param->line);
56 return NULL;
59 if (strcmp(name, filter_template_name) == 0)
60 return param;
63 g_set_error(error_r, filter_quark(), 1,
64 "filter template not found: %s",
65 filter_template_name);
67 return NULL;
70 /**
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
79 unsigned int
80 filter_chain_parse(struct filter *chain, const char *spec, GError **error_r)
83 // Split on comma
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) {
91 struct filter *f;
92 const struct config_param *cfg;
94 // Squeeze whitespace
95 g_strstrip(*template_names);
97 cfg = filter_plugin_config(*template_names, error_r);
98 if (cfg == NULL) {
99 // The error has already been set, just stop.
100 break;
103 // Instantiate one of those filter plugins with the template name as a hint
104 f = filter_configured_new(cfg, error_r);
105 if (f == NULL) {
106 // The error has already been set, just stop.
107 break;
110 filter_chain_append(chain, f);
111 ++added_filters;
113 ++template_names;
116 g_strfreev(tokens);
118 return added_filters;