]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
fade: Introduce --mixer-api to choose between ALSA and OSS.
authorAndre Noll <maan@systemlinux.org>
Sun, 15 Jul 2012 17:58:59 +0000 (19:58 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 7 Oct 2012 09:12:07 +0000 (11:12 +0200)
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.

fade.c
m4/gengetopt/fade.m4

diff --git a/fade.c b/fade.c
index 1bfa0ba1ee8e9ca862de62fef4104d6c3e9cd4a4..cbfb62308a79ab85aa73b2d3f88c77cb25a6c725 100644 (file)
--- 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};
 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, ...)
 {
 
 __printf_2_3 void date_log(__a_unused int ll, const char *fmt, ...)
 {
@@ -233,7 +234,7 @@ static void init_mixers(void)
 {
        int i;
 
 {
        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]);
                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;
 }
 
        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;
 int main(int argc, char *argv[])
 {
        int ret;
@@ -286,8 +310,7 @@ int main(int argc, char *argv[])
                        &conf, &params);
        }
        init_mixers();
                        &conf, &params);
        }
        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;
        ret = m->open(conf.mixer_device_arg, &h);
        if (ret < 0)
                goto out;
index 42f135fa3ee5d3ed6d61faf9b4088fd00d8302e2..450e05423db66925449934e0c5efab0b8d850c3e 100644 (file)
@@ -32,6 +32,18 @@ option "config-file" c
        string typestr = "filename"
        optional
 
        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"
 option "mixer-device" m
 #~~~~~~~~~~~~~~~~~~~~~~
 "choose mixer device"