Source-Changes-HG archive

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

[src/netbsd-8]: src Pull up following revision(s) (requested by nat in ticket...



details:   https://anonhg.NetBSD.org/src/rev/bfd587ca7f59
branches:  netbsd-8
changeset: 851298:bfd587ca7f59
user:      snj <snj%NetBSD.org@localhost>
date:      Mon Jan 15 00:08:55 2018 +0000

description:
Pull up following revision(s) (requested by nat in ticket #489):
        share/man/man4/audio.4: 1.81-1.82
        sys/dev/audio.c: 1.376 via patch, 1.407-1.413, 1.415-1.440, 1.441 via patch, 1.443-1.450
        sys/dev/audiovar.h: 1.59 via patch, 1.65-1.68
Improve audio_set_vchan_defaults().
- Correct confused input/output parameters.
- Remove sc->{sc_channels, sc_precision, sc_frequency}.  They are
  the same as sc->sc_vchan_params.{channels, precision, sample_rate}.
The input parameter of audio_set_vchan_defaults() is now only
sc->sc_vchan_params.
Fix PR kern/52437
Move play/rec mix ring buffers into a virtual channel sc_mixring.  NFCI.
Call audio_mix for a third time - thus ensuring there is a block of data
in the mix ring before the audio interrupt occurs.
This addresses the instability seen in the audio atf tests.
Improve logic in audio_initbufs().  No functional changes intended.
Ensure proper use of sc_opens (play back) and sc_recopens (recording).
Fix logic for /dev/sound so audiosetinfo is only called once.
These changes are to ensure that init_output/input is only called once for
the respective function play back or recording.  For multiple recording or
plack back streams init_input/output is only called once fot the first
play/rec stream.
This addresses PR kern/52580, PR kern/52581 and PR kern/52582 analyzed and
reported by isaki@.
Fix return value.  fo_mmap is expected to return errno on error.
Fix return value.  fo_poll is expected to return revents on error.
Fix return value.  fo_kqfilter is expected to return errno on error.
This is the rest of 1.226 (10 years ago).
Add latency sysctl to adjust hw blocksize and hence latency of the mixer.
        usage: sysctl -w hw.hdafg0.lantency="value in milliseconds"
It is possible to set the latency of the mixer unless a static blocksize
is configured by the underlying hardware driver (pad, vcaudio on RPI).
Documentation updates to audio.4 will occur in a follow up commit.
OK christos@.
Ensure that the low/high water marks are at least PREFILL_BLOCKS.
Independent blocksizes for virtual channels where a static blocksize is
not stipulated by the underlying hw driver.
This improves latency in games esp. when the stream format differs from
the harware format.
OK christos@.
No externs in .c files!  Include ioconf.h for struct cfdriver xyz_cd.
round_blocksize is only used for the hardware ring buffer.  All other
buffers (mix ring, streams) are set to be a power of 2.
This allows for consistent latency where a static blocksize is enforced by
the underlying audio device driver.
Ok christos@.
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@.
Only allow blocksizes greater or equal to the calculated one.
This should help applications as the blocksize obtained (AUDIO_SET/GETINFO)
will work without stutter.
Ok christos@.
Revert commit rev 1.419 to audio.c.  This should address PR kern/52685.
This also means that drivers that have a static block size will have more
latency at lower sample rates/precision/channels.  Also audio drivers that
do more than supply rounded blocksizes in their round_blocksize functions
will have to be changed.
Use mix ring block size in audio write, startp, and audio drain.
Allow for block sizes less than hw block size.  This allows for the lowest
possible latency for all precision, sample rate and frequencies.
This is a rework of rev 1.419.
Calc latency when altering precision, frequency and channels sysctls.
No need to ratify block size twice as this is done in audio_initbufs.
This is a rework of rev 1.421.
Revert to previous.  It is necessary to use the calculated blocksize if
none supplied.
Tested by martin@.
Blocksizes sould be rounded to a power of 2 as OSS applications need this.
Tested by martin@.
AU_RING_SIZE -> s.bufsize in audio_initbufs.
A sysctl is now available to disable the in kernel mixer.
        sysctl -w hw.hdafg0.usemixer=0
There currently is a problem draining the last block with the mixer
disabled.  I will fix this in a follow up commit.
AFAIK there will be a problem wiht vs(4) on x68k with the mixer disabled
as the filters for mulaw, alaw and unsigned linear have been removed post
audio mixing changes.
Documentation for this sysctl variable will be made to audio.4 in a follow
up commit.
Ok christos@.
Use mixring blocksizes in the right places when mixer is enabled.
This means that x68k's vs audio works once again with sysctl usemixer=1.
Tested with xm6i.
Don't return EIO falsely when dealing with the hardware vc.
Draining of the hardware vc on close is now possible.
Plug memory leak as the mixer state does not grow or shrink when audio
mixing is disabled.  This avoids triggering a panic also.
Improved draining function for when the mixer is and is not enabled.
One block of silence is also played in audio drivers using start_output
when draining the hardware, this helps playback of short (less than
blocksize) samples.
Improved audiostartp for when audio mixing is disabled.
audio_pint improvements for when audio mixing is disabled.
When audio mixing is disabled there is only the hardware vc the mix ring
is not used.
The harware vc is rounded to a power of two then round_blocksize is called.
This improves playback and makes it possibile to use mmapped audio on usb.
For the virtual stream it is required to insert silence.  As these streams
are not harware streams audio_pint_silence is ineffective.
As audio_mix() was the only consumer of audio_pint_silence it has been
removed along with sc_sil_count - which was only used by this function.
Add vc to debug messages in audio_mix.
Also add debug message when available data in the vc is less than the mix
ring blocksize.  NFC.
Use correct combination of mix ring block size and vc playring used low
for signalling the writer or fetching data from the vc play ring filters.
When dealing with the ring buffer sc_mpr.s it is necessary to use the hwvc
or mixring block sizes as they represent the final size of the data to be
played back from the stream vc.
When dealing with sc_pustream when there is play back filters or not one
should use the vc->sc_mpr.blocksize, as this represents the amount of data
before going through play back filters.
This should address PR kern/52685.
Speed up improvements for MIX_FUNC.
As suggested by jmcneill@.
Only init the mix ring if sc_usemixer is enabled as with mixing set to
false the mix ring is not used.
Allow the hwvc block size to be set to any amount with audio mixing
disabled.
Convert double block size of data though the play back filters.  This is
primarily for when audio mixing is disabled to stop inserting silence when
there is data available.
This change should have no effect when mixing is enabled as there is only
1 block of data in the mix ring.
Whitespace.
Only signal a pause change on a transition of a pause change.
This addresses a problem found in audio/sox causing high cpu usage.
Path and analysis by Onno van der Linden.
Rework of play/rec threads to ensure effective use of locks.
Addresses part of PR kern/52889 where the mixing thread would not exit on
audio detach.
Forcefully detach children of audio instances.
This addresses part of PR kern/52889 as children of pad(4) were not
detaching.
Document the hw.driverN.latency sysctl variable.
Bump date for previous. Remove superfluous Pp.
Allow open of audioctl devices whilst audio is open with the mixer
disabled.

diffstat:

 share/man/man4/audio.4 |    29 +-
 sys/dev/audio.c        |  1028 +++++++++++++++++++++++++++++------------------
 sys/dev/audiovar.h     |    16 +-
 3 files changed, 655 insertions(+), 418 deletions(-)

diffs (truncated from 2035 to 300 lines):

diff -r 24412a6f2e18 -r bfd587ca7f59 share/man/man4/audio.4
--- a/share/man/man4/audio.4    Sat Jan 13 22:33:12 2018 +0000
+++ b/share/man/man4/audio.4    Mon Jan 15 00:08:55 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: audio.4,v 1.79 2017/05/07 08:19:39 nat Exp $
+.\"    $NetBSD: audio.4,v 1.79.2.1 2018/01/15 00:08:55 snj Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 11, 2016
+.Dd October 27, 2017
 .Dt AUDIO 4
 .Os
 .Sh NAME
@@ -107,11 +107,11 @@
 These can be modified to taste by the following
 .Xr sysctl 8
 variables.
-.Pp
 .Bl -tag -width -compact
 .It hw.driverN.precision
 .It hw.driverN.frequency
 .It hw.driverN.channels
+.It hw.driverN.latency
 .It hw.driverN.multiuser
 .El
 .Pp
@@ -124,10 +124,28 @@
 For best results, values close to the underlying hardware should be chosen.
 These variables may only be changed when the sampling device is not in use.
 .Pp
-An additional
+The hw.driverN.latency
+.Xr sysctl 8
+variable controls the latency of the in-kernel mixer by varying the hardware
+blocksize.
+It accepts a value in milliseconds(ms), fractional values are not allowed.
+A value of zero will default to 150ms.
+.Pp
+If a static blocksize is enforced by the underlying hardware driver this value
+cannot be changed.
+.Pp
+For audio applications that do not specify a preferred blocksize when configuring
+the audio device, this will be the latency these applications have.
+.Pp
+For audio applications that
+.Xr mmap 2
+the audio device for play back the resultant latency is a third (1/3) of the value
+of the hw.driverN.latency variable.
+.Pp
+The hw.driverN.multiuser
 .Xr sysctl 8
 variable determines if multiple users are allowed to access the sampling
-device, hw.driverN.multiuser.
+device.
 .Pp
 By default it is set to false.
 This means that the sampling device may be only used by
@@ -227,7 +245,6 @@
 The following
 .Xr ioctl 2
 commands are supported on the sample devices:
-.Pp
 .Bl -tag -width indent
 .It Dv AUDIO_GETCHAN (int)
 This command will return the audio channel in use.
diff -r 24412a6f2e18 -r bfd587ca7f59 sys/dev/audio.c
--- a/sys/dev/audio.c   Sat Jan 13 22:33:12 2018 +0000
+++ b/sys/dev/audio.c   Mon Jan 15 00:08:55 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.357.2.9 2017/09/23 17:39:34 snj Exp $      */
+/*     $NetBSD: audio.c,v 1.357.2.10 2018/01/15 00:08:55 snj 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.357.2.9 2017/09/23 17:39:34 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.357.2.10 2018/01/15 00:08:55 snj Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -195,6 +195,8 @@
 
 #include <uvm/uvm.h>
 
+#include "ioconf.h"
+
 /* #define AUDIO_DEBUG 1 */
 #ifdef AUDIO_DEBUG
 #define DPRINTF(x)     if (audiodebug) printf x
@@ -205,6 +207,7 @@
 #define DPRINTFN(n,x)
 #endif
 
+#define PREFILL_BLOCKS 3       /* no. audioblocks required to start stream */
 #define ROUNDSIZE(x)   (x) &= -16      /* round to nice boundary */
 #define SPECIFIED(x)   ((x) != ~0)
 #define SPECIFIED_CH(x)        ((x) != (u_char)~0)
@@ -275,6 +278,9 @@
 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 *);
 void   audio_fill_silence(struct audio_params *, uint8_t *, int);
 int    audio_silence_copyout(struct audio_softc *, int, struct uio *);
@@ -288,9 +294,6 @@
 void   audio_clear(struct audio_softc *, struct virtual_channel *);
 void   audio_clear_intr_unlocked(struct audio_softc *sc,
                                  struct virtual_channel *);
-static inline void
-       audio_pint_silence(struct audio_softc *, struct audio_ringbuffer *,
-                          uint8_t *, int, struct virtual_channel *);
 int    audio_alloc_ring(struct audio_softc *, struct audio_ringbuffer *, int,
                         size_t);
 void   audio_free_ring(struct audio_softc *, struct audio_ringbuffer *);
@@ -313,6 +316,8 @@
 static int audio_sysctl_frequency(SYSCTLFN_PROTO);
 static int audio_sysctl_precision(SYSCTLFN_PROTO);
 static int audio_sysctl_channels(SYSCTLFN_PROTO);
+static int audio_sysctl_latency(SYSCTLFN_PROTO);
+static int audio_sysctl_usemixer(SYSCTLFN_PROTO);
 
 static int     audiomatch(device_t, cfdata_t, void *);
 static void    audioattach(device_t, device_t, void *);
@@ -394,8 +399,7 @@
                 struct virtual_channel *);
 static int
 audio_query_encoding(struct audio_softc *, struct audio_encoding *);
-static int audio_set_vchan_defaults
-       (struct audio_softc *, u_int, const struct audio_format *);
+static int audio_set_vchan_defaults(struct audio_softc *, u_int);
 static int vchan_autoconfig(struct audio_softc *);
 int    au_get_lr_value(struct audio_softc *, mixer_ctrl_t *, int *, int *);
 int    au_set_lr_value(struct audio_softc *, mixer_ctrl_t *, int, int);
@@ -463,8 +467,6 @@
     audiomatch, audioattach, audiodetach, audioactivate, audiorescan,
     audiochilddet, DVF_DETACH_SHUTDOWN);
 
-extern struct cfdriver audio_cd;
-
 static int
 audiomatch(device_t parent, cfdata_t match, void *aux)
 {
@@ -499,6 +501,7 @@
        sc->sc_recopens = 0;
        sc->sc_aivalid = false;
        sc->sc_ready = true;
+       sc->sc_latency = audio_blk_ms * PREFILL_BLOCKS;
 
        sc->sc_format[0].mode = AUMODE_PLAY | AUMODE_RECORD;
        sc->sc_format[0].encoding =
@@ -514,16 +517,6 @@
        sc->sc_format[0].frequency_type = 1;
        sc->sc_format[0].frequency[0] = 44100;
 
-       sc->sc_vchan_params.sample_rate = 44100;
-#if BYTE_ORDER == LITTLE_ENDIAN
-       sc->sc_vchan_params.encoding = AUDIO_ENCODING_SLINEAR_LE;
-#else
-       sc->sc_vchan_params.encoding = AUDIO_ENCODING_SLINEAR_BE;
-#endif
-       sc->sc_vchan_params.precision = 16;
-       sc->sc_vchan_params.validbits = 16;
-       sc->sc_vchan_params.channels = 2;
-
        sc->sc_trigger_started = false;
        sc->sc_rec_started = false;
        sc->sc_dying = false;
@@ -539,9 +532,6 @@
        vc->sc_lastinfovalid = false;
        vc->sc_swvol = 255;
        vc->sc_recswvol = 255;
-       sc->sc_frequency = 44100;
-       sc->sc_precision = 16;
-       sc->sc_channels = 2;
 
        if (auconv_create_encodings(sc->sc_format, VAUDIO_NFORMATS,
            &sc->sc_encodings) != 0) {
@@ -615,6 +605,7 @@
 
        sc->sc_lastgain = 128;
        sc->sc_multiuser = false;
+       sc->sc_usemixer = true;
 
        error = vchan_autoconfig(sc);
        if (error != 0) {
@@ -806,12 +797,30 @@
 
                sysctl_createv(&sc->sc_log, 0, NULL, NULL,
                        CTLFLAG_READWRITE,
+                       CTLTYPE_INT, "latency",
+                       SYSCTL_DESCR("latency"),
+                       audio_sysctl_latency, 0,
+                       (void *)sc, 0,
+                       CTL_HW, node->sysctl_num,
+                       CTL_CREATE, CTL_EOL);
+
+               sysctl_createv(&sc->sc_log, 0, NULL, NULL,
+                       CTLFLAG_READWRITE,
                        CTLTYPE_BOOL, "multiuser",
                        SYSCTL_DESCR("allow multiple user acess"),
                        NULL, 0,
                        &sc->sc_multiuser, 0,
                        CTL_HW, node->sysctl_num,
                        CTL_CREATE, CTL_EOL);
+
+               sysctl_createv(&sc->sc_log, 0, NULL, NULL,
+                       CTLFLAG_READWRITE,
+                       CTLTYPE_BOOL, "usemixer",
+                       SYSCTL_DESCR("allow in-kernel mixing"),
+                       audio_sysctl_usemixer, 0,
+                       (void *)sc, 0,
+                       CTL_HW, node->sysctl_num,
+                       CTL_CREATE, CTL_EOL);
        }
 
        selinit(&sc->sc_rsel);
@@ -879,7 +888,7 @@
        DPRINTF(("audio_detach: sc=%p flags=%d\n", sc, flags));
 
        /* Start draining existing accessors of the device. */
-       if ((rc = config_detach_children(self, flags)) != 0)
+       if ((rc = config_detach_children(self, flags | DETACH_FORCE)) != 0)
                return rc;
        mutex_enter(sc->sc_lock);
        sc->sc_dying = true;
@@ -939,8 +948,8 @@
        }
        audio_free_ring(sc, &sc->sc_hwvc->sc_mpr);
        audio_free_ring(sc, &sc->sc_hwvc->sc_mrr);
-       audio_free_ring(sc, &sc->sc_pr);
-       audio_free_ring(sc, &sc->sc_rr);
+       audio_free_ring(sc, &sc->sc_mixring.sc_mpr);
+       audio_free_ring(sc, &sc->sc_mixring.sc_mrr);
        SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
                audio_destroy_pfilters(chan->vc);
                audio_destroy_rfilters(chan->vc);
@@ -1120,13 +1129,13 @@
 {
        int error;
 
-       sc->sc_pr.s.start = NULL;
+       sc->sc_mixring.sc_mpr.s.start = NULL;
        vc->sc_mpr.s.start = NULL;
-       sc->sc_rr.s.start = NULL;
+       sc->sc_mixring.sc_mrr.s.start = NULL;
        vc->sc_mrr.s.start = NULL;
 
        if (audio_can_playback(sc)) {
-               error = audio_alloc_ring(sc, &sc->sc_pr,
+               error = audio_alloc_ring(sc, &sc->sc_mixring.sc_mpr,
                    AUMODE_PLAY, AU_RING_SIZE);
                if (error)
                        goto bad_play1;
@@ -1137,7 +1146,7 @@
                        goto bad_play2;
        }
        if (audio_can_capture(sc)) {
-               error = audio_alloc_ring(sc, &sc->sc_rr,
+               error = audio_alloc_ring(sc, &sc->sc_mixring.sc_mrr,
                    AUMODE_RECORD, AU_RING_SIZE);
                if (error)
                        goto bad_rec1;
@@ -1150,14 +1159,14 @@
        return 0;
 
 bad_rec2:
-       if (sc->sc_rr.s.start != NULL)
-               audio_free_ring(sc, &sc->sc_rr);
+       if (sc->sc_mixring.sc_mrr.s.start != NULL)
+               audio_free_ring(sc, &sc->sc_mixring.sc_mrr);
 bad_rec1:
        if (vc->sc_mpr.s.start != NULL)
                audio_free_ring(sc, &vc->sc_mpr);
 bad_play2:
-       if (sc->sc_pr.s.start != NULL)
-               audio_free_ring(sc, &sc->sc_pr);
+       if (sc->sc_mixring.sc_mpr.s.start != NULL)
+               audio_free_ring(sc, &sc->sc_mixring.sc_mpr);
 bad_play1:
        return error;
 }
@@ -1585,6 +1594,9 @@
        /* Wait for pending I/O to complete. */
        error = cv_wait_sig(chan, sc->sc_lock);
 
+       if (!sc->sc_usemixer || vc == sc->sc_hwvc)
+               return error;
+
        found = false;



Home | Main Index | Thread Index | Old Index