config/Param: split block-specific attributes to new struct ConfigBlock
The old struct config_param remains only for top-level string options.
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
#include "EncoderPlugin.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "tag/Tag.hxx"
|
||||
#include "config/Param.hxx"
|
||||
#include "config/Block.hxx"
|
||||
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
|
@@ -24,14 +24,14 @@
|
||||
|
||||
struct Encoder;
|
||||
struct AudioFormat;
|
||||
struct config_param;
|
||||
struct ConfigBlock;
|
||||
struct Tag;
|
||||
class Error;
|
||||
|
||||
struct EncoderPlugin {
|
||||
const char *name;
|
||||
|
||||
Encoder *(*init)(const config_param ¶m,
|
||||
Encoder *(*init)(const ConfigBlock &block,
|
||||
Error &error);
|
||||
|
||||
void (*finish)(Encoder *encoder);
|
||||
@@ -69,10 +69,10 @@ struct EncoderPlugin {
|
||||
* @return an encoder object on success, nullptr on failure
|
||||
*/
|
||||
static inline Encoder *
|
||||
encoder_init(const EncoderPlugin &plugin, const config_param ¶m,
|
||||
encoder_init(const EncoderPlugin &plugin, const ConfigBlock &block,
|
||||
Error &error_r)
|
||||
{
|
||||
return plugin.init(param, error_r);
|
||||
return plugin.init(block, error_r);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -56,21 +56,21 @@ struct flac_encoder {
|
||||
static constexpr Domain flac_encoder_domain("vorbis_encoder");
|
||||
|
||||
static bool
|
||||
flac_encoder_configure(struct flac_encoder *encoder, const config_param ¶m,
|
||||
flac_encoder_configure(struct flac_encoder *encoder, const ConfigBlock &block,
|
||||
gcc_unused Error &error)
|
||||
{
|
||||
encoder->compression = param.GetBlockValue("compression", 5u);
|
||||
encoder->compression = block.GetBlockValue("compression", 5u);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
flac_encoder_init(const config_param ¶m, Error &error)
|
||||
flac_encoder_init(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
flac_encoder *encoder = new flac_encoder();
|
||||
|
||||
/* load configuration from "param" */
|
||||
if (!flac_encoder_configure(encoder, param, error)) {
|
||||
/* load configuration from "block" */
|
||||
if (!flac_encoder_configure(encoder, block, error)) {
|
||||
/* configuration has failed, roll back and return error */
|
||||
delete encoder;
|
||||
return nullptr;
|
||||
|
@@ -47,18 +47,18 @@ struct LameEncoder final {
|
||||
|
||||
LameEncoder():encoder(lame_encoder_plugin) {}
|
||||
|
||||
bool Configure(const config_param ¶m, Error &error);
|
||||
bool Configure(const ConfigBlock &block, Error &error);
|
||||
};
|
||||
|
||||
static constexpr Domain lame_encoder_domain("lame_encoder");
|
||||
|
||||
bool
|
||||
LameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
LameEncoder::Configure(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
const char *value;
|
||||
char *endptr;
|
||||
|
||||
value = param.GetBlockValue("quality");
|
||||
value = block.GetBlockValue("quality");
|
||||
if (value != nullptr) {
|
||||
/* a quality was configured (VBR) */
|
||||
|
||||
@@ -72,7 +72,7 @@ LameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (param.GetBlockValue("bitrate") != nullptr) {
|
||||
if (block.GetBlockValue("bitrate") != nullptr) {
|
||||
error.Set(config_domain,
|
||||
"quality and bitrate are both defined");
|
||||
return false;
|
||||
@@ -80,7 +80,7 @@ LameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
} else {
|
||||
/* a bit rate was configured */
|
||||
|
||||
value = param.GetBlockValue("bitrate");
|
||||
value = block.GetBlockValue("bitrate");
|
||||
if (value == nullptr) {
|
||||
error.Set(config_domain,
|
||||
"neither bitrate nor quality defined");
|
||||
@@ -101,12 +101,12 @@ LameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
lame_encoder_init(const config_param ¶m, Error &error)
|
||||
lame_encoder_init(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
LameEncoder *encoder = new LameEncoder();
|
||||
|
||||
/* load configuration from "param" */
|
||||
if (!encoder->Configure(param, error)) {
|
||||
/* load configuration from "block" */
|
||||
if (!encoder->Configure(block, error)) {
|
||||
/* configuration has failed, roll back and return error */
|
||||
delete encoder;
|
||||
return nullptr;
|
||||
|
@@ -36,7 +36,7 @@ struct NullEncoder final {
|
||||
};
|
||||
|
||||
static Encoder *
|
||||
null_encoder_init(gcc_unused const config_param ¶m,
|
||||
null_encoder_init(gcc_unused const ConfigBlock &block,
|
||||
gcc_unused Error &error)
|
||||
{
|
||||
NullEncoder *encoder = new NullEncoder();
|
||||
|
@@ -73,9 +73,9 @@ static constexpr Domain opus_encoder_domain("opus_encoder");
|
||||
|
||||
static bool
|
||||
opus_encoder_configure(struct opus_encoder *encoder,
|
||||
const config_param ¶m, Error &error)
|
||||
const ConfigBlock &block, Error &error)
|
||||
{
|
||||
const char *value = param.GetBlockValue("bitrate", "auto");
|
||||
const char *value = block.GetBlockValue("bitrate", "auto");
|
||||
if (strcmp(value, "auto") == 0)
|
||||
encoder->bitrate = OPUS_AUTO;
|
||||
else if (strcmp(value, "max") == 0)
|
||||
@@ -90,13 +90,13 @@ opus_encoder_configure(struct opus_encoder *encoder,
|
||||
}
|
||||
}
|
||||
|
||||
encoder->complexity = param.GetBlockValue("complexity", 10u);
|
||||
encoder->complexity = block.GetBlockValue("complexity", 10u);
|
||||
if (encoder->complexity > 10) {
|
||||
error.Format(config_domain, "Invalid complexity");
|
||||
return false;
|
||||
}
|
||||
|
||||
value = param.GetBlockValue("signal", "auto");
|
||||
value = block.GetBlockValue("signal", "auto");
|
||||
if (strcmp(value, "auto") == 0)
|
||||
encoder->signal = OPUS_AUTO;
|
||||
else if (strcmp(value, "voice") == 0)
|
||||
@@ -112,12 +112,12 @@ opus_encoder_configure(struct opus_encoder *encoder,
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
opus_encoder_init(const config_param ¶m, Error &error)
|
||||
opus_encoder_init(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
opus_encoder *encoder = new opus_encoder();
|
||||
|
||||
/* load configuration from "param" */
|
||||
if (!opus_encoder_configure(encoder, param, error)) {
|
||||
/* load configuration from "block" */
|
||||
if (!opus_encoder_configure(encoder, block, error)) {
|
||||
/* configuration has failed, roll back and return error */
|
||||
delete encoder;
|
||||
return nullptr;
|
||||
|
@@ -53,7 +53,7 @@ struct ShineEncoder {
|
||||
|
||||
ShineEncoder():encoder(shine_encoder_plugin){}
|
||||
|
||||
bool Configure(const config_param ¶m, Error &error);
|
||||
bool Configure(const ConfigBlock &block, Error &error);
|
||||
|
||||
bool Setup(Error &error);
|
||||
|
||||
@@ -63,22 +63,21 @@ struct ShineEncoder {
|
||||
static constexpr Domain shine_encoder_domain("shine_encoder");
|
||||
|
||||
inline bool
|
||||
ShineEncoder::Configure(const config_param ¶m,
|
||||
gcc_unused Error &error)
|
||||
ShineEncoder::Configure(const ConfigBlock &block, gcc_unused Error &error)
|
||||
{
|
||||
shine_set_config_mpeg_defaults(&config.mpeg);
|
||||
config.mpeg.bitr = param.GetBlockValue("bitrate", 128);
|
||||
config.mpeg.bitr = block.GetBlockValue("bitrate", 128);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
shine_encoder_init(const config_param ¶m, Error &error)
|
||||
shine_encoder_init(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
ShineEncoder *encoder = new ShineEncoder();
|
||||
|
||||
/* load configuration from "param" */
|
||||
if (!encoder->Configure(param, error)) {
|
||||
/* load configuration from "block" */
|
||||
if (!encoder->Configure(block, error)) {
|
||||
/* configuration has failed, roll back and return error */
|
||||
delete encoder;
|
||||
return nullptr;
|
||||
|
@@ -53,18 +53,18 @@ struct TwolameEncoder final {
|
||||
|
||||
TwolameEncoder():encoder(twolame_encoder_plugin) {}
|
||||
|
||||
bool Configure(const config_param ¶m, Error &error);
|
||||
bool Configure(const ConfigBlock &block, Error &error);
|
||||
};
|
||||
|
||||
static constexpr Domain twolame_encoder_domain("twolame_encoder");
|
||||
|
||||
bool
|
||||
TwolameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
TwolameEncoder::Configure(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
const char *value;
|
||||
char *endptr;
|
||||
|
||||
value = param.GetBlockValue("quality");
|
||||
value = block.GetBlockValue("quality");
|
||||
if (value != nullptr) {
|
||||
/* a quality was configured (VBR) */
|
||||
|
||||
@@ -78,7 +78,7 @@ TwolameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (param.GetBlockValue("bitrate") != nullptr) {
|
||||
if (block.GetBlockValue("bitrate") != nullptr) {
|
||||
error.Set(config_domain,
|
||||
"quality and bitrate are both defined");
|
||||
return false;
|
||||
@@ -86,7 +86,7 @@ TwolameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
} else {
|
||||
/* a bit rate was configured */
|
||||
|
||||
value = param.GetBlockValue("bitrate");
|
||||
value = block.GetBlockValue("bitrate");
|
||||
if (value == nullptr) {
|
||||
error.Set(config_domain,
|
||||
"neither bitrate nor quality defined");
|
||||
@@ -107,15 +107,15 @@ TwolameEncoder::Configure(const config_param ¶m, Error &error)
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
twolame_encoder_init(const config_param ¶m, Error &error_r)
|
||||
twolame_encoder_init(const ConfigBlock &block, Error &error_r)
|
||||
{
|
||||
FormatDebug(twolame_encoder_domain,
|
||||
"libtwolame version %s", get_twolame_version());
|
||||
|
||||
TwolameEncoder *encoder = new TwolameEncoder();
|
||||
|
||||
/* load configuration from "param" */
|
||||
if (!encoder->Configure(param, error_r)) {
|
||||
/* load configuration from "block" */
|
||||
if (!encoder->Configure(block, error_r)) {
|
||||
/* configuration has failed, roll back and return error */
|
||||
delete encoder;
|
||||
return nullptr;
|
||||
|
@@ -58,9 +58,9 @@ static constexpr Domain vorbis_encoder_domain("vorbis_encoder");
|
||||
|
||||
static bool
|
||||
vorbis_encoder_configure(struct vorbis_encoder &encoder,
|
||||
const config_param ¶m, Error &error)
|
||||
const ConfigBlock &block, Error &error)
|
||||
{
|
||||
const char *value = param.GetBlockValue("quality");
|
||||
const char *value = block.GetBlockValue("quality");
|
||||
if (value != nullptr) {
|
||||
/* a quality was configured (VBR) */
|
||||
|
||||
@@ -76,7 +76,7 @@ vorbis_encoder_configure(struct vorbis_encoder &encoder,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (param.GetBlockValue("bitrate") != nullptr) {
|
||||
if (block.GetBlockValue("bitrate") != nullptr) {
|
||||
error.Set(config_domain,
|
||||
"quality and bitrate are both defined");
|
||||
return false;
|
||||
@@ -84,7 +84,7 @@ vorbis_encoder_configure(struct vorbis_encoder &encoder,
|
||||
} else {
|
||||
/* a bit rate was configured */
|
||||
|
||||
value = param.GetBlockValue("bitrate");
|
||||
value = block.GetBlockValue("bitrate");
|
||||
if (value == nullptr) {
|
||||
error.Set(config_domain,
|
||||
"neither bitrate nor quality defined");
|
||||
@@ -106,12 +106,12 @@ vorbis_encoder_configure(struct vorbis_encoder &encoder,
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
vorbis_encoder_init(const config_param ¶m, Error &error)
|
||||
vorbis_encoder_init(const ConfigBlock &block, Error &error)
|
||||
{
|
||||
vorbis_encoder *encoder = new vorbis_encoder();
|
||||
|
||||
/* load configuration from "param" */
|
||||
if (!vorbis_encoder_configure(*encoder, param, error)) {
|
||||
/* load configuration from "block" */
|
||||
if (!vorbis_encoder_configure(*encoder, block, error)) {
|
||||
/* configuration has failed, roll back and return error */
|
||||
delete encoder;
|
||||
return nullptr;
|
||||
|
@@ -79,7 +79,7 @@ fill_wave_header(struct wave_header *header, int channels, int bits,
|
||||
}
|
||||
|
||||
static Encoder *
|
||||
wave_encoder_init(gcc_unused const config_param ¶m,
|
||||
wave_encoder_init(gcc_unused const ConfigBlock &block,
|
||||
gcc_unused Error &error)
|
||||
{
|
||||
WaveEncoder *encoder = new WaveEncoder();
|
||||
|
Reference in New Issue
Block a user