From 1f2d8e47aba1b9e6ffeb11c73637c0ecdde85034 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 3 Nov 2003 10:43:32 +0000 Subject: [PATCH] Clemens Ladisch - add error handler for ALSA errors - enumerate all controls to find the desired control (because SPDIF is device 1 on ymfpci) --- iecset/iecset.c | 63 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/iecset/iecset.c b/iecset/iecset.c index 03f812f..d8c063f 100644 --- a/iecset/iecset.c +++ b/iecset/iecset.c @@ -76,6 +76,12 @@ static struct cmdtbl cmds[] = { }; +static void error(const char *s, int err) +{ + fprintf(stderr, "%s: %s\n", s, snd_strerror(err)); +} + + static void usage(void) { int i; @@ -279,13 +285,16 @@ static int update_iec958_status(snd_aes_iec958_t *iec958, int *parms) int main(int argc, char **argv) { const char *dev = "default"; - const char *spdif_str = "IEC958 Playback Default"; + const char *spdif_str = SND_CTL_NAME_IEC958("", PLAYBACK, DEFAULT); snd_ctl_t *ctl; + snd_ctl_elem_list_t *clist; + snd_ctl_elem_id_t *cid; snd_ctl_elem_value_t *cval; snd_aes_iec958_t iec958; int from_stdin = 0; int dumphex = 0; - int i, c; + int i, c, err; + unsigned int controls, cidx; char tmpname[32]; int parms[IDX_LAST]; @@ -318,20 +327,42 @@ int main(int argc, char **argv) } } - if (snd_ctl_open(&ctl, dev, 0) < 0) { - perror("snd_ctl_open"); + if ((err = snd_ctl_open(&ctl, dev, 0)) < 0) { + error("snd_ctl_open", err); return 1; } + snd_ctl_elem_list_alloca(&clist); + if ((err = snd_ctl_elem_list(ctl, clist)) < 0) { + error("snd_ctl_elem_list", err); + return 1; + } + if ((err = snd_ctl_elem_list_alloc_space(clist, snd_ctl_elem_list_get_count(clist))) < 0) { + error("snd_ctl_elem_list_alloc_space", err); + return 1; + } + if ((err = snd_ctl_elem_list(ctl, clist)) < 0) { + error("snd_ctl_elem_list", err); + return 1; + } + + controls = snd_ctl_elem_list_get_used(clist); + for (cidx = 0; cidx < controls; cidx++) { + if (!strcmp(snd_ctl_elem_list_get_name(clist, cidx), spdif_str)) + break; + } + if (cidx >= controls) { + fprintf(stderr, "control \"%s\" not found\n", spdif_str); + return 1; + } + + snd_ctl_elem_id_alloca(&cid); + snd_ctl_elem_list_get_id(clist, cidx, cid); snd_ctl_elem_value_alloca(&cval); - snd_ctl_elem_value_set_interface(cval, SND_CTL_ELEM_IFACE_MIXER); - snd_ctl_elem_value_set_name(cval, spdif_str); - if (snd_ctl_elem_read(ctl, cval) < 0) { - snd_ctl_elem_value_set_interface(cval, SND_CTL_ELEM_IFACE_PCM); - if (snd_ctl_elem_read(ctl, cval) < 0) { - perror("snd_ctl_elem_read"); - return 1; - } + snd_ctl_elem_value_set_id(cval, cid); + if ((err = snd_ctl_elem_read(ctl, cval)) < 0) { + error("snd_ctl_elem_read", err); + return 1; } snd_ctl_elem_value_get_iec958(cval, &iec958); @@ -347,12 +378,12 @@ int main(int argc, char **argv) if (update_iec958_status(&iec958, parms)) { /* store the values */ snd_ctl_elem_value_set_iec958(cval, &iec958); - if (snd_ctl_elem_write(ctl, cval) < 0) { - perror("snd_ctl_elem_write"); + if ((err = snd_ctl_elem_write(ctl, cval)) < 0) { + error("snd_ctl_elem_write", err); return 1; } - if (snd_ctl_elem_read(ctl, cval) < 0) { - perror("snd_ctl_elem_write"); + if ((err = snd_ctl_elem_read(ctl, cval)) < 0) { + error("snd_ctl_elem_write", err); return 1; } snd_ctl_elem_value_get_iec958(cval, &iec958);