Commit 791fae4e authored by P V's avatar P V
Browse files

policy-node: handle nodes-follow-default in handleLinkable

Since nodes may have a target specified in their props, the logic in
cleanupTargetNodeMetadata does not work correctly.

Instead, set target via metadata in handleLinkable, if we see a
reconnectable node with a defined target that is the same as the
configured default target.
parent 7ad0fa0a
Pipeline #521244 passed with stages
in 2 minutes and 24 seconds
......@@ -590,6 +590,35 @@ function checkPending ()
return false
end
function checkFollowDefault (si, si_target)
local si_props = si.properties
local target_props = si_target.properties
local reconnect = not parseBool(si_props["node.dont-reconnect"])
if config.follow and default_nodes ~= nil and reconnect then
-- If it got linked to the configured default target, it should
-- follow it from now on. We don't consider linkings to non-configured
-- defaults, because this can move streams the user doesn't want to move.
local def_id = getDefaultNode(si_props, getTargetDirection(si_props))
local configured_name =
default_nodes:call("get-default-configured-node-name", target_props['media.class'])
if target_props["node.id"] == tostring(def_id) and
target_props["node.name"] == configured_name then
local metadata = metadata_om:lookup()
-- Until pipewire-pulse starts setting target.object to metadata,
-- set it only if it was already present.
if metadata:find(si_props["node.id"], "target.object") ~= nil then
metadata:set(tonumber(si_props["node.id"]), "target.object", "Spa:Id", "-1")
metadata:set(tonumber(si_props["node.id"]), "target.node", nil, nil)
else
metadata:set(tonumber(si_props["node.id"]), "target.node", "Spa:Id", "-1")
end
Log.info (si, "... set metadata to follow default")
end
end
end
function handleLinkable (si)
if checkPending () then
return
......@@ -650,6 +679,10 @@ function handleLinkable (si)
if si_flags[si_id].peer_id then
if si_target and si_flags[si_id].peer_id == si_target.id then
Log.debug (si, "... already linked to proper target")
if has_defined_target then
-- Check this also here, in case in default targets changed
checkFollowDefault (si, si_target)
end
return
end
local link = lookupLink (si_id, si_flags[si_id].peer_id)
......@@ -723,6 +756,10 @@ function handleLinkable (si)
else
createLink (si, si_target, can_passthrough, exclusive)
si_flags[si.id].was_handled = true
if has_defined_target then
checkFollowDefault (si, si_target)
end
end
end
......@@ -796,38 +833,9 @@ links_om = ObjectManager {
}
}
function cleanupTargetNodeMetadata()
local metadata = metadata_om:lookup()
if metadata and default_nodes ~= nil then
local to_remove = {}
for s, k, t, v in metadata:iterate(Id.ANY) do
if k == "target.node" then
if v == "-1" then
-- target.node == -1 is useless, it means the default node
table.insert(to_remove, s)
else
-- if the target.node value is the same as the default node
-- that would be selected for this stream, remove it
local si = linkables_om:lookup { Constraint { "node.id", "=", s } }
local properties = si.properties
local def_id = getDefaultNode(properties, getTargetDirection(properties))
if tostring(def_id) == v then
table.insert(to_remove, s)
end
end
end
end
for _, s in ipairs(to_remove) do
metadata:set(s, "target.node", nil, nil)
end
end
end
-- listen for default node changes if config.follow is enabled
if config.follow and default_nodes ~= nil then
default_nodes:connect("changed", function ()
cleanupTargetNodeMetadata()
scheduleRescan ()
end)
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment