find-selected-default-node.lua: add a new default node hook

Hook accords higher priority to the currently selected device over and on top of
the previously selected devices.
This commit is contained in:
Ashok Sidipotu
2023-01-27 06:40:38 +05:30
committed by Julian Bouzas
parent 9a0f8647ac
commit 03bdf7d283
3 changed files with 65 additions and 0 deletions

View File

@@ -219,6 +219,7 @@ wireplumber.components = [
{ name = default-nodes/find-echo-cancel-default-node.lua, type = script/lua, priority = 120 }
{ name = default-nodes/state-default-nodes.lua, type = script/lua, priority = 120 }
{ name = default-nodes/find-best-default-node.lua, type = script/lua, priority = 120 }
{ name = default-nodes/find-selected-default-node.lua, type = script/lua, priority = 120 }
{ name = default-nodes/select-default-nodes.lua, type = script/lua, priority = 120 }
{ name = linking/find-virtual-target.lua, type = script/lua, priority = 100 }

View File

@@ -8,6 +8,7 @@ SimpleEventHook {
name = "default-nodes/apply-default-node",
after = { "default-nodes/find-best-default-node",
"default-nodes/find-echo-cancel-default-node",
"default-nodes/find-selected-default-node",
"default-nodes/find-stored-default-node" },
interests = {
EventInterest {

View File

@@ -0,0 +1,63 @@
-- WirePlumber
--
-- Copyright © 2022 Collabora Ltd.
--
-- SPDX-License-Identifier: MIT
-- hook to make sure the user prefered device(default.configured.*) is higher
-- priority.
SimpleEventHook {
name = "default-nodes/find-selected-default-node",
interests = {
EventInterest {
Constraint { "event.type", "=", "select-default-node" },
},
},
execute = function (event)
local available_nodes = event:get_data ("available-nodes")
available_nodes = available_nodes and available_nodes:parse ()
if not available_nodes then
return
end
local selected_prio = event:get_data ("selected-node-priority") or 0
local selected_node = event:get_data ("selected-node")
local source = event:get_source ()
local props = event:get_properties ()
local def_node_type = props ["default-node.type"]
local metadata_om = source:call ("get-object-manager", "metadata")
local metadata = metadata_om:lookup { Constraint { "metadata.name", "=", "default" } }
local obj = metadata:find (0, "default.configured." .. def_node_type)
if not obj then
return
end
local json = Json.Raw (obj)
local current_configured_node = json:parse ().name
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
if current_configured_node == name then
priority = 30000 + priority
if priority > selected_prio then
selected_prio = priority
selected_node = name
event:set_data ("selected-node-priority", selected_prio)
event:set_data ("selected-node", selected_node)
end
break
end
end
end
}:register ()