aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/conf.c22
-rw-r--r--src/conf.h4
-rw-r--r--src/output/alsa_plugin.c8
-rw-r--r--src/output/ao_plugin.c11
-rw-r--r--src/output/jack_plugin.c17
-rw-r--r--src/output/shout_plugin.c10
6 files changed, 33 insertions, 39 deletions
diff --git a/src/conf.c b/src/conf.c
index 73990d45d..116a4ea5f 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <errno.h>
#define MAX_STRING_SIZE MPD_PATH_MAX+80
@@ -457,6 +458,27 @@ config_get_block_string(struct config_param *param, const char *name,
return bp->value;
}
+unsigned
+config_get_block_unsigned(struct config_param *param, const char *name,
+ unsigned default_value)
+{
+ struct block_param *bp = getBlockParam(param, name);
+ long value;
+ char *endptr;
+
+ if (bp == NULL)
+ return default_value;
+
+ value = strtol(bp->value, &endptr, 0);
+ if (*endptr != 0)
+ g_error("Not a valid number in line %i", bp->line);
+
+ if (value < 0)
+ g_error("Not a positive number in line %i", bp->line);
+
+ return (unsigned)value;
+}
+
bool
config_get_block_bool(struct config_param *param, const char *name,
bool default_value)
diff --git a/src/conf.h b/src/conf.h
index 3026c9579..2aed9af9a 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -125,6 +125,10 @@ config_dup_block_string(struct config_param *param, const char *name,
return g_strdup(config_get_block_string(param, name, default_value));
}
+unsigned
+config_get_block_unsigned(struct config_param *param, const char *name,
+ unsigned default_value);
+
bool
config_get_block_bool(struct config_param *param, const char *name,
bool default_value);
diff --git a/src/output/alsa_plugin.c b/src/output/alsa_plugin.c
index 0dc357ff5..b3520191e 100644
--- a/src/output/alsa_plugin.c
+++ b/src/output/alsa_plugin.c
@@ -90,16 +90,12 @@ static void freeAlsaData(AlsaData * ad)
static void
alsa_configure(AlsaData *ad, struct config_param *param)
{
- struct block_param *bp;
-
ad->device = config_dup_block_string(param, "device", NULL);
ad->useMmap = config_get_block_bool(param, "use_mmap", false);
- if ((bp = getBlockParam(param, "buffer_time")))
- ad->buffer_time = atoi(bp->value);
- if ((bp = getBlockParam(param, "period_time")))
- ad->period_time = atoi(bp->value);
+ ad->buffer_time = config_get_block_unsigned(param, "buffer_time", 0);
+ ad->period_time = config_get_block_unsigned(param, "period_time", 0);
#ifdef SND_PCM_NO_AUTO_RESAMPLE
if (!config_get_block_bool(param, "auto_resample", true))
diff --git a/src/output/ao_plugin.c b/src/output/ao_plugin.c
index d20496e2c..f24805de0 100644
--- a/src/output/ao_plugin.c
+++ b/src/output/ao_plugin.c
@@ -80,19 +80,10 @@ audioOutputAo_initDriver(struct audio_output *ao,
struct config_param *param)
{
ao_info *ai;
- char *test;
AoData *ad = newAoData();
- struct block_param *blockParam;
const char *value;
- if ((blockParam = getBlockParam(param, "write_size"))) {
- ad->writeSize = strtol(blockParam->value, &test, 10);
- if (*test != '\0') {
- g_error("\"%s\" is not a valid write size at line %i\n",
- blockParam->value, blockParam->line);
- }
- } else
- ad->writeSize = 1024;
+ ad->writeSize = config_get_block_unsigned(param, "write_size", 1024);
if (driverInitCount == 0) {
ao_initialize();
diff --git a/src/output/jack_plugin.c b/src/output/jack_plugin.c
index 224fcd341..185f73860 100644
--- a/src/output/jack_plugin.c
+++ b/src/output/jack_plugin.c
@@ -187,9 +187,6 @@ mpd_jack_init(struct audio_output *ao,
{
struct jack_data *jd;
const char *value;
- struct block_param *bp;
- char *endptr;
- int val;
jd = mpd_jack_new();
jd->ao = ao;
@@ -212,18 +209,8 @@ mpd_jack_init(struct audio_output *ao,
g_free(ports);
}
- if ( (bp = getBlockParam(param, "ringbuffer_size")) ) {
- errno = 0;
- val = strtol(bp->value, &endptr, 10);
-
- if ( errno == 0 && endptr != bp->value) {
- jd->ringbuffer_size = val < 32768 ? 32768 : val;
- g_debug("ringbuffer_size=%d", jd->ringbuffer_size);
- } else {
- g_error("%s is not a number; ringbuf_size=%d",
- bp->value, jd->ringbuffer_size);
- }
- }
+ jd->ringbuffer_size =
+ config_get_block_unsigned(param, "ringbuffer_size", 32768);
return jd;
}
diff --git a/src/output/shout_plugin.c b/src/output/shout_plugin.c
index 069a0b307..7d3e4aaf0 100644
--- a/src/output/shout_plugin.c
+++ b/src/output/shout_plugin.c
@@ -221,14 +221,8 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
}
/* optional paramters */
- block_param = getBlockParam(param, "timeout");
- if (block_param) {
- sd->timeout = (int)strtol(block_param->value, &test, 10);
- if (*test != '\0' || sd->timeout <= 0) {
- g_error("shout timeout is not a positive integer, "
- "line %i\n", block_param->line);
- }
- }
+ sd->timeout = config_get_block_unsigned(param, "timeout",
+ DEFAULT_CONN_TIMEOUT);
value = config_get_block_string(param, "genre", NULL);
if (value != NULL && shout_set_genre(sd->shout_conn, value)) {