diff options
author | Max Kellermann <max@duempel.org> | 2009-02-11 18:00:41 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-02-11 18:00:41 +0100 |
commit | 5090cf6484f5e7464aeba54d19500cc334a80fad (patch) | |
tree | 1e6cc079a0b23128a529aea3f6042581027828c9 /src/audio.c | |
parent | 5484aaee5f9407e61d77e81236b4942c12b94556 (diff) | |
download | mpd-5090cf6484f5e7464aeba54d19500cc334a80fad.tar.gz mpd-5090cf6484f5e7464aeba54d19500cc334a80fad.tar.xz mpd-5090cf6484f5e7464aeba54d19500cc334a80fad.zip |
audio: replaced parseAudioConfig() with audio_format_parse()
Added audio_format_parse() in a separate library, with a modern
interface: return a GError instead of logging errors. This allows the
caller to deal with the error.
Diffstat (limited to '')
-rw-r--r-- | src/audio.c | 65 |
1 files changed, 8 insertions, 57 deletions
diff --git a/src/audio.c b/src/audio.c index d3e66fdb2..eef8d2de8 100644 --- a/src/audio.c +++ b/src/audio.c @@ -18,6 +18,7 @@ #include "audio.h" #include "audio_format.h" +#include "audio_parser.h" #include "output_api.h" #include "output_control.h" #include "output_internal.h" @@ -44,67 +45,17 @@ void getOutputAudioFormat(const struct audio_format *inAudioFormat, void initAudioConfig(void) { const struct config_param *param = config_get_param(CONF_AUDIO_OUTPUT_FORMAT); + GError *error = NULL; + bool ret; if (NULL == param || NULL == param->value) return; - if (0 != parseAudioConfig(&configured_audio_format, param->value)) { - g_error("error parsing \"%s\" at line %i\n", - CONF_AUDIO_OUTPUT_FORMAT, param->line); - } -} - -int parseAudioConfig(struct audio_format *audioFormat, char *conf) -{ - char *test; - - memset(audioFormat, 0, sizeof(*audioFormat)); - - audioFormat->sample_rate = strtol(conf, &test, 10); - - if (*test != ':') { - g_warning("error parsing audio output format: %s\n", conf); - return -1; - } - - if (audioFormat->sample_rate <= 0) { - g_warning("sample rate %u is not >= 0\n", - audioFormat->sample_rate); - return -1; - } - - audioFormat->bits = (uint8_t)strtoul(test + 1, &test, 10); - - if (*test != ':') { - g_warning("error parsing audio output format: %s\n", conf); - return -1; - } - - if (audioFormat->bits != 16 && audioFormat->bits != 24 && - audioFormat->bits != 8) { - g_warning("bits %u can not be used for audio output\n", - audioFormat->bits); - return -1; - } - - audioFormat->channels = (uint8_t)strtoul(test + 1, &test, 10); - - if (*test != '\0') { - g_warning("error parsing audio output format: %s\n", conf); - return -1; - } - - switch (audioFormat->channels) { - case 1: - case 2: - break; - default: - g_warning("channels %u can not be used for audio output\n", - audioFormat->channels); - return -1; - } - - return 0; + ret = audio_format_parse(&configured_audio_format, param->value, + &error); + if (!ret) + g_error("error parsing \"%s\" at line %i: %s", + CONF_AUDIO_OUTPUT_FORMAT, param->line, error->message); } void finishAudioConfig(void) |