doc: Remove superfluous comment already described in footnotes.
[mpd-mk.git] / src / filter_plugin.c
blobe5c1d5cd8226c3e6fdac485057dc4e809d6062d8
1 /*
2 * Copyright (C) 2003-2009 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_plugin.h"
21 #include "filter_internal.h"
22 #include "filter_registry.h"
23 #include "conf.h"
25 #ifndef NDEBUG
26 #include "audio_format.h"
27 #endif
29 #include <assert.h>
31 struct filter *
32 filter_new(const struct filter_plugin *plugin,
33 const struct config_param *param, GError **error_r)
35 assert(plugin != NULL);
36 assert(error_r == NULL || *error_r == NULL);
38 return plugin->init(param, error_r);
41 struct filter *
42 filter_configured_new(const struct config_param *param, GError **error_r)
44 const char *plugin_name;
45 const struct filter_plugin *plugin;
47 assert(param != NULL);
48 assert(error_r == NULL || *error_r == NULL);
50 plugin_name = config_get_block_string(param, "plugin", NULL);
51 if (plugin_name == NULL)
52 g_set_error(error_r, config_quark(), 0,
53 "No filter plugin specified");
55 plugin = filter_plugin_by_name(plugin_name);
56 if (plugin == NULL)
57 g_set_error(error_r, config_quark(), 0,
58 "No such filter plugin: %s", plugin_name);
60 return filter_new(plugin, param, error_r);
63 void
64 filter_free(struct filter *filter)
66 assert(filter != NULL);
68 filter->plugin->finish(filter);
71 const struct audio_format *
72 filter_open(struct filter *filter, const struct audio_format *audio_format,
73 GError **error_r)
75 assert(filter != NULL);
76 assert(audio_format != NULL);
77 assert(audio_format_valid(audio_format));
78 assert(error_r == NULL || *error_r == NULL);
80 audio_format = filter->plugin->open(filter, audio_format, error_r);
81 assert(audio_format == NULL || audio_format_valid(audio_format));
83 return audio_format;
86 void
87 filter_close(struct filter *filter)
89 assert(filter != NULL);
91 filter->plugin->close(filter);
94 const void *
95 filter_filter(struct filter *filter, const void *src, size_t src_size,
96 size_t *dest_size_r,
97 GError **error_r)
99 assert(filter != NULL);
100 assert(src != NULL);
101 assert(src_size > 0);
102 assert(dest_size_r != NULL);
103 assert(error_r == NULL || *error_r == NULL);
105 return filter->plugin->filter(filter, src, src_size, dest_size_r, error_r);