mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-08 10:28:03 +02:00
linking-utils: improve haveAvailableRoutes
Based on nodeHasAvailableRoutes() from default-nodes/rescan.lua
This commit is contained in:
parent
050cd772be
commit
af3c520d3e
1 changed files with 37 additions and 43 deletions
|
|
@ -348,68 +348,62 @@ function lutils.checkPassthroughCompatibility (si, si_target)
|
||||||
return true, can_passthrough
|
return true, can_passthrough
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Does the target device have any active/available paths/routes to
|
-- If the node has an associated device, does it have any active/available
|
||||||
-- the physical device(spkr/mic/cam)?
|
-- paths/routes to the physical device?
|
||||||
function lutils.haveAvailableRoutes (si_props)
|
-- Some UCM profiles expose all paths (headphones, HDMI, etc) as nodes,
|
||||||
|
-- even though they may not be connected... See #145
|
||||||
|
function lutils.haveAvailableRoutes (si_props, devices_om)
|
||||||
local card_profile_device = si_props ["card.profile.device"]
|
local card_profile_device = si_props ["card.profile.device"]
|
||||||
local device_id = si_props ["device.id"]
|
local device_id = si_props ["device.id"]
|
||||||
local device = device_id and cutils.get_object_manager ("device"):lookup {
|
|
||||||
|
-- if the node does not have an associated device, it's all good
|
||||||
|
if not card_profile_device or not device_id then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get the device
|
||||||
|
devices_om = devices_om or cutils.get_object_manager ("device")
|
||||||
|
local device = devices_om:lookup {
|
||||||
Constraint { "bound-id", "=", device_id, type = "gobject" },
|
Constraint { "bound-id", "=", device_id, type = "gobject" },
|
||||||
}
|
}
|
||||||
|
|
||||||
if not card_profile_device or not device then
|
if not device then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local found = 0
|
-- Check if at least one of the current device routes supports
|
||||||
local avail = 0
|
-- the node's card.profile.device and is available
|
||||||
|
|
||||||
-- First check "SPA_PARAM_Route" if there are any active devices
|
|
||||||
-- in an active profile.
|
|
||||||
for p in device:iterate_params ("Route") do
|
for p in device:iterate_params ("Route") do
|
||||||
local route = cutils.parseParam (p, "Route")
|
local route = cutils.parseParam (p, "Route")
|
||||||
if not route then
|
if route and (route.device == tonumber (card_profile_device)) then
|
||||||
goto skip_route
|
if (route.available == "no") then
|
||||||
end
|
return false
|
||||||
|
else
|
||||||
if (route.device ~= tonumber (card_profile_device)) then
|
return true
|
||||||
goto skip_route
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if (route.available == "no") then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
do return true end
|
|
||||||
|
|
||||||
::skip_route::
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Second check "SPA_PARAM_EnumRoute" if there is any route that
|
-- Check if available routes support the node's card.profile.device
|
||||||
-- is available if not active.
|
local found = 0
|
||||||
for p in device:iterate_params ("EnumRoute") do
|
for r in device:iterate_params ("EnumRoute") do
|
||||||
local route = cutils.parseParam (p, "EnumRoute")
|
local route = cutils.parseParam (p, "EnumRoute")
|
||||||
if not route then
|
if route and type (route.devices) == "table" then
|
||||||
goto skip_enum_route
|
for _, i in ipairs (route.devices) do
|
||||||
|
if i == tonumber (cpd) then
|
||||||
|
found = found + 1
|
||||||
|
if route.available ~= "no" then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not cutils.arrayContains
|
|
||||||
(route.devices, tonumber (card_profile_device)) then
|
|
||||||
goto skip_enum_route
|
|
||||||
end
|
|
||||||
found = found + 1;
|
|
||||||
if (route.available ~= "no") then
|
|
||||||
avail = avail + 1
|
|
||||||
end
|
|
||||||
::skip_enum_route::
|
|
||||||
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
|
if found == 0 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if avail > 0 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue