acp: Don't sync hardware volumes while UCM device is disabled

The hardware controls we track for volume and mute state can change as
part of enabling or disabling the UCM device. This then triggers a
re-sync of our state with the hardware controls, which can e.g. set our
volume to an unwanted value as the result of enabling the device, or set
a hardware control to a wrong value based on our volume while disabling
the device. So these UCM-triggered changes to enable/disable the device
will at best show up on user interfaces and cause confusion, but maybe
even will push the hardware into an unexpected state.

The volume and mute state we set from user interfaces only make sense
when the devices are enabled. They should not be kept in sync with
hardware for inactive UCM devices [1]. Skip the callbacks for reading
and changing volume and mute state if the UCM device is disabled. This
way, the volume/mute controls for sinks/sources are essentially detached
from the hardware controls until the UCM device is re-enabled.

[1] https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/772#note_1872757

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/772
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
Alper Nebi Yasak 2023-11-28 11:03:22 +03:00 committed by Wim Taymans
parent 0bdad320cd
commit 9b9ce21b1d
3 changed files with 42 additions and 0 deletions

View file

@ -1143,6 +1143,14 @@ static int read_volume(pa_alsa_device *dev)
uint32_t i;
int res;
if (dev->ucm_context) {
if (!dev->active_port)
return 0;
pa_alsa_ucm_port_data *data = PA_DEVICE_PORT_DATA(dev->active_port);
if (pa_alsa_ucm_port_device_status(data) <= 0)
return 0;
}
if (!dev->mixer_handle)
return 0;
@ -1178,6 +1186,14 @@ static void set_volume(pa_alsa_device *dev, const pa_cvolume *v)
if (v != &dev->real_volume)
dev->real_volume = *v;
if (dev->ucm_context) {
if (!dev->active_port)
return;
pa_alsa_ucm_port_data *data = PA_DEVICE_PORT_DATA(dev->active_port);
if (pa_alsa_ucm_port_device_status(data) <= 0)
return;
}
if (!dev->mixer_handle)
return;
@ -1231,6 +1247,14 @@ static int read_mute(pa_alsa_device *dev)
bool mute;
int res;
if (dev->ucm_context) {
if (!dev->active_port)
return 0;
pa_alsa_ucm_port_data *data = PA_DEVICE_PORT_DATA(dev->active_port);
if (pa_alsa_ucm_port_device_status(data) <= 0)
return 0;
}
if (!dev->mixer_handle)
return 0;
@ -1253,6 +1277,14 @@ static void set_mute(pa_alsa_device *dev, bool mute)
{
dev->muted = mute;
if (dev->ucm_context) {
if (!dev->active_port)
return;
pa_alsa_ucm_port_data *data = PA_DEVICE_PORT_DATA(dev->active_port);
if (pa_alsa_ucm_port_device_status(data) <= 0)
return;
}
if (!dev->mixer_handle)
return;