Debian Codegraph @

src/scripts/linking/find-audio-group-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 agutils = require ("audio-group-utils")
12
13 log = Log.open_topic ("s-linking")
14
15 SimpleEventHook {
16 name = "linking/find-audio-group-target",
17 after = "linking/find-defined-target",
18 interests = {
19 EventInterest {
20 Constraint { "event.type", "=", "select-target" },
21 },
22 },
23 execute = function (event)
24 local source, om, si, si_props, si_flags, target =
25 lutils:unwrap_select_target_event (event)
26
27 -- bypass the hook if the target is already picked up
28 if target then
29 return
30 end
31
32 local target_direction = cutils.getTargetDirection (si_props)
33 local target_picked = nil
34 local target_can_passthrough = false
35 local node = nil
36 local audio_group = nil
37
38 log:info (si, string.format ("handling item %d: %s (%s)", si.id,
39 tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
40
41 -- Get associated node
42 node = si:get_associated_proxy ("node")
43 if node == nil then
44 return
45 end
46
47 -- audio group
48 audio_group = agutils.get_audio_group (node)
49 if audio_group == nil then
50 return
51 end
52
53 -- find the target with same audio group, if any
54 for target in om:iterate {
55 type = "SiLinkable",
56 Constraint { "item.node.type", "=", "device" },
57 Constraint { "item.node.direction", "=", target_direction },
58 Constraint { "media.type", "=", si_props ["media.type"] },
59 } do
60 target_node = target:get_associated_proxy ("node")
61 target_node_props = target_node.properties
62 target_audio_group = target_node_props ["session.audio-group"]
63
64 if target_audio_group == nil then
65 goto skip_linkable
66 end
67
68 if target_audio_group ~= audio_group then
69 goto skip_linkable
70 end
71
72 local passthrough_compatible, can_passthrough =
73 lutils.checkPassthroughCompatibility (si, target)
74 if not passthrough_compatible then
75 log:debug ("... passthrough is not compatible, skip linkable")
76 goto skip_linkable
77 end
78
79 target_picked = target
80 target_can_passthrough = can_passthrough
81 break
82
83 ::skip_linkable::
84 end
85
86 -- set target
87 if target_picked then
88 log:info (si,
89 string.format ("... audio group target picked: %s (%s), can_passthrough:%s",
90 tostring (target_picked.properties ["node.name"]),
91 tostring (target_picked.properties ["node.id"]),
92 tostring (target_can_passthrough)))
93 si_flags.can_passthrough = target_can_passthrough
94 event:set_data ("target", target_picked)
95 end
96 end
97 }:register ()