2012-04-04 22:56:38 +02:00
|
|
|
/*
|
2015-01-01 19:48:13 +01:00
|
|
|
* Copyright (C) 2003-2015 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"
|
2014-01-23 23:09:14 +01:00
|
|
|
#include "encoder/EncoderList.hxx"
|
|
|
|
#include "encoder/EncoderPlugin.hxx"
|
2015-01-08 19:31:57 +01:00
|
|
|
#include "encoder/EncoderInterface.hxx"
|
2015-01-14 21:56:28 +01:00
|
|
|
#include "encoder/ToOutputStream.hxx"
|
2013-08-03 21:00:50 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "config/Block.hxx"
|
2015-01-14 21:56:28 +01:00
|
|
|
#include "fs/io/StdioOutputStream.hxx"
|
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"
|
2015-01-14 21:56:28 +01:00
|
|
|
#include "Log.hxx"
|
2012-04-04 22:56:38 +02:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
static uint8_t zero[256];
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
ConfigBlock block;
|
|
|
|
block.AddBlockParam("quality", "5.0", -1);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-01-21 22:13:44 +01:00
|
|
|
const auto encoder = encoder_init(*plugin, block, 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);
|
2015-01-08 19:36:19 +01:00
|
|
|
success = encoder->Open(audio_format, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2015-01-14 21:56:28 +01:00
|
|
|
StdioOutputStream os(stdout);
|
|
|
|
|
|
|
|
Error error;
|
|
|
|
if (!EncoderToOutputStream(os, *encoder, error)) {
|
|
|
|
LogError(error);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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);
|
|
|
|
|
2015-01-14 21:56:28 +01:00
|
|
|
if (!EncoderToOutputStream(os, *encoder, error)) {
|
|
|
|
LogError(error);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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);
|
|
|
|
|
2015-01-14 21:56:28 +01:00
|
|
|
if (!EncoderToOutputStream(os, *encoder, error)) {
|
|
|
|
LogError(error);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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
|
|
|
|
2014-12-26 22:30:54 +01:00
|
|
|
success = encoder_tag(encoder, tag, IgnoreError());
|
2012-04-04 22:56:38 +02:00
|
|
|
assert(success);
|
|
|
|
|
2015-01-14 21:56:28 +01:00
|
|
|
if (!EncoderToOutputStream(os, *encoder, error)) {
|
|
|
|
LogError(error);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
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);
|
|
|
|
|
2015-01-14 21:56:28 +01:00
|
|
|
if (!EncoderToOutputStream(os, *encoder, error)) {
|
|
|
|
LogError(error);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-01-08 19:36:19 +01:00
|
|
|
encoder->Close();
|
|
|
|
encoder->Dispose();
|
2012-04-04 22:56:38 +02:00
|
|
|
}
|