Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/audio Limit the number of channels that userland app...



details:   https://anonhg.NetBSD.org/src/rev/e4b9ae6d219b
branches:  trunk
changeset: 745042:e4b9ae6d219b
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sat Feb 22 05:51:39 2020 +0000

description:
Limit the number of channels that userland apps can set (by AUDIO_SETINFO)
to the number of channels supported by the hardware or less, if the hardware
supports multi channels.
- On monaural or stereo hardware, userland apps can always set 1ch or 2ch.
  The kernel (audio layer) can convert mono-stereo each other.
- On 3ch (2.1ch) hardware, for example, userland apps can set 1, 2, or 3ch,
  but not 4ch or more.
This allows userland apps to know actual number of channels supported by
the hardware in the same way as before.
PR kern/54973.

diffstat:

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

diffs (71 lines):

diff -r c3bfaccc4ad0 -r e4b9ae6d219b sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Sat Feb 22 02:28:06 2020 +0000
+++ b/sys/dev/audio/audio.c     Sat Feb 22 05:51:39 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.42 2020/02/15 02:47:00 isaki Exp $ */
+/*     $NetBSD: audio.c,v 1.43 2020/02/22 05:51:39 isaki Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.42 2020/02/15 02:47:00 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.43 2020/02/22 05:51:39 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -541,7 +541,7 @@
 static int audio_file_setinfo(struct audio_softc *, audio_file_t *,
        const struct audio_info *);
 static int audio_track_setinfo_check(audio_format2_t *,
-       const struct audio_prinfo *);
+       const struct audio_prinfo *, const audio_format2_t *);
 static void audio_track_setinfo_water(audio_track_t *,
        const struct audio_info *);
 static int audio_hw_setinfo(struct audio_softc *, const struct audio_info *,
@@ -6634,7 +6634,8 @@
        }
 
        if (ptrack) {
-               pchanges = audio_track_setinfo_check(&pfmt, pi);
+               pchanges = audio_track_setinfo_check(&pfmt, pi,
+                   &sc->sc_pmixer->hwbuf.fmt);
                if (pchanges == -1) {
 #if defined(AUDIO_DEBUG)
                        char fmtbuf[64];
@@ -6648,7 +6649,8 @@
                        pchanges = 1;
        }
        if (rtrack) {
-               rchanges = audio_track_setinfo_check(&rfmt, ri);
+               rchanges = audio_track_setinfo_check(&rfmt, ri,
+                   &sc->sc_rmixer->hwbuf.fmt);
                if (rchanges == -1) {
 #if defined(AUDIO_DEBUG)
                        char fmtbuf[64];
@@ -6760,7 +6762,8 @@
  * Return value of -1 indicates that error EINVAL has occurred.
  */
 static int
-audio_track_setinfo_check(audio_format2_t *fmt, const struct audio_prinfo *info)
+audio_track_setinfo_check(audio_format2_t *fmt, const struct audio_prinfo *info,
+       const audio_format2_t *hwfmt)
 {
        int changes;
 
@@ -6784,6 +6787,13 @@
                changes = 1;
        }
        if (SPECIFIED(info->channels)) {
+               /*
+                * We can convert between monaural and stereo each other.
+                * We can reduce than the number of channels that the hardware
+                * supports.
+                */
+               if (info->channels > 2 && info->channels > hwfmt->channels)
+                       return -1;
                fmt->channels = info->channels;
                changes = 1;
        }



Home | Main Index | Thread Index | Old Index