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