summaryrefslogtreecommitdiff
path: root/sys/dev/audio/audio.c
diff options
context:
space:
mode:
authorisaki <isaki@NetBSD.org>2022-04-20 07:11:13 +0000
committerisaki <isaki@NetBSD.org>2022-04-20 07:11:13 +0000
commit7cc25583f8165fd2228ea2be7bb02c58eeae1d29 (patch)
tree554c4efa12ea2bf43efd54e4f0e66e66f008901a /sys/dev/audio/audio.c
parent3619e2342119c11400be1796503ce6eb927b2ed4 (diff)
audio(4): Rework AUDIO_GETOOFFS.
- Count .samples/.deltablks in blocks. It makes .deltablks integer wrap around safe. - Remove suspicious one block offset from .offset. I added the offset because it was observed so on NetBSD7. But according to manpage, it should not be. And it looks fine without the offset. - Related to that, remove a comment in AUDIO_WSEEK. Limit the user-visible buffer to usrbuf only.
Diffstat (limited to 'sys/dev/audio/audio.c')
-rw-r--r--sys/dev/audio/audio.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/sys/dev/audio/audio.c b/sys/dev/audio/audio.c
index 9f6d6684e54..aeff107392f 100644
--- a/sys/dev/audio/audio.c
+++ b/sys/dev/audio/audio.c
@@ -1,4 +1,4 @@
-/* $NetBSD: audio.c,v 1.126 2022/04/20 06:05:22 isaki Exp $ */
+/* $NetBSD: audio.c,v 1.127 2022/04/20 07:11:13 isaki Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.126 2022/04/20 06:05:22 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.127 2022/04/20 07:11:13 isaki Exp $");
#ifdef _KERNEL_OPT
#include "audio.h"
@@ -2985,7 +2985,7 @@ audio_ioctl(dev_t dev, struct audio_softc *sc, u_long cmd, void *addr, int flag,
audio_encoding_t *ae;
audio_format_query_t *query;
u_int stamp;
- u_int offs;
+ u_int offset;
int val;
int index;
int error;
@@ -3104,28 +3104,23 @@ audio_ioctl(dev_t dev, struct audio_softc *sc, u_long cmd, void *addr, int flag,
}
mutex_enter(sc->sc_lock);
mutex_enter(sc->sc_intr_lock);
- /* figure out where next DMA will start */
- stamp = track->usrbuf_stamp;
- offs = track->usrbuf.head;
+ /* figure out where next transfer will start */
+ stamp = track->stamp;
+ offset = track->usrbuf.head;
mutex_exit(sc->sc_intr_lock);
mutex_exit(sc->sc_lock);
- ao->samples = stamp;
- ao->deltablks = (stamp / track->usrbuf_blksize) -
- (track->usrbuf_stamp_last / track->usrbuf_blksize);
- track->usrbuf_stamp_last = stamp;
- offs = rounddown(offs, track->usrbuf_blksize)
- + track->usrbuf_blksize;
- if (offs >= track->usrbuf.capacity)
- offs -= track->usrbuf.capacity;
- ao->offset = offs;
-
+ /* samples will overflow soon but is as per spec. */
+ ao->samples = stamp * track->usrbuf_blksize;
+ ao->deltablks = stamp - track->last_stamp;
+ ao->offset = offset;
TRACET(2, track, "%s samples=%u deltablks=%u offset=%u",
pre, ao->samples, ao->deltablks, ao->offset);
+
+ track->last_stamp = stamp;
break;
case AUDIO_WSEEK:
- /* XXX return value does not include outbuf one. */
track = file->ptrack;
if (track) {
val = track->usrbuf.used;
@@ -4964,8 +4959,6 @@ audio_track_play(audio_track_t *track)
count = uimin(usrbuf->used, track->usrbuf_blksize) / framesize;
bytes = count * framesize;
- track->usrbuf_stamp += bytes;
-
if (usrbuf->head + bytes < usrbuf->capacity) {
memcpy((uint8_t *)input->mem + auring_tail(input) * framesize,
(uint8_t *)usrbuf->mem + usrbuf->head,
@@ -5060,6 +5053,8 @@ audio_track_play(audio_track_t *track)
track->outputcounter += track->outbuf.used - track_count_0;
}
+ track->stamp++;
+
#if defined(AUDIO_DEBUG)
if (audiodebug >= 3) {
struct audio_track_debugbuf m;
@@ -6311,6 +6306,8 @@ audio_track_clear(struct audio_softc *sc, audio_track_t *track)
track->outbuf.used = 0;
/* Clear counters. */
+ track->stamp = 0;
+ track->last_stamp = 0;
track->dropframes = 0;
audio_track_lock_exit(track);
@@ -7773,7 +7770,7 @@ audiogetinfo(struct audio_softc *sc, struct audio_info *ai, int need_mixerinfo,
if (ptrack) {
pi->seek = ptrack->usrbuf.used;
- pi->samples = ptrack->usrbuf_stamp;
+ pi->samples = ptrack->stamp * ptrack->usrbuf_blksize;
pi->eof = ptrack->eofcounter;
pi->error = (ptrack->dropframes != 0) ? 1 : 0;
pi->open = 1;
@@ -7784,7 +7781,7 @@ audiogetinfo(struct audio_softc *sc, struct audio_info *ai, int need_mixerinfo,
if (rtrack) {
ri->seek = audio_track_readablebytes(rtrack);
- ri->samples = rtrack->usrbuf_stamp;
+ ri->samples = rtrack->stamp * rtrack->usrbuf_blksize;
ri->eof = 0;
ri->error = (rtrack->dropframes != 0) ? 1 : 0;
ri->open = 1;