2022-08-16 06:05:55 +05:30
|
|
|
-- WirePlumber
|
|
|
|
|
|
|
|
|
|
-- Copyright © 2022 Collabora Ltd.
|
|
|
|
|
-- @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
|
|
|
|
|
|
|
|
|
|
-- SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
|
|
-- Script is a Lua Module of common Lua utility functions
|
|
|
|
|
|
|
|
|
|
local cutils = {}
|
|
|
|
|
|
|
|
|
|
function cutils.parseBool (var)
|
|
|
|
|
return var and (var:lower () == "true" or var == "1")
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-26 12:22:02 +05:30
|
|
|
function cutils.parseParam (param, id)
|
2022-09-05 05:14:08 +05:30
|
|
|
local props = param:parse ()
|
|
|
|
|
if props.pod_type == "Object" and props.object_id == id then
|
|
|
|
|
return props.properties
|
2022-08-26 12:22:02 +05:30
|
|
|
else
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-15 18:16:52 +02:00
|
|
|
function cutils.mediaClassToDirection (media_class)
|
|
|
|
|
if media_class:find ("Sink") or
|
|
|
|
|
media_class:find ("Input") or
|
|
|
|
|
media_class:find ("Duplex") then
|
|
|
|
|
return "input"
|
|
|
|
|
elseif media_class:find ("Source") or media_class:find ("Output") then
|
|
|
|
|
return "output"
|
|
|
|
|
else
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-16 06:05:55 +05:30
|
|
|
function cutils.getTargetDirection (properties)
|
|
|
|
|
local target_direction = nil
|
2023-02-03 12:09:26 -05:00
|
|
|
|
|
|
|
|
-- retrun same direction for si-audio-virtual session items
|
|
|
|
|
if properties ["item.factory.name"] == "si-audio-virtual" then
|
|
|
|
|
return properties ["item.node.direction"]
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-16 06:05:55 +05:30
|
|
|
if properties ["item.node.direction"] == "output" or
|
|
|
|
|
(properties ["item.node.direction"] == "input" and
|
|
|
|
|
cutils.parseBool (properties ["stream.capture.sink"])) then
|
|
|
|
|
target_direction = "input"
|
|
|
|
|
else
|
|
|
|
|
target_direction = "output"
|
|
|
|
|
end
|
|
|
|
|
return target_direction
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-20 10:43:34 +05:30
|
|
|
local default_nodes = Plugin.find ("default-nodes-api")
|
|
|
|
|
|
2022-08-16 06:05:55 +05:30
|
|
|
function cutils.getDefaultNode (properties, target_direction)
|
|
|
|
|
local target_media_class =
|
|
|
|
|
properties ["media.type"] ..
|
|
|
|
|
(target_direction == "input" and "/Sink" or "/Source")
|
2023-01-20 10:43:34 +05:30
|
|
|
|
|
|
|
|
if not default_nodes then
|
|
|
|
|
default_nodes = Plugin.find ("default-nodes-api")
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-16 06:05:55 +05:30
|
|
|
return default_nodes:call ("get-default-node", target_media_class)
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-03 18:28:31 +05:30
|
|
|
cutils.source_plugin = nil
|
|
|
|
|
cutils.object_managers = {}
|
|
|
|
|
|
|
|
|
|
function cutils.get_object_manager (name)
|
|
|
|
|
cutils.source_plugin = cutils.source_plugin or
|
|
|
|
|
Plugin.find ("standard-event-source")
|
|
|
|
|
cutils.object_managers [name] = cutils.object_managers [name] or
|
|
|
|
|
cutils.source_plugin:call ("get-object-manager", name)
|
|
|
|
|
return cutils.object_managers [name]
|
|
|
|
|
end
|
2022-08-16 06:05:55 +05:30
|
|
|
|
2023-03-03 18:28:31 +05:30
|
|
|
function cutils.get_default_metadata_object ()
|
|
|
|
|
return cutils.get_object_manager ("metadata"):lookup {
|
2022-09-05 05:14:08 +05:30
|
|
|
Constraint { "metadata.name", "=", "default" },
|
|
|
|
|
}
|
2023-03-03 18:28:31 +05:30
|
|
|
end
|
2022-09-05 05:14:08 +05:30
|
|
|
|
|
|
|
|
function cutils.evaluateRulesApplyProperties (properties, name)
|
2023-11-07 12:44:13 +02:00
|
|
|
local section = Conf.get_section (name)
|
2023-11-15 12:57:41 +02:00
|
|
|
if not section then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-07 12:44:13 +02:00
|
|
|
local matched, mprops = JsonUtils.match_rules_update_properties (
|
|
|
|
|
section, properties)
|
2022-09-05 05:14:08 +05:30
|
|
|
|
2023-11-07 12:44:13 +02:00
|
|
|
if (matched > 0 and mprops) then
|
2022-09-05 05:14:08 +05:30
|
|
|
for k, v in pairs (mprops) do
|
|
|
|
|
properties [k] = v
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-06 19:24:33 +05:30
|
|
|
function cutils.arrayContains (a, value)
|
|
|
|
|
for _, v in ipairs (a) do
|
|
|
|
|
if v == value then
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2023-12-09 15:52:24 +02:00
|
|
|
function cutils.get_application_name ()
|
|
|
|
|
return Core.get_properties()["application.name"] or "WirePlumber"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function cutils.get_config_section (name, defaults)
|
|
|
|
|
local section = Conf.get_section (name)
|
|
|
|
|
if not section then
|
|
|
|
|
section = defaults or {}
|
|
|
|
|
else
|
|
|
|
|
section = section:parse ()
|
2023-12-18 10:56:30 +02:00
|
|
|
if defaults then
|
|
|
|
|
for k, v in pairs (defaults) do
|
|
|
|
|
if section [k] == nil then
|
|
|
|
|
section [k] = v
|
|
|
|
|
end
|
2023-12-09 15:52:24 +02:00
|
|
|
end
|
2023-12-18 10:56:30 +02:00
|
|
|
for k, v in ipairs (defaults) do
|
|
|
|
|
if section [k] == nil then
|
|
|
|
|
section [k] = v
|
|
|
|
|
end
|
2023-12-09 15:52:24 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return section
|
|
|
|
|
end
|
2022-09-05 05:14:08 +05:30
|
|
|
|
2022-09-19 12:12:38 -04:00
|
|
|
return cutils
|