iecset - Add -n option

Added -n option to iecset to specify the index number of the control
element.  This is needed for handling multiple SPDIF devices.
This commit is contained in:
Takashi Iwai 2008-02-05 08:11:02 +01:00
parent eedab6e3e3
commit 318258f294
2 changed files with 14 additions and 3 deletions

View file

@ -42,6 +42,10 @@ Specifies the device name of the control to open
\fI\-c\fP card
Specifies the card index to open. Equivalent with \fI\-Dhw:x\fP.
.TP
\fI\-n\fP index
Specifies the IEC958 control element index, in case you have multiple
IEC958 devices and need to choose one of them.
.TP
\fI\-x\fP
Dumps the status in the form of AESx bytes.
.TP

View file

@ -286,6 +286,7 @@ int main(int argc, char **argv)
{
const char *dev = "default";
const char *spdif_str = SND_CTL_NAME_IEC958("", PLAYBACK, DEFAULT);
int spdif_index = -1;
snd_ctl_t *ctl;
snd_ctl_elem_list_t *clist;
snd_ctl_elem_id_t *cid;
@ -301,7 +302,7 @@ int main(int argc, char **argv)
for (i = 0; i < IDX_LAST; i++)
parms[i] = -1; /* not set */
while ((c = getopt(argc, argv, "D:c:xhi")) != -1) {
while ((c = getopt(argc, argv, "D:c:n:xhi")) != -1) {
switch (c) {
case 'D':
dev = optarg;
@ -315,6 +316,9 @@ int main(int argc, char **argv)
sprintf(tmpname, "hw:%d", i);
dev = tmpname;
break;
case 'n':
spdif_index = atoi(optarg);
break;
case 'x':
dumphex = 1;
break;
@ -349,10 +353,13 @@ int main(int argc, char **argv)
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 (spdif_index < 0 ||
snd_ctl_elem_list_get_index(clist, cidx) == spdif_index)
break;
}
if (cidx >= controls) {
fprintf(stderr, "control \"%s\" not found\n", spdif_str);
fprintf(stderr, "control \"%s\" (index %d) not found\n",
spdif_str, spdif_index);
return 1;
}