2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2012-04-04 22:56:38 +02:00
|
|
|
|
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"
|
2021-12-03 14:02:07 +01:00
|
|
|
#include "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>
|
|
|
|
|
|
|
|
int
|
2020-03-12 20:56:11 +01:00
|
|
|
main([[maybe_unused]] int argc, [[maybe_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
|
|
|
|
2022-07-11 22:14:48 +02:00
|
|
|
static constexpr std::byte zero[256]{};
|
|
|
|
encoder->Write(std::span{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
|
|
|
|
2022-07-11 22:14:48 +02:00
|
|
|
encoder->Write(std::span{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
|
|
|
}
|