device-port: moving streams due to changing the status of active_port
authorHui Wang <hui.wang@canonical.com>
Wed, 16 Jan 2019 04:58:16 +0000 (12:58 +0800)
committerHui Wang <hui.wang@canonical.com>
Wed, 27 Nov 2019 04:23:17 +0000 (12:23 +0800)
When the active port of a sink becomes unavailable, all streams from
that sink should be moved to the default sink.

When the active port of a sink changes state from unavailable, all
streams that have their preferred_sink set to this sink should be moved
to this sink.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
src/pulsecore/device-port.c
src/pulsecore/device-port.h

index fb12772..4a42cf7 100644 (file)
@@ -100,6 +100,18 @@ void pa_device_port_set_available(pa_device_port *p, pa_available_t status) {
         else
             pa_core_update_default_source(p->core);
 
+        if (p->direction == PA_DIRECTION_OUTPUT) {
+            pa_sink *sink;
+
+            sink = pa_device_port_get_sink(p);
+            if (sink && p == sink->active_port) {
+                if (sink->active_port->available == PA_AVAILABLE_NO)
+                    pa_sink_move_streams_to_default_sink(p->core, sink);
+                else
+                    pa_core_move_streams_to_newly_available_preferred_sink(p->core, sink);
+            }
+        }
+
         pa_subscription_post(p->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index);
         pa_hook_fire(&p->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p);
     }
@@ -224,3 +236,16 @@ pa_device_port *pa_device_port_find_best(pa_hashmap *ports)
 
     return best;
 }
+
+pa_sink *pa_device_port_get_sink(pa_device_port *p) {
+    pa_sink *rs = NULL;
+    pa_sink *sink;
+    uint32_t state;
+
+    PA_IDXSET_FOREACH(sink, p->card->sinks, state)
+        if (p == pa_hashmap_get(sink->ports, p->name)) {
+            rs = sink;
+            break;
+        }
+    return rs;
+}
index fbdce1a..41988e5 100644 (file)
@@ -87,4 +87,6 @@ void pa_device_port_set_preferred_profile(pa_device_port *p, const char *new_pp)
 
 pa_device_port *pa_device_port_find_best(pa_hashmap *ports);
 
+pa_sink *pa_device_port_get_sink(pa_device_port *p);
+
 #endif