diff options
author | Max Kellermann <max@duempel.org> | 2009-03-26 19:48:21 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-03-26 19:48:21 +0100 |
commit | c552d17c03f3903e862e4958b530aa0c5c1b84f4 (patch) | |
tree | 5e20c2d92d6e01cd8ad3b3f9023c5970b7faef39 /src | |
parent | 881026623c16fa1bd4846329731c693390a7bb68 (diff) | |
download | mpd-c552d17c03f3903e862e4958b530aa0c5c1b84f4.tar.gz mpd-c552d17c03f3903e862e4958b530aa0c5c1b84f4.tar.xz mpd-c552d17c03f3903e862e4958b530aa0c5c1b84f4.zip |
oss_mixer: call oss_find_mixer() in init() method
Detect misconfiguration during MPD startup.
Diffstat (limited to '')
-rw-r--r-- | src/mixer/oss_mixer.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/mixer/oss_mixer.c b/src/mixer/oss_mixer.c index acbd05fdb..85b59fbe7 100644 --- a/src/mixer/oss_mixer.c +++ b/src/mixer/oss_mixer.c @@ -49,6 +49,21 @@ struct oss_mixer { int volume_control; }; +static int +oss_find_mixer(const char *name) +{ + const char *labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS; + size_t name_length = strlen(name); + + for (unsigned i = 0; i < SOUND_MIXER_NRDEVICES; i++) { + if (g_ascii_strncasecmp(name, labels[i], name_length) == 0 && + (labels[i][name_length] == 0 || + labels[i][name_length] == ' ')) + return i; + } + return -1; +} + static struct mixer * oss_mixer_init(const struct config_param *param) { @@ -60,7 +75,16 @@ oss_mixer_init(const struct config_param *param) VOLUME_MIXER_OSS_DEFAULT); om->control = config_get_block_string(param, "mixer_control", NULL); - om->volume_control = SOUND_MIXER_PCM; + if (om->control != NULL) { + om->volume_control = oss_find_mixer(om->control); + if (om->volume_control < 0) { + g_warning("mixer control \"%s\" not found", + om->control); + g_free(om); + return NULL; + } + } else + om->volume_control = SOUND_MIXER_PCM; return &om->base; } @@ -83,21 +107,6 @@ oss_mixer_close(struct mixer *data) close(om->device_fd); } -static int -oss_find_mixer(const char *name) -{ - const char *labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS; - size_t name_length = strlen(name); - - for (unsigned i = 0; i < SOUND_MIXER_NRDEVICES; i++) { - if (g_ascii_strncasecmp(name, labels[i], name_length) == 0 && - (labels[i][name_length] == 0 || - labels[i][name_length] == ' ')) - return i; - } - return -1; -} - static bool oss_mixer_open(struct mixer *data) { @@ -110,7 +119,6 @@ oss_mixer_open(struct mixer *data) } if (om->control) { - int i; int devmask = 0; if (ioctl(om->device_fd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0) { @@ -118,20 +126,13 @@ oss_mixer_open(struct mixer *data) oss_mixer_close(data); return false; } - i = oss_find_mixer(om->control); - if (i < 0) { - g_warning("mixer control \"%s\" not found\n", - om->control); - oss_mixer_close(data); - return false; - } else if (!((1 << i) & devmask)) { + if (((1 << om->volume_control) & devmask) == 0) { g_warning("mixer control \"%s\" not usable\n", om->control); oss_mixer_close(data); return false; } - om->volume_control = i; } return true; } |