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.
22
#include "audio_parser.h"
23
#include "audio_format.h"
24
#include "filter_plugin.h"
25
#include "pcm_volume.h"
27
#include "mixer_control.h"
38
struct playlist g_playlist;
41
idle_add(G_GNUC_UNUSED unsigned flags)
46
mixer_set_volume(G_GNUC_UNUSED struct mixer *mixer,
47
G_GNUC_UNUSED unsigned volume, G_GNUC_UNUSED GError **error_r)
53
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
54
const gchar *message, G_GNUC_UNUSED gpointer user_data)
56
if (log_domain != NULL)
57
g_printerr("%s: %s\n", log_domain, message);
59
g_printerr("%s\n", message);
62
static const struct config_param *
63
find_named_config_block(const char *block, const char *name)
65
const struct config_param *param = NULL;
67
while ((param = config_get_next_param(block, param)) != NULL) {
68
const char *current_name =
69
config_get_block_string(param, "name", NULL);
70
if (current_name != NULL && strcmp(current_name, name) == 0)
77
static struct filter *
78
load_filter(const char *name)
80
const struct config_param *param;
81
struct filter *filter;
84
param = find_named_config_block("filter", name);
86
g_printerr("No such configured filter: %s\n", name);
90
filter = filter_configured_new(param, &error);
92
g_printerr("Failed to load filter: %s\n", error->message);
100
int main(int argc, char **argv)
102
struct audio_format audio_format;
103
struct audio_format_string af_string;
105
GError *error = NULL;
106
struct filter *filter;
107
const struct audio_format *out_audio_format;
111
if (argc < 3 || argc > 4) {
112
g_printerr("Usage: run_filter CONFIG NAME [FORMAT] <IN\n");
116
audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2);
118
/* initialize GLib */
121
g_log_set_default_handler(my_log_func, NULL);
123
/* read configuration file (mpd.conf) */
125
config_global_init();
126
success = config_read_file(argv[1], &error);
128
g_printerr("%s:", error->message);
133
/* parse the audio format */
136
success = audio_format_parse(&audio_format, argv[3],
139
g_printerr("Failed to parse audio format: %s\n",
146
/* initialize the filter */
148
filter = load_filter(argv[2]);
152
/* open the filter */
154
out_audio_format = filter_open(filter, &audio_format, &error);
155
if (out_audio_format == NULL) {
156
g_printerr("Failed to open filter: %s\n", error->message);
162
g_printerr("audio_format=%s\n",
163
audio_format_to_string(out_audio_format, &af_string));
165
frame_size = audio_format_frame_size(&audio_format);
174
nbytes = read(0, buffer, sizeof(buffer));
178
dest = filter_filter(filter, buffer, (size_t)nbytes,
181
g_printerr("Filter failed: %s\n", error->message);
182
filter_close(filter);
187
nbytes = write(1, dest, length);
189
g_printerr("Failed to write: %s\n", strerror(errno));
190
filter_close(filter);
196
/* cleanup and exit */
198
filter_close(filter);
201
config_global_finish();