From nobody Sat Jul 06 18:24:17 2024 X-Original-To: dev-commits-src-main@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 4WGf0y5gK7z5PMVN; Sat, 06 Jul 2024 18:24:18 +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 4WGf0y0JYpz54QK; Sat, 6 Jul 2024 18:24:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720290258; 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=Xy4XKOaz1l3HzHSWNVCYFQj1qkm5N4BaHuYxjfWX+8E=; b=Vbv6cbylt17uxapuuHii6SmYcy8ezVSFkZGWPc17YtGc2Cc4lBIIxSQ2WkyRJrfaVU8QI+ vL+B4gL0FYTjB48B9g7PkO0/Idzhbjd5RxFTRw6BFb93fKv3ePRIYJwoBqZTTLtWiQFJlC T2JP5ZvVhfAI/gPRBFcVzuGiDkvMnCiTyomBuIZu2ntwHc707FFewJjtf6cJkvZRHyF4RU Pio+JY+KBzkAaHmoyfdc5xW6rhzTnpbj0ypwvlUm4cXTuehd917HtjLETPMVL6FU7UfGlx OK37nXkOkgd0jH241nGN0DFdSRHcKUyg0CokTrJ+wGNvyf3SekZ5k14+ckW0uw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720290258; a=rsa-sha256; cv=none; b=EvLOokvXrT5wkzy0svT3R75N0+n1uO78DTOrT0M3nFcPR9UsyyMLN7Bs6iLbsZbPKs+WwU SZqWYRIbBoVSOW3UVC337+R4eDd3+srzyV3yvxc3OEM7+5g8R9E3Wlfh146QH4m9iubSHx z5KSkFBUVIuAEpKX98Ib3leI3xrcOK/vAfVhvri9tyKHbHzQ2StN5dmtOmU12M731kdm+Q V4tPysNPeNwfPxVV+v2hL37tES74OLd1LQ2gu+gZEmN7BV+mdOF0h2AYC9EyAIQKrpdubb LSJ2qtb537W1Lfzu4O0jq9awxeNPA8bHGPGNz/v7F/UTcxywJ/AFyb6t8vDR1w== 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=1720290258; 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=Xy4XKOaz1l3HzHSWNVCYFQj1qkm5N4BaHuYxjfWX+8E=; b=iEEcg4guSdtA9zZ1S41u/NaiRqSzmMWFw0WYN6xoHxKW85txI2F/BkfSRS7F1Ua/sLBTfJ FiXd2l7a6md20Y8m8IMlsaZQw+pSTs5MzwmtvlZ3jvw8+bLPrB9WLkC82wgwsaDKvQQ5ey 4eFCdGHCNoLgNCLslvVtdDJUPcXQ56Bv8ItgXk8N27yS2/1BPxCT3eY1EwaJytVdKJMbn3 lX1kgzS8aZUZxfvzcBcl3OGDnC1NaZtdRXEIEX4PqYBj1701D2oObLeUAulEYdHsAMzk2R Qt9Nw5lIW33ifXlFyMf1ybb8yLIoHO+2GN7jHp3VVf3hSIx0vJxVWYFJNBMpvg== 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 4WGf0x70wFzrVw; Sat, 6 Jul 2024 18:24:17 +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 466IOHqJ091024; Sat, 6 Jul 2024 18:24:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 466IOH54091021; Sat, 6 Jul 2024 18:24:17 GMT (envelope-from git) Date: Sat, 6 Jul 2024 18:24:17 GMT Message-Id: <202407061824.466IOH54091021@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 9d8b93bc9cce - main - sound: Refactor sndstat_get_caps() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 9d8b93bc9ccea82b648ffa9354200c9e4d3f211b Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=9d8b93bc9ccea82b648ffa9354200c9e4d3f211b commit 9d8b93bc9ccea82b648ffa9354200c9e4d3f211b Author: Christos Margiolis AuthorDate: 2024-07-06 18:23:09 +0000 Commit: Christos Margiolis CommitDate: 2024-07-06 18:23:09 +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 --- 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);