2
* Copyright (C) 2003-2009 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 "encoder_list.h"
21
#include "encoder_plugin.h"
22
#include "audio_format.h"
23
#include "audio_parser.h"
32
encoder_to_stdout(struct encoder *encoder)
35
static char buffer[32768];
37
while ((length = encoder_read(encoder, buffer, sizeof(buffer))) > 0)
38
write(1, buffer, length);
41
int main(int argc, char **argv)
44
struct audio_format audio_format = {
50
const char *encoder_name;
51
const struct encoder_plugin *plugin;
52
struct encoder *encoder;
53
struct config_param *param;
54
static char buffer[32768];
57
/* parse command line */
60
g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n");
65
encoder_name = argv[1];
67
encoder_name = "vorbis";
69
/* create the encoder */
71
plugin = encoder_plugin_get(encoder_name);
73
g_printerr("No such encoder: %s\n", encoder_name);
77
param = config_new_param(NULL, -1);
78
config_add_block_param(param, "quality", "5.0", -1);
80
encoder = encoder_init(plugin, param, &error);
81
if (encoder == NULL) {
82
g_printerr("Failed to initialize encoder: %s\n",
88
/* open the encoder */
91
ret = audio_format_parse(&audio_format, argv[2], &error);
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);