2012-04-04 22:56:38 +02:00
|
|
|
/*
|
2016-02-26 17:54:05 +01:00
|
|
|
* Copyright 2003-2016 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
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
const auto p_encoder = encoder_init(*plugin, block, IgnoreError());
|
|
|
|
assert(p_encoder != nullptr);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
try {
|
|
|
|
/* open the encoder */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
AudioFormat audio_format(44100, SampleFormat::S16, 2);
|
2016-05-04 09:31:21 +02:00
|
|
|
auto encoder = p_encoder->Open(audio_format, IgnoreError());
|
|
|
|
assert(encoder != nullptr);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
StdioOutputStream os(stdout);
|
2015-01-14 21:56:28 +01:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-10-01 23:17:13 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
/* write a block of data */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
success = encoder->Write(zero, sizeof(zero), IgnoreError());
|
2015-12-16 10:24:43 +01:00
|
|
|
assert(success);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
/* write a tag */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
success = encoder->PreTag(IgnoreError());
|
2015-12-16 10:24:43 +01:00
|
|
|
assert(success);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
Tag tag;
|
2013-12-03 12:12:30 +01:00
|
|
|
|
2015-12-16 10:24:43 +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
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
success = encoder->SendTag(tag, IgnoreError());
|
2015-12-16 10:24:43 +01:00
|
|
|
assert(success);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
/* write another block of data */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
success = encoder->Write(zero, sizeof(zero), IgnoreError());
|
2015-12-16 10:24:43 +01:00
|
|
|
assert(success);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
/* finish */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
success = encoder->End(IgnoreError());
|
2015-12-16 10:24:43 +01:00
|
|
|
assert(success);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2015-12-16 10:24:43 +01:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
delete encoder;
|
|
|
|
p_encoder->Dispose();
|
2015-12-16 10:24:43 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
LogError(e);
|
2015-01-14 21:56:28 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2012-04-04 22:56:38 +02:00
|
|
|
}
|