Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Move calculation of sc_latency into a function.



details:   https://anonhg.NetBSD.org/src/rev/5ccca5f89f78
branches:  trunk
changeset: 827523:5ccca5f89f78
user:      nat <nat%NetBSD.org@localhost>
date:      Tue Oct 31 21:13:24 2017 +0000

description:
Move calculation of sc_latency into a function.

The latency of the audio device is updated on attach in the audio auto
config and shown on screen.

Ok christos@.

diffstat:

 sys/dev/audio.c |  44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 deletions(-)

diffs (93 lines):

diff -r 7bb5ef1fbe48 -r 5ccca5f89f78 sys/dev/audio.c
--- a/sys/dev/audio.c   Tue Oct 31 21:09:26 2017 +0000
+++ b/sys/dev/audio.c   Tue Oct 31 21:13:24 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.419 2017/10/31 21:09:26 nat Exp $  */
+/*     $NetBSD: audio.c,v 1.420 2017/10/31 21:13:24 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.419 2017/10/31 21:09:26 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.420 2017/10/31 21:13:24 nat Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -278,6 +278,7 @@
 int    mix_read(void *);
 int    audio_check_params(struct audio_params *);
 
+static void    audio_calc_latency(struct audio_softc *);
 static void    audio_setblksize(struct audio_softc *,
                                 struct virtual_channel *, int, int);
 int    audio_calc_blksize(struct audio_softc *, const audio_params_t *);
@@ -2653,6 +2654,18 @@
 }
 
 static void
+audio_calc_latency(struct audio_softc *sc)
+{
+       const struct audio_params *ap = &sc->sc_vchan_params;
+
+       if (ap->sample_rate == 0 || ap->channels == 0 || ap->precision == 0)
+               return;
+
+       sc->sc_latency = sc->sc_hwvc->sc_mpr.blksize * 1000 * PREFILL_BLOCKS
+           * NBBY / ap->sample_rate / ap->channels / ap->precision;
+}
+
+static void
 audio_setblksize(struct audio_softc *sc, struct virtual_channel *vc,
     int blksize, int mode)
 {
@@ -6043,14 +6056,7 @@
                    AUMODE_PLAY | AUMODE_PLAY_ALL | AUMODE_RECORD);
        }
 
-       if (sc->sc_vchan_params.sample_rate > 0 &&
-           sc->sc_vchan_params.channels > 0 &&
-           sc->sc_vchan_params.precision > 0) {
-                   sc->sc_latency = sc->sc_hwvc->sc_mpr.blksize * 1000 * 
-                   PREFILL_BLOCKS / sc->sc_vchan_params.sample_rate /
-                   sc->sc_vchan_params.channels * NBBY /
-                   sc->sc_vchan_params.precision;
-       }
+       audio_calc_latency(sc);
        mutex_exit(sc->sc_lock);
 
        return error;
@@ -6100,19 +6106,25 @@
                                                sc->sc_vchan_params.precision,
                                                sc->sc_vchan_params.channels,
                                                sc->sc_vchan_params.sample_rate);
-                                       mutex_exit(sc->sc_lock);
-
-                                       return 0;
+
+                                       goto found;
                                }
                        }
                }
        }
 
-       aprint_error_dev(sc->sc_dev, "Virtual format auto config failed!\n"
-                    "Please check hardware capabilities\n");
+found:
+       if (error == 0) {
+               audio_calc_latency(sc);
+               aprint_normal_dev(sc->sc_dev, "Latency: %d milliseconds\n",
+                   sc->sc_latency);
+       } else {
+               aprint_error_dev(sc->sc_dev, "Virtual format auto config failed!\n");
+               aprint_error_dev(sc->sc_dev, "Please check hardware capabilities\n");
+       }
        mutex_exit(sc->sc_lock);
 
-       return EINVAL;
+       return error;
 }
 
 static void



Home | Main Index | Thread Index | Old Index