diff options
author | Max Kellermann <max@duempel.org> | 2008-11-14 18:05:13 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-14 18:05:13 +0100 |
commit | 19131f1eda36594b748747b88568e70c5d356aa5 (patch) | |
tree | f1b98a8776c0288749c45a891ac2ee856a0a4691 | |
parent | eb199ca207d69512d671607ddd9c2f3f9ac5c668 (diff) | |
download | mpd-19131f1eda36594b748747b88568e70c5d356aa5.tar.gz mpd-19131f1eda36594b748747b88568e70c5d356aa5.tar.xz mpd-19131f1eda36594b748747b88568e70c5d356aa5.zip |
volume: moved code to oss_mixer_find()
Diffstat (limited to '')
-rw-r--r-- | src/volume.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/volume.c b/src/volume.c index 4b619f916..b1f7f186b 100644 --- a/src/volume.c +++ b/src/volume.c @@ -87,6 +87,27 @@ static void closeOssMixer(void) volume_ossFd = -1; } +static int +oss_find_mixer(const char *name) +{ + const char *labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS; + + for (unsigned i = 0; i < SOUND_MIXER_NRDEVICES; i++) { + ssize_t len = strlen(labels[i]); + char *duplicated = alloca(len + 1); + + /* eliminate spaces at the end */ + memcpy(duplicated, labels[i], len + 1); + len -= 2; + while (len >= 0 && duplicated[len] == ' ') + duplicated[len--] = '\0'; + if (strcasecmp(duplicated, name) == 0) + return i; + } + + return -1; +} + static int prepOssMixer(const char *device) { ConfigParam *param; @@ -97,7 +118,6 @@ static int prepOssMixer(const char *device) } if ((param = getConfigParam(CONF_MIXER_CONTROL))) { - const char *labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS; int i; int devmask = 0; @@ -107,20 +127,9 @@ static int prepOssMixer(const char *device) return -1; } - for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { - ssize_t len = strlen(labels[i]); - char *duplicated = alloca(len + 1); - - /* eliminate spaces at the end */ - memcpy(duplicated, labels[i], len + 1); - len -= 2; - while (len >= 0 && duplicated[len] == ' ') - duplicated[len--] = '\0'; - if (strcasecmp(duplicated, param->value) == 0) - break; - } + i = oss_find_mixer(param->value); - if (i >= SOUND_MIXER_NRDEVICES) { + if (i < 0) { WARNING("mixer control \"%s\" not found at line %i\n", param->value, param->line); closeOssMixer(); |