From: Andre Noll Date: Sun, 15 Jul 2012 17:58:59 +0000 (+0200) Subject: fade: Introduce --mixer-api to choose between ALSA and OSS. X-Git-Tag: v0.4.12~10^2~4 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=0968b226713f7bab3be9185b426f766932394bc7;p=paraslash.git fade: Introduce --mixer-api to choose between ALSA and OSS. Currently, if both OSS and ALSA are supported, there is no way to select the OSS mixer API. This adds a new option to para_fade which allows to force the given mixer API. --- diff --git a/fade.c b/fade.c index 1bfa0ba1..cbfb6230 100644 --- a/fade.c +++ b/fade.c @@ -23,6 +23,7 @@ enum mixer_id {MIXER_ENUM}; static char *mixer_name[] = {MIXER_NAMES}; DECLARE_MIXER_INITS; static struct mixer supported_mixer[] = {MIXER_ARRAY}; +#define FOR_EACH_MIXER(i) for ((i) = 0; (i) < NUM_SUPPORTED_MIXERS; (i)++) __printf_2_3 void date_log(__a_unused int ll, const char *fmt, ...) { @@ -233,7 +234,7 @@ static void init_mixers(void) { int i; - for (i = 0; i < NUM_SUPPORTED_MIXERS; i++) { + FOR_EACH_MIXER(i) { struct mixer *m = &supported_mixer[i]; PARA_DEBUG_LOG("initializing mixer API #%d (%s)\n", i, mixer_name[i]); @@ -259,6 +260,29 @@ static int set_channel(struct mixer *m, struct mixer_handle *h) return ret; } +static struct mixer *get_mixer_or_die(void) +{ + int i; + + if (!conf.mixer_api_given) + i = DEFAULT_MIXER; + else + FOR_EACH_MIXER(i) + if (!strcmp(mixer_name[i], conf.mixer_api_arg)) + break; + if (i < NUM_SUPPORTED_MIXERS) { + PARA_NOTICE_LOG("using %s mixer API\n", mixer_name[i]); + return supported_mixer + i; + } + printf("available mixer APIs: "); + FOR_EACH_MIXER(i) { + int d = (i == DEFAULT_MIXER); + printf("%s%s%s ", d? "[" : "", mixer_name[i], d? "]" : ""); + } + printf("\n"); + exit(EXIT_FAILURE); +} + int main(int argc, char *argv[]) { int ret; @@ -286,8 +310,7 @@ int main(int argc, char *argv[]) &conf, ¶ms); } init_mixers(); - m = &supported_mixer[DEFAULT_MIXER]; - PARA_INFO_LOG("using %s mixer\n", mixer_name[DEFAULT_MIXER]); + m = get_mixer_or_die(); ret = m->open(conf.mixer_device_arg, &h); if (ret < 0) goto out; diff --git a/m4/gengetopt/fade.m4 b/m4/gengetopt/fade.m4 index 42f135fa..450e0542 100644 --- a/m4/gengetopt/fade.m4 +++ b/m4/gengetopt/fade.m4 @@ -32,6 +32,18 @@ option "config-file" c string typestr = "filename" optional +option "mixer-api" a +#~~~~~~~~~~~~~~~~~~~ +"choose the mixer API" + string typestr = "api" + optional + details = " + ALSA is preferred over OSS if both APIs are supported + and this option is not given. To see the supported + mixer APIs, use this option with an invalid string + as the mixer API, e.g. --mixer-api help. + " + option "mixer-device" m #~~~~~~~~~~~~~~~~~~~~~~ "choose mixer device"