Debian Codegraph @

src/scripts/linking/get-filter-from-target.lua

raw
1 -- WirePlumber
2 --
3 -- Copyright © 2023 Collabora Ltd.
4 --
5 -- SPDX-License-Identifier: MIT
6 --
7 -- Check if the target node is a filter target.
8
9 lutils = require ("linking-utils")
10 cutils = require ("common-utils")
11 futils = require ("filter-utils")
12 log = Log.open_topic ("s-linking")
13
14 SimpleEventHook {
15 name = "linking/get-filter-from-target",
16 after = { "linking/find-defined-target",
17 "linking/find-filter-target",
18 "linking/find-media-role-target",
19 "linking/find-default-target",
20 "linking/find-best-target" },
21 before = "linking/prepare-link",
22 interests = {
23 EventInterest {
24 Constraint { "event.type", "=", "select-target" },
25 },
26 },
27 execute = function (event)
28 local source, om, si, si_props, si_flags, target =
29 lutils:unwrap_select_target_event (event)
30
31 -- bypass the hook if the target was not found or if it is a role-based policy target
32 if target == nil or lutils.is_role_policy_target (si_props, target.properties) then
33 return
34 end
35
36 -- bypass the hook if the session item is a smart filter
37 local node = si:get_associated_proxy ("node")
38 local node_props = node.properties
39 local link_group = node_props ["node.link-group"]
40 local target_direction = cutils.getTargetDirection (si.properties)
41 if link_group ~= nil and
42 futils.is_filter_smart (target_direction, link_group) then
43 return
44 end
45
46 -- bypass the hook if the target is an audio group
47 local target_node = target:get_associated_proxy ("node")
48 local target_node_props = target_node.properties
49 local target_audio_group = target_node_props ["session.audio-group"]
50 if target_audio_group ~= nil then
51 return
52 end
53
54 -- bypass the hook if target is defined, is a filter and is targetable
55 local target_link_group = target_node_props ["node.link-group"]
56 if target_link_group ~= nil and si_flags.has_defined_target then
57 if futils.is_filter_smart (target_direction, target_link_group) and
58 not futils.is_filter_disabled (target_direction, target_link_group) and
59 futils.is_filter_targetable (target_direction, target_link_group) then
60 return
61 end
62 end
63
64 -- Get the filter from the given target if it exists, otherwise get the
65 -- default filter, but only if target was not defined
66 local media_type = si_props["media.type"]
67 local filter_target = futils.get_filter_from_target (target_direction, media_type, target)
68 if filter_target ~= nil then
69 target = filter_target
70 log:info (si, "... got filter for given target")
71 elseif filter_target == nil and not si_flags.has_defined_target then
72 filter_target = futils.get_filter_from_target (target_direction, media_type, nil)
73 if filter_target ~= nil then
74 target = filter_target
75 log:info (si, "... got default filter for given target")
76 end
77 end
78
79 local can_passthrough, passthrough_compatible
80 if target ~= nil then
81 passthrough_compatible, can_passthrough =
82 lutils.checkPassthroughCompatibility (si, target)
83 if lutils.canLink (si_props, target) and passthrough_compatible then
84 target_picked = true;
85 end
86 end
87
88 if target_picked then
89 log:info (si,
90 string.format ("... target picked: %s (%s), can_passthrough:%s",
91 tostring (target.properties ["node.name"]),
92 tostring (target.properties ["node.id"]),
93 tostring (can_passthrough)))
94 si_flags.can_passthrough = can_passthrough
95 event:set_data ("target", target)
96 end
97 end
98 }:register ()