diff --git a/src/scripts/default-nodes/find-best-default-node.lua b/src/scripts/default-nodes/find-best-default-node.lua index 37c68a27..fe97a2b2 100644 --- a/src/scripts/default-nodes/find-best-default-node.lua +++ b/src/scripts/default-nodes/find-best-default-node.lua @@ -6,6 +6,8 @@ log = Log.open_topic ("s-default-nodes") +nutils = require ("node-utils") + SimpleEventHook { name = "default-nodes/find-best-default-node", interests = { @@ -25,8 +27,7 @@ SimpleEventHook { for _, node_props in ipairs (available_nodes) do -- Highest priority node wins - local priority = node_props ["priority.session"] - priority = math.tointeger (priority) or 0 + local priority = nutils.get_session_priority (node_props) if priority > selected_prio or selected_node == nil then selected_prio = priority diff --git a/src/scripts/default-nodes/find-selected-default-node.lua b/src/scripts/default-nodes/find-selected-default-node.lua index c3df754d..294cde53 100644 --- a/src/scripts/default-nodes/find-selected-default-node.lua +++ b/src/scripts/default-nodes/find-selected-default-node.lua @@ -13,6 +13,8 @@ log = Log.open_topic ("s-default-nodes") +nutils = require ("node-utils") + SimpleEventHook { name = "default-nodes/find-selected-default-node", interests = { @@ -47,8 +49,7 @@ SimpleEventHook { for _, node_props in ipairs (available_nodes) do local name = node_props ["node.name"] - local priority = node_props ["priority.session"] - priority = math.tointeger (priority) or 0 + local priority = nutils.get_session_priority (node_props) if current_configured_node == name then priority = 30000 + priority diff --git a/src/scripts/default-nodes/state-default-nodes.lua b/src/scripts/default-nodes/state-default-nodes.lua index c3980881..c571d0e2 100644 --- a/src/scripts/default-nodes/state-default-nodes.lua +++ b/src/scripts/default-nodes/state-default-nodes.lua @@ -12,6 +12,8 @@ log = Log.open_topic ("s-default-nodes") +nutils = require ("node-utils") + -- the state storage state = nil state_table = nil @@ -42,8 +44,7 @@ find_stored_default_node_hook = SimpleEventHook { for i, v in ipairs (stored) do if name == v then - local priority = node_props ["priority.session"] - priority = math.tointeger (priority) or 0 + local priority = nutils.get_session_priority (node_props) priority = priority + 20001 - i if priority > selected_prio then diff --git a/src/scripts/lib/node-utils.lua b/src/scripts/lib/node-utils.lua new file mode 100644 index 00000000..38b6e6b3 --- /dev/null +++ b/src/scripts/lib/node-utils.lua @@ -0,0 +1,18 @@ +-- WirePlumber +-- +-- Copyright © 2024 Collabora Ltd. +-- +-- SPDX-License-Identifier: MIT + +local module = {} + +function module.get_session_priority (node_props) + local priority = node_props ["priority.session"] + -- fallback to driver priority if session priority is not set + if not priority then + priority = node_props ["priority.driver"] + end + return math.tointeger (priority) or 0 +end + +return module