Then fall back to the unknown ones, and only then pick one we know to be unavailable as a last resort. --- src/pulsecore/sink.c | 18 ++++++++++++++++-- src/pulsecore/source.c | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 95cf9b6..0f5a0de 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -304,17 +304,31 @@ pa_sink* pa_sink_new( void *state; pa_device_port *p; + /* Try hard to pick an available port, first */ PA_HASHMAP_FOREACH(p, s->ports, state) { - if (p->available == PA_AVAILABLE_NO) + if (s->available != PA_AVAILABLE_YES) continue; if (!s->active_port || p->priority > s->active_port->priority) s->active_port = p; } + + /* If we don't have any available ports, try the unknown ones... */ if (!s->active_port) { - PA_HASHMAP_FOREACH(p, s->ports, state) + PA_HASHMAP_FOREACH(p, s->ports, state) { + if (s->available != PA_AVAILABLE_UNKNOWN) + continue; + if (!s->active_port || p->priority > s->active_port->priority) s->active_port = p; + } + + /* OK, if we can't find one in a good state of availability, just pick any port */ + if (!s->active_port) { + PA_HASHMAP_FOREACH(p, s->ports, state) + if (!s->active_port || p->priority > s->active_port->priority) + s->active_port = p; + } } } diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index c52d6e7..965aff1 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -292,18 +292,31 @@ pa_source* pa_source_new( void *state; pa_device_port *p; + /* Try hard to pick an available port, first */ PA_HASHMAP_FOREACH(p, s->ports, state) { - if (s->available == PA_AVAILABLE_NO) + if (s->available != PA_AVAILABLE_YES) continue; if (!s->active_port || p->priority > s->active_port->priority) s->active_port = p; } + /* If we don't have any available ports, try the unknown ones... */ if (!s->active_port) { - PA_HASHMAP_FOREACH(p, s->ports, state) + PA_HASHMAP_FOREACH(p, s->ports, state) { + if (s->available != PA_AVAILABLE_UNKNOWN) + continue; + if (!s->active_port || p->priority > s->active_port->priority) s->active_port = p; + } + + /* OK, if we can't find one in a good state of availability, just pick any port */ + if (!s->active_port) { + PA_HASHMAP_FOREACH(p, s->ports, state) + if (!s->active_port || p->priority > s->active_port->priority) + s->active_port = p; + } } } -- 1.8.4.3