diff options
author | nia <nia@netbsd.org> | 2020-03-11 23:16:28 +0000 |
---|---|---|
committer | nia <nia@netbsd.org> | 2020-03-11 23:29:56 +0000 |
commit | 9b8403ac84fb638bd317e1d3cf0d807f375de7dc (patch) | |
tree | 2352cfde543011b1af4246072a6590a3b41e49d2 /src/print_volume.c | |
parent | 6eb70f10d202e1d6ea7f7c01527191de6e861872 (diff) |
print_volume: Native NetBSD audio support
Avoid using the OSS emulation layer to fetch the master volume,
and instead share the audioio code with OpenBSD.
Avoid a failed read on the master control's mute enum if it can't
be found, because sometimes there isn't one.
Diffstat (limited to 'src/print_volume.c')
-rw-r--r-- | src/print_volume.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/print_volume.c b/src/print_volume.c index 575024a..89955a8 100644 --- a/src/print_volume.c +++ b/src/print_volume.c @@ -15,13 +15,13 @@ #include <math.h> #endif -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) +#if defined(__FreeBSD__) || defined(__DragonFly__) #include <fcntl.h> #include <unistd.h> #include <sys/soundcard.h> #endif -#if defined(__OpenBSD__) +#if defined(__NetBSD__) || defined(__OpenBSD__) #include <fcntl.h> #include <unistd.h> #include <sys/audioio.h> @@ -261,7 +261,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char * mixerpath = defaultmixer; if ((mixfd = open(mixerpath, O_RDWR)) < 0) { -#if defined(__OpenBSD__) +#if defined(__NetBSD__) || defined(__OpenBSD__) warn("audioio: Cannot open mixer"); #else warn("OSS: Cannot open mixer"); @@ -272,7 +272,7 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char * if (mixer_idx > 0) free(mixerpath); -#if defined(__OpenBSD__) +#if defined(__NetBSD__) || defined(__OpenBSD__) int oclass_idx = -1, master_idx = -1, master_mute_idx = -1; int master_next = AUDIO_MIXER_LAST; mixer_devinfo_t devinfo, devinfo2; @@ -327,15 +327,17 @@ void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char * vol = (int)vinfo.un.value.level[AUDIO_MIXER_LEVEL_MONO]; } - vinfo.dev = master_mute_idx; - vinfo.type = AUDIO_MIXER_ENUM; - if (ioctl(mixfd, AUDIO_MIXER_READ, &vinfo) == -1) - goto out; + if (master_mute_idx != -1) { + vinfo.dev = master_mute_idx; + vinfo.type = AUDIO_MIXER_ENUM; + if (ioctl(mixfd, AUDIO_MIXER_READ, &vinfo) == -1) + goto out; - if (master_mute_idx != -1 && vinfo.un.ord) { - START_COLOR("color_degraded"); - fmt = fmt_muted; - pbval = 0; + if (vinfo.un.ord) { + START_COLOR("color_degraded"); + fmt = fmt_muted; + pbval = 0; + } } #else |