xref: /freebsd/share/man/man4/sndstat.4 (revision f0eceecf5ab51a68d713f9a5a7f360964d0a49ce)
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.
32810530aaSChristos 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
77810530aaSChristos Margiolis		status (STRING): on hdaa0
78c96151d3SKa Ho Ng		bitperfect (BOOL): FALSE
79bbca3a75SChristos Margiolis		pvchan (NUMBER): 1
80a6283717SChristos Margiolis		pvchanrate (NUMBER): 48000
81a6283717SChristos Margiolis		pvchanformat (NUMBER): 0x00000010
82bbca3a75SChristos Margiolis		rvchan (NUMBER): 0
83a6283717SChristos Margiolis		rvchanrate (NUMBER): 48000
84a6283717SChristos Margiolis		rvchanformat (NUMBER): 0x00000010
85bbca3a75SChristos Margiolis		channel_info (NVLIST_ARRAY): 1
86bbca3a75SChristos Margiolis			name (STRING): pcm0:virtual_play:dsp0.vp0
87bbca3a75SChristos Margiolis			parentchan (STRING): pcm0:play:dsp0.p0
88bbca3a75SChristos Margiolis			unit (NUMBER): 1
89bd5bcc84SChristos Margiolis			caps (NUMBER): 0x073200
90bbca3a75SChristos Margiolis			latency (NUMBER): 2
91bbca3a75SChristos Margiolis			rate (NUMBER): 48000
92bbca3a75SChristos Margiolis			format (NUMBER): 0x201000
93bbca3a75SChristos Margiolis			pid (NUMBER): 1234
94bbca3a75SChristos Margiolis			comm (STRING): mpv
95bbca3a75SChristos Margiolis			interrupts (NUMBER): 0
96bbca3a75SChristos Margiolis			feedcount (NUMBER): 0
97bbca3a75SChristos Margiolis			xruns (NUMBER): 0
98bbca3a75SChristos Margiolis			left_volume (NUMBER): 45
99bbca3a75SChristos Margiolis			right_volume (NUMBER): 45
100bbca3a75SChristos Margiolis			hwbuf_fmt (NUMBER): 0x200010
101bbca3a75SChristos Margiolis			hwbuf_size (NUMBER): 0
102bbca3a75SChristos Margiolis			hwbuf_blksz (NUMBER): 0
103bbca3a75SChristos Margiolis			hwbuf_blkcnt (NUMBER): 0
104bbca3a75SChristos Margiolis			hwbuf_free (NUMBER): 0
105bbca3a75SChristos Margiolis			hwbuf_ready (NUMBER): 0
106bbca3a75SChristos Margiolis			swbuf_fmt (NUMBER): 0x201000
107bbca3a75SChristos Margiolis			swbuf_size (NUMBER): 16384
108bbca3a75SChristos Margiolis			swbuf_blksz (NUMBER): 2048
109bbca3a75SChristos Margiolis			swbuf_blkcnt (NUMBER): 8
110bbca3a75SChristos Margiolis			swbuf_free (NUMBER): 16384
111bbca3a75SChristos Margiolis			swbuf_ready (NUMBER): 0
112bbca3a75SChristos Margiolis			feederchain (STRING):
113bbca3a75SChristos Margiolis				[userland ->
114bbca3a75SChristos Margiolis				feeder_root(0x00201000) ->
115bbca3a75SChristos Margiolis				feeder_format(0x00201000 -> 0x00200010) ->
116bbca3a75SChristos Margiolis				feeder_volume(0x00200010) -> hardware]
117c96151d3SKa Ho Ng	provider (STRING): [sound(4)]
118c96151d3SKa Ho Ng.Ed
119c96151d3SKa Ho Ng.Bl -tag -width ".Dv provider_info"
120c96151d3SKa Ho Ng.It Dv from_user
121c96151d3SKa Ho NgWhether the PCM audio device node is created by in-kernel audio subsystem or
122c96151d3SKa Ho Nguserspace providers.
123c96151d3SKa Ho Ng.It Dv nameunit
124c96151d3SKa Ho NgThe device identification in the form of subsystem plus a unit number.
125c96151d3SKa Ho Ng.It Dv devnode
126c96151d3SKa Ho NgThe PCM audio device node relative path in devfs.
127c96151d3SKa Ho Ng.It Dv desc
128ffc4f93eSBenedict ReuschlingThe description of the PCM audio device.
129c96151d3SKa Ho Ng.It Dv pchan
130c96151d3SKa Ho NgThe number of playback channels supported by hardware.
131c96151d3SKa Ho NgThis can be 0 if this PCM audio device does not support playback at all.
132c96151d3SKa Ho Ng.It Dv rchan
133c96151d3SKa Ho NgThe number of recording channels supported by hardware.
134c96151d3SKa Ho NgThis can be 0 if this PCM audio device does not support recording at all.
1354ce1ba65SKa Ho Ng.It Dv info_play
1364ce1ba65SKa Ho NgSupported configurations in playback direction.
1374ce1ba65SKa Ho NgThis exists only if this PCM audio device supports playback.
1384ce1ba65SKa Ho NgThere are a number of name/value pairs inside this field:
1394ce1ba65SKa Ho Ng.Bl -tag -width ".Dv min_rate"
1404ce1ba65SKa Ho Ng.It Dv min_rate
1414ce1ba65SKa Ho NgMinimum supported sampling rate.
1424ce1ba65SKa Ho Ng.It Dv max_rate
1434ce1ba65SKa Ho NgMaximum supported sampling rate.
1444ce1ba65SKa Ho Ng.It Dv formats
1454ce1ba65SKa Ho NgSupported sample formats.
1464ce1ba65SKa Ho Ng.It Dv min_chn
1474ce1ba65SKa Ho NgMinimum supported number of channels in channel layout
1484ce1ba65SKa Ho Ng.It Dv max_chn
1494ce1ba65SKa Ho NgMaximum supported number of channels in channel layout
1504ce1ba65SKa Ho Ng.El
1514ce1ba65SKa Ho Ng.It Dv info_rec
1524ce1ba65SKa Ho NgSupported configurations in recording direction.
1534ce1ba65SKa Ho NgThis exists only if this PCM audio device supports recording.
1544ce1ba65SKa Ho NgThere are a number of name/value pairs inside this field:
1554ce1ba65SKa Ho Ng.Bl -tag -width ".Dv min_rate"
1564ce1ba65SKa Ho Ng.It Dv min_rate
1574ce1ba65SKa Ho NgMinimum supported sampling rate.
1584ce1ba65SKa Ho Ng.It Dv max_rate
1594ce1ba65SKa Ho NgMaximum supported sampling rate.
1604ce1ba65SKa Ho Ng.It Dv formats
1614ce1ba65SKa Ho NgSupported sample formats.
1624ce1ba65SKa Ho Ng.It Dv min_chn
1634ce1ba65SKa Ho NgMinimum supported number of channels in channel layout
1644ce1ba65SKa Ho Ng.It Dv max_chn
1654ce1ba65SKa Ho NgMaximum supported number of channels in channel layout
1664ce1ba65SKa Ho Ng.El
167c96151d3SKa Ho Ng.It Dv provider_info
168c96151d3SKa Ho NgProvider-specific fields.
169c96151d3SKa Ho NgThis field may not exist if the PCM audio device is not provided by in-kernel
170c96151d3SKa Ho Nginterface.
171c96151d3SKa Ho NgThis field will not exist if the provider field is an empty string.
172bbca3a75SChristos MargiolisFor the
173bbca3a75SChristos Margiolis.Xr sound 4
174bbca3a75SChristos Margiolisprovider, there are a number of name/value pairs inside this field:
175bbca3a75SChristos Margiolis.Bl -tag -width ".Dv channel_info"
176bbca3a75SChristos Margiolis.It Dv unit
177bbca3a75SChristos MargiolisSound card unit.
178810530aaSChristos Margiolis.It Dv status
179810530aaSChristos MargiolisStatus string.
180810530aaSChristos MargiolisUsually reports the driver the device is attached on.
181bbca3a75SChristos Margiolis.It Dv bitperfect
182bbca3a75SChristos MargiolisWhether the sound card has bit-perfect mode enabled.
183bbca3a75SChristos Margiolis.It Dv pvchan
184bbca3a75SChristos MargiolisNumber of playback virtual channels.
185a6283717SChristos Margiolis.It Dv pvchanrate
186a6283717SChristos MargiolisPlayback virtual channel sample rate.
187a6283717SChristos Margiolis.It Dv pvchanformat
188a6283717SChristos MargiolisPlayback virtual channel format.
189bbca3a75SChristos Margiolis.It Dv rvchan
190bbca3a75SChristos MargiolisNumber of recording virtual channels.
191a6283717SChristos Margiolis.It Dv rvchanrate
192a6283717SChristos MargiolisRecording virtual channel sample rate.
193a6283717SChristos Margiolis.It Dv rvchanformat
194a6283717SChristos MargiolisRecording virtual channel format.
195bbca3a75SChristos Margiolis.It Dv channel_info
196bbca3a75SChristos MargiolisChannel information.
197bbca3a75SChristos MargiolisThere are a number of name/value pairs inside this field:
198bbca3a75SChristos Margiolis.Bl -tag -width ".Dv hwbuf_blkcnt"
199bbca3a75SChristos Margiolis.It Dv name
200bbca3a75SChristos MargiolisChannel name.
201*f0eceecfSChristos Margiolis.It Dv parentchan
202bbca3a75SChristos MargiolisParent channel name (e.g., in the case of virtual channels).
203bbca3a75SChristos Margiolis.It Dv unit
204bbca3a75SChristos MargiolisChannel unit.
205bd5bcc84SChristos Margiolis.It Dv caps
206bd5bcc84SChristos MargiolisOSS capabilities.
207bbca3a75SChristos Margiolis.It Dv latency
208bbca3a75SChristos MargiolisLatency.
209bbca3a75SChristos Margiolis.It Dv rate
210bbca3a75SChristos MargiolisSampling rate.
211bbca3a75SChristos Margiolis.It Dv format
212bbca3a75SChristos MargiolisSampling format.
213bbca3a75SChristos Margiolis.It Dv pid
214bbca3a75SChristos MargiolisPID of the process consuming the channel.
215bbca3a75SChristos Margiolis.It Dv comm
216bbca3a75SChristos MargiolisName of the process consuming the channel.
217bbca3a75SChristos Margiolis.It Dv interrupts
218bbca3a75SChristos MargiolisNumber of interrupts since the channel has been opened.
219bbca3a75SChristos Margiolis.It Dv xruns
220bbca3a75SChristos MargiolisNumber of overruns/underruns, depending on channel direction.
221bbca3a75SChristos Margiolis.It Dv feedcount
222bbca3a75SChristos MargiolisNumber of read/written bytes since the channel has been opened.
223bbca3a75SChristos Margiolis.It Dv left_volume
224bbca3a75SChristos MargiolisLeft volume.
225bbca3a75SChristos Margiolis.It Dv right_volume
226bbca3a75SChristos MargiolisRight volume.
227bbca3a75SChristos Margiolis.It Dv hwbuf_format
228bbca3a75SChristos MargiolisHardware buffer format.
229bbca3a75SChristos Margiolis.It Dv hwbuf_size
230bbca3a75SChristos MargiolisHardware buffer size.
231bbca3a75SChristos Margiolis.It Dv hwbuf_blksz
232bbca3a75SChristos MargiolisHardware buffer block size.
233bbca3a75SChristos Margiolis.It Dv hwbuf_blkcnt
234bbca3a75SChristos MargiolisHardware buffer block count.
235bbca3a75SChristos Margiolis.It Dv hwbuf_free
236bbca3a75SChristos MargiolisFree space in hardware buffer (in bytes).
237bbca3a75SChristos Margiolis.It Dv hwbuf_ready
238bbca3a75SChristos MargiolisNumber of bytes ready to be read/written from hardware buffer.
239bbca3a75SChristos Margiolis.It Dv swbuf_format
240bbca3a75SChristos MargiolisSoftware buffer format.
241bbca3a75SChristos Margiolis.It Dv swbuf_size
242bbca3a75SChristos MargiolisSoftware buffer size.
243bbca3a75SChristos Margiolis.It Dv swbuf_blksz
244bbca3a75SChristos MargiolisSoftware buffer block size.
245bbca3a75SChristos Margiolis.It Dv swbuf_blkcnt
246bbca3a75SChristos MargiolisSoftware buffer block count.
247bbca3a75SChristos Margiolis.It Dv swbuf_free
248bbca3a75SChristos MargiolisFree space in software buffer (in bytes).
249bbca3a75SChristos Margiolis.It Dv swbuf_ready
250bbca3a75SChristos MargiolisNumber of bytes ready to be read/written from software buffer.
251bbca3a75SChristos Margiolis.It Dv feederchain
252bbca3a75SChristos MargiolisChannel feeder chain.
253bbca3a75SChristos Margiolis.El
254bbca3a75SChristos Margiolis.El
255c96151d3SKa Ho Ng.It Dv provider
256c96151d3SKa Ho NgA string specifying the provider of the PCm audio device.
257c96151d3SKa Ho Ng.El
258c96151d3SKa Ho Ng.Pp
2594ce1ba65SKa Ho NgThe following ioctls are provided for use:
2604ce1ba65SKa Ho Ng.Bl -tag -width ".Dv SNDSTIOC_FLUSH_USER_DEVS"
2614ce1ba65SKa Ho Ng.It Dv SNDSTIOC_REFRESH_DEVS
262c96151d3SKa Ho NgDrop any previously fetched PCM audio devices list snapshots.
263c96151d3SKa Ho NgThis ioctl takes no arguments.
2644ce1ba65SKa Ho Ng.It Dv SNDSTIOC_GET_DEVS
265c96151d3SKa Ho NgGenerate and/or return PCM audio devices list snapshots to callers.
266c96151d3SKa Ho NgThis ioctl takes a pointer to
2674ce1ba65SKa Ho Ng.Fa struct sndstioc_nv_arg
268c96151d3SKa Ho Ngas the first and the only argument.
269c96151d3SKa Ho NgCallers need to provide a sufficiently large buffer to hold a serialized
270c96151d3SKa Ho Ngnvlist.
271c96151d3SKa Ho NgIf there is no existing PCM audio device list snapshot available in the
272c96151d3SKa Ho Nginternal structure of the opened sndstat.
273c96151d3SKa Ho Ng.Fa fd ,
274c96151d3SKa Ho Nga new PCM audio device list snapshot will be automatically generated.
275c96151d3SKa Ho NgCallers have to set
276c96151d3SKa Ho Ng.Fa nbytes
277c96151d3SKa Ho Ngto either 0 or the size of buffer provided.
278c96151d3SKa Ho NgIn case
279c96151d3SKa Ho Ng.Fa nbytes
280c96151d3SKa Ho Ngis 0, the buffer size required to hold a serialized nvlist
281c96151d3SKa Ho Ngstream of current snapshot will be returned in
282c96151d3SKa Ho Ng.Fa nbytes ,
283c96151d3SKa Ho Ngand
284c96151d3SKa Ho Ng.Fa buf
285c96151d3SKa Ho Ngwill be ignored.
286c96151d3SKa Ho NgOtherwise, if the buffer is not sufficiently large,
287c96151d3SKa Ho Ngthe ioctl returns success, and
288c96151d3SKa Ho Ng.Fa nbytes
289c96151d3SKa Ho Ngwill be set to 0.
290c96151d3SKa Ho NgIf the buffer provided is sufficiently large,
291c96151d3SKa Ho Ng.Fa nbytes
292c96151d3SKa Ho Ngwill be set to the size of the serialized nvlist written to the provided buffer.
293c96151d3SKa Ho NgOnce a PCM audio device list snapshot is returned to user-space successfully,
294c96151d3SKa Ho Ngthe snapshot stored in the subsystem's internal structure of the given
295c96151d3SKa Ho Ng.Fa fd
296c96151d3SKa Ho Ngwill be freed.
2974ce1ba65SKa Ho Ng.It Dv SNDSTIOC_ADD_USER_DEVS
298c96151d3SKa Ho NgAdd a list of PCM audio devices provided by callers to
299c96151d3SKa Ho Ng.Pa /dev/sndstat
300c96151d3SKa Ho Ngdevice.
301c96151d3SKa Ho NgThis ioctl takes a pointer to
3024ce1ba65SKa Ho Ng.Fa struct sndstioc_nv_arg
303c96151d3SKa Ho Ngas the first and the only argument.
304c96151d3SKa Ho NgCallers have to provide a buffer holding a serialized nvlist.
305c96151d3SKa Ho Ng.Fa nbytes
306c96151d3SKa Ho Ngshould be set to the length in bytes of the serialized nvlist.
307c96151d3SKa Ho Ng.Fa buf
308c96151d3SKa Ho Ngshould be pointed to a buffer storing the serialized nvlist.
309c96151d3SKa Ho NgUserspace-backed PCM audio device nodes should be listed inside the serialized
310c96151d3SKa Ho Ngnvlist.
3114ce1ba65SKa Ho Ng.It Dv SNDSTIOC_FLUSH_USER_DEVS
312c96151d3SKa Ho NgFlush any PCM audio devices previously added by callers.
313c96151d3SKa Ho NgThis ioctl takes no arguments.
314c96151d3SKa Ho Ng.El
315c96151d3SKa Ho Ng.Sh FILES
316c96151d3SKa Ho Ng.Bl -tag -width ".Pa /dev/sndstat" -compact
317c96151d3SKa Ho Ng.It Pa /dev/sndstat
318c96151d3SKa Ho Ng.El
319c96151d3SKa Ho Ng.Sh EXAMPLES
320c96151d3SKa Ho NgThe following code enumerates all available PCM audio devices:
321c96151d3SKa Ho Ng.Bd -literal -offset indent
322c96151d3SKa Ho Ng#include <sys/types.h>
323c96151d3SKa Ho Ng#include <err.h>
324c96151d3SKa Ho Ng#include <fcntl.h>
325c96151d3SKa Ho Ng#include <stdio.h>
326c96151d3SKa Ho Ng#include <stdlib.h>
327c96151d3SKa Ho Ng#include <sys/nv.h>
328c96151d3SKa Ho Ng#include <sys/sndstat.h>
329c96151d3SKa Ho Ng#include <sysexits.h>
330c96151d3SKa Ho Ng#include <unistd.h>
331c96151d3SKa Ho Ng
332c96151d3SKa Ho Ngint
333c96151d3SKa Ho Ngmain()
334c96151d3SKa Ho Ng{
335c96151d3SKa Ho Ng	int fd;
3364ce1ba65SKa Ho Ng	struct sndstioc_nv_arg arg;
337c96151d3SKa Ho Ng	const nvlist_t * const *di;
338c96151d3SKa Ho Ng	size_t i, nitems;
339c96151d3SKa Ho Ng	nvlist_t *nvl;
340c96151d3SKa Ho Ng
341c96151d3SKa Ho Ng	/* Open sndstat node in read-only first */
342c96151d3SKa Ho Ng	fd = open("/dev/sndstat", O_RDONLY);
343c96151d3SKa Ho Ng
3444ce1ba65SKa Ho Ng	if (ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL))
3454ce1ba65SKa Ho Ng		err(1, "ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL)");
346c96151d3SKa Ho Ng
347c96151d3SKa Ho Ng	/* Get the size of snapshot, when nbytes = 0 */
348c96151d3SKa Ho Ng	arg.nbytes = 0;
349c96151d3SKa Ho Ng	arg.buf = NULL;
3504ce1ba65SKa Ho Ng	if (ioctl(fd, SNDSTIOC_GET_DEVS, &arg))
3514ce1ba65SKa Ho Ng		err(1, "ioctl(fd, SNDSTIOC_GET_DEVS, &arg)");
352c96151d3SKa Ho Ng
353c96151d3SKa Ho Ng	/* Get snapshot data */
354c96151d3SKa Ho Ng	arg.buf = malloc(arg.nbytes);
355c96151d3SKa Ho Ng	if (arg.buf == NULL)
356c96151d3SKa Ho Ng		err(EX_OSERR, "malloc");
3574ce1ba65SKa Ho Ng	if (ioctl(fd, SNDSTIOC_GET_DEVS, &arg))
3584ce1ba65SKa Ho Ng		err(1, "ioctl(fd, SNDSTIOC_GET_DEVS, &arg)");
359c96151d3SKa Ho Ng
360c96151d3SKa Ho Ng	/* Deserialize the nvlist stream */
361c96151d3SKa Ho Ng	nvl = nvlist_unpack(arg.buf, arg.nbytes, 0);
362c96151d3SKa Ho Ng	free(arg.buf);
363c96151d3SKa Ho Ng
364c96151d3SKa Ho Ng	/* Get DSPs array */
3654ce1ba65SKa Ho Ng	di = nvlist_get_nvlist_array(nvl, SNDST_DSPS, &nitems);
366c96151d3SKa Ho Ng	for (i = 0; i < nitems; i++) {
367c96151d3SKa Ho Ng		const char *nameunit, *devnode, *desc;
368c96151d3SKa Ho Ng
369c96151d3SKa Ho Ng		/*
370c96151d3SKa Ho Ng		 * Examine each device nvlist item
371c96151d3SKa Ho Ng		 */
372c96151d3SKa Ho Ng
3734ce1ba65SKa Ho Ng		nameunit = nvlist_get_string(di[i], SNDST_DSPS_NAMEUNIT);
3744ce1ba65SKa Ho Ng		devnode = nvlist_get_string(di[i], SNDST_DSPS_DEVNODE);
3754ce1ba65SKa Ho Ng		desc = nvlist_get_string(di[i], SNDST_DSPS_DESC);
376c96151d3SKa Ho Ng		printf("Name unit: `%s`, Device node: `%s`, Description: `%s`\n",
377c96151d3SKa Ho Ng		    nameunit, devnode, desc);
378c96151d3SKa Ho Ng	}
379c96151d3SKa Ho Ng
380c96151d3SKa Ho Ng	nvlist_destroy(nvl);
381c96151d3SKa Ho Ng	return (0);
382c96151d3SKa Ho Ng}
383c96151d3SKa Ho Ng.Ed
384c96151d3SKa Ho Ng.Sh SEE ALSO
385c96151d3SKa Ho Ng.Xr sound 4 ,
386c96151d3SKa Ho Ng.Xr nv 9
387c96151d3SKa Ho Ng.Sh HISTORY
388c96151d3SKa Ho NgThe nvlist-based ioctls support for
389c96151d3SKa Ho Ng.Nm
390c96151d3SKa Ho Ngdevice first appeared in
391c96151d3SKa Ho Ng.Fx 13.0 .
392c96151d3SKa Ho Ng.Sh AUTHORS
393c96151d3SKa Ho NgThis manual page was written by
394c96151d3SKa Ho Ng.An Ka Ho Ng Aq Mt khng@FreeBSD.org .
395