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"
37 idle_add(G_GNUC_UNUSED
unsigned flags
)
42 mixer_set_volume(G_GNUC_UNUSED
struct mixer
*mixer
,
43 G_GNUC_UNUSED
unsigned volume
, G_GNUC_UNUSED GError
**error_r
)
49 my_log_func(const gchar
*log_domain
, G_GNUC_UNUSED GLogLevelFlags log_level
,
50 const gchar
*message
, G_GNUC_UNUSED gpointer user_data
)
52 if (log_domain
!= NULL
)
53 g_printerr("%s: %s\n", log_domain
, message
);
55 g_printerr("%s\n", message
);
58 static const struct config_param
*
59 find_named_config_block(const char *block
, const char *name
)
61 const struct config_param
*param
= NULL
;
63 while ((param
= config_get_next_param(block
, param
)) != NULL
) {
64 const char *current_name
=
65 config_get_block_string(param
, "name", NULL
);
66 if (current_name
!= NULL
&& strcmp(current_name
, name
) == 0)
73 static struct filter
*
74 load_filter(const char *name
)
76 const struct config_param
*param
;
77 struct filter
*filter
;
80 param
= find_named_config_block("filter", name
);
82 g_printerr("No such configured filter: %s\n", name
);
86 filter
= filter_configured_new(param
, &error
);
88 g_printerr("Failed to load filter: %s\n", error
->message
);
96 int main(int argc
, char **argv
)
98 struct audio_format audio_format
;
99 struct audio_format_string af_string
;
101 GError
*error
= NULL
;
102 struct filter
*filter
;
103 const struct audio_format
*out_audio_format
;
107 if (argc
< 3 || argc
> 4) {
108 g_printerr("Usage: run_filter CONFIG NAME [FORMAT] <IN\n");
112 audio_format_init(&audio_format
, 44100, SAMPLE_FORMAT_S16
, 2);
114 /* initialize GLib */
117 g_log_set_default_handler(my_log_func
, NULL
);
119 /* read configuration file (mpd.conf) */
121 config_global_init();
122 success
= config_read_file(argv
[1], &error
);
124 g_printerr("%s:", error
->message
);
129 /* parse the audio format */
132 success
= audio_format_parse(&audio_format
, argv
[3],
135 g_printerr("Failed to parse audio format: %s\n",
142 /* initialize the filter */
144 filter
= load_filter(argv
[2]);
148 /* open the filter */
150 out_audio_format
= filter_open(filter
, &audio_format
, &error
);
151 if (out_audio_format
== NULL
) {
152 g_printerr("Failed to open filter: %s\n", error
->message
);
158 g_printerr("audio_format=%s\n",
159 audio_format_to_string(out_audio_format
, &af_string
));
161 frame_size
= audio_format_frame_size(&audio_format
);
170 nbytes
= read(0, buffer
, sizeof(buffer
));
174 dest
= filter_filter(filter
, buffer
, (size_t)nbytes
,
177 g_printerr("Filter failed: %s\n", error
->message
);
178 filter_close(filter
);
183 nbytes
= write(1, dest
, length
);
185 g_printerr("Failed to write: %s\n", strerror(errno
));
186 filter_close(filter
);
192 /* cleanup and exit */
194 filter_close(filter
);
197 config_global_finish();