policy-node.lua: Second round of cleanup.
- WirePlumber Lua now facilitates Lua libraries/modules, utilize this and create modules. Add some tests around this functionality. - Create policy-hooks.lua containing all the hooks to find-target events - Create policy-utils.lua module and push all the policy utility functions to it. - Create common-utils.lua module and push the common utility functions to it. - Remove all the above functionality from policy-node.lua and clean it up.
This commit is contained in:

committed by
Julian Bouzas

parent
3832e14c1c
commit
72536261e9
37
src/scripts/lib/common-utils.lua
Normal file
37
src/scripts/lib/common-utils.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
-- 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
|
||||
|
||||
function cutils.getTargetDirection (properties)
|
||||
local target_direction = nil
|
||||
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
|
||||
|
||||
function cutils.getDefaultNode (properties, target_direction)
|
||||
local target_media_class =
|
||||
properties ["media.type"] ..
|
||||
(target_direction == "input" and "/Sink" or "/Source")
|
||||
return default_nodes:call ("get-default-node", target_media_class)
|
||||
end
|
||||
|
||||
default_nodes = Plugin.find ("default-nodes-api")
|
||||
|
||||
return cutils
|
Reference in New Issue
Block a user