|
|
0386fe |
From fa883e254c28a36657b0f28443bd69ee5a1821e0 Mon Sep 17 00:00:00 2001
|
|
|
0386fe |
From: Tanu Kaskinen <tanuk@iki.fi>
|
|
|
0386fe |
Date: Thu, 16 Feb 2017 12:09:39 +0200
|
|
|
0386fe |
Subject: [PATCH 4/4] core, device-port: check availability when choosing the
|
|
|
0386fe |
default device
|
|
|
0386fe |
|
|
|
0386fe |
It doesn't make sense to use a sink or source whose active port is
|
|
|
0386fe |
unavailable, so let's take this into account when choosing the default
|
|
|
0386fe |
sink and source.
|
|
|
0386fe |
---
|
|
|
0386fe |
src/pulsecore/core.c | 16 ++++++++++++++++
|
|
|
0386fe |
src/pulsecore/device-port.c | 8 ++++++++
|
|
|
0386fe |
2 files changed, 24 insertions(+)
|
|
|
0386fe |
|
|
|
0386fe |
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
|
|
|
0386fe |
index da1abb3ba..340b41ff3 100644
|
|
|
0386fe |
--- a/src/pulsecore/core.c
|
|
|
0386fe |
+++ b/src/pulsecore/core.c
|
|
|
0386fe |
@@ -265,6 +265,14 @@ static int compare_sinks(pa_sink *a, pa_sink *b) {
|
|
|
0386fe |
|
|
|
0386fe |
core = a->core;
|
|
|
0386fe |
|
|
|
0386fe |
+ /* Available sinks always beat unavailable sinks. */
|
|
|
0386fe |
+ if (a->active_port && a->active_port->available == PA_AVAILABLE_NO
|
|
|
0386fe |
+ && (!b->active_port || b->active_port->available != PA_AVAILABLE_NO))
|
|
|
0386fe |
+ return -1;
|
|
|
0386fe |
+ if (b->active_port && b->active_port->available == PA_AVAILABLE_NO
|
|
|
0386fe |
+ && (!a->active_port || a->active_port->available != PA_AVAILABLE_NO))
|
|
|
0386fe |
+ return 1;
|
|
|
0386fe |
+
|
|
|
0386fe |
/* The configured default sink is preferred over any other sink. */
|
|
|
0386fe |
if (b == core->configured_default_sink)
|
|
|
0386fe |
return -1;
|
|
|
0386fe |
@@ -331,6 +339,14 @@ static int compare_sources(pa_source *a, pa_source *b) {
|
|
|
0386fe |
|
|
|
0386fe |
core = a->core;
|
|
|
0386fe |
|
|
|
0386fe |
+ /* Available sources always beat unavailable sources. */
|
|
|
0386fe |
+ if (a->active_port && a->active_port->available == PA_AVAILABLE_NO
|
|
|
0386fe |
+ && (!b->active_port || b->active_port->available != PA_AVAILABLE_NO))
|
|
|
0386fe |
+ return -1;
|
|
|
0386fe |
+ if (b->active_port && b->active_port->available == PA_AVAILABLE_NO
|
|
|
0386fe |
+ && (!a->active_port || a->active_port->available != PA_AVAILABLE_NO))
|
|
|
0386fe |
+ return 1;
|
|
|
0386fe |
+
|
|
|
0386fe |
/* The configured default source is preferred over any other source. */
|
|
|
0386fe |
if (b == core->configured_default_source)
|
|
|
0386fe |
return -1;
|
|
|
0386fe |
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
|
|
|
0386fe |
index 7c9ddf325..76a7e80a1 100644
|
|
|
0386fe |
--- a/src/pulsecore/device-port.c
|
|
|
0386fe |
+++ b/src/pulsecore/device-port.c
|
|
|
0386fe |
@@ -93,6 +93,14 @@ void pa_device_port_set_available(pa_device_port *p, pa_available_t status) {
|
|
|
0386fe |
* be created before port objects, and then p->card could be non-NULL for
|
|
|
0386fe |
* the whole lifecycle of pa_device_port. */
|
|
|
0386fe |
if (p->card) {
|
|
|
0386fe |
+ /* A sink or source whose active port is unavailable can't be the
|
|
|
0386fe |
+ * default sink/source, so port availability changes may affect the
|
|
|
0386fe |
+ * default sink/source choice. */
|
|
|
0386fe |
+ if (p->direction == PA_DIRECTION_OUTPUT)
|
|
|
0386fe |
+ pa_core_update_default_sink(p->core);
|
|
|
0386fe |
+ else
|
|
|
0386fe |
+ pa_core_update_default_source(p->core);
|
|
|
0386fe |
+
|
|
|
0386fe |
pa_subscription_post(p->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
|
|
|
0386fe |
pa_hook_fire(&p->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p);
|
|
|
0386fe |
}
|
|
|
0386fe |
--
|
|
|
0386fe |
2.14.3
|
|
|
0386fe |
|