mpd/test/test_vorbis_encoder.cxx

84 lines
1.7 KiB
C++
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "encoder/EncoderList.hxx"
#include "encoder/EncoderPlugin.hxx"
#include "encoder/EncoderInterface.hxx"
#include "encoder/ToOutputStream.hxx"
2020-01-18 20:07:09 +01:00
#include "pcm/AudioFormat.hxx"
#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"
#include <cassert>
2016-05-04 18:46:06 +02:00
#include <memory>
#include <stddef.h>
int
main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
try {
/* 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);
ConfigBlock block;
block.AddBlockParam("quality", "5.0", -1);
std::unique_ptr<PreparedEncoder> p_encoder(encoder_init(*plugin, block));
assert(p_encoder != nullptr);
/* open the encoder */
AudioFormat audio_format(44100, SampleFormat::S16, 2);
std::unique_ptr<Encoder> encoder(p_encoder->Open(audio_format));
assert(encoder != nullptr);
StdioOutputStream os(stdout);
EncoderToOutputStream(os, *encoder);
/* write a block of data */
static constexpr std::byte zero[256]{};
encoder->Write(std::span{zero});
EncoderToOutputStream(os, *encoder);
/* write a tag */
encoder->PreTag();
EncoderToOutputStream(os, *encoder);
Tag tag;
{
TagBuilder tag_builder;
tag_builder.AddItem(TAG_ARTIST, "Foo");
tag_builder.AddItem(TAG_TITLE, "Bar");
tag_builder.Commit(tag);
}
encoder->SendTag(tag);
EncoderToOutputStream(os, *encoder);
/* write another block of data */
encoder->Write(std::span{zero});
/* finish */
encoder->End();
EncoderToOutputStream(os, *encoder);
return EXIT_SUCCESS;
2018-07-17 21:56:43 +02:00
} catch (...) {
PrintException(std::current_exception());
return EXIT_FAILURE;
}