xref: /freebsd/share/man/man4/sndstat.4 (revision 810530aa2648812860e84d951d9cf96dfd24e595)
1c96151d3SKa Ho Ng.\"
24d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause
3c96151d3SKa Ho Ng.\"
4c96151d3SKa Ho Ng.\" This software was developed by Ka Ho Ng
5c96151d3SKa Ho Ng.\" under sponsorship from the FreeBSD Foundation.
6c96151d3SKa Ho Ng.\"
7c96151d3SKa Ho Ng.\" Copyright (c) 2020 The FreeBSD Foundation
8c96151d3SKa Ho Ng.\"
9c96151d3SKa Ho Ng.\" Redistribution and use in source and binary forms, with or without
10c96151d3SKa Ho Ng.\" modification, are permitted provided that the following conditions
11c96151d3SKa Ho Ng.\" are met:
12c96151d3SKa Ho Ng.\" 1. Redistributions of source code must retain the above copyright
13c96151d3SKa Ho Ng.\"    notice, this list of conditions and the following disclaimer.
14c96151d3SKa Ho Ng.\" 2. Redistributions in binary form must reproduce the above copyright
15c96151d3SKa Ho Ng.\"    notice, this list of conditions and the following disclaimer in the
16c96151d3SKa Ho Ng.\"    documentation and/or other materials provided with the distribution.
17c96151d3SKa Ho Ng.\"
18c96151d3SKa Ho Ng.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19c96151d3SKa Ho Ng.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20c96151d3SKa Ho Ng.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21c96151d3SKa Ho Ng.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22c96151d3SKa Ho Ng.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23c96151d3SKa Ho Ng.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24c96151d3SKa Ho Ng.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25c96151d3SKa Ho Ng.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26c96151d3SKa Ho Ng.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27c96151d3SKa Ho Ng.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28c96151d3SKa Ho Ng.\" SUCH DAMAGE.
29c96151d3SKa Ho Ng.\"
30c96151d3SKa Ho Ng.\" Note: The date here should be updated whenever a non-trivial
31c96151d3SKa Ho Ng.\" change is made to the manual page.
32*810530aaSChristos Margiolis.Dd July 26, 2024
33c96151d3SKa Ho Ng.Dt SNDSTAT 4
34c96151d3SKa Ho Ng.Os
35c96151d3SKa Ho Ng.Sh NAME
36c96151d3SKa Ho Ng.Nm sndstat
37c96151d3SKa Ho Ng.Nd "nvlist-based PCM audio device enumeration interface"
38c96151d3SKa Ho Ng.Sh SYNOPSIS
39c96151d3SKa Ho NgTo compile the driver into the kernel,
40c96151d3SKa Ho Ngplace the following lines in the
41c96151d3SKa Ho Ngkernel configuration file:
42c96151d3SKa Ho Ng.Bd -ragged -offset indent
43c96151d3SKa Ho Ng.Cd "device sound"
44c96151d3SKa Ho Ng.Ed
45c96151d3SKa Ho Ng.Sh DESCRIPTION
46c96151d3SKa Ho NgThe ioctl interface provided by
47c96151d3SKa Ho Ng.Pa /dev/sndstat
48c232fd4bSGoran Mekićdevice allows callers to enumerate PCM audio devices available for use.
49c232fd4bSGoran MekićIn other words, it provides means to get the list of all audio devices
50c232fd4bSGoran Mekićavailable to the system.
51c96151d3SKa Ho Ng.Sh IOCTLS
52c232fd4bSGoran MekićFor ioctl calls that take an argument, the following structure is used:
53c96151d3SKa Ho Ng.Bd -literal -offset indent
544ce1ba65SKa Ho Ngstruct sndstioc_nv_arg {
55c96151d3SKa Ho Ng	size_t nbytes;
56c96151d3SKa Ho Ng	void *buf;
57c96151d3SKa Ho Ng};
58c96151d3SKa Ho Ng.Ed
59c96151d3SKa Ho Ng.Pp
60c232fd4bSGoran MekićHere is an example of an nvlist object with explanations of the common fields:
61c96151d3SKa Ho Ng.Bd -literal -offset indent
62c96151d3SKa Ho Ngdsps (NVLIST ARRAY): 1
63c96151d3SKa Ho Ng	from_user (BOOL): FALSE
64c96151d3SKa Ho Ng	nameunit (STRING): [pcm0]
65c96151d3SKa Ho Ng	devnode (STRING): [dsp0]
66c96151d3SKa Ho Ng	desc (STRING): [Generic (0x8086) (Analog Line-out)]
67bbca3a75SChristos Margiolis	pchan (NUMBER): 1
68bbca3a75SChristos Margiolis	rchan (NUMBER): 0
694ce1ba65SKa Ho Ng	info_play (NVLIST):
70bbca3a75SChristos Margiolis		min_rate (NUMBER): 48000
71bbca3a75SChristos Margiolis		max_rate (NUMBER): 48000
72bbca3a75SChristos Margiolis		formats (NUMBER): 16
73bbca3a75SChristos Margiolis		min_chn (NUMBER): 2
74bbca3a75SChristos Margiolis		max_chn (NUMBER): 2
75c96151d3SKa Ho Ng	provider_info (NVLIST):
76bbca3a75SChristos Margiolis		unit (NUMBER): 0
77*810530aaSChristos Margiolis		status (STRING): on hdaa0
78c96151d3SKa Ho Ng		bitperfect (BOOL): FALSE
79bbca3a75SChristos Margiolis		pvchan (NUMBER): 1
80bbca3a75SChristos Margiolis		rvchan (NUMBER): 0
81bbca3a75SChristos Margiolis		channel_info (NVLIST_ARRAY): 1
82bbca3a75SChristos Margiolis			name (STRING): pcm0:virtual_play:dsp0.vp0
83bbca3a75SChristos Margiolis			parentchan (STRING): pcm0:play:dsp0.p0
84bbca3a75SChristos Margiolis			unit (NUMBER): 1
85bbca3a75SChristos Margiolis			latency (NUMBER): 2
86bbca3a75SChristos Margiolis			rate (NUMBER): 48000
87bbca3a75SChristos Margiolis			format (NUMBER): 0x201000
88bbca3a75SChristos Margiolis			pid (NUMBER): 1234
89bbca3a75SChristos Margiolis			comm (STRING): mpv
90bbca3a75SChristos Margiolis			interrupts (NUMBER): 0
91bbca3a75SChristos Margiolis			feedcount (NUMBER): 0
92bbca3a75SChristos Margiolis			xruns (NUMBER): 0
93bbca3a75SChristos Margiolis			left_volume (NUMBER): 45
94bbca3a75SChristos Margiolis			right_volume (NUMBER): 45
95bbca3a75SChristos Margiolis			hwbuf_fmt (NUMBER): 0x200010
96bbca3a75SChristos Margiolis			hwbuf_size (NUMBER): 0
97bbca3a75SChristos Margiolis			hwbuf_blksz (NUMBER): 0
98bbca3a75SChristos Margiolis			hwbuf_blkcnt (NUMBER): 0
99bbca3a75SChristos Margiolis			hwbuf_free (NUMBER): 0
100bbca3a75SChristos Margiolis			hwbuf_ready (NUMBER): 0
101bbca3a75SChristos Margiolis			swbuf_fmt (NUMBER): 0x201000
102bbca3a75SChristos Margiolis			swbuf_size (NUMBER): 16384
103bbca3a75SChristos Margiolis			swbuf_blksz (NUMBER): 2048
104bbca3a75SChristos Margiolis			swbuf_blkcnt (NUMBER): 8
105bbca3a75SChristos Margiolis			swbuf_free (NUMBER): 16384
106bbca3a75SChristos Margiolis			swbuf_ready (NUMBER): 0
107bbca3a75SChristos Margiolis			feederchain (STRING):
108bbca3a75SChristos Margiolis				[userland ->
109bbca3a75SChristos Margiolis				feeder_root(0x00201000) ->
110bbca3a75SChristos Margiolis				feeder_format(0x00201000 -> 0x00200010) ->
111bbca3a75SChristos Margiolis				feeder_volume(0x00200010) -> hardware]
112c96151d3SKa Ho Ng	provider (STRING): [sound(4)]
113c96151d3SKa Ho Ng.Ed
114c96151d3SKa Ho Ng.Bl -tag -width ".Dv provider_info"
115c96151d3SKa Ho Ng.It Dv from_user
116c96151d3SKa Ho NgWhether the PCM audio device node is created by in-kernel audio subsystem or
117c96151d3SKa Ho Nguserspace providers.
118c96151d3SKa Ho Ng.It Dv nameunit
119c96151d3SKa Ho NgThe device identification in the form of subsystem plus a unit number.
120c96151d3SKa Ho Ng.It Dv devnode
121c96151d3SKa Ho NgThe PCM audio device node relative path in devfs.
122c96151d3SKa Ho Ng.It Dv desc
123ffc4f93eSBenedict ReuschlingThe description of the PCM audio device.
124c96151d3SKa Ho Ng.It Dv pchan
125c96151d3SKa Ho NgThe number of playback channels supported by hardware.
126c96151d3SKa Ho NgThis can be 0 if this PCM audio device does not support playback at all.
127c96151d3SKa Ho Ng.It Dv rchan
128c96151d3SKa Ho NgThe number of recording channels supported by hardware.
129c96151d3SKa Ho NgThis can be 0 if this PCM audio device does not support recording at all.
1304ce1ba65SKa Ho Ng.It Dv info_play
1314ce1ba65SKa Ho NgSupported configurations in playback direction.
1324ce1ba65SKa Ho NgThis exists only if this PCM audio device supports playback.
1334ce1ba65SKa Ho NgThere are a number of name/value pairs inside this field:
1344ce1ba65SKa Ho Ng.Bl -tag -width ".Dv min_rate"
1354ce1ba65SKa Ho Ng.It Dv min_rate
1364ce1ba65SKa Ho NgMinimum supported sampling rate.
1374ce1ba65SKa Ho Ng.It Dv max_rate
1384ce1ba65SKa Ho NgMaximum supported sampling rate.
1394ce1ba65SKa Ho Ng.It Dv formats
1404ce1ba65SKa Ho NgSupported sample formats.
1414ce1ba65SKa Ho Ng.It Dv min_chn
1424ce1ba65SKa Ho NgMinimum supported number of channels in channel layout
1434ce1ba65SKa Ho Ng.It Dv max_chn
1444ce1ba65SKa Ho NgMaximum supported number of channels in channel layout
1454ce1ba65SKa Ho Ng.El
1464ce1ba65SKa Ho Ng.It Dv info_rec
1474ce1ba65SKa Ho NgSupported configurations in recording direction.
1484ce1ba65SKa Ho NgThis exists only if this PCM audio device supports recording.
1494ce1ba65SKa Ho NgThere are a number of name/value pairs inside this field:
1504ce1ba65SKa Ho Ng.Bl -tag -width ".Dv min_rate"
1514ce1ba65SKa Ho Ng.It Dv min_rate
1524ce1ba65SKa Ho NgMinimum supported sampling rate.
1534ce1ba65SKa Ho Ng.It Dv max_rate
1544ce1ba65SKa Ho NgMaximum supported sampling rate.
1554ce1ba65SKa Ho Ng.It Dv formats
1564ce1ba65SKa Ho NgSupported sample formats.
1574ce1ba65SKa Ho Ng.It Dv min_chn
1584ce1ba65SKa Ho NgMinimum supported number of channels in channel layout
1594ce1ba65SKa Ho Ng.It Dv max_chn
1604ce1ba65SKa Ho NgMaximum supported number of channels in channel layout
1614ce1ba65SKa Ho Ng.El
162c96151d3SKa Ho Ng.It Dv provider_info
163c96151d3SKa Ho NgProvider-specific fields.
164c96151d3SKa Ho NgThis field may not exist if the PCM audio device is not provided by in-kernel
165c96151d3SKa Ho Nginterface.
166c96151d3SKa Ho NgThis field will not exist if the provider field is an empty string.
167bbca3a75SChristos MargiolisFor the
168bbca3a75SChristos Margiolis.Xr sound 4
169bbca3a75SChristos Margiolisprovider, there are a number of name/value pairs inside this field:
170bbca3a75SChristos Margiolis.Bl -tag -width ".Dv channel_info"
171bbca3a75SChristos Margiolis.It Dv unit
172bbca3a75SChristos MargiolisSound card unit.
173*810530aaSChristos Margiolis.It Dv status
174*810530aaSChristos MargiolisStatus string.
175*810530aaSChristos MargiolisUsually reports the driver the device is attached on.
176bbca3a75SChristos Margiolis.It Dv bitperfect
177bbca3a75SChristos MargiolisWhether the sound card has bit-perfect mode enabled.
178bbca3a75SChristos Margiolis.It Dv pvchan
179bbca3a75SChristos MargiolisNumber of playback virtual channels.
180bbca3a75SChristos Margiolis.It Dv rvchan
181bbca3a75SChristos MargiolisNumber of recording virtual channels.
182bbca3a75SChristos Margiolis.It Dv channel_info
183bbca3a75SChristos MargiolisChannel information.
184bbca3a75SChristos MargiolisThere are a number of name/value pairs inside this field:
185bbca3a75SChristos Margiolis.Bl -tag -width ".Dv hwbuf_blkcnt"
186bbca3a75SChristos Margiolis.It Dv name
187bbca3a75SChristos MargiolisChannel name.
188bbca3a75SChristos Margiolis.It Dv parenchan
189bbca3a75SChristos MargiolisParent channel name (e.g., in the case of virtual channels).
190bbca3a75SChristos Margiolis.It Dv unit
191bbca3a75SChristos MargiolisChannel unit.
192bbca3a75SChristos Margiolis.It Dv latency
193bbca3a75SChristos MargiolisLatency.
194bbca3a75SChristos Margiolis.It Dv rate
195bbca3a75SChristos MargiolisSampling rate.
196bbca3a75SChristos Margiolis.It Dv format
197bbca3a75SChristos MargiolisSampling format.
198bbca3a75SChristos Margiolis.It Dv pid
199bbca3a75SChristos MargiolisPID of the process consuming the channel.
200bbca3a75SChristos Margiolis.It Dv comm
201bbca3a75SChristos MargiolisName of the process consuming the channel.
202bbca3a75SChristos Margiolis.It Dv interrupts
203bbca3a75SChristos MargiolisNumber of interrupts since the channel has been opened.
204bbca3a75SChristos Margiolis.It Dv xruns
205bbca3a75SChristos MargiolisNumber of overruns/underruns, depending on channel direction.
206bbca3a75SChristos Margiolis.It Dv feedcount
207bbca3a75SChristos MargiolisNumber of read/written bytes since the channel has been opened.
208bbca3a75SChristos Margiolis.It Dv left_volume
209bbca3a75SChristos MargiolisLeft volume.
210bbca3a75SChristos Margiolis.It Dv right_volume
211bbca3a75SChristos MargiolisRight volume.
212bbca3a75SChristos Margiolis.It Dv hwbuf_format
213bbca3a75SChristos MargiolisHardware buffer format.
214bbca3a75SChristos Margiolis.It Dv hwbuf_size
215bbca3a75SChristos MargiolisHardware buffer size.
216bbca3a75SChristos Margiolis.It Dv hwbuf_blksz
217bbca3a75SChristos MargiolisHardware buffer block size.
218bbca3a75SChristos Margiolis.It Dv hwbuf_blkcnt
219bbca3a75SChristos MargiolisHardware buffer block count.
220bbca3a75SChristos Margiolis.It Dv hwbuf_free
221bbca3a75SChristos MargiolisFree space in hardware buffer (in bytes).
222bbca3a75SChristos Margiolis.It Dv hwbuf_ready
223bbca3a75SChristos MargiolisNumber of bytes ready to be read/written from hardware buffer.
224bbca3a75SChristos Margiolis.It Dv swbuf_format
225bbca3a75SChristos MargiolisSoftware buffer format.
226bbca3a75SChristos Margiolis.It Dv swbuf_size
227bbca3a75SChristos MargiolisSoftware buffer size.
228bbca3a75SChristos Margiolis.It Dv swbuf_blksz
229bbca3a75SChristos MargiolisSoftware buffer block size.
230bbca3a75SChristos Margiolis.It Dv swbuf_blkcnt
231bbca3a75SChristos MargiolisSoftware buffer block count.
232bbca3a75SChristos Margiolis.It Dv swbuf_free
233bbca3a75SChristos MargiolisFree space in software buffer (in bytes).
234bbca3a75SChristos Margiolis.It Dv swbuf_ready
235bbca3a75SChristos MargiolisNumber of bytes ready to be read/written from software buffer.
236bbca3a75SChristos Margiolis.It Dv feederchain
237bbca3a75SChristos MargiolisChannel feeder chain.
238bbca3a75SChristos Margiolis.El
239bbca3a75SChristos Margiolis.El
240c96151d3SKa Ho Ng.It Dv provider
241c96151d3SKa Ho NgA string specifying the provider of the PCm audio device.
242c96151d3SKa Ho Ng.El
243c96151d3SKa Ho Ng.Pp
2444ce1ba65SKa Ho NgThe following ioctls are provided for use:
2454ce1ba65SKa Ho Ng.Bl -tag -width ".Dv SNDSTIOC_FLUSH_USER_DEVS"
2464ce1ba65SKa Ho Ng.It Dv SNDSTIOC_REFRESH_DEVS
247c96151d3SKa Ho NgDrop any previously fetched PCM audio devices list snapshots.
248c96151d3SKa Ho NgThis ioctl takes no arguments.
2494ce1ba65SKa Ho Ng.It Dv SNDSTIOC_GET_DEVS
250c96151d3SKa Ho NgGenerate and/or return PCM audio devices list snapshots to callers.
251c96151d3SKa Ho NgThis ioctl takes a pointer to
2524ce1ba65SKa Ho Ng.Fa struct sndstioc_nv_arg
253c96151d3SKa Ho Ngas the first and the only argument.
254c96151d3SKa Ho NgCallers need to provide a sufficiently large buffer to hold a serialized
255c96151d3SKa Ho Ngnvlist.
256c96151d3SKa Ho NgIf there is no existing PCM audio device list snapshot available in the
257c96151d3SKa Ho Nginternal structure of the opened sndstat.
258c96151d3SKa Ho Ng.Fa fd ,
259c96151d3SKa Ho Nga new PCM audio device list snapshot will be automatically generated.
260c96151d3SKa Ho NgCallers have to set
261c96151d3SKa Ho Ng.Fa nbytes
262c96151d3SKa Ho Ngto either 0 or the size of buffer provided.
263c96151d3SKa Ho NgIn case
264c96151d3SKa Ho Ng.Fa nbytes
265c96151d3SKa Ho Ngis 0, the buffer size required to hold a serialized nvlist
266c96151d3SKa Ho Ngstream of current snapshot will be returned in
267c96151d3SKa Ho Ng.Fa nbytes ,
268c96151d3SKa Ho Ngand
269c96151d3SKa Ho Ng.Fa buf
270c96151d3SKa Ho Ngwill be ignored.
271c96151d3SKa Ho NgOtherwise, if the buffer is not sufficiently large,
272c96151d3SKa Ho Ngthe ioctl returns success, and
273c96151d3SKa Ho Ng.Fa nbytes
274c96151d3SKa Ho Ngwill be set to 0.
275c96151d3SKa Ho NgIf the buffer provided is sufficiently large,
276c96151d3SKa Ho Ng.Fa nbytes
277c96151d3SKa Ho Ngwill be set to the size of the serialized nvlist written to the provided buffer.
278c96151d3SKa Ho NgOnce a PCM audio device list snapshot is returned to user-space successfully,
279c96151d3SKa Ho Ngthe snapshot stored in the subsystem's internal structure of the given
280c96151d3SKa Ho Ng.Fa fd
281c96151d3SKa Ho Ngwill be freed.
2824ce1ba65SKa Ho Ng.It Dv SNDSTIOC_ADD_USER_DEVS
283c96151d3SKa Ho NgAdd a list of PCM audio devices provided by callers to
284c96151d3SKa Ho Ng.Pa /dev/sndstat
285c96151d3SKa Ho Ngdevice.
286c96151d3SKa Ho NgThis ioctl takes a pointer to
2874ce1ba65SKa Ho Ng.Fa struct sndstioc_nv_arg
288c96151d3SKa Ho Ngas the first and the only argument.
289c96151d3SKa Ho NgCallers have to provide a buffer holding a serialized nvlist.
290c96151d3SKa Ho Ng.Fa nbytes
291c96151d3SKa Ho Ngshould be set to the length in bytes of the serialized nvlist.
292c96151d3SKa Ho Ng.Fa buf
293c96151d3SKa Ho Ngshould be pointed to a buffer storing the serialized nvlist.
294c96151d3SKa Ho NgUserspace-backed PCM audio device nodes should be listed inside the serialized
295c96151d3SKa Ho Ngnvlist.
2964ce1ba65SKa Ho Ng.It Dv SNDSTIOC_FLUSH_USER_DEVS
297c96151d3SKa Ho NgFlush any PCM audio devices previously added by callers.
298c96151d3SKa Ho NgThis ioctl takes no arguments.
299c96151d3SKa Ho Ng.El
300c96151d3SKa Ho Ng.Sh FILES
301c96151d3SKa Ho Ng.Bl -tag -width ".Pa /dev/sndstat" -compact
302c96151d3SKa Ho Ng.It Pa /dev/sndstat
303c96151d3SKa Ho Ng.El
304c96151d3SKa Ho Ng.Sh EXAMPLES
305c96151d3SKa Ho NgThe following code enumerates all available PCM audio devices:
306c96151d3SKa Ho Ng.Bd -literal -offset indent
307c96151d3SKa Ho Ng#include <sys/types.h>
308c96151d3SKa Ho Ng#include <err.h>
309c96151d3SKa Ho Ng#include <fcntl.h>
310c96151d3SKa Ho Ng#include <stdio.h>
311c96151d3SKa Ho Ng#include <stdlib.h>
312c96151d3SKa Ho Ng#include <sys/nv.h>
313c96151d3SKa Ho Ng#include <sys/sndstat.h>
314c96151d3SKa Ho Ng#include <sysexits.h>
315c96151d3SKa Ho Ng#include <unistd.h>
316c96151d3SKa Ho Ng
317c96151d3SKa Ho Ngint
318c96151d3SKa Ho Ngmain()
319c96151d3SKa Ho Ng{
320c96151d3SKa Ho Ng	int fd;
3214ce1ba65SKa Ho Ng	struct sndstioc_nv_arg arg;
322c96151d3SKa Ho Ng	const nvlist_t * const *di;
323c96151d3SKa Ho Ng	size_t i, nitems;
324c96151d3SKa Ho Ng	nvlist_t *nvl;
325c96151d3SKa Ho Ng
326c96151d3SKa Ho Ng	/* Open sndstat node in read-only first */
327c96151d3SKa Ho Ng	fd = open("/dev/sndstat", O_RDONLY);
328c96151d3SKa Ho Ng
3294ce1ba65SKa Ho Ng	if (ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL))
3304ce1ba65SKa Ho Ng		err(1, "ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL)");
331c96151d3SKa Ho Ng
332c96151d3SKa Ho Ng	/* Get the size of snapshot, when nbytes = 0 */
333c96151d3SKa Ho Ng	arg.nbytes = 0;
334c96151d3SKa Ho Ng	arg.buf = NULL;
3354ce1ba65SKa Ho Ng	if (ioctl(fd, SNDSTIOC_GET_DEVS, &arg))
3364ce1ba65SKa Ho Ng		err(1, "ioctl(fd, SNDSTIOC_GET_DEVS, &arg)");
337c96151d3SKa Ho Ng
338c96151d3SKa Ho Ng	/* Get snapshot data */
339c96151d3SKa Ho Ng	arg.buf = malloc(arg.nbytes);
340c96151d3SKa Ho Ng	if (arg.buf == NULL)
341c96151d3SKa Ho Ng		err(EX_OSERR, "malloc");
3424ce1ba65SKa Ho Ng	if (ioctl(fd, SNDSTIOC_GET_DEVS, &arg))
3434ce1ba65SKa Ho Ng		err(1, "ioctl(fd, SNDSTIOC_GET_DEVS, &arg)");
344c96151d3SKa Ho Ng
345c96151d3SKa Ho Ng	/* Deserialize the nvlist stream */
346c96151d3SKa Ho Ng	nvl = nvlist_unpack(arg.buf, arg.nbytes, 0);
347c96151d3SKa Ho Ng	free(arg.buf);
348c96151d3SKa Ho Ng
349c96151d3SKa Ho Ng	/* Get DSPs array */
3504ce1ba65SKa Ho Ng	di = nvlist_get_nvlist_array(nvl, SNDST_DSPS, &nitems);
351c96151d3SKa Ho Ng	for (i = 0; i < nitems; i++) {
352c96151d3SKa Ho Ng		const char *nameunit, *devnode, *desc;
353c96151d3SKa Ho Ng
354c96151d3SKa Ho Ng		/*
355c96151d3SKa Ho Ng		 * Examine each device nvlist item
356c96151d3SKa Ho Ng		 */
357c96151d3SKa Ho Ng
3584ce1ba65SKa Ho Ng		nameunit = nvlist_get_string(di[i], SNDST_DSPS_NAMEUNIT);
3594ce1ba65SKa Ho Ng		devnode = nvlist_get_string(di[i], SNDST_DSPS_DEVNODE);
3604ce1ba65SKa Ho Ng		desc = nvlist_get_string(di[i], SNDST_DSPS_DESC);
361c96151d3SKa Ho Ng		printf("Name unit: `%s`, Device node: `%s`, Description: `%s`\n",
362c96151d3SKa Ho Ng		    nameunit, devnode, desc);
363c96151d3SKa Ho Ng	}
364c96151d3SKa Ho Ng
365c96151d3SKa Ho Ng	nvlist_destroy(nvl);
366c96151d3SKa Ho Ng	return (0);
367c96151d3SKa Ho Ng}
368c96151d3SKa Ho Ng.Ed
369c96151d3SKa Ho Ng.Sh SEE ALSO
370c96151d3SKa Ho Ng.Xr sound 4 ,
371c96151d3SKa Ho Ng.Xr nv 9
372c96151d3SKa Ho Ng.Sh HISTORY
373c96151d3SKa Ho NgThe nvlist-based ioctls support for
374c96151d3SKa Ho Ng.Nm
375c96151d3SKa Ho Ngdevice first appeared in
376c96151d3SKa Ho Ng.Fx 13.0 .
377c96151d3SKa Ho Ng.Sh AUTHORS
378c96151d3SKa Ho NgThis manual page was written by
379c96151d3SKa Ho Ng.An Ka Ho Ng Aq Mt khng@FreeBSD.org .
380