Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Improved drain function for vc[0].



details:   https://anonhg.NetBSD.org/src/rev/025d133539ab
branches:  trunk
changeset: 351152:025d133539ab
user:      nat <nat%NetBSD.org@localhost>
date:      Fri Feb 03 20:07:55 2017 +0000

description:
Improved drain function for vc[0].
No need to drain vc[0] for drivers written with start_output.

diffstat:

 sys/dev/audio.c |  64 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 41 insertions(+), 23 deletions(-)

diffs (140 lines):

diff -r 7cc2025b9ab1 -r 025d133539ab sys/dev/audio.c
--- a/sys/dev/audio.c   Fri Feb 03 17:24:43 2017 +0000
+++ b/sys/dev/audio.c   Fri Feb 03 20:07:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.298 2017/01/27 05:05:51 nat Exp $  */
+/*     $NetBSD: audio.c,v 1.299 2017/02/03 20:07:55 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.298 2017/01/27 05:05:51 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.299 2017/02/03 20:07:55 nat Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -1761,7 +1761,7 @@
        rp->copying = false;
        rp->needfill = false;
        rp->mmapped = false;
-       memset(rp->s.start, 0, AU_RING_SIZE);
+       memset(rp->s.start, 0, blksize * 2);
 }
 
 int
@@ -2084,9 +2084,11 @@
                return 0;
 
        used = audio_stream_get_used(&cb->s);
+       if (n == 0)
+               used += audio_stream_get_used(&sc->sc_pr.s);
        for (i = 0; i < sc->sc_vchan[n]->sc_npfilters; i++)
                used += audio_stream_get_used(&sc->sc_vchan[n]->sc_pstreams[i]);
-       if (used <= 0)
+       if (used <= 0 || (n == 0 && sc->hw_if->trigger_output == NULL))
                return 0;
 
        if (n != 0 && !sc->sc_vchan[n]->sc_pbus) {
@@ -2101,8 +2103,19 @@
                error = audiostartp(sc, n);
                if (error)
                        return error;
-       } else if (n == 0)
-               goto silence_buffer;
+       } else if (n == 0) {
+               used = cb->blksize * 2;
+               while (used > 0) {
+                       cc = sc->sc_pr.s.end - sc->sc_pr.s.inp;
+                       if (cc > used)
+                               cc = used;
+                       audio_fill_silence(&cb->s.param, sc->sc_pr.s.inp, cc);
+                       sc->sc_pr.s.inp = audio_stream_add_inp(&sc->sc_pr.s,
+                           sc->sc_pr.s.inp, cc);
+                       used -= cc;
+               }
+               mix_write(sc);
+       }
        /*
         * Play until a silence block has been played, then we
         * know all has been drained.
@@ -2116,6 +2129,9 @@
        }
 #endif
        sc->sc_vchan[n]->sc_draining = true;
+
+       i = 0;
+drain_again:
        drops = cb->drops;
        error = 0;
        while (cb->drops == drops && !error) {
@@ -2128,21 +2144,12 @@
                if (sc->sc_dying)
                        error = EIO;
        }
-
-silence_buffer:
-
-       used = 0;
-       if (sc->sc_opens == 1) {
-               cb = &sc->sc_pr;
-               cc = cb->blksize;
-               
-               while (used < cb->s.bufsize) {
-                       memset(sc->sc_pr.s.start, 0, cc);
-                       mix_write(sc);
-                       used += cc;
-               }
-       }
+       i++;
+       if (n == 0 && i < 2)
+               goto drain_again;
+
        sc->sc_vchan[n]->sc_draining = false;
+
        return error;
 }
 
@@ -3368,18 +3375,30 @@
 {
        struct audio_softc *sc;
        struct virtual_channel *vc;
+       int blksize, i, used;
 
        sc = v;
        vc = sc->sc_vchan[0];
+       blksize = vc->sc_mpr.blksize;
 
        if (sc->sc_dying == true)
                return;
 
-       if (audio_stream_get_used(&sc->sc_pr.s) < vc->sc_mpr.blksize)
+       used = audio_stream_get_used(&vc->sc_mpr.s);
+       for (i = 0; i < vc->sc_npfilters; i++)
+               used += audio_stream_get_used(&vc->sc_pstreams[i]);
+
+       if (audio_stream_get_used(&sc->sc_pr.s) <blksize)
                goto wake_mix;
 
+       if (vc->sc_draining == true && used <= 0) {
+               vc->sc_mpr.drops += blksize;
+               cv_broadcast(&sc->sc_wchan);
+       }
+
        vc->sc_mpr.s.outp = audio_stream_add_outp(&vc->sc_mpr.s,
-           vc->sc_mpr.s.outp, vc->sc_mpr.blksize);
+           vc->sc_mpr.s.outp, blksize);
+
        mix_write(sc);
 
 wake_mix:
@@ -5767,7 +5786,6 @@
 
                audio_mix(sc);
        }
-
 }
 
 void



Home | Main Index | Thread Index | Old Index