]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
fade: Improve error diagnostics.
authorAndre Noll <maan@systemlinux.org>
Thu, 26 Dec 2013 13:35:08 +0000 (13:35 +0000)
committerAndre Noll <maan@systemlinux.org>
Sat, 25 Jan 2014 20:14:13 +0000 (21:14 +0100)
This adds a new generic error code "invalid mixer channel", which is
returned from both ALSA and OSS in case the specified mixer channel
could not be set.

Prior to this patch, ALSA would return a bad channel error also when
the given value was out of range. This is fixed by replacing the now
unused ALSA_MIX_BAD_ELEM error code by the new ALSA_MIX_RANGE code.

Finally, para_fade is changed to no longer print the list of available
channels after it failed to set the initial mode.

alsa_mix.c
error.h
fade.c
oss_mix.c

index 01f1c51260a7b6753ba8b14aac0c255120b4b331..c5daebc2682b13eb0d6e2a12b9956ae5b77ff4b8 100644 (file)
@@ -141,19 +141,19 @@ static int alsa_mix_set_channel(struct mixer_handle *h,
                PARA_NOTICE_LOG("unable to find simple control '%s',%i\n",
                        snd_mixer_selem_id_get_name(sid),
                        snd_mixer_selem_id_get_index(sid));
-               return -E_ALSA_MIX_BAD_ELEM;
+               return -E_BAD_CHANNEL;
        }
        ret = snd_mixer_selem_get_playback_volume_range(h->elem,
                &h->pmin, &h->pmax);
        if (ret < 0) {
                PARA_NOTICE_LOG("unable to get %s range (%s): %s\n",
                        mixer_channel, h->card, snd_strerror(ret));
-               return -E_ALSA_MIX_BAD_ELEM;
+               return -E_ALSA_MIX_RANGE;
        }
        if (h->pmin < 0 || h->pmax < 0 || h->pmin >= h->pmax) {
                PARA_NOTICE_LOG("alsa reported %s range %ld-%ld (%s)\n",
                        mixer_channel, h->pmin, h->pmax, h->card);
-               return -E_ALSA_MIX_BAD_ELEM;
+               return -E_ALSA_MIX_RANGE;
        }
        return 1;
 }
diff --git a/error.h b/error.h
index 82df5ca90d5035c2f458f2b7fbf9f97f55b83334..1db656b95dbe1413330b76fcea93f63ebff6bae2 100644 (file)
--- a/error.h
+++ b/error.h
@@ -28,7 +28,7 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 #define GGO_ERRORS
 #define COLOR_ERRORS
 #define SIGNAL_ERRORS
-#define FADE_ERRORS
+#define OSS_MIX_ERRORS
 #define STDOUT_ERRORS
 #define FILE_WRITE_ERRORS
 #define STDIN_ERRORS
@@ -39,15 +39,11 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 
 extern const char **para_errlist[];
 
-#define OSS_MIX_ERRORS \
-       PARA_ERROR(OSS_MIXER_CHANNEL, "invalid mixer channel"), \
-
-
 #define ALSA_MIX_ERRORS \
        PARA_ERROR(ALSA_MIX_OPEN, "could not open mixer"), \
-       PARA_ERROR(ALSA_MIX_BAD_ELEM, "invalid/unsupported control element"), \
        PARA_ERROR(ALSA_MIX_GET_VAL, "could not read control element state"), \
        PARA_ERROR(ALSA_MIX_SET_VAL, "could not set control element state"), \
+       PARA_ERROR(ALSA_MIX_RANGE, "value control element out of range"), \
 
 
 #define RESAMPLE_FILTER_ERRORS \
@@ -78,6 +74,8 @@ extern const char **para_errlist[];
        PARA_ERROR(NO_VALID_FILES, "no valid file found in playlist"), \
        PARA_ERROR(BAD_PLAY_CMD, "invalid command"), \
 
+#define FADE_ERRORS \
+       PARA_ERROR(BAD_CHANNEL, "invalid channel"), \
 
 #define FLACDEC_FILTER_ERRORS \
        PARA_ERROR(FLACDEC_DECODER_ALLOC, "could not allocate stream decoder"), \
diff --git a/fade.c b/fade.c
index d7f28d6666faa121021ab4927ff354ddbc581242..0a3ccebb844326267f421044d998d77c27096356 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -46,19 +46,10 @@ __printf_2_3 void (*para_log)(int, const char*, ...) = date_log;
 
 static int set_channel(struct mixer *m, struct mixer_handle *h, const char *channel)
 {
-       char *channels;
-       int ret;
 
-       ret = m->set_channel(h, channel);
-       if (ret >= 0) {
-               PARA_NOTICE_LOG("using %s mixer channel\n",
-                       channel? channel : "default");
-               return ret;
-       }
-       channels = m->get_channels(h);
-       printf("Available channels: %s\n", channels);
-       free(channels);
-       return ret;
+       PARA_NOTICE_LOG("using %s mixer channel\n", channel?
+               channel : "default");
+       return m->set_channel(h, channel);
 }
 
 /* Fade to new volume in fade_time seconds. */
@@ -377,6 +368,11 @@ int main(int argc, char *argv[])
        if (ret < 0)
                goto out;
        ret = set_channel(m, h, conf.mixer_channel_arg);
+       if (ret == -E_BAD_CHANNEL) {
+               char *channels = m->get_channels(h);
+               printf("Available channels: %s\n", channels);
+               free(channels);
+       }
        if (ret < 0)
                goto out;
        switch (conf.mode_arg) {
index 5182ad238b81f706ebac2f6abdcaec3859b809dc..7e19fcbe3f9e7dd473f49f20f15442683dfff32d 100644 (file)
--- a/oss_mix.c
+++ b/oss_mix.c
@@ -98,7 +98,7 @@ static int oss_mix_set_channel(struct mixer_handle *handle,
                handle->id = i;
                return 1;
        }
-       return -E_OSS_MIXER_CHANNEL;
+       return -E_BAD_CHANNEL;
 }
 
 static int oss_mix_get(struct mixer_handle *handle)