conf: added config_get_block_string()
This replaces lots of getBlockParam() invocations.
This commit is contained in:
parent
73e466cfef
commit
a531a1e650
12
src/conf.c
12
src/conf.c
@ -445,6 +445,18 @@ bool config_get_bool(const char *name, bool default_value)
|
|||||||
return !!value;
|
return !!value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
config_get_block_string(struct config_param *param, const char *name,
|
||||||
|
const char *default_value)
|
||||||
|
{
|
||||||
|
struct block_param *bp = getBlockParam(param, name);
|
||||||
|
|
||||||
|
if (bp == NULL)
|
||||||
|
return default_value;
|
||||||
|
|
||||||
|
return bp->value;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
config_get_block_bool(struct config_param *param, const char *name,
|
config_get_block_bool(struct config_param *param, const char *name,
|
||||||
bool default_value)
|
bool default_value)
|
||||||
|
11
src/conf.h
11
src/conf.h
@ -114,6 +114,17 @@ getBlockParam(struct config_param *param, const char *name);
|
|||||||
|
|
||||||
bool config_get_bool(const char *name, bool default_value);
|
bool config_get_bool(const char *name, bool default_value);
|
||||||
|
|
||||||
|
const char *
|
||||||
|
config_get_block_string(struct config_param *param, const char *name,
|
||||||
|
const char *default_value);
|
||||||
|
|
||||||
|
static inline char *
|
||||||
|
config_dup_block_string(struct config_param *param, const char *name,
|
||||||
|
const char *default_value)
|
||||||
|
{
|
||||||
|
return g_strdup(config_get_block_string(param, name, default_value));
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
config_get_block_bool(struct config_param *param, const char *name,
|
config_get_block_bool(struct config_param *param, const char *name,
|
||||||
bool default_value);
|
bool default_value);
|
||||||
|
@ -46,18 +46,21 @@ static void
|
|||||||
alsa_mixer_configure(struct mixer_data *data, struct config_param *param)
|
alsa_mixer_configure(struct mixer_data *data, struct config_param *param)
|
||||||
{
|
{
|
||||||
struct alsa_mixer *am = (struct alsa_mixer *)data;
|
struct alsa_mixer *am = (struct alsa_mixer *)data;
|
||||||
struct block_param *bp;
|
const char *value;
|
||||||
|
|
||||||
if (param == NULL)
|
if (param == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((bp = getBlockParam(param, "mixer_device"))) {
|
value = config_get_block_string(param, "mixer_device", NULL);
|
||||||
|
if (value != NULL) {
|
||||||
g_free(am->device);
|
g_free(am->device);
|
||||||
am->device = g_strdup(bp->value);
|
am->device = g_strdup(value);
|
||||||
}
|
}
|
||||||
if ((bp = getBlockParam(param, "mixer_control"))) {
|
|
||||||
|
value = config_get_block_string(param, "mixer_control", NULL);
|
||||||
|
if (value != NULL) {
|
||||||
g_free(am->control);
|
g_free(am->control);
|
||||||
am->control = g_strdup(bp->value);
|
am->control = g_strdup(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,21 +50,21 @@ static void
|
|||||||
oss_mixer_configure(struct mixer_data *data, struct config_param *param)
|
oss_mixer_configure(struct mixer_data *data, struct config_param *param)
|
||||||
{
|
{
|
||||||
struct oss_mixer *om = (struct oss_mixer *) data;
|
struct oss_mixer *om = (struct oss_mixer *) data;
|
||||||
struct block_param *bp;
|
const char *value;
|
||||||
|
|
||||||
if (param == NULL)
|
if (param == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bp = getBlockParam(param, "mixer_device");
|
value = config_get_block_string(param, "mixer_device", NULL);
|
||||||
if (bp) {
|
if (value != NULL) {
|
||||||
g_free(om->device);
|
g_free(om->device);
|
||||||
om->device = g_strdup(bp->value);
|
om->device = g_strdup(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bp = getBlockParam(param, "mixer_control");
|
value = config_get_block_string(param, "mixer_control", NULL);
|
||||||
if (bp) {
|
if (value != NULL) {
|
||||||
g_free(om->control);
|
g_free(om->control);
|
||||||
om->control = g_strdup(bp->value);
|
om->control = g_strdup(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +92,7 @@ alsa_configure(AlsaData *ad, struct config_param *param)
|
|||||||
{
|
{
|
||||||
struct block_param *bp;
|
struct block_param *bp;
|
||||||
|
|
||||||
if ((bp = getBlockParam(param, "device")))
|
ad->device = config_dup_block_string(param, "device", NULL);
|
||||||
ad->device = g_strdup(bp->value);
|
|
||||||
|
|
||||||
ad->useMmap = config_get_block_bool(param, "use_mmap", false);
|
ad->useMmap = config_get_block_bool(param, "use_mmap", false);
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ audioOutputAo_initDriver(struct audio_output *ao,
|
|||||||
char *test;
|
char *test;
|
||||||
AoData *ad = newAoData();
|
AoData *ad = newAoData();
|
||||||
struct block_param *blockParam;
|
struct block_param *blockParam;
|
||||||
|
const char *value;
|
||||||
|
|
||||||
if ((blockParam = getBlockParam(param, "write_size"))) {
|
if ((blockParam = getBlockParam(param, "write_size"))) {
|
||||||
ad->writeSize = strtol(blockParam->value, &test, 10);
|
ad->writeSize = strtol(blockParam->value, &test, 10);
|
||||||
@ -98,14 +99,12 @@ audioOutputAo_initDriver(struct audio_output *ao,
|
|||||||
}
|
}
|
||||||
driverInitCount++;
|
driverInitCount++;
|
||||||
|
|
||||||
blockParam = getBlockParam(param, "driver");
|
value = config_get_block_string(param, "driver", "default");
|
||||||
|
if (0 == strcmp(value, "default")) {
|
||||||
if (!blockParam || 0 == strcmp(blockParam->value, "default")) {
|
|
||||||
ad->driverId = ao_default_driver_id();
|
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",
|
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) {
|
if ((ai = ao_driver_info(ad->driverId)) == NULL) {
|
||||||
g_error("problems getting driver info for device defined at line %i\n"
|
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,
|
g_debug("using ao driver \"%s\" for \"%s\"\n", ai->short_name,
|
||||||
audio_output_get_name(ao));
|
audio_output_get_name(ao));
|
||||||
|
|
||||||
blockParam = getBlockParam(param, "options");
|
value = config_get_block_string(param, "options", NULL);
|
||||||
if (blockParam) {
|
if (value != NULL) {
|
||||||
gchar **options = g_strsplit(blockParam->value, ";", 0);
|
gchar **options = g_strsplit(value, ";", 0);
|
||||||
|
|
||||||
for (unsigned i = 0; options[i] != NULL; ++i) {
|
for (unsigned i = 0; options[i] != NULL; ++i) {
|
||||||
gchar **key_value = g_strsplit(options[i], "=", 2);
|
gchar **key_value = g_strsplit(options[i], "=", 2);
|
||||||
|
@ -164,19 +164,18 @@ static void *fifo_initDriver(G_GNUC_UNUSED struct audio_output *ao,
|
|||||||
struct config_param *param)
|
struct config_param *param)
|
||||||
{
|
{
|
||||||
FifoData *fd;
|
FifoData *fd;
|
||||||
struct block_param *blockParam;
|
char *value, *path;
|
||||||
char *path;
|
|
||||||
|
|
||||||
blockParam = getBlockParam(param, "path");
|
value = config_dup_block_string(param, "path", NULL);
|
||||||
if (!blockParam) {
|
if (value == NULL)
|
||||||
g_error("No \"path\" parameter specified for fifo output "
|
g_error("No \"path\" parameter specified for fifo output "
|
||||||
"defined at line %i", param->line);
|
"defined at line %i", param->line);
|
||||||
}
|
|
||||||
|
|
||||||
path = parsePath(blockParam->value);
|
path = parsePath(value);
|
||||||
|
g_free(value);
|
||||||
if (!path) {
|
if (!path) {
|
||||||
g_error("Could not parse \"path\" parameter for fifo output "
|
g_error("Could not parse \"path\" parameter for fifo output "
|
||||||
"at line %i", blockParam->line);
|
"at line %i", param->line);
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = newFifoData();
|
fd = newFifoData();
|
||||||
|
@ -186,6 +186,7 @@ mpd_jack_init(struct audio_output *ao,
|
|||||||
struct config_param *param)
|
struct config_param *param)
|
||||||
{
|
{
|
||||||
struct jack_data *jd;
|
struct jack_data *jd;
|
||||||
|
const char *value;
|
||||||
struct block_param *bp;
|
struct block_param *bp;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
int val;
|
int val;
|
||||||
@ -197,12 +198,13 @@ mpd_jack_init(struct audio_output *ao,
|
|||||||
if (param == NULL)
|
if (param == NULL)
|
||||||
return jd;
|
return jd;
|
||||||
|
|
||||||
if ( (bp = getBlockParam(param, "ports")) ) {
|
value = config_get_block_string(param, "ports", NULL);
|
||||||
char **ports = g_strsplit(bp->value, ",", 0);
|
if (value != NULL) {
|
||||||
|
char **ports = g_strsplit(value, ",", 0);
|
||||||
|
|
||||||
if (ports[0] == NULL || ports[1] == NULL || ports[2] != NULL)
|
if (ports[0] == NULL || ports[1] == NULL || ports[2] != NULL)
|
||||||
g_error("two port names expected in line %d",
|
g_error("two port names expected in line %d",
|
||||||
bp->line);
|
param->line);
|
||||||
|
|
||||||
jd->output_ports[0] = ports[0];
|
jd->output_ports[0] = ports[0];
|
||||||
jd->output_ports[1] = ports[1];
|
jd->output_ports[1] = ports[1];
|
||||||
|
@ -393,10 +393,11 @@ oss_initDriver(G_GNUC_UNUSED struct audio_output *audioOutput,
|
|||||||
struct config_param *param)
|
struct config_param *param)
|
||||||
{
|
{
|
||||||
if (param) {
|
if (param) {
|
||||||
struct block_param *bp = getBlockParam(param, "device");
|
const char *device =
|
||||||
if (bp) {
|
config_get_block_string(param, "device", NULL);
|
||||||
|
if (device != NULL) {
|
||||||
OssData *od = newOssData();
|
OssData *od = newOssData();
|
||||||
od->device = bp->value;
|
od->device = device;
|
||||||
mixer_configure(&od->mixer, param);
|
mixer_configure(&od->mixer, param);
|
||||||
return od;
|
return od;
|
||||||
}
|
}
|
||||||
|
@ -57,19 +57,14 @@ pulse_init(struct audio_output *ao,
|
|||||||
G_GNUC_UNUSED const struct audio_format *audio_format,
|
G_GNUC_UNUSED const struct audio_format *audio_format,
|
||||||
struct config_param *param)
|
struct config_param *param)
|
||||||
{
|
{
|
||||||
struct block_param *server = NULL;
|
|
||||||
struct block_param *sink = NULL;
|
|
||||||
struct pulse_data *pd;
|
struct pulse_data *pd;
|
||||||
|
|
||||||
if (param) {
|
|
||||||
server = getBlockParam(param, "server");
|
|
||||||
sink = getBlockParam(param, "sink");
|
|
||||||
}
|
|
||||||
|
|
||||||
pd = pulse_new_data();
|
pd = pulse_new_data();
|
||||||
pd->ao = ao;
|
pd->ao = ao;
|
||||||
pd->server = server != NULL ? g_strdup(server->value) : NULL;
|
pd->server = param != NULL
|
||||||
pd->sink = sink != NULL ? g_strdup(sink->value) : NULL;
|
? config_dup_block_string(param, "server", NULL) : NULL;
|
||||||
|
pd->sink = param != NULL
|
||||||
|
? config_dup_block_string(param, "sink", NULL) : NULL;
|
||||||
|
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,7 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
|
|||||||
unsigned protocol;
|
unsigned protocol;
|
||||||
const char *user;
|
const char *user;
|
||||||
char *name;
|
char *name;
|
||||||
|
const char *value;
|
||||||
struct block_param *block_param;
|
struct block_param *block_param;
|
||||||
int public;
|
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);
|
public = config_get_block_bool(param, "public", false);
|
||||||
|
|
||||||
block_param = getBlockParam(param, "user");
|
user = config_get_block_string(param, "user", "source");
|
||||||
if (block_param)
|
|
||||||
user = block_param->value;
|
|
||||||
else
|
|
||||||
user = "source";
|
|
||||||
|
|
||||||
block_param = getBlockParam(param, "quality");
|
value = config_get_block_string(param, "quality", NULL);
|
||||||
|
if (value != NULL) {
|
||||||
if (block_param) {
|
sd->quality = strtod(value, &test);
|
||||||
int line = block_param->line;
|
|
||||||
|
|
||||||
sd->quality = strtod(block_param->value, &test);
|
|
||||||
|
|
||||||
if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) {
|
if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) {
|
||||||
g_error("shout quality \"%s\" is not a number in the "
|
g_error("shout quality \"%s\" is not a number in the "
|
||||||
"range -1 to 10, line %i\n", block_param->value,
|
"range -1 to 10, line %i",
|
||||||
block_param->line);
|
value, param->line);
|
||||||
}
|
}
|
||||||
|
|
||||||
block_param = getBlockParam(param, "bitrate");
|
if (config_get_block_string(param, "bitrate", NULL) != NULL) {
|
||||||
|
g_error("quality and bitrate are "
|
||||||
if (block_param) {
|
"both defined for shout output (line %i)",
|
||||||
g_error("quality (line %i) and bitrate (line %i) are "
|
param->line);
|
||||||
"both defined for shout output\n", line,
|
|
||||||
block_param->line);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
block_param = getBlockParam(param, "bitrate");
|
value = config_get_block_string(param, "bitrate", NULL);
|
||||||
|
if (value == NULL)
|
||||||
if (!block_param) {
|
|
||||||
g_error("neither bitrate nor quality defined for shout "
|
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) {
|
if (*test != '\0' || sd->bitrate <= 0) {
|
||||||
g_error("bitrate at line %i should be a positive integer "
|
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);
|
assert(audio_format != NULL);
|
||||||
sd->audio_format = *audio_format;
|
sd->audio_format = *audio_format;
|
||||||
|
|
||||||
block_param = getBlockParam(param, "encoding");
|
encoding = config_get_block_string(param, "encoding", "ogg");
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
sd->encoder = shout_encoder_plugin_get(encoding);
|
sd->encoder = shout_encoder_plugin_get(encoding);
|
||||||
if (sd->encoder == NULL)
|
if (sd->encoder == NULL)
|
||||||
g_error("couldn't find shout encoder plugin \"%s\"\n",
|
g_error("couldn't find shout encoder plugin \"%s\"\n",
|
||||||
encoding);
|
encoding);
|
||||||
|
|
||||||
block_param = getBlockParam(param, "protocol");
|
value = config_get_block_string(param, "protocol", NULL);
|
||||||
if (block_param) {
|
if (value != NULL) {
|
||||||
if (0 == strcmp(block_param->value, "shoutcast") &&
|
if (0 == strcmp(value, "shoutcast") &&
|
||||||
0 != strcmp(encoding, "mp3"))
|
0 != strcmp(encoding, "mp3"))
|
||||||
g_error("you cannot stream \"%s\" to shoutcast, use mp3\n",
|
g_error("you cannot stream \"%s\" to shoutcast, use mp3\n",
|
||||||
encoding);
|
encoding);
|
||||||
else if (0 == strcmp(block_param->value, "shoutcast"))
|
else if (0 == strcmp(value, "shoutcast"))
|
||||||
protocol = SHOUT_PROTOCOL_ICY;
|
protocol = SHOUT_PROTOCOL_ICY;
|
||||||
else if (0 == strcmp(block_param->value, "icecast1"))
|
else if (0 == strcmp(value, "icecast1"))
|
||||||
protocol = SHOUT_PROTOCOL_XAUDIOCAST;
|
protocol = SHOUT_PROTOCOL_XAUDIOCAST;
|
||||||
else if (0 == strcmp(block_param->value, "icecast2"))
|
else if (0 == strcmp(value, "icecast2"))
|
||||||
protocol = SHOUT_PROTOCOL_HTTP;
|
protocol = SHOUT_PROTOCOL_HTTP;
|
||||||
else
|
else
|
||||||
g_error("shout protocol \"%s\" is not \"shoutcast\" or "
|
g_error("shout protocol \"%s\" is not \"shoutcast\" or "
|
||||||
"\"icecast1\"or "
|
"\"icecast1\"or "
|
||||||
"\"icecast2\", line %i\n", block_param->value,
|
"\"icecast2\", line %i\n",
|
||||||
block_param->line);
|
value, param->line);
|
||||||
} else {
|
} else {
|
||||||
protocol = SHOUT_PROTOCOL_HTTP;
|
protocol = SHOUT_PROTOCOL_HTTP;
|
||||||
}
|
}
|
||||||
@ -253,15 +230,14 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
block_param = getBlockParam(param, "genre");
|
value = config_get_block_string(param, "genre", NULL);
|
||||||
if (block_param && shout_set_genre(sd->shout_conn, block_param->value)) {
|
if (value != NULL && shout_set_genre(sd->shout_conn, value)) {
|
||||||
g_error("error configuring shout defined at line %i: %s\n",
|
g_error("error configuring shout defined at line %i: %s\n",
|
||||||
param->line, shout_get_error(sd->shout_conn));
|
param->line, shout_get_error(sd->shout_conn));
|
||||||
}
|
}
|
||||||
|
|
||||||
block_param = getBlockParam(param, "description");
|
value = config_get_block_string(param, "description", NULL);
|
||||||
if (block_param && shout_set_description(sd->shout_conn,
|
if (value != NULL && shout_set_description(sd->shout_conn, value)) {
|
||||||
block_param->value)) {
|
|
||||||
g_error("error configuring shout defined at line %i: %s\n",
|
g_error("error configuring shout defined at line %i: %s\n",
|
||||||
param->line, shout_get_error(sd->shout_conn));
|
param->line, shout_get_error(sd->shout_conn));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user