From 414644dff1abd32294db3be1fde001f56ec9e65a Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Wed, 22 Jul 2020 13:28:47 +0300 Subject: [PATCH] device-port: send sink and source change events when availability changes The lack of change events caused GUIs to not update the port status. Related bug report: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/941 --- src/pulsecore/device-port.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c index 07761365e..416bb1a8a 100644 --- a/src/pulsecore/device-port.c +++ b/src/pulsecore/device-port.c @@ -107,8 +107,20 @@ void pa_device_port_set_available(pa_device_port *p, pa_available_t status) { * be created before port objects, and then p->card could be non-NULL for * the whole lifecycle of pa_device_port. */ if (p->card && p->card->linked) { + pa_sink *sink; + pa_source *source; + pa_subscription_post(p->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, p->card->index); + + sink = pa_device_port_get_sink(p); + source = pa_device_port_get_source(p); + if (sink) + pa_subscription_post(p->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, sink->index); + if (source) + pa_subscription_post(p->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, source->index); + pa_hook_fire(&p->core->hooks[PA_CORE_HOOK_PORT_AVAILABLE_CHANGED], p); + /* A sink or source whose active port is unavailable can't be the * default sink/source, so port availability changes may affect the * default sink/source choice. */ @@ -118,9 +130,6 @@ void pa_device_port_set_available(pa_device_port *p, pa_available_t status) { 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) { if (p->core->rescue_streams) @@ -129,9 +138,6 @@ void pa_device_port_set_available(pa_device_port *p, pa_available_t status) { 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) { if (p->core->rescue_streams)