Module Name:    src
Committed By:   nia
Date:           Mon Oct 19 09:01:24 UTC 2020

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

Log Message:
ossaudio(3): Add SNDCTL_DSP_CURRENT_(I|O)PTR

In OSSv4 these are supposed to avoid the wrapping problems with the
older GET(I|O)PTR ioctls but we don't quite get the same benefit here.

XXX: We could probably fake it by maintaining some state in-between calls.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/lib/libossaudio/ossaudio.c
cvs rdiff -u -r1.26 -r1.27 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.49 src/lib/libossaudio/ossaudio.c:1.50
--- src/lib/libossaudio/ossaudio.c:1.49	Sat Oct 17 23:23:06 2020
+++ src/lib/libossaudio/ossaudio.c	Mon Oct 19 09:01:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ossaudio.c,v 1.49 2020/10/17 23:23:06 nia Exp $	*/
+/*	$NetBSD: ossaudio.c,v 1.50 2020/10/19 09:01:24 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: ossaudio.c,v 1.49 2020/10/17 23:23:06 nia Exp $");
+__RCSID("$NetBSD: ossaudio.c,v 1.50 2020/10/19 09:01:24 nia Exp $");
 
 /*
  * This is an Open Sound System compatibility layer, which provides
@@ -121,6 +121,7 @@ audio_ioctl(int fd, unsigned long com, v
 	int perrors, rerrors;
 	static int totalperrors = 0;
 	static int totalrerrors = 0;
+	oss_count_t osscount;
 	int idat, idata;
 	int retval;
 
@@ -577,6 +578,16 @@ audio_ioctl(int fd, unsigned long com, v
 		cntinfo.ptr = tmpoffs.offset;
 		*(struct count_info *)argp = cntinfo;
 		break;
+	case SNDCTL_DSP_CURRENT_IPTR:
+		retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
+		if (retval < 0)
+			return retval;
+		/* XXX: 'samples' may wrap */
+		memset(osscount.filler, 0, sizeof(osscount.filler));
+		osscount.samples = tmpinfo.record.samples;
+		osscount.fifo_samples = tmpinfo.record.seek;
+		*(oss_count_t *)argp = osscount;
+		break;
 	case SNDCTL_DSP_GETOPTR:
 		retval = ioctl(fd, AUDIO_GETOOFFS, &tmpoffs);
 		if (retval < 0)
@@ -586,6 +597,16 @@ audio_ioctl(int fd, unsigned long com, v
 		cntinfo.ptr = tmpoffs.offset;
 		*(struct count_info *)argp = cntinfo;
 		break;
+	case SNDCTL_DSP_CURRENT_OPTR:
+		retval = ioctl(fd, AUDIO_GETBUFINFO, &tmpinfo);
+		if (retval < 0)
+			return retval;
+		/* XXX: 'samples' may wrap */
+		memset(osscount.filler, 0, sizeof(osscount.filler));
+		osscount.samples = tmpinfo.play.samples;
+		osscount.fifo_samples = tmpinfo.play.seek;
+		*(oss_count_t *)argp = osscount;
+		break;
 	case SNDCTL_DSP_SETPLAYVOL:
 		setvol(fd, INTARG, false);
 		/* FALLTHRU */

Index: src/lib/libossaudio/soundcard.h
diff -u src/lib/libossaudio/soundcard.h:1.26 src/lib/libossaudio/soundcard.h:1.27
--- src/lib/libossaudio/soundcard.h:1.26	Sat Oct 17 23:23:06 2020
+++ src/lib/libossaudio/soundcard.h	Mon Oct 19 09:01:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: soundcard.h,v 1.26 2020/10/17 23:23:06 nia Exp $	*/
+/*	$NetBSD: soundcard.h,v 1.27 2020/10/19 09:01:24 nia Exp $	*/
 
 /*-
  * Copyright (c) 1997, 2020 The NetBSD Foundation, Inc.
@@ -326,6 +326,14 @@ typedef struct buffmem_desc {
 #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)
+#define SNDCTL_DSP_CURRENT_IPTR		_IOR ('P',35, oss_count_t)
+#define SNDCTL_DSP_CURRENT_OPTR		_IOR ('P',36, oss_count_t)
+
+typedef struct {
+	long long samples;
+	int fifo_samples;
+	int filler[32];			/* "Future use" */
+} oss_count_t;
 
 typedef struct audio_errinfo {
 	int play_underruns;

Reply via email to