summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sndio.h2
-rw-r--r--lib/libsndio/sioctl_open.32
-rw-r--r--usr.bin/sndioctl/sndioctl.c2
-rw-r--r--usr.bin/sndiod/dev.c44
-rw-r--r--usr.bin/sndiod/dev.h5
-rw-r--r--usr.bin/sndiod/dev_sioctl.c9
-rw-r--r--usr.bin/sndiod/siofile.c15
-rw-r--r--usr.bin/sndiod/sndiod.89
8 files changed, 74 insertions, 14 deletions
diff --git a/include/sndio.h b/include/sndio.h
index ac9c084361a..03550a0b23f 100644
--- a/include/sndio.h
+++ b/include/sndio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndio.h,v 1.12 2020/06/28 05:17:25 ratchov Exp $ */
+/* $OpenBSD: sndio.h,v 1.13 2020/06/28 05:21:38 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
diff --git a/lib/libsndio/sioctl_open.3 b/lib/libsndio/sioctl_open.3
index 1f8a1dbd7f9..e4ddd219304 100644
--- a/lib/libsndio/sioctl_open.3
+++ b/lib/libsndio/sioctl_open.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sioctl_open.3,v 1.10 2020/06/28 05:17:25 ratchov Exp $
+.\" $OpenBSD: sioctl_open.3,v 1.11 2020/06/28 05:21:38 ratchov Exp $
.\"
.\" Copyright (c) 2011-2020 Alexandre Ratchov <alex@caoua.org>
.\"
diff --git a/usr.bin/sndioctl/sndioctl.c b/usr.bin/sndioctl/sndioctl.c
index 2403f85be9d..d95eb322437 100644
--- a/usr.bin/sndioctl/sndioctl.c
+++ b/usr.bin/sndioctl/sndioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndioctl.c,v 1.14 2020/06/28 05:17:26 ratchov Exp $ */
+/* $OpenBSD: sndioctl.c,v 1.15 2020/06/28 05:21:39 ratchov Exp $ */
/*
* Copyright (c) 2014-2020 Alexandre Ratchov <alex@caoua.org>
*
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 0866098c9d8..9c850eee25b 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.74 2020/06/28 05:17:25 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.75 2020/06/28 05:21:39 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -67,6 +67,7 @@ int dev_init(struct dev *);
void dev_done(struct dev *);
struct dev *dev_bynum(int);
void dev_del(struct dev *);
+void dev_setalt(struct dev *, unsigned int);
unsigned int dev_roundof(struct dev *, unsigned int);
void dev_wakeup(struct dev *);
void dev_sync_attach(struct dev *);
@@ -1088,6 +1089,30 @@ dev_addname(struct dev *d, char *name)
}
/*
+ * set prefered alt device name
+ */
+void
+dev_setalt(struct dev *d, unsigned int idx)
+{
+ struct dev_alt **pa, *a;
+
+ /* find alt with given index */
+ for (pa = &d->alt_list; (a = *pa)->idx != idx; pa = &a->next)
+ ;
+
+ /* detach from list */
+ *pa = a->next;
+
+ /* attach at head */
+ a->next = d->alt_list;
+ d->alt_list = a;
+
+ /* reopen device with the new alt */
+ if (idx != d->alt_num)
+ dev_reopen(d);
+}
+
+/*
* adjust device parameters and mode
*/
void
@@ -1176,6 +1201,7 @@ dev_open(struct dev *d)
{
int i;
char name[CTL_NAMEMAX];
+ struct dev_alt *a;
d->master_enabled = 0;
d->mode = d->reqmode;
@@ -1209,6 +1235,14 @@ dev_open(struct dev *d)
NULL, -1, 127, d->slot[i].vol);
}
+ for (a = d->alt_list; a != NULL; a = a->next) {
+ snprintf(name, sizeof(name), "%d", a->idx);
+ dev_addctl(d, "", CTL_SEL,
+ CTLADDR_ALT_SEL + a->idx,
+ "server", -1, "device",
+ name, -1, 1, a->idx == d->alt_num);
+ }
+
d->pstate = DEV_INIT;
return 1;
}
@@ -2472,7 +2506,13 @@ dev_setctl(struct dev *d, int addr, int val)
c->dirty = 1;
dev_ref(d);
} else {
- if (addr == CTLADDR_MASTER) {
+ if (addr >= CTLADDR_ALT_SEL) {
+ if (val) {
+ num = addr - CTLADDR_ALT_SEL;
+ dev_setalt(d, num);
+ }
+ return 1;
+ } else if (addr == CTLADDR_MASTER) {
if (d->master_enabled) {
dev_master(d, val);
dev_midi_master(d);
diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h
index 3a879b8b3be..735f7d1386f 100644
--- a/usr.bin/sndiod/dev.h
+++ b/usr.bin/sndiod/dev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.h,v 1.28 2020/06/28 05:17:26 ratchov Exp $ */
+/* $OpenBSD: dev.h,v 1.29 2020/06/28 05:21:39 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -24,7 +24,8 @@
#define CTLADDR_SLOT_LEVEL(n) (n)
#define CTLADDR_MASTER (DEV_NSLOT)
-#define CTLADDR_END (DEV_NSLOT + 1)
+#define CTLADDR_ALT_SEL (CTLADDR_MASTER + 1)
+#define CTLADDR_END (CTLADDR_ALT_SEL + DEV_NMAX)
/*
* audio stream state structure
diff --git a/usr.bin/sndiod/dev_sioctl.c b/usr.bin/sndiod/dev_sioctl.c
index 6785d9bbf05..3809542b6ac 100644
--- a/usr.bin/sndiod/dev_sioctl.c
+++ b/usr.bin/sndiod/dev_sioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev_sioctl.c,v 1.5 2020/04/24 11:33:28 ratchov Exp $ */
+/* $OpenBSD: dev_sioctl.c,v 1.6 2020/06/28 05:21:39 ratchov Exp $ */
/*
* Copyright (c) 2014-2020 Alexandre Ratchov <alex@caoua.org>
*
@@ -64,11 +64,12 @@ dev_sioctl_ondesc(void *arg, struct sioctl_desc *desc, int val)
dev_rmctl(d, addr);
/*
- * prefix group names we use (currently "app") with "hw/"
- * to ensure that all controls have unique names when multiple
+ * prefix with "hw/" group names of controls we expose, to
+ * ensure that all controls have unique names when multiple
* sndiod's are chained
*/
- if (strcmp(desc->group, "app") == 0) {
+ if (strcmp(desc->group, "app") == 0 || (desc->group[0] == 0 &&
+ strcmp(desc->node0.name, "server") == 0)) {
group = group_buf;
if (snprintf(group_buf, CTL_NAMEMAX, GROUP_PREFIX "/%s",
desc->group) >= CTL_NAMEMAX)
diff --git a/usr.bin/sndiod/siofile.c b/usr.bin/sndiod/siofile.c
index 5ae66167dfe..ddc6a5973d1 100644
--- a/usr.bin/sndiod/siofile.c
+++ b/usr.bin/sndiod/siofile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: siofile.c,v 1.21 2020/06/18 05:11:13 ratchov Exp $ */
+/* $OpenBSD: siofile.c,v 1.22 2020/06/28 05:21:39 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -96,6 +96,8 @@ dev_sio_openlist(struct dev *d, unsigned int mode, struct sioctl_hdl **rctlhdl)
struct dev_alt *n;
struct sio_hdl *hdl;
struct sioctl_hdl *ctlhdl;
+ struct ctl *c;
+ int val;
for (n = d->alt_list; n != NULL; n = n->next) {
if (d->alt_num == n->idx)
@@ -117,6 +119,17 @@ dev_sio_openlist(struct dev *d, unsigned int mode, struct sioctl_hdl **rctlhdl)
}
}
d->alt_num = n->idx;
+ for (c = d->ctl_list; c != NULL; c = c->next) {
+ if (c->addr < CTLADDR_ALT_SEL ||
+ c->addr >= CTLADDR_ALT_SEL + DEV_NMAX)
+ continue;
+ val = (c->addr - CTLADDR_ALT_SEL) == n->idx;
+ if (c->curval == val)
+ continue;
+ c->curval = val;
+ if (val)
+ c->val_mask = ~0U;
+ }
*rctlhdl = ctlhdl;
return hdl;
}
diff --git a/usr.bin/sndiod/sndiod.8 b/usr.bin/sndiod/sndiod.8
index 725c21d7626..93e0cac3818 100644
--- a/usr.bin/sndiod/sndiod.8
+++ b/usr.bin/sndiod/sndiod.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sndiod.8,v 1.7 2020/04/25 05:35:52 ratchov Exp $
+.\" $OpenBSD: sndiod.8,v 1.8 2020/06/28 05:21:39 ratchov Exp $
.\"
.\" Copyright (c) 2006-2012 Alexandre Ratchov <alex@caoua.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 25 2020 $
+.Dd $Mdocdate: June 28 2020 $
.Dt SNDIOD 8
.Os
.Sh NAME
@@ -196,6 +196,11 @@ PCI device allows
.Nm
to use the USB one preferably when it's connected
and to fall back to the PCI one when it's disconnected.
+Alternate devices may be switched with the
+.Va server.device
+control of the
+.Xr sndioctl 1
+utility.
.It Fl f Ar device
Add this
.Xr sndio 7