configure.ac: Move wavpack to Decoder Plugins, add header.
[mpd-mk.git] / test / run_decoder.c
blobd85cf10fe55eae61c30ecca065c961b59e6f8538
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 "config.h"
21 #include "decoder_list.h"
22 #include "decoder_api.h"
23 #include "input_init.h"
24 #include "input_stream.h"
25 #include "audio_format.h"
26 #include "pcm_volume.h"
27 #include "idle.h"
29 #include <glib.h>
31 #include <assert.h>
32 #include <unistd.h>
34 static void
35 my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
36 const gchar *message, G_GNUC_UNUSED gpointer user_data)
38 if (log_domain != NULL)
39 g_printerr("%s: %s\n", log_domain, message);
40 else
41 g_printerr("%s\n", message);
44 /**
45 * No-op dummy.
47 void
48 idle_add(G_GNUC_UNUSED unsigned flags)
52 /**
53 * No-op dummy.
55 bool
56 pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length,
57 G_GNUC_UNUSED const struct audio_format *format,
58 G_GNUC_UNUSED int volume)
60 return true;
63 struct decoder {
64 const char *uri;
66 const struct decoder_plugin *plugin;
68 bool initialized;
71 void
72 decoder_initialized(struct decoder *decoder,
73 const struct audio_format *audio_format,
74 G_GNUC_UNUSED bool seekable,
75 G_GNUC_UNUSED float total_time)
77 struct audio_format_string af_string;
79 assert(!decoder->initialized);
80 assert(audio_format_valid(audio_format));
82 g_printerr("audio_format=%s\n",
83 audio_format_to_string(audio_format, &af_string));
85 decoder->initialized = true;
88 enum decoder_command
89 decoder_get_command(G_GNUC_UNUSED struct decoder *decoder)
91 return DECODE_COMMAND_NONE;
94 void decoder_command_finished(G_GNUC_UNUSED struct decoder *decoder)
98 double decoder_seek_where(G_GNUC_UNUSED struct decoder *decoder)
100 return 1.0;
103 void decoder_seek_error(G_GNUC_UNUSED struct decoder *decoder)
107 size_t
108 decoder_read(G_GNUC_UNUSED struct decoder *decoder,
109 struct input_stream *is,
110 void *buffer, size_t length)
112 return input_stream_read(is, buffer, length, NULL);
115 void
116 decoder_timestamp(G_GNUC_UNUSED struct decoder *decoder,
117 G_GNUC_UNUSED double t)
121 enum decoder_command
122 decoder_data(G_GNUC_UNUSED struct decoder *decoder,
123 G_GNUC_UNUSED struct input_stream *is,
124 const void *data, size_t datalen,
125 G_GNUC_UNUSED uint16_t kbit_rate)
127 write(1, data, datalen);
128 return DECODE_COMMAND_NONE;
131 enum decoder_command
132 decoder_tag(G_GNUC_UNUSED struct decoder *decoder,
133 G_GNUC_UNUSED struct input_stream *is,
134 G_GNUC_UNUSED const struct tag *tag)
136 return DECODE_COMMAND_NONE;
139 void
140 decoder_replay_gain(G_GNUC_UNUSED struct decoder *decoder,
141 G_GNUC_UNUSED const struct replay_gain_info *replay_gain_info)
145 void
146 decoder_mixramp(G_GNUC_UNUSED struct decoder *decoder,
147 char *mixramp_start, char *mixramp_end)
149 g_free(mixramp_start);
150 g_free(mixramp_end);
153 int main(int argc, char **argv)
155 GError *error = NULL;
156 const char *decoder_name;
157 struct decoder decoder;
159 if (argc != 3) {
160 g_printerr("Usage: run_decoder DECODER URI >OUT\n");
161 return 1;
164 decoder_name = argv[1];
165 decoder.uri = argv[2];
167 g_log_set_default_handler(my_log_func, NULL);
169 if (!input_stream_global_init(&error)) {
170 g_warning("%s", error->message);
171 g_error_free(error);
172 return 2;
175 decoder_plugin_init_all();
177 decoder.plugin = decoder_plugin_from_name(decoder_name);
178 if (decoder.plugin == NULL) {
179 g_printerr("No such decoder: %s\n", decoder_name);
180 return 1;
183 decoder.initialized = false;
185 if (decoder.plugin->file_decode != NULL) {
186 decoder_plugin_file_decode(decoder.plugin, &decoder,
187 decoder.uri);
188 } else if (decoder.plugin->stream_decode != NULL) {
189 struct input_stream *is =
190 input_stream_open(decoder.uri, &error);
191 if (is == NULL) {
192 if (error != NULL) {
193 g_warning("%s", error->message);
194 g_error_free(error);
195 } else
196 g_printerr("input_stream_open() failed\n");
198 return 1;
201 decoder_plugin_stream_decode(decoder.plugin, &decoder, is);
203 input_stream_close(is);
204 } else {
205 g_printerr("Decoder plugin is not usable\n");
206 return 1;
209 decoder_plugin_deinit_all();
210 input_stream_global_finish();
212 if (!decoder.initialized) {
213 g_printerr("Decoding failed\n");
214 return 1;
217 return 0;