Debian Codegraph @

src/scripts/lib/node-utils.lua

raw
1 -- WirePlumber
2 --
3 -- Copyright © 2024 Collabora Ltd.
4 --
5 -- SPDX-License-Identifier: MIT
6
7 local cutils = require ("common-utils")
8
9 local module = {}
10
11 function module.get_session_priority (node_props)
12 local priority = node_props ["priority.session"]
13 -- fallback to driver priority if session priority is not set
14 if not priority then
15 priority = node_props ["priority.driver"]
16 end
17 return math.tointeger (priority) or 0
18 end
19
20 function module.get_route_priority (node_props)
21 local card_profile_device = node_props ["card.profile.device"]
22 local device_id = node_props ["device.id"]
23
24 -- if the node does not have an associated device, just return 0
25 if not card_profile_device or not device_id then
26 return 0
27 end
28
29 -- Get the device
30 devices_om = cutils.get_object_manager ("device")
31 local device = devices_om:lookup {
32 Constraint { "bound-id", "=", device_id, type = "gobject" },
33 }
34
35 if not device then
36 return 0
37 end
38
39 -- Get the priority of the associated route
40 for p in device:iterate_params ("Route") do
41 local route = cutils.parseParam (p, "Route")
42 if route and (route.device == tonumber (card_profile_device)) then
43 return route.priority
44 end
45 end
46
47 return 0
48 end
49
50 return module