alsa-ucm: Always create device conflicting/supported device idxsets

This is intended to make the current and upcoming code a bit clearer, as
we won't need to constantly check for the existence of these idxsets
before using or operating on them.
This commit is contained in:
buque 2023-04-27 12:09:02 +08:00
parent 8c97c51ab0
commit 4486e0d28f
2 changed files with 143 additions and 1 deletions

View File

@ -0,0 +1,138 @@
From d8c89de24dbe261cadb76f9715e25215af3a6faa Mon Sep 17 00:00:00 2001
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Date: Thu, 24 Jun 2021 08:32:19 +0300
Subject: [PATCH] alsa-ucm: Always create device conflicting/supported device
idxsets
This is intended to make the current and upcoming code a bit clearer, as
we won't need to constantly check for the existence of these idxsets
before using or operating on them.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/596>
Signed-off-by: buque <wuxu.wu@huawei.com>
---
src/modules/alsa/alsa-ucm.c | 64 ++++++++++++++++---------------------
1 file changed, 27 insertions(+), 37 deletions(-)
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index 08e36b571..3e23bc416 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -523,10 +523,10 @@ static int ucm_get_device_property(
n_confdev = snd_use_case_get_list(uc_mgr, id, &devices);
pa_xfree(id);
+ device->conflicting_devices = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
if (n_confdev <= 0)
pa_log_debug("No %s for device %s", "_conflictingdevs", device_name);
else {
- device->conflicting_devices = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
ucm_add_devices_to_idxset(device->conflicting_devices, device, verb->devices, devices, n_confdev);
snd_use_case_free_list(devices, n_confdev);
}
@@ -535,10 +535,10 @@ static int ucm_get_device_property(
n_suppdev = snd_use_case_get_list(uc_mgr, id, &devices);
pa_xfree(id);
+ device->supported_devices = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
if (n_suppdev <= 0)
pa_log_debug("No %s for device %s", "_supporteddevs", device_name);
else {
- device->supported_devices = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
ucm_add_devices_to_idxset(device->supported_devices, device, verb->devices, devices, n_suppdev);
snd_use_case_free_list(devices, n_suppdev);
}
@@ -730,29 +730,17 @@ static void append_lost_relationship(pa_alsa_ucm_device *dev) {
uint32_t idx;
pa_alsa_ucm_device *d;
- if (dev->conflicting_devices) {
- PA_IDXSET_FOREACH(d, dev->conflicting_devices, idx) {
- if (!d->conflicting_devices)
- d->conflicting_devices = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+ PA_IDXSET_FOREACH(d, dev->conflicting_devices, idx)
+ if (pa_idxset_put(d->conflicting_devices, dev, NULL) == 0)
+ pa_log_warn("Add lost conflicting device %s to %s",
+ pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME),
+ pa_proplist_gets(d->proplist, PA_ALSA_PROP_UCM_NAME));
- if (pa_idxset_put(d->conflicting_devices, dev, NULL) == 0)
- pa_log_warn("Add lost conflicting device %s to %s",
- pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME),
- pa_proplist_gets(d->proplist, PA_ALSA_PROP_UCM_NAME));
- }
- }
-
- if (dev->supported_devices) {
- PA_IDXSET_FOREACH(d, dev->supported_devices, idx) {
- if (!d->supported_devices)
- d->supported_devices = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
-
- if (pa_idxset_put(d->supported_devices, dev, NULL) == 0)
- pa_log_warn("Add lost supported device %s to %s",
- pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME),
- pa_proplist_gets(d->proplist, PA_ALSA_PROP_UCM_NAME));
- }
- }
+ PA_IDXSET_FOREACH(d, dev->supported_devices, idx)
+ if (pa_idxset_put(d->supported_devices, dev, NULL) == 0)
+ pa_log_warn("Add lost supported device %s to %s",
+ pa_proplist_gets(dev->proplist, PA_ALSA_PROP_UCM_NAME),
+ pa_proplist_gets(d->proplist, PA_ALSA_PROP_UCM_NAME));
}
int pa_alsa_ucm_query_profiles(pa_alsa_ucm_config *ucm, int card_index) {
@@ -1199,23 +1187,27 @@ static int ucm_check_conformance(
return 1;
}
- if (dev->conflicting_devices) { /* the device defines conflicting devices */
- PA_IDXSET_FOREACH(d, dev->conflicting_devices, idx) {
- for (i = 0; i < dev_num; i++) {
- if (pdevices[i] == d) {
- pa_log_debug("Conflicting device found");
- return 0;
- }
+ PA_IDXSET_FOREACH(d, dev->conflicting_devices, idx) {
+ /* No conflicting device must already be selected */
+ for (i = 0; i < dev_num; i++) {
+ if (pdevices[i] == d) {
+ pa_log_debug("Conflicting device found");
+ return 0;
}
}
- } else if (dev->supported_devices) { /* the device defines supported devices */
+ }
+
+ if (!pa_idxset_isempty(dev->supported_devices)) {
+ /* No already selected device must be unsupported */
for (i = 0; i < dev_num; i++) {
if (!ucm_device_exists(dev->supported_devices, pdevices[i])) {
pa_log_debug("Supported device not found");
return 0;
}
}
- } else { /* not support any other devices */
+ }
+
+ if (pa_idxset_isempty(dev->conflicting_devices) && pa_idxset_isempty(dev->supported_devices)) {
pa_log_debug("Not support any other devices");
return 0;
}
@@ -2113,10 +2105,8 @@ static void free_verb(pa_alsa_ucm_verb *verb) {
pa_proplist_free(di->proplist);
- if (di->conflicting_devices)
- pa_idxset_free(di->conflicting_devices, NULL);
- if (di->supported_devices)
- pa_idxset_free(di->supported_devices, NULL);
+ pa_idxset_free(di->conflicting_devices, NULL);
+ pa_idxset_free(di->supported_devices, NULL);
pa_xfree(di->eld_mixer_device_name);
--
2.33.0

View File

@ -6,7 +6,7 @@
Name: pulseaudio
Summary: Improved Linux Sound Server
Version: 16.1
Release: 8
Release: 9
License: LGPLv2+
URL: https://www.freedesktop.org/wiki/Software/PulseAudio
Source0: https://freedesktop.org/software/pulseaudio/releases/pulseaudio-%{version}.tar.xz
@ -20,6 +20,7 @@ Patch1003: 0001-alsa-mixer-allow-to-re-attach-the-mixer-control-elem.patch
Patch1004: 0001-idxset-Add-set-contains-function.patch
Patch1005: 0002-idxset-Add-set-comparison-operations.patch
Patch1006: 0003-idxset-Add-reverse-iteration-functions.patch
Patch1007: 0001-alsa-ucm-Always-create-device-conflicting-supported-.patch
BuildRequires: meson
BuildRequires: automake libtool gcc-c++ bash-completion
@ -247,6 +248,9 @@ exit 0
%{_mandir}/man*/*
%changelog
* Thu April 27 2023 wuxu <wuxu.wu@huawei.com> - 16.1-9
- alsa-ucm: Always create device conflicting/supported device idxsets
* Tue Mar 14 2023 peijiankang <peijiankang@kylinos.cn> - 16.1-8
- fix cannot open shared object file libprotocol-native.so libalsa-util.so