2012-04-04 22:56:38 +02:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 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.
|
|
|
|
*/
|
|
|
|
|
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"
|
2020-01-18 20:07:09 +01:00
|
|
|
#include "pcm/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"
|
2017-02-08 08:26:58 +01:00
|
|
|
#include "tag/Builder.hxx"
|
2018-07-17 21:56:43 +02:00
|
|
|
#include "util/PrintException.hxx"
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2020-03-12 23:20:59 +01:00
|
|
|
#include <cassert>
|
2016-05-04 18:46:06 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2012-04-04 22:56:38 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
static uint8_t zero[256];
|
|
|
|
|
|
|
|
int
|
2013-08-04 23:48:01 +02:00
|
|
|
main(gcc_unused int argc, gcc_unused char **argv)
|
2016-10-28 21:29:01 +02:00
|
|
|
try {
|
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");
|
2020-02-01 13:49:19 +01:00
|
|
|
assert(plugin != nullptr);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
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-10-28 21:29:01 +02:00
|
|
|
std::unique_ptr<PreparedEncoder> p_encoder(encoder_init(*plugin, block));
|
2016-05-04 09:31:21 +02:00
|
|
|
assert(p_encoder != nullptr);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
/* open the encoder */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
AudioFormat audio_format(44100, SampleFormat::S16, 2);
|
2016-11-07 09:20:12 +01:00
|
|
|
std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format));
|
2016-10-28 21:29:01 +02:00
|
|
|
assert(encoder != nullptr);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
StdioOutputStream os(stdout);
|
2015-01-14 21:56:28 +01:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-10-01 23:17:13 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
/* write a block of data */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
encoder->Write(zero, sizeof(zero));
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
/* write a tag */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
encoder->PreTag();
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
Tag tag;
|
2013-12-03 12:12:30 +01:00
|
|
|
|
2016-10-28 21:29:01 +02: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-11-07 09:20:12 +01:00
|
|
|
encoder->SendTag(tag);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
/* write another block of data */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
encoder->Write(zero, sizeof(zero));
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
/* finish */
|
2012-04-04 22:56:38 +02:00
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
encoder->End();
|
2016-10-28 21:29:01 +02:00
|
|
|
EncoderToOutputStream(os, *encoder);
|
2015-12-16 10:24:43 +01:00
|
|
|
|
2016-10-28 21:29:01 +02:00
|
|
|
return EXIT_SUCCESS;
|
2018-07-17 21:56:43 +02:00
|
|
|
} catch (...) {
|
|
|
|
PrintException(std::current_exception());
|
2016-10-28 21:29:01 +02:00
|
|
|
return EXIT_FAILURE;
|
2012-04-04 22:56:38 +02:00
|
|
|
}
|