Partition: pass configuration as struct
This commit is contained in:
71
src/Main.cxx
71
src/Main.cxx
@@ -32,7 +32,6 @@
|
||||
#include "command/AllCommands.hxx"
|
||||
#include "Partition.hxx"
|
||||
#include "tag/Config.hxx"
|
||||
#include "ReplayGainGlobal.hxx"
|
||||
#include "IdleFlags.hxx"
|
||||
#include "Log.hxx"
|
||||
#include "LogInit.hxx"
|
||||
@@ -46,7 +45,6 @@
|
||||
#include "playlist/PlaylistRegistry.hxx"
|
||||
#include "zeroconf/Glue.hxx"
|
||||
#include "decoder/DecoderList.hxx"
|
||||
#include "pcm/AudioParser.hxx"
|
||||
#include "pcm/Convert.hxx"
|
||||
#include "unix/SignalHandlers.hxx"
|
||||
#include "thread/Slack.hxx"
|
||||
@@ -60,6 +58,7 @@
|
||||
#include "config/Option.hxx"
|
||||
#include "config/Domain.hxx"
|
||||
#include "config/Parser.hxx"
|
||||
#include "config/PartitionConfig.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/ScopeExit.hxx"
|
||||
|
||||
@@ -116,15 +115,6 @@
|
||||
#include <clocale>
|
||||
#endif
|
||||
|
||||
static constexpr size_t KILOBYTE = 1024;
|
||||
static constexpr size_t MEGABYTE = 1024 * KILOBYTE;
|
||||
|
||||
static constexpr size_t DEFAULT_BUFFER_SIZE = 4 * MEGABYTE;
|
||||
|
||||
static constexpr
|
||||
size_t MIN_BUFFER_SIZE = std::max(CHUNK_SIZE * 32,
|
||||
64 * KILOBYTE);
|
||||
|
||||
#ifdef ANDROID
|
||||
Context *context;
|
||||
LogListener *logListener;
|
||||
@@ -132,13 +122,6 @@ LogListener *logListener;
|
||||
|
||||
Instance *global_instance;
|
||||
|
||||
struct Config {
|
||||
ReplayGainConfig replay_gain;
|
||||
|
||||
explicit Config(const ConfigData &raw)
|
||||
:replay_gain(LoadReplayGainConfig(raw)) {}
|
||||
};
|
||||
|
||||
#ifdef ENABLE_DAEMON
|
||||
|
||||
static void
|
||||
@@ -293,53 +276,11 @@ glue_state_file_init(Instance &instance, const ConfigData &raw_config)
|
||||
static void
|
||||
initialize_decoder_and_player(Instance &instance,
|
||||
const ConfigData &config,
|
||||
const ReplayGainConfig &replay_gain_config)
|
||||
const PartitionConfig &partition_config)
|
||||
{
|
||||
const ConfigParam *param;
|
||||
|
||||
size_t buffer_size;
|
||||
param = config.GetParam(ConfigOption::AUDIO_BUFFER_SIZE);
|
||||
if (param != nullptr) {
|
||||
buffer_size = param->With([](const char *s){
|
||||
size_t result = ParseSize(s, KILOBYTE);
|
||||
if (result <= 0)
|
||||
throw FormatRuntimeError("buffer size \"%s\" is not a "
|
||||
"positive integer", s);
|
||||
|
||||
if (result < MIN_BUFFER_SIZE) {
|
||||
FmtWarning(config_domain, "buffer size {} is too small, using {} bytes instead",
|
||||
result, MIN_BUFFER_SIZE);
|
||||
result = MIN_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
} else
|
||||
buffer_size = DEFAULT_BUFFER_SIZE;
|
||||
|
||||
const unsigned buffered_chunks = buffer_size / CHUNK_SIZE;
|
||||
|
||||
if (buffered_chunks >= 1 << 15)
|
||||
throw FormatRuntimeError("buffer size \"%lu\" is too big",
|
||||
(unsigned long)buffer_size);
|
||||
|
||||
const unsigned max_length =
|
||||
config.GetPositive(ConfigOption::MAX_PLAYLIST_LENGTH,
|
||||
DEFAULT_PLAYLIST_MAX_LENGTH);
|
||||
|
||||
AudioFormat configured_audio_format = config.With(ConfigOption::AUDIO_OUTPUT_FORMAT, [](const char *s){
|
||||
if (s == nullptr)
|
||||
return AudioFormat::Undefined();
|
||||
|
||||
return ParseAudioFormat(s, true);
|
||||
});
|
||||
|
||||
instance.partitions.emplace_back(instance,
|
||||
"default",
|
||||
max_length,
|
||||
buffered_chunks,
|
||||
configured_audio_format,
|
||||
replay_gain_config);
|
||||
partition_config);
|
||||
auto &partition = instance.partitions.back();
|
||||
|
||||
partition.replay_gain_mode = config.With(ConfigOption::REPLAYGAIN, [](const char *s){
|
||||
@@ -392,7 +333,7 @@ MainConfigured(const CommandLineOptions &options,
|
||||
#endif
|
||||
|
||||
InitPathParser(raw_config);
|
||||
const Config config(raw_config);
|
||||
const PartitionConfig partition_config{raw_config};
|
||||
|
||||
#ifdef ENABLE_DAEMON
|
||||
glue_daemonize_init(options, raw_config);
|
||||
@@ -426,7 +367,7 @@ MainConfigured(const CommandLineOptions &options,
|
||||
}
|
||||
|
||||
initialize_decoder_and_player(instance,
|
||||
raw_config, config.replay_gain);
|
||||
raw_config, partition_config);
|
||||
|
||||
listen_global_init(raw_config, *instance.partitions.front().listener);
|
||||
|
||||
@@ -465,7 +406,7 @@ MainConfigured(const CommandLineOptions &options,
|
||||
partition.outputs.Configure(instance.io_thread.GetEventLoop(),
|
||||
instance.rtio_thread.GetEventLoop(),
|
||||
raw_config,
|
||||
config.replay_gain);
|
||||
partition_config.player.replay_gain);
|
||||
partition.UpdateEffectiveReplayGainMode();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user