| 1 |
-- WirePlumber |
| 2 |
-- |
| 3 |
-- Copyright © 2022 Collabora Ltd. |
| 4 |
-- |
| 5 |
-- SPDX-License-Identifier: MIT |
| 6 |
-- |
| 7 |
-- Check if default nodes can be picked up as target node. |
| 8 |
|
| 9 |
lutils = require ("linking-utils") |
| 10 |
log = Log.open_topic ("s-linking") |
| 11 |
|
| 12 |
SimpleEventHook { |
| 13 |
name = "linking/find-default-target", |
| 14 |
after = { "linking/find-defined-target", |
| 15 |
"linking/find-filter-target", |
| 16 |
"linking/find-media-role-target", |
| 17 |
"linking/find-media-role-sink-target" }, |
| 18 |
before = "linking/prepare-link", |
| 19 |
interests = { |
| 20 |
EventInterest { |
| 21 |
Constraint { "event.type", "=", "select-target" }, |
| 22 |
}, |
| 23 |
}, |
| 24 |
execute = function (event) |
| 25 |
local source, om, si, si_props, si_flags, target = |
| 26 |
lutils:unwrap_select_target_event (event) |
| 27 |
|
| 28 |
-- bypass the hook if the target is already picked up |
| 29 |
if target then |
| 30 |
return |
| 31 |
end |
| 32 |
|
| 33 |
local target_picked = false |
| 34 |
|
| 35 |
log:info (si, string.format ("handling item: %s (%s)", |
| 36 |
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) |
| 37 |
|
| 38 |
target = lutils.findDefaultLinkable (si) |
| 39 |
|
| 40 |
local can_passthrough, passthrough_compatible |
| 41 |
if target then |
| 42 |
passthrough_compatible, can_passthrough = |
| 43 |
lutils.checkPassthroughCompatibility (si, target) |
| 44 |
if lutils.canLink (si_props, target) and passthrough_compatible then |
| 45 |
target_picked = true; |
| 46 |
end |
| 47 |
end |
| 48 |
|
| 49 |
if target_picked then |
| 50 |
log:info (si, |
| 51 |
string.format ("... default target picked: %s (%s), can_passthrough:%s", |
| 52 |
tostring (target.properties ["node.name"]), |
| 53 |
tostring (target.properties ["node.id"]), |
| 54 |
tostring (can_passthrough))) |
| 55 |
si_flags.can_passthrough = can_passthrough |
| 56 |
event:set_data ("target", target) |
| 57 |
end |
| 58 |
end |
| 59 |
}:register () |