Debian Codegraph @

src/scripts/monitors/libcamera/create-device.lua

raw
1 -- WirePlumber
2 --
3 -- Copyright © 2023 Collabora Ltd.
4 -- @author Ashok Sidipotu <[email protected]>
5 --
6 -- SPDX-License-Identifier: MIT
7
8 cutils = require ("common-utils")
9 mutils = require ("monitor-utils")
10
11 log = Log.open_topic ("s-monitors-libcamera")
12
13 config = {}
14 config.rules = Conf.get_section_as_json ("monitor.libcamera.rules", Json.Array {})
15
16 function createLibcamNode (parent, id, type, factory, properties)
17 mutils:register_cam_node (parent, id, factory, properties)
18 end
19
20 SimpleEventHook {
21 name = "monitor/libcamera/create-device",
22 after = "monitor/libcamera/name-device",
23 interests = {
24 EventInterest {
25 Constraint { "event.type", "=", "create-libcamera-device" },
26 },
27 },
28 execute = function(event)
29 local properties = event:get_data ("device-properties")
30 local factory = event:get_data ("factory")
31 local parent = event:get_subject ()
32 local id = event:get_data ("device-sub-id")
33
34 -- apply properties from rules defined in JSON .conf file
35 properties = JsonUtils.match_rules_update_properties (config.rules, properties)
36
37 if cutils.parseBool (properties ["device.disabled"]) then
38 log:notice ("libcam device " .. properties["device.name"] .. " disabled")
39 return
40 end
41 local device = SpaDevice (factory, properties)
42
43 if device then
44 device:connect ("create-object", createLibcamNode)
45 device:activate (Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND)
46 parent:store_managed_object (id, device)
47 else
48 log:warning ("Failed to create '" .. factory .. "' device")
49 end
50 end
51 }:register ()