commit:     916a0b55068c037e5871ab411da6c3a2e5444349
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 26 10:51:07 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 26 10:51:07 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=916a0b55

media-video/wireplumber: backport 100% CPU loop fixes

Closes: https://bugs.gentoo.org/866551
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../files/wireplumber-0.4.11-loop.patch            | 147 +++++++++++++++++++++
 .../wireplumber/wireplumber-0.4.11-r3.ebuild       | 131 ++++++++++++++++++
 2 files changed, 278 insertions(+)

diff --git a/media-video/wireplumber/files/wireplumber-0.4.11-loop.patch 
b/media-video/wireplumber/files/wireplumber-0.4.11-loop.patch
new file mode 100644
index 000000000000..75e2bafcaddc
--- /dev/null
+++ b/media-video/wireplumber/files/wireplumber-0.4.11-loop.patch
@@ -0,0 +1,147 @@
+https://bugs.gentoo.org/866551
+https://gitlab.freedesktop.org/pipewire/wireplumber/-/commit/37c839b9308cd3d6580bf01077db8cb29ec2aa2f
+https://gitlab.freedesktop.org/pipewire/wireplumber/-/commit/370b692933634675213110048fcda6dff52eb52b
+
+From: Pauli Virtanen <[email protected]>
+Date: Tue, 19 Jul 2022 20:39:06 +0300
+Subject: [PATCH] policy-node: fix potential rescan loop
+
+SiLink activation might be delayed indefinitely under some error
+conditions. Currently, policy-node schedules a rescan when it sees a
+non-activated link on a stream to be moved, which produces busy loop if
+the si-link doesn't activate.
+
+Instead of rescheduling on non-active si-links, just remove and emit a
+warning. The si-link then gets removed once it gets activated.
+
+Reproducer:
+
+1. Play audio from Rhythmbox and pause.
+2. Switch default output with pactl between two different outputs
+3. Links from the paused stream stay at "init"
+--- a/src/scripts/policy-node.lua
++++ b/src/scripts/policy-node.lua
+@@ -694,16 +694,15 @@ function handleLinkable (si)
+     local link = lookupLink (si_id, si_flags[si_id].peer_id)
+     if reconnect then
+       if link ~= nil then
+-        -- remove old link if active, otherwise schedule rescan
+-        if ((link:get_active_features() & Feature.SessionItem.ACTIVE) ~= 0) 
then
+-          si_flags[si_id].peer_id = nil
+-          link:remove ()
+-          Log.info (si, "... moving to new target")
+-        else
+-          scheduleRescan()
+-          Log.info (si, "... scheduled rescan")
+-          return
++        -- remove old link
++        if ((link:get_active_features() & Feature.SessionItem.ACTIVE) == 0) 
then
++          -- remove also not yet activated links: they might never become 
active,
++          -- and we should not loop waiting for them
++          Log.warning (link, "Link was not activated before removing")
+         end
++        si_flags[si_id].peer_id = nil
++        link:remove ()
++        Log.info (si, "... moving to new target")
+       end
+     else
+       if link ~= nil then
+GitLab
+
+From: Pauli Virtanen <[email protected]>
+Date: Tue, 19 Jul 2022 20:01:10 +0300
+Subject: [PATCH] m-si-link: don't wait for establish before activation +
+ cleanup links
+
+SiLink should not wait for WpLinks becoming ESTABLISHED, before
+activation. That flag shows whether a link has moved away from the
+"init" state, however, links to e.g. Pulseaudio corked streams can stay
+in "init" state until uncorking.  This causes trouble for policies,
+which needlessly wait for such links to establish.
+
+The WpLink objects may also be kept alive by other referents, and
+just unrefing them does not necessarily destroy the PW objects.
+
+Activate SiLink even if the WpLink is still in "init" state. It's enough
+that the link otherwise successfully establishes.
+
+At dispose time, explicitly request destroying the WpLinks that were
+created by the SiLink, to ensure they are removed even if there's
+something else referring to them.
+--- a/modules/module-si-standard-link.c
++++ b/modules/module-si-standard-link.c
+@@ -132,6 +132,27 @@ si_standard_link_get_associated_proxy (WpSessionItem * 
item, GType proxy_type)
+   return NULL;
+ }
+ 
++static void
++request_destroy_link (gpointer data, gpointer user_data)
++{
++  WpLink *link = WP_LINK (data);
++
++  wp_global_proxy_request_destroy (WP_GLOBAL_PROXY (link));
++}
++
++static void
++clear_node_links (GPtrArray **node_links_p)
++{
++  /*
++   * Something else (eg. object managers) may be keeping the WpLink
++   * objects alive. Deactive the links now, to destroy the PW objects.
++   */
++  if (*node_links_p)
++    g_ptr_array_foreach (*node_links_p, request_destroy_link, NULL);
++
++  g_clear_pointer (node_links_p, g_ptr_array_unref);
++}
++
+ static void
+ si_standard_link_disable_active (WpSessionItem *si)
+ {
+@@ -154,7 +175,8 @@ si_standard_link_disable_active (WpSessionItem *si)
+           WP_SI_LINKABLE (si_in));
+   }
+ 
+-  g_clear_pointer (&self->node_links, g_ptr_array_unref);
++  clear_node_links (&self->node_links);
++
+   self->n_active_links = 0;
+   self->n_failed_links = 0;
+   self->n_async_ops_wait = 0;
+@@ -168,7 +190,7 @@ on_link_activated (WpObject * proxy, GAsyncResult * res,
+     WpTransition * transition)
+ {
+   WpSiStandardLink *self = wp_transition_get_source_object (transition);
+-  guint len = self->node_links->len;
++  guint len = self->node_links ? self->node_links->len : 0;
+ 
+   /* Count the number of failed and active links */
+   if (wp_object_activate_finish (proxy, res, NULL))
+@@ -182,7 +204,7 @@ on_link_activated (WpObject * proxy, GAsyncResult * res,
+ 
+   /* We only active feature if all links activated successfully */
+   if (self->n_failed_links > 0) {
+-    g_clear_pointer (&self->node_links, g_ptr_array_unref);
++    clear_node_links (&self->node_links);
+     wp_transition_return_error (transition, g_error_new (
+         WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED,
+         "%d of %d PipeWire links failed to activate",
+@@ -251,7 +273,7 @@ create_links (WpSiStandardLink * self, WpTransition * 
transition,
+   /* Clear old links if any */
+   self->n_active_links = 0;
+   self->n_failed_links = 0;
+-  g_clear_pointer (&self->node_links, g_ptr_array_unref);
++  clear_node_links (&self->node_links);
+ 
+   /* tuple format:
+       uint32 node_id;
+@@ -327,7 +349,7 @@ create_links (WpSiStandardLink * self, WpTransition * 
transition,
+ 
+     /* activate to ensure it is created without errors */
+     wp_object_activate_closure (WP_OBJECT (link),
+-        WP_OBJECT_FEATURES_ALL, NULL,
++        WP_OBJECT_FEATURES_ALL & ~WP_LINK_FEATURE_ESTABLISHED, NULL,
+         g_cclosure_new_object (
+             (GCallback) on_link_activated, G_OBJECT (transition)));
+   }
+GitLab

diff --git a/media-video/wireplumber/wireplumber-0.4.11-r3.ebuild 
b/media-video/wireplumber/wireplumber-0.4.11-r3.ebuild
new file mode 100644
index 000000000000..99ca2c5c7956
--- /dev/null
+++ b/media-video/wireplumber/wireplumber-0.4.11-r3.ebuild
@@ -0,0 +1,131 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+# 1. Please regularly check (even at the point of bumping) Fedora's packaging
+# for needed backports at 
https://src.fedoraproject.org/rpms/wireplumber/tree/rawhide
+#
+# 2. Keep an eye on git master (for both PipeWire and WirePlumber) as things
+# continue to move quickly. It's not uncommon for fixes to be made shortly
+# after releases.
+
+LUA_COMPAT=( lua5-{3,4} )
+
+inherit lua-single meson systemd
+
+if [[ ${PV} == 9999 ]]; then
+       EGIT_REPO_URI="https://gitlab.freedesktop.org/pipewire/${PN}.git";
+       EGIT_BRANCH="master"
+       inherit git-r3
+else
+       
SRC_URI="https://gitlab.freedesktop.org/pipewire/${PN}/-/archive/${PV}/${P}.tar.gz";
+       KEYWORDS="~amd64 ~arm ~arm64 ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86"
+fi
+
+DESCRIPTION="Replacement for pipewire-media-session"
+HOMEPAGE="https://gitlab.freedesktop.org/pipewire/wireplumber";
+
+LICENSE="MIT"
+SLOT="0/0.4"
+IUSE="elogind system-service systemd test"
+
+REQUIRED_USE="
+       ${LUA_REQUIRED_USE}
+       ?? ( elogind systemd )
+       system-service? ( systemd )
+"
+
+RESTRICT="!test? ( test )"
+
+# introspection? ( dev-libs/gobject-introspection ) is valid but likely only 
used for doc building
+BDEPEND="
+       dev-libs/glib
+       dev-util/gdbus-codegen
+       dev-util/glib-utils
+       sys-devel/gettext
+"
+
+DEPEND="
+       ${LUA_DEPS}
+       >=dev-libs/glib-2.62
+       >=media-video/pipewire-0.3.53-r1:=
+       virtual/libintl
+       elogind? ( sys-auth/elogind )
+       systemd? ( sys-apps/systemd )
+"
+
+# Any dev-lua/* deps get declared like this inside RDEPEND:
+#      $(lua_gen_cond_dep '
+#              dev-lua/<NAME>[${LUA_USEDEP}]
+#      ')
+RDEPEND="${DEPEND}
+       system-service? (
+               acct-user/pipewire
+               acct-group/pipewire
+       )
+"
+
+DOCS=( {NEWS,README}.rst )
+
+PATCHES=(
+       "${FILESDIR}"/${PN}-0.4.10-config-disable-sound-server-parts.patch # 
defer enabling sound server parts to media-video/pipewire
+       "${FILESDIR}"/${P}-alsa-lua-crash.patch
+       "${FILESDIR}"/${P}-dbus-reconnect-crash.patch
+       "${FILESDIR}"/${P}-loop.patch
+)
+
+src_configure() {
+       local emesonargs=(
+               -Ddoc=disabled # Ebuild not wired up yet (Sphinx, Doxygen?)
+               -Dintrospection=disabled # Only used for Sphinx doc generation
+               -Dsystem-lua=true # We always unbundle everything we can
+               -Dsystem-lua-version=$(ver_cut 1-2 $(lua_get_version))
+               $(meson_feature elogind)
+               $(meson_feature systemd)
+               $(meson_use system-service systemd-system-service)
+               $(meson_use systemd systemd-user-service)
+               -Dsystemd-system-unit-dir=$(systemd_get_systemunitdir)
+               -Dsystemd-user-unit-dir=$(systemd_get_userunitdir)
+               $(meson_use test tests)
+       )
+
+       meson_src_configure
+}
+
+src_install() {
+       meson_src_install
+
+       # We copy the default config, so that Gentoo tools can pick up on any
+       # updates and /etc does not end up with stale overrides.
+       # If a reflinking CoW filesystem is used (e.g. Btrfs), then the files
+       # will not actually get stored twice until modified.
+       insinto /etc
+       doins -r "${ED}"/usr/share/wireplumber
+}
+
+pkg_postinst() {
+       if systemd_is_booted ; then
+               ewarn "pipewire-media-session.service is no longer installed. 
You must switch"
+               ewarn "to wireplumber.service user unit before your next 
logout/reboot:"
+               ewarn "systemctl --user disable pipewire-media-session.service"
+               ewarn "systemctl --user --force enable wireplumber.service"
+       else
+               ewarn "Switch to WirePlumber will happen the next time 
gentoo-pipewire-launcher"
+               ewarn "is started (a replacement for directly calling pipewire 
binary)."
+               ewarn
+               ewarn "Please ensure that ${EROOT}/etc/pipewire/pipewire.conf 
either does not exist"
+               ewarn "or, if it does exist, that any reference to"
+               ewarn "${EROOT}/usr/bin/pipewire-media-session is commented out 
(begins with a #)."
+       fi
+       if use system-service; then
+               ewarn
+               ewarn "WARNING: you have enabled the system-service USE flag, 
which installs"
+               ewarn "the system-wide systemd units that enable WirePlumber to 
run as a system"
+               ewarn "service. This is more than likely NOT what you want. You 
are strongly"
+               ewarn "advised not to enable this mode and instead stick with 
systemd user"
+               ewarn "units. The default configuration files will likely not 
work out of"
+               ewarn "box, and you are on your own with configuration."
+               ewarn
+       fi
+}

Reply via email to