wireplumber/src/scripts/linking/find-default-target.lua
Guido Günther c095ae5254 role-based-policy: Allow to set target sink for media role loopbacks
There are streams that should go to a speaker rather than a headphone
or earpiece by default. Examples are alarms and emergency alerts on
phones. Allow to set a preference via
`policy.role-based.preferred-target` which then looks up the target
via `node.name` and `node.nick`.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2025-10-25 16:12:01 +03:00

59 lines
1.7 KiB
Lua

-- WirePlumber
--
-- Copyright © 2022 Collabora Ltd.
--
-- SPDX-License-Identifier: MIT
--
-- Check if default nodes can be picked up as target node.
lutils = require ("linking-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook {
name = "linking/find-default-target",
after = { "linking/find-defined-target",
"linking/find-filter-target",
"linking/find-media-role-target",
"linking/find-media-role-sink-target" },
before = "linking/prepare-link",
interests = {
EventInterest {
Constraint { "event.type", "=", "select-target" },
},
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
lutils:unwrap_select_target_event (event)
-- bypass the hook if the target is already picked up
if target then
return
end
local target_picked = false
log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
target = lutils.findDefaultLinkable (si)
local can_passthrough, passthrough_compatible
if target then
passthrough_compatible, can_passthrough =
lutils.checkPassthroughCompatibility (si, target)
if lutils.canLink (si_props, target) and passthrough_compatible then
target_picked = true;
end
end
if target_picked then
log:info (si,
string.format ("... default target picked: %s (%s), can_passthrough:%s",
tostring (target.properties ["node.name"]),
tostring (target.properties ["node.id"]),
tostring (can_passthrough)))
si_flags.can_passthrough = can_passthrough
event:set_data ("target", target)
end
end
}:register ()