From nobody Wed Jul 10 16:49:11 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WK3jN0VyFz5Qn2C; Wed, 10 Jul 2024 16:49:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WK3jM4Sg1z4gTD; Wed, 10 Jul 2024 16:49:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720630151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lvD1hPaSQVYMrc9RAkK7zuls0CLuvj9MQrYb4sX5q2Y=; b=LVc1CJTRrY/mpeCElH9pwuT5uMbXv2XRxQptEPxZFl7aWu/wfYoeSQ2cLzd3zVNS4CJb6X mqYlKG3WS1jd2a6+QrAukn76qpUUqovXGN+T8AV9OCg8wAKZQLpAgQRvhxH1T61qQINGpq zCxN1fL7LCjvQT7oljfniK3fbSHWhOVWERwRxGQNR13QY4oCHbVdlsHjrX6RMvI+c6ag3+ t/6lXkomTrbvMpOh/prMCFKLW46dO5NJLFDB3IK/zC5GsD0AVsU/v91rozl8EbaXAFhK5w CRm3PuaxLJXq1eCihL1IvTCXNzkIdjZbuerYP9NdpCByNV6nkvIvIsqVPY/HZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720630151; a=rsa-sha256; cv=none; b=PhOTStdAFmDJu3vpFdCkfM0VrIeMov/j3bT4Nkz8XmL3d99WgUFm6LQ2FbOvT46lG4sjSH cn3XQ+DVoEAdFwyukr6zN5Ro2KSlVdw2qOFQRgA0CuxgiFv/jDfEEUz10PypneaJagPhvE TtdUIaNRapSmJ/SUIdJYc+iSdq/RarsBIq0zm9IBzXtF1cyAsQHGmVTTaq+DFva4x/wkhb ufYdg8oufXFWi8B9sI1VUl3SCkqtERgtdsFknIfBK+Y2fTeC4Fe4UvpLqxqoEswGjwMiw/ gMylUgFzweiPa0LbzPtonT1nt3uufNul9i4DL2ZMlv37B0/qNyGuPyryPCEmWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720630151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lvD1hPaSQVYMrc9RAkK7zuls0CLuvj9MQrYb4sX5q2Y=; b=gT8d4vBVKFsYiEgUe0DdLqQ2I9zfHW4OGnZuZwpp9m0+mLSGMEApEuXqeNQs0AtnVpvG8w bO5m/iS9glzU6a3fPJqhLazrfD8XsVxGmwRUT4o+oWFUVW4pD+LKlvw+viDvAqCvUe87TB ulSDJN23sNUZoxbvJPndVYmN4NMGlWAIzptlw6qTZkjVbkEiz46wTI+fPYzhAgEg59DL+Y Tq2MCDhz+pansSO8VZUYkXbU8vYJWchH8GB/Wj6VUzQwfQ6lwDJu5ppzEvwTK7wzBmFwYB 6dHw0u/5IL7WSo6TMfztARTwjw1xUjIN0irpUYV7hmPCIbcnPUWNibDmuj1t0w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WK3jM44HJzPpH; Wed, 10 Jul 2024 16:49:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46AGnBWs035168; Wed, 10 Jul 2024 16:49:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46AGnBfv035165; Wed, 10 Jul 2024 16:49:11 GMT (envelope-from git) Date: Wed, 10 Jul 2024 16:49:11 GMT Message-Id: <202407101649.46AGnBfv035165@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: ecb0a2ed2f40 - stable/14 - sound: Refactor sndstat_get_caps() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ecb0a2ed2f40ed51b97c17e0be5529b4183dfa32 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=ecb0a2ed2f40ed51b97c17e0be5529b4183dfa32 commit ecb0a2ed2f40ed51b97c17e0be5529b4183dfa32 Author: Christos Margiolis AuthorDate: 2024-07-06 18:23:09 +0000 Commit: Christos Margiolis CommitDate: 2024-07-10 16:48:13 +0000 sound: Refactor sndstat_get_caps() The current implementation of sndstat_get_caps() does not work properly when VCHANs are enabled, as it skips all information about physical channels, and also assigns the min/max rates and channels to same values, which is usually not the case. A device either supports any sample rate within the [feeder_rate_min, feeder_rate_max] range, or [hw_rate_min, hw_rate_max] range when the device is opened in exclusive or bitperfect mode. The number of channels can also vary and is not always the same for both min and max. Refactor the whole function to resemble the way we handle fetching of these values in dsp_oss_audioinfo() and dsp_oss_engineinfo(). Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45872 (cherry picked from commit 9d8b93bc9ccea82b648ffa9354200c9e4d3f211b) --- sys/dev/sound/pcm/sndstat.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index 3be376e1da01..5b770810d19b 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -323,47 +323,37 @@ sndstat_write(struct cdev *i_dev, struct uio *buf, int flag) } static void -sndstat_get_caps(struct snddev_info *d, bool play, uint32_t *min_rate, +sndstat_get_caps(struct snddev_info *d, int dir, uint32_t *min_rate, uint32_t *max_rate, uint32_t *fmts, uint32_t *minchn, uint32_t *maxchn) { struct pcm_channel *c; - int dir; - - dir = play ? PCMDIR_PLAY : PCMDIR_REC; - - if (play && d->pvchancount > 0) { - *min_rate = *max_rate = d->pvchanrate; - *fmts = AFMT_ENCODING(d->pvchanformat); - *minchn = *maxchn = AFMT_CHANNEL(d->pvchanformat); - return; - } else if (!play && d->rvchancount > 0) { - *min_rate = *max_rate = d->rvchanrate; - *fmts = AFMT_ENCODING(d->rvchanformat); - *minchn = *maxchn = AFMT_CHANNEL(d->rvchanformat); - return; - } + struct pcmchan_caps *caps; + int i; *fmts = 0; *min_rate = UINT32_MAX; *max_rate = 0; *minchn = UINT32_MAX; *maxchn = 0; - CHN_FOREACH(c, d, channels.pcm) { - struct pcmchan_caps *caps; - int i; - if (c->direction != dir || (c->flags & CHN_F_VIRTUAL) != 0) + CHN_FOREACH(c, d, channels.pcm) { + if (c->direction != dir) continue; - CHN_LOCK(c); caps = chn_getcaps(c); - *min_rate = min(caps->minspeed, *min_rate); - *max_rate = max(caps->maxspeed, *max_rate); for (i = 0; caps->fmtlist[i]; i++) { *fmts |= AFMT_ENCODING(caps->fmtlist[i]); *minchn = min(AFMT_CHANNEL(caps->fmtlist[i]), *minchn); *maxchn = max(AFMT_CHANNEL(caps->fmtlist[i]), *maxchn); } + if ((c->flags & CHN_F_EXCLUSIVE) || + (pcm_getflags(d->dev) & SD_F_BITPERFECT)) { + *min_rate = min(*min_rate, caps->minspeed); + *max_rate = max(*max_rate, caps->maxspeed); + } else { + *min_rate = min(*min_rate, feeder_rate_min); + *max_rate = max(*max_rate, feeder_rate_max); + } CHN_UNLOCK(c); } if (*min_rate == UINT32_MAX) @@ -422,8 +412,8 @@ sndstat_build_sound4_nvlist(struct snddev_info *d, nvlist_t **dip) nvlist_add_number(di, SNDST_DSPS_PCHAN, d->playcount); nvlist_add_number(di, SNDST_DSPS_RCHAN, d->reccount); if (d->playcount > 0) { - sndstat_get_caps(d, true, &minrate, &maxrate, &fmts, &minchn, - &maxchn); + sndstat_get_caps(d, PCMDIR_PLAY, &minrate, &maxrate, &fmts, + &minchn, &maxchn); nvlist_add_number(di, "pminrate", minrate); nvlist_add_number(di, "pmaxrate", maxrate); nvlist_add_number(di, "pfmts", fmts); @@ -435,8 +425,8 @@ sndstat_build_sound4_nvlist(struct snddev_info *d, nvlist_t **dip) nvlist_move_nvlist(di, SNDST_DSPS_INFO_PLAY, diinfo); } if (d->reccount > 0) { - sndstat_get_caps(d, false, &minrate, &maxrate, &fmts, &minchn, - &maxchn); + sndstat_get_caps(d, PCMDIR_REC, &minrate, &maxrate, &fmts, + &minchn, &maxchn); nvlist_add_number(di, "rminrate", minrate); nvlist_add_number(di, "rmaxrate", maxrate); nvlist_add_number(di, "rfmts", fmts);