default-nodes/rescan: Check available routes using linking-utils

The linking-utils module already implements a way to check for available routes,
this patch uses it in default-nodes/rescan.lua to remove redundant code.
This commit is contained in:
Julian Bouzas 2025-05-18 14:04:33 +02:00 committed by George Kiagiadakis
parent b8506d0d56
commit 0251d644a8

View file

@ -7,6 +7,8 @@
-- looks for changes in user-preferences and devices added/removed and schedules
-- rescan and pushes "select-default-node" event for each of the media_classes
lutils = require ("linking-utils")
log = Log.open_topic ("s-default-nodes")
-- looks for changes in user-preferences and devices added/removed and schedules
@ -107,7 +109,7 @@ function collectAvailableNodes (si_om, devices_om, port_direction, media_classes
-- check that the node has available routes,
-- if it is associated to a real device
if not nodeHasAvailableRoutes (node, devices_om) then
if not lutils.haveAvailableRoutes (node.properties, devices_om) then
goto next_linkable
end
@ -118,62 +120,3 @@ function collectAvailableNodes (si_om, devices_om, port_direction, media_classes
return collected
end
-- If the node has an associated device, verify that it has an available
-- route. Some UCM profiles expose all paths (headphones, HDMI, etc) as nodes,
-- even though they may not be connected... See #145
function nodeHasAvailableRoutes (node, devices_om)
local properties = node.properties
local device_id = properties ["device.id"]
local cpd = properties ["card.profile.device"]
if not device_id or not cpd then
return true
end
-- Get the device
local device = devices_om:lookup {
Constraint { "bound-id", "=", device_id, type = "gobject" }
}
if not device then
return true
end
-- Check if the current device route supports the node card device profile
for r in device:iterate_params ("Route") do
local route = r:parse ()
local route_props = route.properties
if route_props.device == tonumber (cpd) then
if route_props.available == "no" then
return false
else
return true
end
end
end
-- Check if available routes support the node card device profile
local found = 0
for r in device:iterate_params ("EnumRoute") do
local route = r:parse ()
local route_props = route.properties
if type (route_props.devices) == "table" then
for _, i in ipairs (route_props.devices) do
if i == tonumber (cpd) then
found = found + 1
if route_props.available ~= "no" then
return true
end
end
end
end
end
-- The node is part of a profile without routes so we assume it
-- is available. This can happen for Pro Audio profiles
if found == 0 then
return true
end
return false
end