From 391fa81fa8e7c48440461f76e0a874d2fa11e4ea Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 9 Oct 2020 16:43:31 +0200 Subject: [PATCH] impl-link: add an active state Avoid emission of events for each state change. Add an active state and aim to only emit events for paused<->active state changed or error. --- src/pipewire/impl-link.c | 12 ++++++++---- src/pipewire/introspect.c | 2 ++ src/pipewire/link.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pipewire/impl-link.c b/src/pipewire/impl-link.c index 5e2a4c4f0..d2d823974 100644 --- a/src/pipewire/impl-link.c +++ b/src/pipewire/impl-link.c @@ -112,7 +112,10 @@ static void link_update_state(struct pw_impl_link *link, enum pw_link_state stat pw_impl_link_emit_state_changed(link, old, state, error); link->info.change_mask |= PW_LINK_CHANGE_MASK_STATE; - info_changed(link); + if (state == PW_LINK_STATE_ERROR || + state == PW_LINK_STATE_PAUSED || + state == PW_LINK_STATE_ACTIVE) + info_changed(link); if (state == PW_LINK_STATE_ERROR && link->global) { struct pw_resource *resource; @@ -331,10 +334,9 @@ static int do_negotiate(struct pw_impl_link *this) free(this->info.format); this->info.format = format; - if (changed) { + if (changed) this->info.change_mask |= PW_LINK_CHANGE_MASK_FORMAT; - info_changed(this); - } + pw_log_debug(NAME" %p: result %d", this, res); return res; @@ -551,6 +553,7 @@ int pw_impl_link_activate(struct pw_impl_link *this) impl->activated = true; pw_log_info("(%s) activated", this->name); + link_update_state(this, PW_LINK_STATE_ACTIVE, 0, NULL); return 0; } @@ -719,6 +722,7 @@ int pw_impl_link_deactivate(struct pw_impl_link *this) impl->io_set = false; impl->activated = false; pw_log_info("(%s) deactivated", this->name); + link_update_state(this, PW_LINK_STATE_PAUSED, 0, NULL); return 0; } diff --git a/src/pipewire/introspect.c b/src/pipewire/introspect.c index c4269836a..e139267f2 100644 --- a/src/pipewire/introspect.c +++ b/src/pipewire/introspect.c @@ -78,6 +78,8 @@ const char *pw_link_state_as_string(enum pw_link_state state) return "allocating"; case PW_LINK_STATE_PAUSED: return "paused"; + case PW_LINK_STATE_ACTIVE: + return "active"; } return "invalid-state"; } diff --git a/src/pipewire/link.h b/src/pipewire/link.h index f291985e3..3be46b1d3 100644 --- a/src/pipewire/link.h +++ b/src/pipewire/link.h @@ -47,6 +47,7 @@ enum pw_link_state { PW_LINK_STATE_NEGOTIATING = 1, /**< the link is negotiating formats */ PW_LINK_STATE_ALLOCATING = 2, /**< the link is allocating buffers */ PW_LINK_STATE_PAUSED = 3, /**< the link is paused */ + PW_LINK_STATE_ACTIVE = 4, /**< the link is active */ }; /** Convert a \ref pw_link_state to a readable string \memberof pw_link */