card: Only update port's preferred profile if profile is saved

In case pa_card_set_profile is called with save=false, then probably
it makes more sense not to update the port's preferred profile as well.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This commit is contained in:
David Henningsson 2015-11-26 14:29:23 +01:00
parent 55f065301a
commit cd46a4ef06

View file

@ -258,12 +258,22 @@ static const char* profile_name_for_dir(pa_card_profile *cp, pa_direction_t dir)
return cp->name; return cp->name;
} }
int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save) { static void update_port_preferred_profile(pa_card *c) {
int r;
pa_sink *sink; pa_sink *sink;
pa_source *source; pa_source *source;
uint32_t state; uint32_t state;
PA_IDXSET_FOREACH(sink, c->sinks, state)
if (sink->active_port)
pa_device_port_set_preferred_profile(sink->active_port, profile_name_for_dir(c->active_profile, PA_DIRECTION_OUTPUT));
PA_IDXSET_FOREACH(source, c->sources, state)
if (source->active_port)
pa_device_port_set_preferred_profile(source->active_port, profile_name_for_dir(c->active_profile, PA_DIRECTION_INPUT));
}
int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save) {
int r;
pa_assert(c); pa_assert(c);
pa_assert(profile); pa_assert(profile);
pa_assert(profile->card == c); pa_assert(profile->card == c);
@ -274,7 +284,10 @@ int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save) {
} }
if (c->active_profile == profile) { if (c->active_profile == profile) {
c->save_profile = c->save_profile || save; if (save && !c->save_profile) {
update_port_preferred_profile(c);
c->save_profile = true;
}
return 0; return 0;
} }
@ -288,12 +301,8 @@ int pa_card_set_profile(pa_card *c, pa_card_profile *profile, bool save) {
c->active_profile = profile; c->active_profile = profile;
c->save_profile = save; c->save_profile = save;
PA_IDXSET_FOREACH(sink, c->sinks, state) if (save)
if (sink->active_port) update_port_preferred_profile(c);
pa_device_port_set_preferred_profile(sink->active_port, profile_name_for_dir(profile, PA_DIRECTION_OUTPUT));
PA_IDXSET_FOREACH(source, c->sources, state)
if (source->active_port)
pa_device_port_set_preferred_profile(source->active_port, profile_name_for_dir(profile, PA_DIRECTION_INPUT));
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], c); pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], c);