From 8dec140ed06a2c35a13336fec95b77b28b6b7b96 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 26 Dec 2013 13:35:08 +0000 Subject: [PATCH] fade: Improve error diagnostics. 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 | 6 +++--- error.h | 10 ++++------ fade.c | 20 ++++++++------------ oss_mix.c | 2 +- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/alsa_mix.c b/alsa_mix.c index 01f1c512..c5daebc2 100644 --- a/alsa_mix.c +++ b/alsa_mix.c @@ -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 82df5ca9..1db656b9 100644 --- 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 d7f28d66..0a3ccebb 100644 --- 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) { diff --git a/oss_mix.c b/oss_mix.c index 5182ad23..7e19fcbe 100644 --- 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) -- 2.39.2