Module Name:    src
Committed By:   nia
Date:           Fri Oct 16 20:24:35 UTC 2020

Modified Files:
        src/lib/libossaudio: ossaudio.c soundcard.h

Log Message:
ossaudio(3): Add SNDCTL_DSP_COOKEDMODE, SNDCTL_DSP_GETERROR

SNDCTL_DSP_COOKEDMODE simply always returns 1.
"Cooked mode" is a silly way the OSSv4 authors chose to refer to allowing
for reprocessed streams. The NetBSD kernel always performs format
conversion and it can't be turned off.

SNDCTL_DSP_GETERROR provides access to the read/write over/underrun
counters. There are other things it might return, but they don't make
sense for our implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/lib/libossaudio/ossaudio.c
cvs rdiff -u -r1.24 -r1.25 src/lib/libossaudio/soundcard.h

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.47 src/lib/libossaudio/ossaudio.c:1.48
--- src/lib/libossaudio/ossaudio.c:1.47	Fri Oct 16 15:40:16 2020
+++ src/lib/libossaudio/ossaudio.c	Fri Oct 16 20:24:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ossaudio.c,v 1.47 2020/10/16 15:40:16 nia Exp $	*/
+/*	$NetBSD: ossaudio.c,v 1.48 2020/10/16 20:24:35 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: ossaudio.c,v 1.47 2020/10/16 15:40:16 nia Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.48 2020/10/16 20:24:35 nia Exp $");
 
 /*
  * This is an Open Sound System compatibility layer, which provides
@@ -106,6 +106,7 @@ audio_ioctl(int fd, unsigned long com, v
 	struct audio_offset tmpoffs;
 	struct audio_buf_info bufinfo;
 	struct audio_format_query fmtq;
+	struct audio_errinfo *tmperrinfo;
 	struct count_info cntinfo;
 	struct audio_encoding tmpenc;
 	struct oss_sysinfo tmpsysinfo;
@@ -118,6 +119,9 @@ audio_ioctl(int fd, unsigned long com, v
 	u_int u;
 	u_int encoding;
 	u_int precision;
+	int perrors, rerrors;
+	static int totalperrors = 0;
+	static int totalrerrors = 0;
 	int idat, idata;
 	int props;
 	int retval;
@@ -136,6 +140,39 @@ audio_ioctl(int fd, unsigned long com, v
 		if (retval < 0)
 			return retval;
 		break;
+	case SNDCTL_DSP_GETERROR:
+		tmperrinfo = (struct audio_errinfo *)argp;
+		if (tmperrinfo == NULL)
+			return EINVAL;
+		memset(tmperrinfo, 0, sizeof(struct audio_errinfo));
+		if ((retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo)) < 0)
+			return retval;
+		/*
+		 * OSS requires that we return counters that are relative to
+		 * the last call. We must maintain state here...
+		 */
+		if (ioctl(fd, AUDIO_PERROR, &perrors) != -1) {
+			perrors /= ((tmpinfo.play.precision / NBBY) *
+			    tmpinfo.play.channels);
+			tmperrinfo->play_underruns =
+			    (perrors / tmpinfo.blocksize) - totalperrors;
+			totalperrors += tmperrinfo->play_underruns;
+		}
+		if (ioctl(fd, AUDIO_RERROR, &rerrors) != -1) {
+			rerrors /= ((tmpinfo.record.precision / NBBY) *
+			    tmpinfo.record.channels);
+			tmperrinfo->rec_overruns =
+			    (rerrors / tmpinfo.blocksize) - totalrerrors;
+			totalrerrors += tmperrinfo->rec_overruns;
+		}
+		break;
+	case SNDCTL_DSP_COOKEDMODE:
+		/*
+		 * NetBSD is always running in "cooked mode" - the kernel
+		 * always performs format conversions.
+		 */
+		INTARG = 1;
+		break;
 	case SNDCTL_DSP_POST:
 		/* This call is merely advisory, and may be a nop. */
 		break;

Index: src/lib/libossaudio/soundcard.h
diff -u src/lib/libossaudio/soundcard.h:1.24 src/lib/libossaudio/soundcard.h:1.25
--- src/lib/libossaudio/soundcard.h:1.24	Tue Sep  9 10:45:18 2014
+++ src/lib/libossaudio/soundcard.h	Fri Oct 16 20:24:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: soundcard.h,v 1.24 2014/09/09 10:45:18 nat Exp $	*/
+/*	$NetBSD: soundcard.h,v 1.25 2020/10/16 20:24:35 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -327,6 +327,22 @@ typedef struct buffmem_desc {
 #define SNDCTL_DSP_SETRECVOL		_IOW ('P',30, uint)
 #define SNDCTL_DSP_SKIP			_IO ('P',31)
 #define SNDCTL_DSP_SILENCE		_IO ('P',32)
+#define SNDCTL_DSP_COOKEDMODE		_IOW ('P',33, int)
+#define SNDCTL_DSP_GETERROR		_IOR ('P',34, struct audio_errinfo)
+
+typedef struct audio_errinfo {
+	int play_underruns;
+	int rec_overruns;
+	unsigned int play_ptradjust;	/* Obsolete */
+	unsigned int rec_ptradjust;	/* Obsolete */
+	int play_errorcount;		/* Unused */
+	int rec_errorcount;		/* Unused */
+	int play_lasterror;		/* Unused */
+	int rec_lasterror;		/* Unused */
+	int play_errorparm;		/* Unused */
+	int rec_errorparm;		/* Unused */
+	int filler[16];			/* Unused */
+} audio_errinfo;
 
 typedef struct oss_sysinfo {
 	char product[32];

Reply via email to