node/software-dsp: get match rules from conf.d

This allows DSP rules to be specified in a wireplumber.conf.d file under
the node.software-dsp.rules section. Properties are specified in the
software-dsp action.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
This commit is contained in:
James Calligeros
2024-03-27 19:12:10 +10:00
parent d5217fd4b6
commit 9ab7c024f8

View File

@@ -5,25 +5,12 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
local config = ... or {} log = Log.open_topic("s-node")
config.rules = config.rules or {}
for _, r in ipairs(config.rules) do config = {}
r.interests = {} config.rules = Conf.get_section_as_json("node.software-dsp.rules", Json.Array{})
for _, i in ipairs(r.matches) do
local interest_desc = { type = "properties" }
for _, c in ipairs(i) do -- TODO: port from Obj Manager to Hooks
c.type = "pw"
table.insert(interest_desc, Constraint(c))
end
local interest = Interest(interest_desc)
table.insert(r.interests, interest)
end
end
-- TODO: only check for hotplug of nodes with known DSP rules
nodes_om = ObjectManager { nodes_om = ObjectManager {
Interest { type = "node" }, Interest { type = "node" },
} }
@@ -32,45 +19,37 @@ clients_om = ObjectManager {
Interest { type = "client" } Interest { type = "client" }
} }
filter_chains = {} filter_nodes = {}
hidden_nodes = {} hidden_nodes = {}
nodes_om:connect("object-added", function (om, node) nodes_om:connect("object-added", function (om, node)
for _, r in ipairs(config.rules or {}) do JsonUtils.match_rules (config.rules, node.properties, function (action, value)
for _, interest in ipairs(r.interests) do if action == "create-filter" then
if interest:matches(node.properties) then log:debug("DSP rule found for " .. node.properties["node.name"])
local id = node.properties["object.id"] local props = value:parse (1)
if r.filter_chain then if props["filter-graph"] then
if filter_chains[id] then log:debug("Loading filter graph for " .. node.properties["node.name"])
Log.warning("Sink " .. id .. " has been plugged now, but has a filter chain loaded. Skipping") filter_nodes[node.properties["object.id"]] = LocalModule("libpipewire-module-filter-chain", props["filter-graph"], {})
else end
filter_chains[id] = LocalModule("libpipewire-module-filter-chain", r.filter_chain, {}, true)
if props["hide-parent"] then
log:debug("Setting permissions to '-' on " .. node.properties["node.name"] .. " for open clients")
for client in clients_om:iterate{ type = "client" } do
if not client["properties"]["wireplumber.daemon"] then
client:update_permissions{ [node["bound-id"]] = "-" }
end end
end end
hidden_nodes[node["bound-id"]] = node.properties["object.id"]
if r.hide_parent then
Log.debug("Hiding node " .. node["bound-id"] .. " from clients")
for client in clients_om:iterate { type = "client" } do
if not client["properties"]["wireplumber.daemon"] then
client:update_permissions { [node["bound-id"]] = "-" }
end
end
hidden_nodes[node["bound-id"]] = id
end
end end
end end
end end)
end) end)
nodes_om:connect("object-removed", function (om, node) nodes_om:connect("object-removed", function (om, node)
local id = node.properties["object.id"] if filter_nodes[node.properties["object.id"]] then
if filter_chains[id] then log:debug("Freeing filter graph on disconnected node " .. node.properties["node.name"])
Log.debug("Unloading filter chain associated with sink " .. id) filter_nodes[node.properties["object.id"]] = nil
filter_chains[id] = nil
else
Log.debug("Disconnected sink " .. id .. " does not have any filters to be removed")
end end
end) end)