Clemens Ladisch <clemens@ladisch.de>

- add error handler for ALSA errors
- enumerate all controls to find the desired control
  (because SPDIF is device 1 on ymfpci)
This commit is contained in:
Jaroslav Kysela 2003-11-03 10:43:32 +00:00
parent 394fde8b0e
commit 1f2d8e47ab

View file

@ -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) static void usage(void)
{ {
int i; int i;
@ -279,13 +285,16 @@ static int update_iec958_status(snd_aes_iec958_t *iec958, int *parms)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
const char *dev = "default"; 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_t *ctl;
snd_ctl_elem_list_t *clist;
snd_ctl_elem_id_t *cid;
snd_ctl_elem_value_t *cval; snd_ctl_elem_value_t *cval;
snd_aes_iec958_t iec958; snd_aes_iec958_t iec958;
int from_stdin = 0; int from_stdin = 0;
int dumphex = 0; int dumphex = 0;
int i, c; int i, c, err;
unsigned int controls, cidx;
char tmpname[32]; char tmpname[32];
int parms[IDX_LAST]; int parms[IDX_LAST];
@ -318,20 +327,42 @@ int main(int argc, char **argv)
} }
} }
if (snd_ctl_open(&ctl, dev, 0) < 0) { if ((err = snd_ctl_open(&ctl, dev, 0)) < 0) {
perror("snd_ctl_open"); error("snd_ctl_open", err);
return 1; return 1;
} }
snd_ctl_elem_value_alloca(&cval); snd_ctl_elem_list_alloca(&clist);
snd_ctl_elem_value_set_interface(cval, SND_CTL_ELEM_IFACE_MIXER); if ((err = snd_ctl_elem_list(ctl, clist)) < 0) {
snd_ctl_elem_value_set_name(cval, spdif_str); error("snd_ctl_elem_list", err);
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; 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_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); snd_ctl_elem_value_get_iec958(cval, &iec958);
@ -347,12 +378,12 @@ int main(int argc, char **argv)
if (update_iec958_status(&iec958, parms)) { if (update_iec958_status(&iec958, parms)) {
/* store the values */ /* store the values */
snd_ctl_elem_value_set_iec958(cval, &iec958); snd_ctl_elem_value_set_iec958(cval, &iec958);
if (snd_ctl_elem_write(ctl, cval) < 0) { if ((err = snd_ctl_elem_write(ctl, cval)) < 0) {
perror("snd_ctl_elem_write"); error("snd_ctl_elem_write", err);
return 1; return 1;
} }
if (snd_ctl_elem_read(ctl, cval) < 0) { if ((err = snd_ctl_elem_read(ctl, cval)) < 0) {
perror("snd_ctl_elem_write"); error("snd_ctl_elem_write", err);
return 1; return 1;
} }
snd_ctl_elem_value_get_iec958(cval, &iec958); snd_ctl_elem_value_get_iec958(cval, &iec958);