Module Name: src
Committed By: nia
Date: Fri Nov 13 09:02:39 UTC 2020
Modified Files:
src/lib/libossaudio: ossaudio.c
Log Message:
ossaudio(3): Clone some useful behaviour from the Solaris kernel
Both SNDCTL_DSP_SPEED and SNDCTL_DSP_CHANNELS support a special value
0 to "query the configured value without changing it". In our case,
this actually means setting and querying the hardware rate.
I don't know if OSSv3 or FreeBSD or other implementations also do this.
But it seems safe and sensible to support.
To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libossaudio/ossaudio.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libossaudio/ossaudio.c
diff -u src/lib/libossaudio/ossaudio.c:1.63 src/lib/libossaudio/ossaudio.c:1.64
--- src/lib/libossaudio/ossaudio.c:1.63 Wed Nov 4 22:59:24 2020
+++ src/lib/libossaudio/ossaudio.c Fri Nov 13 09:02:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ossaudio.c,v 1.63 2020/11/04 22:59:24 nia Exp $ */
+/* $NetBSD: ossaudio.c,v 1.64 2020/11/13 09:02:39 nia Exp $ */
/*-
* Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: ossaudio.c,v 1.63 2020/11/04 22:59:24 nia Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.64 2020/11/13 09:02:39 nia Exp $");
/*
* This is an Open Sound System compatibility layer, which provides
@@ -184,7 +184,26 @@ audio_ioctl(int fd, unsigned long com, v
break;
case SNDCTL_DSP_SPEED:
AUDIO_INITINFO(&tmpinfo);
- /* Conform to kernel limits. */
+ /*
+ * In Solaris, 0 is used a special value to query the
+ * current rate. This seems useful to support.
+ */
+ if (INTARG == 0) {
+ retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
+ if (retval < 0)
+ return retval;
+ retval = ioctl(fd, AUDIO_GETFORMAT, &hwfmt);
+ if (retval < 0)
+ return retval;
+ INTARG = (tmpinfo.mode == AUMODE_RECORD) ?
+ hwfmt.record.sample_rate :
+ hwfmt.play.sample_rate;
+ }
+ /*
+ * Conform to kernel limits.
+ * NetBSD will reject unsupported sample rates, but OSS
+ * applications need to be able to negotiate a supported one.
+ */
if (INTARG < 1000)
INTARG = 1000;
if (INTARG > 192000)
@@ -1708,6 +1727,8 @@ setvol(int fd, int volume, bool record)
* case an application is abusing SNDCTL_DSP_CHANNELS - OSSv4 always sets and
* returns a reasonable value, even if it wasn't what the user requested.
*
+ * Solaris guarantees this behaviour if nchannels = 0.
+ *
* XXX: If a device is opened for both playback and recording, and supports
* fewer channels for recording than playback, applications that do both will
* behave very strangely. OSS doesn't allow for reporting separate channel