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.
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"
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
);
41 g_printerr("%s\n", message
);
48 idle_add(G_GNUC_UNUSED
unsigned flags
)
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
)
66 const struct decoder_plugin
*plugin
;
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;
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
)
103 void decoder_seek_error(G_GNUC_UNUSED
struct decoder
*decoder
)
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
);
116 decoder_timestamp(G_GNUC_UNUSED
struct decoder
*decoder
,
117 G_GNUC_UNUSED
double t
)
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
;
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
;
140 decoder_replay_gain(G_GNUC_UNUSED
struct decoder
*decoder
,
141 G_GNUC_UNUSED
const struct replay_gain_info
*replay_gain_info
)
146 decoder_mixramp(G_GNUC_UNUSED
struct decoder
*decoder
,
147 char *mixramp_start
, char *mixramp_end
)
149 g_free(mixramp_start
);
153 int main(int argc
, char **argv
)
155 GError
*error
= NULL
;
156 const char *decoder_name
;
157 struct decoder decoder
;
160 g_printerr("Usage: run_decoder DECODER URI >OUT\n");
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
);
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
);
183 decoder
.initialized
= false;
185 if (decoder
.plugin
->file_decode
!= NULL
) {
186 decoder_plugin_file_decode(decoder
.plugin
, &decoder
,
188 } else if (decoder
.plugin
->stream_decode
!= NULL
) {
189 struct input_stream
*is
=
190 input_stream_open(decoder
.uri
, &error
);
193 g_warning("%s", error
->message
);
196 g_printerr("input_stream_open() failed\n");
201 decoder_plugin_stream_decode(decoder
.plugin
, &decoder
, is
);
203 input_stream_close(is
);
205 g_printerr("Decoder plugin is not usable\n");
209 decoder_plugin_deinit_all();
210 input_stream_global_finish();
212 if (!decoder
.initialized
) {
213 g_printerr("Decoding failed\n");