tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Audio device mmap and kevents



At Sat, 26 Jan 2019 09:07:02 -0000 (UTC),
Michael van Elst wrote:
> >I could run "mpv -ao=oss some.mp3" at 0~1% CPU with rev 1.32
> >on netbsd-8.
> 
> >May I commit(revert) it?
> 
> The change to GETOSPACE is wrong, it basically reduces the returned
> number of fragments by 1, possibly returning a negative value. The
> returned number of bytes is also truncated.
> 
> The change to GETISPACE on the other hand looks correct, but I have
> no idea how fixing the record operation would have helped playback.

Oh, I didn't see GETISPACE chunk well...

For GETOSPACE, rev1.32 is correct.
For GETISPACE fragments, rev1.33 is correct.
For GETISPACE fragstotal, both rev1.32 and 1.33 are not correct.
hiwat is playback-only parameter.
For GETISPACE bytes, both 1.32 and 1.33 are not correct.
'bytes' should return the number of bytes (not rounded down)
that can be read without blocking.

So how about this?
I confirmed that both mpv and mplayer worked fine on netbsd-8.
# I didn't test recording, though.

Index: lib/libossaudio/ossaudio.c
===================================================================
RCS file: /cvsroot/src/lib/libossaudio/ossaudio.c,v
retrieving revision 1.33
diff -u -r1.33 ossaudio.c
--- lib/libossaudio/ossaudio.c	23 Mar 2017 15:50:48 -0000	1.33
+++ lib/libossaudio/ossaudio.c	27 Jan 2019 09:21:00 -0000
@@ -411,11 +411,11 @@
 			return retval;
 		setblocksize(fd, &tmpinfo);
 		bufinfo.fragsize = tmpinfo.blocksize;
-		bufinfo.fragments = (tmpinfo.hiwat * tmpinfo.blocksize -
-		    (tmpinfo.play.seek + tmpinfo.blocksize -1)) /
-		    tmpinfo.blocksize;
+		bufinfo.fragments = tmpinfo.hiwat - (tmpinfo.play.seek
+		    + tmpinfo.blocksize - 1) / tmpinfo.blocksize;
 		bufinfo.fragstotal = tmpinfo.hiwat;
-		bufinfo.bytes = bufinfo.fragments * tmpinfo.blocksize;
+		bufinfo.bytes = tmpinfo.hiwat * tmpinfo.blocksize
+		    - tmpinfo.play.seek;
 		*(struct audio_buf_info *)argp = bufinfo;
 		break;
 	case SNDCTL_DSP_GETISPACE:
@@ -425,8 +425,9 @@
 		setblocksize(fd, &tmpinfo);
 		bufinfo.fragsize = tmpinfo.blocksize;
 		bufinfo.fragments = tmpinfo.record.seek / tmpinfo.blocksize;
-		bufinfo.fragstotal = tmpinfo.hiwat;
-		bufinfo.bytes = bufinfo.fragments * tmpinfo.blocksize;
+		bufinfo.fragstotal =
+		    tmpinfo.record.buffer_size / tmpinfo.blocksize;
+		bufinfo.bytes = tmpinfo.record.seek;
 		*(struct audio_buf_info *)argp = bufinfo;
 		break;
 	case SNDCTL_DSP_NONBLOCK:

Thanks.
---
Tetsuya Isaki <isaki%pastel-flower.jp@localhost / isaki%NetBSD.org@localhost>


Home | Main Index | Thread Index | Old Index