2012-04-04 22:56:38 +02:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2012-04-04 22:56:38 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2013-04-17 22:22:37 +02:00
|
|
|
#include "EncoderList.hxx"
|
2013-07-30 09:04:05 +02:00
|
|
|
#include "EncoderPlugin.hxx"
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2013-09-05 08:47:10 +02:00
|
|
|
#include "ConfigData.hxx"
|
2012-04-04 22:56:38 +02:00
|
|
|
#include "stdbin.h"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2013-12-03 12:12:30 +01:00
|
|
|
#include "tag/TagBuilder.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2012-04-04 22:56:38 +02:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
static uint8_t zero[256];
|
|
|
|
|
|
|
|
static void
|
2013-07-30 09:04:05 +02:00
|
|
|
encoder_to_stdout(Encoder &encoder)
|
2012-04-04 22:56:38 +02:00
|
|
|
{
|
|
|
|
size_t length;
|
|
|
|
static char buffer[32768];
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
while ((length = encoder_read(&encoder, buffer, sizeof(buffer))) > 0) {
|
2013-08-04 23:48:01 +02:00
|
|
|
gcc_unused ssize_t ignored = write(1, buffer, length);
|
2012-04-04 22:56:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-08-04 23:48:01 +02:00
|
|
|
main(gcc_unused int argc, gcc_unused char **argv)
|
2012-04-04 22:56:38 +02:00
|
|
|
{
|
2013-08-04 23:48:01 +02:00
|
|
|
gcc_unused bool success;
|
2012-04-04 22:56:38 +02:00
|
|
|
|
|
|
|
/* create the encoder */
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
const auto plugin = encoder_plugin_get("vorbis");
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(plugin != NULL);
|
|
|
|
|
2013-01-30 22:00:32 +01:00
|
|
|
config_param param;
|
2013-01-30 22:25:17 +01:00
|
|
|
param.AddBlockParam("quality", "5.0", -1);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
const auto encoder = encoder_init(*plugin, param, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(encoder != NULL);
|
|
|
|
|
|
|
|
/* open the encoder */
|
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
AudioFormat audio_format(44100, SampleFormat::S16, 2);
|
2013-08-10 18:02:44 +02:00
|
|
|
success = encoder_open(encoder, audio_format, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
encoder_to_stdout(*encoder);
|
2012-10-01 23:17:13 +02:00
|
|
|
|
2012-04-04 22:56:38 +02:00
|
|
|
/* write a block of data */
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
success = encoder_write(encoder, zero, sizeof(zero), IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
encoder_to_stdout(*encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
|
|
|
/* write a tag */
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
success = encoder_pre_tag(encoder, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
encoder_to_stdout(*encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2013-07-30 20:11:57 +02:00
|
|
|
Tag tag;
|
2013-12-03 12:12:30 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
TagBuilder tag_builder;
|
|
|
|
tag_builder.AddItem(TAG_ARTIST, "Foo");
|
|
|
|
tag_builder.AddItem(TAG_TITLE, "Bar");
|
|
|
|
tag_builder.Commit(tag);
|
|
|
|
}
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
success = encoder_tag(encoder, &tag, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
encoder_to_stdout(*encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
|
|
|
/* write another block of data */
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
success = encoder_write(encoder, zero, sizeof(zero), IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
|
|
|
/* finish */
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
success = encoder_end(encoder, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2013-07-30 09:04:05 +02:00
|
|
|
encoder_to_stdout(*encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
|
|
|
encoder_close(encoder);
|
|
|
|
encoder_finish(encoder);
|
|
|
|
}
|