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 "encoder_list.h"
22 #include "encoder_plugin.h"
23 #include "audio_format.h"
24 #include "audio_parser.h"
33 encoder_to_stdout(struct encoder
*encoder
)
36 static char buffer
[32768];
38 while ((length
= encoder_read(encoder
, buffer
, sizeof(buffer
))) > 0)
39 write(1, buffer
, length
);
42 int main(int argc
, char **argv
)
45 struct audio_format audio_format
;
47 const char *encoder_name
;
48 const struct encoder_plugin
*plugin
;
49 struct encoder
*encoder
;
50 struct config_param
*param
;
51 static char buffer
[32768];
54 /* parse command line */
57 g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n");
62 encoder_name
= argv
[1];
64 encoder_name
= "vorbis";
66 audio_format_init(&audio_format
, 44100, SAMPLE_FORMAT_S16
, 2);
68 /* create the encoder */
70 plugin
= encoder_plugin_get(encoder_name
);
72 g_printerr("No such encoder: %s\n", encoder_name
);
76 param
= config_new_param(NULL
, -1);
77 config_add_block_param(param
, "quality", "5.0", -1, NULL
);
79 encoder
= encoder_init(plugin
, param
, &error
);
80 if (encoder
== NULL
) {
81 g_printerr("Failed to initialize encoder: %s\n",
87 /* open the encoder */
90 ret
= audio_format_parse(&audio_format
, argv
[2],
93 g_printerr("Failed to parse audio format: %s\n",
100 ret
= encoder_open(encoder
, &audio_format
, &error
);
101 if (encoder
== NULL
) {
102 g_printerr("Failed to open encoder: %s\n",
110 while ((nbytes
= read(0, buffer
, sizeof(buffer
))) > 0) {
111 ret
= encoder_write(encoder
, buffer
, nbytes
, &error
);
113 g_printerr("encoder_write() failed: %s\n",
119 encoder_to_stdout(encoder
);
122 ret
= encoder_flush(encoder
, &error
);
124 g_printerr("encoder_flush() failed: %s\n",
130 encoder_to_stdout(encoder
);