config/Block: add method GetPositiveValue()
Adds missing checks to several plugins.
This commit is contained in:
parent
7c5306a841
commit
be65c7d5d0
|
@ -52,6 +52,21 @@ BlockParam::GetUnsignedValue() const
|
|||
return (unsigned)value2;
|
||||
}
|
||||
|
||||
unsigned
|
||||
BlockParam::GetPositiveValue() const
|
||||
{
|
||||
const char *const s = value.c_str();
|
||||
char *endptr;
|
||||
unsigned long value2 = strtoul(s, &endptr, 0);
|
||||
if (endptr == s || *endptr != 0)
|
||||
FormatFatalError("Not a valid number in line %i", line);
|
||||
|
||||
if (value2 <= 0)
|
||||
FormatFatalError("Number in line %i must be positive", line);
|
||||
|
||||
return (unsigned)value2;
|
||||
}
|
||||
|
||||
bool
|
||||
BlockParam::GetBoolValue() const
|
||||
{
|
||||
|
@ -131,6 +146,16 @@ ConfigBlock::GetBlockValue(const char *name, unsigned default_value) const
|
|||
return bp->GetUnsignedValue();
|
||||
}
|
||||
|
||||
unsigned
|
||||
ConfigBlock::GetPositiveValue(const char *name, unsigned default_value) const
|
||||
{
|
||||
const auto *param = GetBlockParam(name);
|
||||
if (param == nullptr)
|
||||
return default_value;
|
||||
|
||||
return param->GetPositiveValue();
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigBlock::GetBlockValue(const char *name, bool default_value) const
|
||||
{
|
||||
|
|
|
@ -47,6 +47,7 @@ struct BlockParam {
|
|||
int GetIntValue() const;
|
||||
|
||||
unsigned GetUnsignedValue() const;
|
||||
unsigned GetPositiveValue() const;
|
||||
|
||||
bool GetBoolValue() const;
|
||||
};
|
||||
|
@ -117,6 +118,8 @@ struct ConfigBlock {
|
|||
|
||||
unsigned GetBlockValue(const char *name, unsigned default_value) const;
|
||||
|
||||
unsigned GetPositiveValue(const char *name, unsigned default_value) const;
|
||||
|
||||
bool GetBlockValue(const char *name, bool default_value) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ adplug_init(const ConfigBlock &block)
|
|||
FormatDebug(adplug_domain, "adplug %s",
|
||||
CAdPlug::get_version().c_str());
|
||||
|
||||
sample_rate = block.GetBlockValue("sample_rate", 48000u);
|
||||
sample_rate = block.GetPositiveValue("sample_rate", 48000u);
|
||||
CheckSampleRate(sample_rate);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -74,7 +74,7 @@ fluidsynth_mpd_log_function(int level, char *message, gcc_unused void *data)
|
|||
static bool
|
||||
fluidsynth_init(const ConfigBlock &block)
|
||||
{
|
||||
sample_rate = block.GetBlockValue("sample_rate", 48000u);
|
||||
sample_rate = block.GetPositiveValue("sample_rate", 48000u);
|
||||
CheckSampleRate(sample_rate);
|
||||
|
||||
soundfont_path = block.GetBlockValue("soundfont",
|
||||
|
|
|
@ -114,7 +114,7 @@ mikmod_decoder_init(const ConfigBlock &block)
|
|||
static char params[] = "";
|
||||
|
||||
mikmod_loop = block.GetBlockValue("loop", false);
|
||||
mikmod_sample_rate = block.GetBlockValue("sample_rate", 44100u);
|
||||
mikmod_sample_rate = block.GetPositiveValue("sample_rate", 44100u);
|
||||
if (!audio_valid_sample_rate(mikmod_sample_rate))
|
||||
throw FormatRuntimeError("Invalid sample rate in line %d: %u",
|
||||
block.line, mikmod_sample_rate);
|
||||
|
|
|
@ -93,7 +93,7 @@ sidplay_init(const ConfigBlock &block)
|
|||
if (!database_path.IsNull())
|
||||
songlength_database = sidplay_load_songlength_db(database_path);
|
||||
|
||||
default_songlength = block.GetBlockValue("default_songlength", 0u);
|
||||
default_songlength = block.GetPositiveValue("default_songlength", 0u);
|
||||
|
||||
all_files_are_containers =
|
||||
block.GetBlockValue("all_files_are_containers", true);
|
||||
|
|
|
@ -331,9 +331,9 @@ AlsaOutput::AlsaOutput(EventLoop &_loop, const ConfigBlock &block)
|
|||
/* legacy name from MPD 0.18 and older: */
|
||||
block.GetBlockValue("dsd_usb", false)),
|
||||
#endif
|
||||
buffer_time(block.GetBlockValue("buffer_time",
|
||||
MPD_ALSA_BUFFER_TIME_US)),
|
||||
period_time(block.GetBlockValue("period_time", 0u))
|
||||
buffer_time(block.GetPositiveValue("buffer_time",
|
||||
MPD_ALSA_BUFFER_TIME_US)),
|
||||
period_time(block.GetPositiveValue("period_time", 0u))
|
||||
{
|
||||
#ifdef SND_PCM_NO_AUTO_RESAMPLE
|
||||
if (!block.GetBlockValue("auto_resample", true))
|
||||
|
|
|
@ -101,7 +101,7 @@ MakeAoError()
|
|||
|
||||
AoOutput::AoOutput(const ConfigBlock &block)
|
||||
:AudioOutput(0),
|
||||
write_size(block.GetBlockValue("write_size", 1024u))
|
||||
write_size(block.GetPositiveValue("write_size", 1024u))
|
||||
{
|
||||
const char *value = block.GetBlockValue("driver", "default");
|
||||
if (0 == strcmp(value, "default"))
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
HaikuOutput(const ConfigBlock &block)
|
||||
:AudioOutput(0),
|
||||
/* XXX: by default we should let the MediaKit propose the buffer size */
|
||||
write_size(block.GetBlockValue("write_size", 4096u)) {}
|
||||
write_size(block.GetPositiveValue("write_size", 4096u)) {}
|
||||
|
||||
~HaikuOutput();
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ JackOutput::JackOutput(const ConfigBlock &block)
|
|||
num_source_ports, num_destination_ports,
|
||||
block.line);
|
||||
|
||||
ringbuffer_size = block.GetBlockValue("ringbuffer_size", 32768u);
|
||||
ringbuffer_size = block.GetPositiveValue("ringbuffer_size", 32768u);
|
||||
}
|
||||
|
||||
inline jack_nframes_t
|
||||
|
|
Loading…
Reference in New Issue