OpenBSD manual page server

Manual Page Search Parameters

SIOCTL_OPEN(3) Library Functions Manual SIOCTL_OPEN(3)

sioctl_open, sioctl_close, sioctl_ondesc, sioctl_onval, sioctl_setval, sioctl_nfds, sioctl_pollfd, sioctl_eofinterface to audio parameters

#include <sndio.h>

struct sioctl_hdl *
sioctl_open(const char *name, unsigned int mode, int nbio_flag);

sioctl_close(struct sioctl_hdl *hdl);

sioctl_ondesc(struct sioctl_hdl *hdl, void (*cb)(void *arg, struct sioctl_desc *desc, int val), void *arg);

sioctl_onval(struct sioctl_hdl *hdl, void (*cb)(void *arg, unsigned int addr, unsigned int val), void *arg);

sioctl_setval(struct sioctl_hdl *hdl, unsigned int addr, unsigned int val);

sioctl_nfds(struct sioctl_hdl *hdl);

sioctl_pollfd(struct sioctl_hdl *hdl, struct pollfd *pfd, int events);

sioctl_revents(struct sioctl_hdl *hdl, struct pollfd *pfd);

sioctl_eof(struct sioctl_hdl *hdl);

Audio devices may expose a number of controls, like the playback volume control. Each control has an integer and an integer . Depending on the control type, its integer value represents either a continuous quantity or a boolean. Any control may be changed by submitting a new value to its address. When values change, asynchronous notifications are sent.

Controls descriptions are available, allowing them to be grouped and represented in a human usable form.

First the application must call the () function to obtain a handle that will be passed as the hdl argument to other functions.

The name parameter gives the device string discussed in sndio(7). In most cases it should be set to SIO_DEVANY to allow the user to select it using the AUDIODEVICE environment variable. The mode parameter is a bitmap of the SIOCTL_READ and SIOCTL_WRITE constants indicating whether control values can be read and modified respectively.

If the nbio_flag argument is 1, then the () function (see below) may fail instead of blocking and the () function doesn't block.

The () function closes the control device and frees any allocated resources associated with the handle.

The () function can be used to obtain the description of all available controls and their initial values. It registers a call-back that is immediately invoked for all controls. It's called once with a NULL argument to indicate that the full description was sent and that the caller has a consistent representation of the controls set.

Then, whenever a control description changes, the call-back is invoked with the updated information followed by a call with a NULL argument.

Controls are described by the sioctl_ondesc structure as follows:

struct sioctl_node {
	char name[SIOCTL_NAMEMAX];	/* ex. "spkr" */
	int unit;			/* optional number or -1 */

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} */

The addr attribute is the control address, usable with () to set its value.

The type attribute indicates what the structure describes. Possible types are:

A previously valid control was deleted.
A continuous control in the 0..SIOCTL_VALMAX range. For instance the volume of the speaker.
A on/off switch control. For instance the switch to mute the speaker.
Element of an array of continuous controls. For instance the knob to control the amount of signal flowing from the line input to the speaker.
An element of an array of on/off switches. For instance the line-in position of the speaker source selector.

The func attribute is the name of the parameter being controlled. There may be no parameters of different types with the same name.

The node0 and node1 attributes indicate the names of the controlled nodes, typically channels of audio streams. node1 is meaningful for SIOCTL_VEC and SIOCTL_LIST only.

Names in the node0 and node1 attributes and func are strings usable as unique identifiers within the the given group.

Controls are changed with the () function, by giving the index of the control and the new value. The () function can be used to register a call-back which will be invoked whenever a control changes. Continuous values are in the 0..127 range.


The sioctl_pollfd() function fills the array pfd of pollfd structures, used by poll(2), with events; the latter is a bit-mask of POLLIN and POLLOUT constants. sioctl_pollfd() returns the number of pollfd structures filled. The () function returns the bit-mask set by poll(2) in the pfd array of pollfd structures. If POLLOUT is set, sioctl_setval() can be called without blocking. POLLHUP may be set if an error occurs, even if it is not selected with sioctl_pollfd(). POLLIN is not used yet.

The () function returns the number of pollfd structures the caller must preallocate in order to be sure that () will never overrun.

sndioctl(1), poll(2), sndio(7)

April 19, 2020 OpenBSD-6.7