Partition: pass configuration as struct

This commit is contained in:
Max Kellermann
2021-12-03 20:22:52 +01:00
parent 2384a240e0
commit 95a155b10d
15 changed files with 230 additions and 105 deletions
-1
View File
@@ -20,7 +20,6 @@
#ifndef MPD_CONFIG_DEFAULTS_HXX
#define MPD_CONFIG_DEFAULTS_HXX
static constexpr unsigned DEFAULT_PLAYLIST_MAX_LENGTH = 16 * 1024;
static constexpr bool DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS = false;
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#include "PartitionConfig.hxx"
#include "Data.hxx"
PartitionConfig::PartitionConfig(const ConfigData &config)
:player(config)
{
queue.max_length =
config.GetPositive(ConfigOption::MAX_PLAYLIST_LENGTH,
QueueConfig::DEFAULT_MAX_LENGTH);
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#pragma once
#include "QueueConfig.hxx"
#include "PlayerConfig.hxx"
struct PartitionConfig {
QueueConfig queue;
PlayerConfig player;
PartitionConfig() = default;
explicit PartitionConfig(const ConfigData &config);
};
+67
View File
@@ -0,0 +1,67 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#include "PartitionConfig.hxx"
#include "Data.hxx"
#include "Domain.hxx"
#include "Parser.hxx"
#include "pcm/AudioParser.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx"
#include "MusicChunk.hxx"
#include "ReplayGainGlobal.hxx"
static constexpr
size_t MIN_BUFFER_SIZE = std::max(CHUNK_SIZE * 32,
64 * KILOBYTE);
PlayerConfig::PlayerConfig(const ConfigData &config)
{
size_t buffer_size = PlayerConfig::DEFAULT_BUFFER_SIZE;
if (auto *param = config.GetParam(ConfigOption::AUDIO_BUFFER_SIZE)) {
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;
});
}
buffer_chunks = buffer_size / CHUNK_SIZE;
if (buffer_chunks >= 1 << 15)
throw FormatRuntimeError("buffer size \"%lu\" is too big",
(unsigned long)buffer_size);
audio_format = config.With(ConfigOption::AUDIO_OUTPUT_FORMAT, [](const char *s){
if (s == nullptr)
return AudioFormat::Undefined();
return ParseAudioFormat(s, true);
});
replay_gain = LoadReplayGainConfig(config);
}
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#pragma once
#include "pcm/AudioFormat.hxx"
#include "ReplayGainConfig.hxx"
struct ConfigData;
static constexpr size_t KILOBYTE = 1024;
static constexpr size_t MEGABYTE = 1024 * KILOBYTE;
struct PlayerConfig {
static constexpr size_t DEFAULT_BUFFER_SIZE = 4 * MEGABYTE;
unsigned buffer_chunks = DEFAULT_BUFFER_SIZE;
/**
* The "audio_output_format" setting.
*/
AudioFormat audio_format = AudioFormat::Undefined();
ReplayGainConfig replay_gain;
PlayerConfig() = default;
explicit PlayerConfig(const ConfigData &config);
};
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#pragma once
struct QueueConfig {
static constexpr unsigned DEFAULT_MAX_LENGTH = 16 * 1024;
unsigned max_length = DEFAULT_MAX_LENGTH;
};