From 13511e92951096179230b57a22a52af716ce3b75 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 24 Jan 2024 12:08:00 +0100 Subject: [PATCH] jack: improve running check When we get a node info about our own state, we can use the active state of the node to decide if we are running or not. Otherwise, we will try to hide ports from JACK clients that suspend (while still active). See #3794 --- pipewire-jack/src/pipewire-jack.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pipewire-jack/src/pipewire-jack.c b/pipewire-jack/src/pipewire-jack.c index b891e60a3..46a992fd0 100644 --- a/pipewire-jack/src/pipewire-jack.c +++ b/pipewire-jack/src/pipewire-jack.c @@ -3241,18 +3241,28 @@ static const struct pw_proxy_events proxy_events = { .destroy = proxy_destroy, }; +static bool node_is_active(struct client *c, struct object *n) +{ + return !n->node.is_jack || + (c->node_id == n->id ? c->active : n->node.is_running); +} + static void node_info(void *data, const struct pw_node_info *info) { struct object *n = data; struct client *c = n->client; - const char *str; + bool active; if (info->change_mask & PW_NODE_CHANGE_MASK_PROPS) { - str = spa_dict_lookup(info->props, PW_KEY_NODE_ALWAYS_PROCESS); + /* JACK clients always need ALWAYS_PROCESS=true or else they don't + * conform to the JACK API. We would try to hide the ports of + * PAUSED JACK clients, for example, even if they are active. */ + const char *str = spa_dict_lookup(info->props, PW_KEY_NODE_ALWAYS_PROCESS); n->node.is_jack = str ? spa_atob(str) : false; } - n->node.is_running = !n->node.is_jack || (info->state == PW_NODE_STATE_RUNNING); + n->node.is_running = info->state == PW_NODE_STATE_RUNNING; + active = node_is_active(c, n); pw_log_debug("DSP node %d %08"PRIx64" jack:%u state change %s running:%d", info->id, info->change_mask, n->node.is_jack, @@ -3264,7 +3274,7 @@ static void node_info(void *data, const struct pw_node_info *info) if (p->type != INTERFACE_Port || p->removed || p->port.node_id != info->id) continue; - if (n->node.is_running) + if (active) queue_notify(c, NOTIFY_TYPE_PORTREGISTRATION, p, 1, NULL); else { spa_list_for_each(l, &c->context.objects, link) { @@ -3492,7 +3502,7 @@ static void registry_event_global(void *data, uint32_t id, o->port.latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT); o->port.latency[SPA_DIRECTION_OUTPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_OUTPUT); - do_emit = !ot->node.is_jack || ot->node.is_running; + do_emit = node_is_active(c, ot); o->proxy = pw_registry_bind(c->registry, id, type, PW_VERSION_PORT, 0);