New wireplumber config

This commit is contained in:
2024-07-26 06:23:40 -04:00
parent f9f2119beb
commit 9716a8df5a
99 changed files with 7572 additions and 5398 deletions

View File

@@ -0,0 +1,61 @@
-- WirePlumber
--
-- Copyright © 2023 Collabora Ltd.
-- @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
--
-- SPDX-License-Identifier: MIT
cutils = require ("common-utils")
mutils = require ("monitor-utils")
log = Log.open_topic ("s-monitors-v4l2")
config = {}
config.rules = Conf.get_section_as_json ("monitor.v4l2.rules", Json.Array {})
function createV4l2camNode (parent, id, type, factory, properties)
local registered = mutils:register_cam_node (parent, id, factory, properties)
if not registered then
source = source or Plugin.find ("standard-event-source")
local e = source:call ("create-event", "create-v4l2-device-node",
parent, nil)
e:set_data ("factory", factory)
e:set_data ("node-properties", properties)
e:set_data ("node-sub-id", id)
EventDispatcher.push_event (e)
end
end
SimpleEventHook {
name = "monitor/v4l2/create-device",
after = "monitor/v4l2/name-device",
interests = {
EventInterest {
Constraint { "event.type", "=", "create-v4l2-device" },
},
},
execute = function(event)
local properties = event:get_data ("device-properties")
local factory = event:get_data ("factory")
local parent = event:get_subject ()
local id = event:get_data ("device-sub-id")
-- apply properties from rules defined in JSON .conf file
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
if cutils.parseBool (properties ["device.disabled"]) then
log:notice ("V4L2 device " .. properties["device.name"] .. " disabled")
return
end
local device = SpaDevice (factory, properties)
if device then
device:connect ("create-object", createV4l2camNode)
device:activate (Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND)
parent:store_managed_object (id, device)
else
log:warning ("Failed to create '" .. factory .. "' device")
end
end
}:register ()

View File

@@ -0,0 +1,42 @@
-- WirePlumber
--
-- Copyright © 2023 Collabora Ltd.
-- @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
--
-- SPDX-License-Identifier: MIT
cutils = require ("common-utils")
mutils = require ("monitor-utils")
log = Log.open_topic ("s-monitors-v4l2")
config = {}
config.rules = Conf.get_section_as_json ("monitor.v4l2.rules", Json.Array {})
SimpleEventHook {
name = "monitor/v4l2/create-node",
after = "monitor/v4l2/name-node",
interests = {
EventInterest {
Constraint { "event.type", "=", "create-v4l2-device-node" },
},
},
execute = function(event)
local properties = event:get_data ("node-properties")
local parent = event:get_subject ()
local id = event:get_data ("node-sub-id")
local factory = event:get_data ("factory")
-- apply properties from rules defined in JSON .conf file
properties = JsonUtils.match_rules_update_properties (config.rules, properties)
if cutils.parseBool (properties ["node.disabled"]) then
log:notice ("V4L2 node" .. properties ["node.name"] .. " disabled")
return
end
-- create the node
local node = Node ("spa-node-factory", properties)
node:activate (Feature.Proxy.BOUND)
parent:store_managed_object (id, node)
end
}:register ()

View File

@@ -0,0 +1,32 @@
-- WirePlumber
--
-- Copyright © 2023 Collabora Ltd.
-- @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
--
-- SPDX-License-Identifier: MIT
cutils = require ("common-utils")
log = Log.open_topic ("s-monitors-v4l2")
config = {}
config.properties = Conf.get_section_as_properties ("monitor.v4l2.properties")
function createCamDevice (parent, id, type, factory, properties)
source = source or Plugin.find ("standard-event-source")
local e = source:call ("create-event", "create-v4l2-device", parent, nil)
e:set_data ("device-properties", properties)
e:set_data ("factory", factory)
e:set_data ("device-sub-id", id)
EventDispatcher.push_event (e)
end
monitor = SpaDevice ("api.v4l2.enum.udev", config.properties)
if monitor then
monitor:connect ("create-object", createCamDevice)
monitor:activate (Feature.SpaDevice.ENABLED)
else
log:notice ("PipeWire's V4L2 SPA plugin is missing or broken. " ..
"Some camera types may not be supported.")
end

View File

@@ -0,0 +1,49 @@
-- WirePlumber
--
-- Copyright © 2023 Collabora Ltd.
-- @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
--
-- SPDX-License-Identifier: MIT
mutils = require ("monitor-utils")
log = Log.open_topic ("s-monitors-v4l2")
SimpleEventHook {
name = "monitor/v4l2/name-device",
interests = {
EventInterest {
Constraint { "event.type", "=", "create-v4l2-device" },
},
},
execute = function(event)
local properties = event:get_data ("device-properties")
local parent = event:get_subject ()
local id = event:get_data ("device-sub-id")
local name = "v4l2_device." ..
(properties["device.name"] or
properties["device.bus-id"] or
properties["device.bus-path"] or
tostring (id)):gsub ("([^%w_%-%.])", "_")
properties["device.name"] = name
-- deduplicate devices with the same name
for counter = 2, 99, 1 do
if mutils.find_duplicate (parent, id, "device.name", properties["node.name"]) then
properties["device.name"] = name .. "." .. counter
else
break
end
end
-- ensure the device has a description
properties["device.description"] =
properties["device.description"]
or properties["device.product.name"]
or "Unknown device"
event:set_data ("device-properties", properties)
end
}:register ()

View File

@@ -0,0 +1,80 @@
-- WirePlumber
--
-- Copyright © 2023 Collabora Ltd.
-- @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
--
-- SPDX-License-Identifier: MIT
mutils = require ("monitor-utils")
log = Log.open_topic ("s-monitors-v4l2")
SimpleEventHook {
name = "monitor/v4l2/name-node",
interests = {
EventInterest {
Constraint { "event.type", "=", "create-v4l2-device-node" },
},
},
execute = function(event)
local properties = event:get_data ("node-properties")
local parent = event:get_subject ()
local dev_props = parent.properties
local factory = event:get_data ("factory")
local id = event:get_data ("node-sub-id")
-- set the device id and spa factory name; REQUIRED, do not change
properties["device.id"] = parent["bound-id"]
properties["factory.name"] = factory
-- set the default pause-on-idle setting
properties["node.pause-on-idle"] = false
-- set the node name
local name =
(factory:find ("sink") and "v4l2_output") or
(factory:find ("source") and "v4l2_input" or factory)
.. "." ..
(dev_props["device.name"]:gsub ("^v4l2_device%.(.+)", "%1") or
dev_props["device.name"] or
dev_props["device.nick"] or
dev_props["device.alias"] or
"v4l2-device")
-- sanitize name
name = name:gsub ("([^%w_%-%.])", "_")
properties["node.name"] = name
-- deduplicate nodes with the same name
for counter = 2, 99, 1 do
if mutils.find_duplicate (parent, id, "node.name", properties["node.name"]) then
properties["node.name"] = name .. "." .. counter
else
break
end
end
-- set the node description
local desc = dev_props["device.description"] or "v4l2-device"
desc = desc .. " (V4L2)"
-- sanitize description, replace ':' with ' '
properties["node.description"] = desc:gsub ("(:)", " ")
-- set the node nick
local nick = properties["node.nick"] or
dev_props["device.product.name"] or
dev_props["api.v4l2.cap.card"] or
dev_props["device.description"] or
dev_props["device.nick"]
properties["node.nick"] = nick:gsub ("(:)", " ")
-- set priority
if not properties["priority.session"] then
local path = properties["api.v4l2.path"] or "/dev/video100"
local dev = path:gsub ("/dev/video(%d+)", "%1")
properties["priority.session"] = 1000 - (tonumber (dev) * 10)
end
event:set_data ("node-properties", properties)
end
}:register ()