aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-18 19:37:27 +0100
committerMax Kellermann <max@duempel.org>2009-01-18 19:37:27 +0100
commita531a1e65075d27574bc31d4bac7ab20cb750efd (patch)
treef06ad8e7359f0845d94d2b8a6f655a0cceb744c2 /src/output
parent73e466cfef6497aff840cfac35d80d74e7b0fd0c (diff)
downloadmpd-a531a1e65075d27574bc31d4bac7ab20cb750efd.tar.gz
mpd-a531a1e65075d27574bc31d4bac7ab20cb750efd.tar.xz
mpd-a531a1e65075d27574bc31d4bac7ab20cb750efd.zip
conf: added config_get_block_string()
This replaces lots of getBlockParam() invocations.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/alsa_plugin.c3
-rw-r--r--src/output/ao_plugin.c17
-rw-r--r--src/output/fifo_plugin.c13
-rw-r--r--src/output/jack_plugin.c8
-rw-r--r--src/output/oss_plugin.c7
-rw-r--r--src/output/pulse_plugin.c13
-rw-r--r--src/output/shout_plugin.c82
7 files changed, 57 insertions, 86 deletions
diff --git a/src/output/alsa_plugin.c b/src/output/alsa_plugin.c
index 8034169ba..0dc357ff5 100644
--- a/src/output/alsa_plugin.c
+++ b/src/output/alsa_plugin.c
@@ -92,8 +92,7 @@ alsa_configure(AlsaData *ad, struct config_param *param)
{
struct block_param *bp;
- if ((bp = getBlockParam(param, "device")))
- ad->device = g_strdup(bp->value);
+ ad->device = config_dup_block_string(param, "device", NULL);
ad->useMmap = config_get_block_bool(param, "use_mmap", false);
diff --git a/src/output/ao_plugin.c b/src/output/ao_plugin.c
index 269620143..d20496e2c 100644
--- a/src/output/ao_plugin.c
+++ b/src/output/ao_plugin.c
@@ -83,6 +83,7 @@ audioOutputAo_initDriver(struct audio_output *ao,
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);
@@ -98,14 +99,12 @@ audioOutputAo_initDriver(struct audio_output *ao,
}
driverInitCount++;
- blockParam = getBlockParam(param, "driver");
-
- if (!blockParam || 0 == strcmp(blockParam->value, "default")) {
+ value = config_get_block_string(param, "driver", "default");
+ if (0 == strcmp(value, "default")) {
ad->driverId = ao_default_driver_id();
- } else if ((ad->driverId = ao_driver_id(blockParam->value)) < 0) {
+ } else if ((ad->driverId = ao_driver_id(value)) < 0)
g_error("\"%s\" is not a valid ao driver at line %i\n",
- blockParam->value, blockParam->line);
- }
+ value, param->line);
if ((ai = ao_driver_info(ad->driverId)) == NULL) {
g_error("problems getting driver info for device defined at line %i\n"
@@ -115,9 +114,9 @@ audioOutputAo_initDriver(struct audio_output *ao,
g_debug("using ao driver \"%s\" for \"%s\"\n", ai->short_name,
audio_output_get_name(ao));
- blockParam = getBlockParam(param, "options");
- if (blockParam) {
- gchar **options = g_strsplit(blockParam->value, ";", 0);
+ value = config_get_block_string(param, "options", NULL);
+ if (value != NULL) {
+ gchar **options = g_strsplit(value, ";", 0);
for (unsigned i = 0; options[i] != NULL; ++i) {
gchar **key_value = g_strsplit(options[i], "=", 2);
diff --git a/src/output/fifo_plugin.c b/src/output/fifo_plugin.c
index 01db714cf..5d1f287b2 100644
--- a/src/output/fifo_plugin.c
+++ b/src/output/fifo_plugin.c
@@ -164,19 +164,18 @@ static void *fifo_initDriver(G_GNUC_UNUSED struct audio_output *ao,
struct config_param *param)
{
FifoData *fd;
- struct block_param *blockParam;
- char *path;
+ char *value, *path;
- blockParam = getBlockParam(param, "path");
- if (!blockParam) {
+ value = config_dup_block_string(param, "path", NULL);
+ if (value == NULL)
g_error("No \"path\" parameter specified for fifo output "
"defined at line %i", param->line);
- }
- path = parsePath(blockParam->value);
+ path = parsePath(value);
+ g_free(value);
if (!path) {
g_error("Could not parse \"path\" parameter for fifo output "
- "at line %i", blockParam->line);
+ "at line %i", param->line);
}
fd = newFifoData();
diff --git a/src/output/jack_plugin.c b/src/output/jack_plugin.c
index 5723a04ca..224fcd341 100644
--- a/src/output/jack_plugin.c
+++ b/src/output/jack_plugin.c
@@ -186,6 +186,7 @@ mpd_jack_init(struct audio_output *ao,
struct config_param *param)
{
struct jack_data *jd;
+ const char *value;
struct block_param *bp;
char *endptr;
int val;
@@ -197,12 +198,13 @@ mpd_jack_init(struct audio_output *ao,
if (param == NULL)
return jd;
- if ( (bp = getBlockParam(param, "ports")) ) {
- char **ports = g_strsplit(bp->value, ",", 0);
+ value = config_get_block_string(param, "ports", NULL);
+ if (value != NULL) {
+ char **ports = g_strsplit(value, ",", 0);
if (ports[0] == NULL || ports[1] == NULL || ports[2] != NULL)
g_error("two port names expected in line %d",
- bp->line);
+ param->line);
jd->output_ports[0] = ports[0];
jd->output_ports[1] = ports[1];
diff --git a/src/output/oss_plugin.c b/src/output/oss_plugin.c
index f66280752..e83a05c5a 100644
--- a/src/output/oss_plugin.c
+++ b/src/output/oss_plugin.c
@@ -393,10 +393,11 @@ oss_initDriver(G_GNUC_UNUSED struct audio_output *audioOutput,
struct config_param *param)
{
if (param) {
- struct block_param *bp = getBlockParam(param, "device");
- if (bp) {
+ const char *device =
+ config_get_block_string(param, "device", NULL);
+ if (device != NULL) {
OssData *od = newOssData();
- od->device = bp->value;
+ od->device = device;
mixer_configure(&od->mixer, param);
return od;
}
diff --git a/src/output/pulse_plugin.c b/src/output/pulse_plugin.c
index 7d746378c..45710b4a9 100644
--- a/src/output/pulse_plugin.c
+++ b/src/output/pulse_plugin.c
@@ -57,19 +57,14 @@ pulse_init(struct audio_output *ao,
G_GNUC_UNUSED const struct audio_format *audio_format,
struct config_param *param)
{
- struct block_param *server = NULL;
- struct block_param *sink = NULL;
struct pulse_data *pd;
- if (param) {
- server = getBlockParam(param, "server");
- sink = getBlockParam(param, "sink");
- }
-
pd = pulse_new_data();
pd->ao = ao;
- pd->server = server != NULL ? g_strdup(server->value) : NULL;
- pd->sink = sink != NULL ? g_strdup(sink->value) : NULL;
+ pd->server = param != NULL
+ ? config_dup_block_string(param, "server", NULL) : NULL;
+ pd->sink = param != NULL
+ ? config_dup_block_string(param, "sink", NULL) : NULL;
return pd;
}
diff --git a/src/output/shout_plugin.c b/src/output/shout_plugin.c
index 7ca885996..069a0b307 100644
--- a/src/output/shout_plugin.c
+++ b/src/output/shout_plugin.c
@@ -106,6 +106,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
unsigned protocol;
const char *user;
char *name;
+ const char *value;
struct block_param *block_param;
int public;
@@ -140,45 +141,34 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
public = config_get_block_bool(param, "public", false);
- block_param = getBlockParam(param, "user");
- if (block_param)
- user = block_param->value;
- else
- user = "source";
+ user = config_get_block_string(param, "user", "source");
- block_param = getBlockParam(param, "quality");
-
- if (block_param) {
- int line = block_param->line;
-
- sd->quality = strtod(block_param->value, &test);
+ value = config_get_block_string(param, "quality", NULL);
+ if (value != NULL) {
+ sd->quality = strtod(value, &test);
if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) {
g_error("shout quality \"%s\" is not a number in the "
- "range -1 to 10, line %i\n", block_param->value,
- block_param->line);
+ "range -1 to 10, line %i",
+ value, param->line);
}
- block_param = getBlockParam(param, "bitrate");
-
- if (block_param) {
- g_error("quality (line %i) and bitrate (line %i) are "
- "both defined for shout output\n", line,
- block_param->line);
+ if (config_get_block_string(param, "bitrate", NULL) != NULL) {
+ g_error("quality and bitrate are "
+ "both defined for shout output (line %i)",
+ param->line);
}
} else {
- block_param = getBlockParam(param, "bitrate");
-
- if (!block_param) {
+ value = config_get_block_string(param, "bitrate", NULL);
+ if (value == NULL)
g_error("neither bitrate nor quality defined for shout "
- "output at line %i\n", param->line);
- }
+ "output at line %i", param->line);
- sd->bitrate = strtol(block_param->value, &test, 10);
+ sd->bitrate = strtol(value, &test, 10);
if (*test != '\0' || sd->bitrate <= 0) {
g_error("bitrate at line %i should be a positive integer "
- "\n", block_param->line);
+ "\n", param->line);
}
}
@@ -187,42 +177,29 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
assert(audio_format != NULL);
sd->audio_format = *audio_format;
- block_param = getBlockParam(param, "encoding");
- if (block_param) {
- if (0 == strcmp(block_param->value, "mp3"))
- encoding = block_param->value;
- else if (0 == strcmp(block_param->value, "ogg"))
- encoding = block_param->value;
- else
- g_error("shout encoding \"%s\" is not \"ogg\" or "
- "\"mp3\", line %i\n", block_param->value,
- block_param->line);
- } else {
- encoding = "ogg";
- }
-
+ encoding = config_get_block_string(param, "encoding", "ogg");
sd->encoder = shout_encoder_plugin_get(encoding);
if (sd->encoder == NULL)
g_error("couldn't find shout encoder plugin \"%s\"\n",
encoding);
- block_param = getBlockParam(param, "protocol");
- if (block_param) {
- if (0 == strcmp(block_param->value, "shoutcast") &&
+ value = config_get_block_string(param, "protocol", NULL);
+ if (value != NULL) {
+ if (0 == strcmp(value, "shoutcast") &&
0 != strcmp(encoding, "mp3"))
g_error("you cannot stream \"%s\" to shoutcast, use mp3\n",
encoding);
- else if (0 == strcmp(block_param->value, "shoutcast"))
+ else if (0 == strcmp(value, "shoutcast"))
protocol = SHOUT_PROTOCOL_ICY;
- else if (0 == strcmp(block_param->value, "icecast1"))
+ else if (0 == strcmp(value, "icecast1"))
protocol = SHOUT_PROTOCOL_XAUDIOCAST;
- else if (0 == strcmp(block_param->value, "icecast2"))
+ else if (0 == strcmp(value, "icecast2"))
protocol = SHOUT_PROTOCOL_HTTP;
else
g_error("shout protocol \"%s\" is not \"shoutcast\" or "
"\"icecast1\"or "
- "\"icecast2\", line %i\n", block_param->value,
- block_param->line);
+ "\"icecast2\", line %i\n",
+ value, param->line);
} else {
protocol = SHOUT_PROTOCOL_HTTP;
}
@@ -253,15 +230,14 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
}
}
- block_param = getBlockParam(param, "genre");
- if (block_param && shout_set_genre(sd->shout_conn, block_param->value)) {
+ value = config_get_block_string(param, "genre", NULL);
+ if (value != NULL && shout_set_genre(sd->shout_conn, value)) {
g_error("error configuring shout defined at line %i: %s\n",
param->line, shout_get_error(sd->shout_conn));
}
- block_param = getBlockParam(param, "description");
- if (block_param && shout_set_description(sd->shout_conn,
- block_param->value)) {
+ value = config_get_block_string(param, "description", NULL);
+ if (value != NULL && shout_set_description(sd->shout_conn, value)) {
g_error("error configuring shout defined at line %i: %s\n",
param->line, shout_get_error(sd->shout_conn));
}