mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
switch-on-port-available: Improve readability
Split a big conditional into separate checks and use pa_safe_streq instead of checking if a pointer is valid and calling pa_streq inside a conditional.
This commit is contained in:
parent
48021941a2
commit
cefe037afc
1 changed files with 13 additions and 4 deletions
|
|
@ -156,7 +156,7 @@ static int try_to_switch_profile(pa_device_port *port) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Give a high bonus in case this is the preferred profile */
|
/* Give a high bonus in case this is the preferred profile */
|
||||||
if (port->preferred_profile && pa_streq(name ? name : profile->name, port->preferred_profile))
|
if (pa_safe_streq(name ? name : profile->name, port->preferred_profile))
|
||||||
prio += 1000000;
|
prio += 1000000;
|
||||||
|
|
||||||
if (best_profile && best_prio >= prio)
|
if (best_profile && best_prio >= prio)
|
||||||
|
|
@ -261,10 +261,19 @@ static void switch_from_port(pa_device_port *port) {
|
||||||
return; /* Already deselected */
|
return; /* Already deselected */
|
||||||
|
|
||||||
/* Try to find a good enough port to switch to */
|
/* Try to find a good enough port to switch to */
|
||||||
PA_HASHMAP_FOREACH(p, port->card->ports, state)
|
PA_HASHMAP_FOREACH(p, port->card->ports, state) {
|
||||||
if (p->direction == port->direction && p != port && p->available != PA_AVAILABLE_NO &&
|
if (p == port)
|
||||||
(!best_port || best_port->priority < p->priority))
|
continue;
|
||||||
|
|
||||||
|
if (p->available == PA_AVAILABLE_NO)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (p->direction != port->direction)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!best_port || best_port->priority < p->priority)
|
||||||
best_port = p;
|
best_port = p;
|
||||||
|
}
|
||||||
|
|
||||||
pa_log_debug("Trying to switch away from port %s, found %s", port->name, best_port ? best_port->name : "no better option");
|
pa_log_debug("Trying to switch away from port %s, found %s", port->name, best_port ? best_port->name : "no better option");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue