From 976a366c9f8cb1962f9ca14cdd70d897b26bb8af Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Sat, 7 Dec 2019 12:05:51 +0800 Subject: [PATCH] device-port: moving streams since active_port on source changes status When the active port of a source becomes unavailable, all streams from that source should be moved to the default source. When the active port of a source changes state from unavailable, all streams that have their preferred_source set to this source should be moved to this source. Signed-off-by: Hui Wang --- src/pulsecore/device-port.c | 23 +++++++++++++++++++++++ src/pulsecore/device-port.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c index 28e78a6e9..5863d7f9e 100644 --- a/src/pulsecore/device-port.c +++ b/src/pulsecore/device-port.c @@ -110,6 +110,16 @@ void pa_device_port_set_available(pa_device_port *p, pa_available_t status) { else pa_core_move_streams_to_newly_available_preferred_sink(p->core, sink); } + } else { + pa_source *source; + + source = pa_device_port_get_source(p); + if (source && p == source->active_port) { + if (source->active_port->available == PA_AVAILABLE_NO) + pa_source_move_streams_to_default_source(p->core, source); + else + pa_core_move_streams_to_newly_available_preferred_source(p->core, source); + } } pa_subscription_post(p->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index); @@ -249,3 +259,16 @@ pa_sink *pa_device_port_get_sink(pa_device_port *p) { } return rs; } + +pa_source *pa_device_port_get_source(pa_device_port *p) { + pa_source *rs = NULL; + pa_source *source; + uint32_t state; + + PA_IDXSET_FOREACH(source, p->card->sources, state) + if (p == pa_hashmap_get(source->ports, p->name)) { + rs = source; + break; + } + return rs; +} diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h index 41988e5bb..41198f64c 100644 --- a/src/pulsecore/device-port.h +++ b/src/pulsecore/device-port.h @@ -89,4 +89,6 @@ pa_device_port *pa_device_port_find_best(pa_hashmap *ports); pa_sink *pa_device_port_get_sink(pa_device_port *p); +pa_source *pa_device_port_get_source(pa_device_port *p); + #endif