From a5a367a7df3fe6ea946e07184fa86ddd3f026049 Mon Sep 17 00:00:00 2001 From: ratchov <> Date: Wed, 26 Feb 2020 13:53:58 +0000 Subject: [PATCH] Add API to control audio device parameters exposed by sndiod. The API exposes controls of modern audio hardware and sndiod software volume knobs in a uniform way. Hardware knobs are exposed through sndiod. Multiple programs may use the controls at the same time without the need to continuously scan the controls. For now sndiod exposes only its own controls and the master output and input volumes of the underlying hardware (if any), i.e. those typically exposed by acpi volume keys. ok deraadt --- src/include/sndio.h | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/include/sndio.h b/src/include/sndio.h index dcb9ddfb..4fed3d5c 100644 --- a/src/include/sndio.h +++ b/src/include/sndio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sndio.h,v 1.9 2015/12/20 11:29:29 ratchov Exp $ */ +/* $OpenBSD: sndio.h,v 1.10 2020/02/26 13:53:58 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -25,11 +25,17 @@ #define SIO_DEVANY "default" #define MIO_PORTANY "default" +/* + * limits + */ +#define SIOCTL_NAMEMAX 12 /* max name length */ + /* * private ``handle'' structure */ struct sio_hdl; struct mio_hdl; +struct sioctl_hdl; /* * parameters of a full-duplex stream @@ -84,6 +90,33 @@ struct sio_cap { #define SIO_XSTRINGS { "ignore", "sync", "error" } +/* + * controlled component of the device + */ +struct sioctl_node { + char name[SIOCTL_NAMEMAX]; /* ex. "spkr" */ + int unit; /* optional number or -1 */ +}; + +/* + * description of a control (index, value) pair + */ +struct sioctl_desc { + unsigned int addr; /* control address */ +#define SIOCTL_NONE 0 /* deleted */ +#define SIOCTL_NUM 2 /* integer in the 0..127 range */ +#define SIOCTL_SW 3 /* on/off switch (0 or 1) */ +#define SIOCTL_VEC 4 /* number, element of vector */ +#define SIOCTL_LIST 5 /* switch, element of a list */ + unsigned int type; /* one of above */ + char func[SIOCTL_NAMEMAX]; /* function name, ex. "level" */ + char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ + struct sioctl_node node0; /* affected node */ + struct sioctl_node node1; /* dito for SIOCTL_{VEC,LIST} */ + unsigned int maxval; /* max value for SIOCTL_{NUM,VEC} */ + int __pad[3]; +}; + /* * mode bitmap */ @@ -91,6 +124,8 @@ struct sio_cap { #define SIO_REC 2 #define MIO_OUT 4 #define MIO_IN 8 +#define SIOCTL_READ 0x100 +#define SIOCTL_WRITE 0x200 /* * default bytes per sample for the given bits per sample @@ -144,10 +179,24 @@ int mio_pollfd(struct mio_hdl *, struct pollfd *, int); int mio_revents(struct mio_hdl *, struct pollfd *); int mio_eof(struct mio_hdl *); +struct sioctl_hdl *sioctl_open(const char *, unsigned int, int); +void sioctl_close(struct sioctl_hdl *); +int sioctl_ondesc(struct sioctl_hdl *, + void (*)(void *, struct sioctl_desc *, int), void *); +int sioctl_onval(struct sioctl_hdl *, + void (*)(void *, unsigned int, unsigned int), void *); +int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int); +int sioctl_nfds(struct sioctl_hdl *); +int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int); +int sioctl_revents(struct sioctl_hdl *, struct pollfd *); +int sioctl_eof(struct sioctl_hdl *); + int mio_rmidi_getfd(const char *, unsigned int, int); struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int); int sio_sun_getfd(const char *, unsigned int, int); struct sio_hdl *sio_sun_fdopen(int, unsigned int, int); +int sioctl_sun_getfd(const char *, unsigned int, int); +struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int); #ifdef __cplusplus }