Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Blksize is now calculated on sc_pustream/sc_rustream.



details:   https://anonhg.NetBSD.org/src/rev/228c2915e087
branches:  trunk
changeset: 823864:228c2915e087
user:      nat <nat%NetBSD.org@localhost>
date:      Fri May 12 04:15:40 2017 +0000

description:
Blksize is now calculated on sc_pustream/sc_rustream.
Don't allow hw ring buffer to be saturated and data overwritten.

It should help PR kern/52175.

diffstat:

 sys/dev/audio.c |  27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diffs (68 lines):

diff -r 373fe1237218 -r 228c2915e087 sys/dev/audio.c
--- a/sys/dev/audio.c   Fri May 12 02:34:45 2017 +0000
+++ b/sys/dev/audio.c   Fri May 12 04:15:40 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.341 2017/05/11 23:39:15 nat Exp $  */
+/*     $NetBSD: audio.c,v 1.342 2017/05/12 04:15:40 nat Exp $  */
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.341 2017/05/11 23:39:15 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.342 2017/05/12 04:15:40 nat Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -2659,20 +2659,23 @@
                   struct virtual_channel *vc)
 {
        const audio_params_t *parm;
-       struct audio_ringbuffer *rb;
+       struct audio_stream *rb;
+       int *blksize;
 
        if (vc->sc_blkset)
                return;
 
        if (mode == AUMODE_PLAY) {
-               rb = &vc->sc_mpr;
-               parm = &rb->s.param;
+               rb = vc->sc_pustream;
+               parm = &rb->param;
+               blksize = &vc->sc_mpr.blksize;
        } else {
-               rb = &vc->sc_mrr;
-               parm = &rb->s.param;
-       }
-
-       rb->blksize = parm->sample_rate * audio_blk_ms / 1000 *
+               rb = vc->sc_rustream;
+               parm = &rb->param;
+               blksize = &vc->sc_mrr.blksize;
+       }
+
+       *blksize = parm->sample_rate * audio_blk_ms / 1000 *
             parm->channels * parm->precision / NBBY;
 
        DPRINTF(("audio_calc_blksize: %s blksize=%d\n",
@@ -5517,6 +5520,9 @@
        cc = blksize;
        error = 0;
 
+       if (audio_stream_get_used(vc->sc_pustream) > blksize)
+               goto done;
+
        tocopy = vc->sc_pustream->inp;
        orig = __UNCONST(sc->sc_pr.s.outp);
        used = blksize;
@@ -5547,6 +5553,7 @@
        sc->sc_pr.s.outp = audio_stream_add_outp(&sc->sc_pr.s,
            sc->sc_pr.s.outp, blksize);
 
+done:
        if (vc->sc_npfilters > 0) {
                null_fetcher.fetch_to = null_fetcher_fetch_to;
                filter = vc->sc_pfilters[0];



Home | Main Index | Thread Index | Old Index