scripts: tidy-up linking related settings

* prefix all settings with just "linking."
* rename settings to make more sense
* fix the handling of the "follow" setting
* move the "move" handler to the rescan.lua script, as it's just a rescan hook
This commit is contained in:
George Kiagiadakis 2023-11-19 18:34:33 +02:00
parent 33fc476cb3
commit 383b0e605d
8 changed files with 44 additions and 69 deletions

View file

@ -512,10 +512,6 @@ wireplumber.components = [
name = linking/rescan.lua, type = script/lua
provides = hooks.linking.rescan
}
{
name = linking/move-follow.lua, type = script/lua
provides = hooks.linking.move-follow
}
{
name = linking/find-defined-target.lua, type = script/lua
provides = hooks.linking.target.find-defined
@ -554,8 +550,7 @@ wireplumber.components = [
requires = [ hooks.linking.rescan,
hooks.linking.target.prepare-link,
hooks.linking.target.link ]
wants = [ hooks.linking.move-follow,
hooks.linking.target.find-defined,
wants = [ hooks.linking.target.find-defined,
hooks.linking.target.find-filter,
hooks.linking.target.find-default,
hooks.linking.target.find-best,

View file

@ -3,22 +3,13 @@
wireplumber.settings = {
## Moves session items when metadata ``target.object`` changes. Also responds to
##`target.node` key. But `target.object` is the canonical key.
# linking.default.move = true
# linking.allow-moving-streams = true
## Moves session items to the default device when it has changed
# linking.default.follow = true
# linking.follow-default-target = true
## Whether to forward the ports format of filter stream nodes to their
## associated filter device nodes. This is needed for application to stream
## surround audio if echo-cancel is enabled.
# linking.default.filter-forward-format = false
## Set to 'true' to disable channel splitting & merging on nodes and enable
## passthrough of audio in the same format as the format of the device.
## Note that this breaks JACK support; it is generally not recommended
# linking.default.audio-no-dsp = false
## How much to lower the volume of lower priority streams when ducking
## note that this is a linear volume modifier (not cubic as in pulseaudio)
# linking.default.duck-level = 0.3
# linking.filter-forward-format = false
}

View file

@ -60,7 +60,7 @@ function putils.canPassthrough (si, si_target)
return false
end
function putils.checkFollowDefault (si, si_target, has_node_defined_target)
function putils.checkFollowDefault (si, si_target)
-- If it got linked to the default target that is defined by node
-- props but not metadata, start ignoring the node prop from now on.
-- This is what Pulseaudio does.
@ -68,15 +68,12 @@ function putils.checkFollowDefault (si, si_target, has_node_defined_target)
-- Pulseaudio skips here filter streams (i->origin_sink and
-- o->destination_source set in PA). Pipewire does not have a flag
-- explicitly for this, but we can use presence of node.link-group.
if not has_node_defined_target then
return
end
local si_props = si.properties
local target_props = si_target.properties
local reconnect = not cutils.parseBool (si_props ["node.dont-reconnect"])
local is_filter = (si_props ["node.link-group"] ~= nil)
if follow and default_nodes ~= nil and reconnect and not is_filter then
if reconnect and not is_filter then
local def_id = cutils.getDefaultNode (si_props,
cutils.getTargetDirection (si_props))

View file

@ -9,11 +9,9 @@
local settings_manager = require ("settings-manager")
local defaults = {
["move"] = true,
["follow"] = true,
["allow-moving-streams"] = true,
["follow-default-target"] = true,
["filter-forward-format"] = false,
["duck-level"] = 0.3,
}
return settings_manager.new ("linking.default.", defaults)
return settings_manager.new ("linking.", defaults)

View file

@ -34,7 +34,7 @@ SimpleEventHook {
log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
local metadata = settings.move and cutils.get_default_metadata_object ()
local metadata = settings.allow_moving_streams and cutils.get_default_metadata_object ()
local dont_fallback = cutils.parseBool (si_props ["target.dont-fallback"])
local dont_move = cutils.parseBool (si_props ["target.dont-move"])
local target_key

View file

@ -1,38 +0,0 @@
-- WirePlumber
--
-- Copyright © 2022 Collabora Ltd.
--
-- SPDX-License-Identifier: MIT
--
-- Move & follow settings handlers. If the relevant settings are enabled,
-- install hooks that will schedule a rescan of the graph when needed
log = Log.open_topic ("s-linking")
settings = require ("settings-linking")
handles = {}
function handleMoveSetting (enable)
if (not handles.move_hook) and (enable == true) then
handles.move_hook = SimpleEventHook {
name = "linking/move",
interests = {
EventInterest {
Constraint { "event.type", "=", "metadata-changed" },
Constraint { "metadata.name", "=", "default" },
Constraint { "event.subject.key", "c", "target.node", "target.object" },
},
},
execute = function (event)
local source = event:get_source ()
source:call ("schedule-rescan", "linking")
end
}
handles.move_hook:register()
elseif (handles.move_hook) and (enable == false) then
handles.move_hook:remove ()
handles.move_hook = nil
end
end
settings:subscribe ("move", handleMoveSetting)
handleMoveSetting (settings.move)

View file

@ -10,6 +10,7 @@
putils = require ("linking-utils")
cutils = require ("common-utils")
settings = require ("settings-linking")
log = Log.open_topic ("s-linking")
SimpleEventHook {
@ -36,9 +37,12 @@ SimpleEventHook {
if si_flags.peer_id then
if target and si_flags.peer_id == target.id then
log:debug (si, "... already linked to proper target")
-- Check this also here, in case in default targets changed
putils.checkFollowDefault (si, target,
si_flags.has_node_defined_target)
if settings.follow_default_target and si_flags.has_node_defined_target then
putils.checkFollowDefault (si, target)
end
target = nil
goto done
end

View file

@ -13,7 +13,9 @@
putils = require ("linking-utils")
cutils = require ("common-utils")
futils = require ("filter-utils")
settings = require ("settings-linking")
log = Log.open_topic ("s-linking")
handles = {}
function checkFilter (si, om, handle_nonstreams)
-- always handle filters if handle_nonstreams is true, even if it is disabled
@ -206,3 +208,29 @@ SimpleEventHook {
source:call ("schedule-rescan", "linking")
end
}:register ()
function handleMoveSetting (enable)
if (not handles.move_hook) and (enable == true) then
handles.move_hook = SimpleEventHook {
name = "linking/rescan-trigger-on-target-metadata-changed",
interests = {
EventInterest {
Constraint { "event.type", "=", "metadata-changed" },
Constraint { "metadata.name", "=", "default" },
Constraint { "event.subject.key", "c", "target.object", "target.node" },
},
},
execute = function (event)
local source = event:get_source ()
source:call ("schedule-rescan", "linking")
end
}
handles.move_hook:register()
elseif (handles.move_hook) and (enable == false) then
handles.move_hook:remove ()
handles.move_hook = nil
end
end
settings:subscribe ("allow-moving-streams", handleMoveSetting)
handleMoveSetting (settings.allow_moving_streams)