From fea6b11ad10575a0ced32a2d11cadd51c7c1d9e3 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Tue, 25 Jun 2024 15:53:11 +0300 Subject: [PATCH] s/create-item: add setting to enforce a media.role on streams that don't have one --- src/config/wireplumber.conf | 5 +++++ .../media-role-nodes.conf | 14 ++++++++++++++ src/scripts/node/create-item.lua | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/src/config/wireplumber.conf b/src/config/wireplumber.conf index b9ca6ce1..1dede9cb 100644 --- a/src/config/wireplumber.conf +++ b/src/config/wireplumber.conf @@ -787,6 +787,11 @@ wireplumber.settings.schema = { min = 0.0 max = 1.0 } + node.stream.default-media-role = { + description = "A media.role to assign on streams that have none specified" + type = "string" + default = null + } node.filter.forward-format = { description = "Whether to forward format on filter nodes or not" type = "bool" diff --git a/src/config/wireplumber.conf.d.examples/media-role-nodes.conf b/src/config/wireplumber.conf.d.examples/media-role-nodes.conf index 30550b09..7a543a0d 100644 --- a/src/config/wireplumber.conf.d.examples/media-role-nodes.conf +++ b/src/config/wireplumber.conf.d.examples/media-role-nodes.conf @@ -12,6 +12,14 @@ wireplumber.profiles = { } } +wireplumber.settings = { + # This sets a default media role to be applied to streams that don't have + # a role already set. This allows you to force all streams to go through + # the role loopbacks. If not set, then streams without a role will follow + # the standard desktop policy and will link to the default sink + node.stream.default-media-role = "Multimedia" +} + wireplumber.components.rules = [ # This encodes common arguments and dependencies of the role loopbacks so that # we don't have to repeateadly write them on all instances below @@ -29,7 +37,13 @@ wireplumber.components.rules = [ media.class = Audio/Sink } playback.props = { + # This must be set to ensure that the real audio sink is suspended + # when there is no active client stream linked node.passive = true + # Set this to an unused role to make sure that loopbacks don't + # accidentally chain-link on to one another, especially when + # node.stream.default-media-role is configured in the settings + media.role = "Loopback" } } requires = [ support.export-core, pw.node-factory.adapter ] diff --git a/src/scripts/node/create-item.lua b/src/scripts/node/create-item.lua index e5adbbf8..813f238b 100644 --- a/src/scripts/node/create-item.lua +++ b/src/scripts/node/create-item.lua @@ -41,6 +41,15 @@ function configProperties (node) Settings.get_boolean ("node.features.audio.control-port") properties ["node.id"] = node ["bound-id"] + -- set the default media.role, if configured + -- avoid Settings.get_string(), as it will parse the default "null" value + -- as a string instead of returning nil + local default_role = Settings.get ("node.stream.default-media-role") + if default_role then + default_role = default_role:parse() + properties ["media.role"] = properties ["media.role"] or default_role + end + return properties end