};
+static void error(const char *s, int err)
+{
+ fprintf(stderr, "%s: %s\n", s, snd_strerror(err));
+}
+
+
static void usage(void)
{
int i;
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];
}
}
- 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);
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);