Rework profile/route handling

Add save property to Profile and Route params to notify the session
manager that they should be saved. Let the session manager only save
the Profile and Routes with the save flag.
Make pulse-server set the save flag on Profile and Route changes.
The result is that we can make a difference between user requested
changes and automatical changes and only remember the user preferences.
When a port changes availability, first check if we need to perform
a profile switch, if not select the new best port.
This commit is contained in:
Wim Taymans 2021-02-22 16:42:29 +01:00
parent 5ae92fd643
commit 8414092763
9 changed files with 176 additions and 105 deletions

View file

@ -1328,7 +1328,7 @@ static int device_enable(pa_card *impl, pa_alsa_mapping *mapping, pa_alsa_device
return 0;
}
int acp_card_set_profile(struct acp_card *card, uint32_t new_index)
int acp_card_set_profile(struct acp_card *card, uint32_t new_index, uint32_t flags)
{
pa_card *impl = (pa_card *)card;
pa_alsa_mapping *am;
@ -1397,8 +1397,8 @@ int acp_card_set_profile(struct acp_card *card, uint32_t new_index)
}
}
if (op)
op->profile.flags &= ~ACP_PROFILE_ACTIVE;
np->profile.flags |= ACP_PROFILE_ACTIVE;
op->profile.flags &= ~(ACP_PROFILE_ACTIVE | ACP_PROFILE_SAVE);
np->profile.flags |= ACP_PROFILE_ACTIVE | flags;
impl->card.active_profile_index = new_index;
if (impl->events && impl->events->profile_changed)
@ -1566,7 +1566,7 @@ struct acp_card *acp_card_new(uint32_t index, const struct acp_dict *props)
profile = "off";
profile_index = acp_card_find_best_profile_index(&impl->card, profile);
acp_card_set_profile(&impl->card, profile_index);
acp_card_set_profile(&impl->card, profile_index, 0);
init_eld_ctls(impl);
@ -1744,7 +1744,7 @@ uint32_t acp_device_find_best_port_index(struct acp_device *dev, const char *nam
return ACP_INVALID_INDEX;
}
int acp_device_set_port(struct acp_device *dev, uint32_t port_index)
int acp_device_set_port(struct acp_device *dev, uint32_t port_index, uint32_t flags)
{
pa_alsa_device *d = (pa_alsa_device*)dev;
pa_card *impl = d->card;
@ -1762,9 +1762,9 @@ int acp_device_set_port(struct acp_device *dev, uint32_t port_index)
return -EINVAL;
if (old)
old->port.flags &= ~ACP_PORT_ACTIVE;
old->port.flags &= ~(ACP_PORT_ACTIVE | ACP_PORT_SAVE);
d->active_port = p;
p->port.flags |= ACP_PORT_ACTIVE;
p->port.flags |= ACP_PORT_ACTIVE | flags;
if (impl->use_ucm) {
pa_alsa_ucm_port_data *data;

View file

@ -186,6 +186,7 @@ struct acp_card_events {
struct acp_port {
uint32_t index; /**< unique index for this port */
#define ACP_PORT_ACTIVE (1<<0)
#define ACP_PORT_SAVE (1<<1) /* if the port needs saving */
uint32_t flags; /**< extra port flags */
const char *name; /**< Name of this port */
@ -229,6 +230,7 @@ struct acp_card_profile {
uint32_t index;
#define ACP_PROFILE_ACTIVE (1<<0)
#define ACP_PROFILE_OFF (1<<1) /* the Off profile */
#define ACP_PROFILE_SAVE (1<<2) /* if the profile needs saving */
uint32_t flags;
const char *name;
@ -274,10 +276,10 @@ int acp_card_poll_descriptors_revents(struct acp_card *card, struct pollfd *pfds
int acp_card_handle_events(struct acp_card *card);
uint32_t acp_card_find_best_profile_index(struct acp_card *card, const char *name);
int acp_card_set_profile(struct acp_card *card, uint32_t profile_index);
int acp_card_set_profile(struct acp_card *card, uint32_t profile_index, uint32_t flags);
uint32_t acp_device_find_best_port_index(struct acp_device *dev, const char *name);
int acp_device_set_port(struct acp_device *dev, uint32_t port_index);
int acp_device_set_port(struct acp_device *dev, uint32_t port_index, uint32_t flags);
int acp_device_set_volume(struct acp_device *dev, const float *volume, uint32_t n_volume);
int acp_device_get_volume(struct acp_device *dev, float *volume, uint32_t n_volume);