default-nodes: fallback to priority.driver if priority.session is not set

See #642
This commit is contained in:
George Kiagiadakis
2024-04-22 11:39:45 +03:00
parent 473e463c56
commit e4f9fb824e
4 changed files with 27 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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