mirror of
https://github.com/openbsd/src.git
synced 2025-01-04 23:35:36 -08:00
Allow switching between alternate devices (-F option) with sndioctl(1)
This commit is contained in:
parent
49f67e12e9
commit
4f3fcc3939
@ -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>
|
||||
*
|
||||
|
@ -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>
|
||||
.\"
|
||||
|
@ -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>
|
||||
*
|
||||
|
@ -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 *);
|
||||
@ -1087,6 +1088,30 @@ dev_addname(struct dev *d, char *name)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user