scripts: change filter.enabled property to filter.disabled

Avoids confusion with default value if the property is not defined.
This commit is contained in:
Julian Bouzas
2023-10-02 08:44:57 -04:00
parent 1e40108d94
commit 0b44d9cf84
3 changed files with 23 additions and 22 deletions

View File

@@ -121,9 +121,10 @@ optional node properties on the main node:
The unique name of the filter. WirePlumber will use the "node.link-group" The unique name of the filter. WirePlumber will use the "node.link-group"
property as filter name if this property is not set. property as filter name if this property is not set.
- filter.enabled: - filter.disabled:
Boolean indicating whether the filter should be used at all or not. If it is Boolean indicating whether the filter should be disabled at all or not. A
not set, wireplumber will consider the filter enabled by default. disabled filter will never be used in any circumstances. If the property is
not set, wireplumber will consider the filter not disabled by default.
- filter.target: - filter.target:
A JSON object that defines the matching properties of the filter's target node. A JSON object that defines the matching properties of the filter's target node.
@@ -162,7 +163,7 @@ The PipeWire configuration files for the 2 filters should be like this:
audio.position = [ FL FR ] audio.position = [ FL FR ]
media.class = Audio/Sink media.class = Audio/Sink
filter.name = loopback-1 filter.name = loopback-1
filter.enabled = true filter.disabled = false
filter.before = [ loopback-2 ] filter.before = [ loopback-2 ]
} }
playback.props = { playback.props = {
@@ -187,7 +188,7 @@ The PipeWire configuration files for the 2 filters should be like this:
audio.position = [ FL FR ] audio.position = [ FL FR ]
media.class = Audio/Sink media.class = Audio/Sink
filter.name = loopback-2 filter.name = loopback-2
filter.enabled = true filter.disabled = false
} }
playback.props = { playback.props = {
audio.position = [ FL FR ] audio.position = [ FL FR ]
@@ -255,7 +256,7 @@ define the filters like this:
audio.position = [ FL FR ] audio.position = [ FL FR ]
media.class = Audio/Sink media.class = Audio/Sink
filter.name = loopback-1 filter.name = loopback-1
filter.enabled = true filter.disabled = false
filter.before = [ loopback-2 ] filter.before = [ loopback-2 ]
filter.target = { node.name = "not-default-audio-device-name" } filter.target = { node.name = "not-default-audio-device-name" }
} }
@@ -281,7 +282,7 @@ define the filters like this:
audio.position = [ FL FR ] audio.position = [ FL FR ]
media.class = Audio/Sink media.class = Audio/Sink
filter.name = loopback-2 filter.name = loopback-2
filter.enabled = true filter.disabled = false
} }
playback.props = { playback.props = {
audio.position = [ FL FR ] audio.position = [ FL FR ]
@@ -321,11 +322,11 @@ properties by using the "filters" metadata. This allow users to change the filte
policy at runtime. policy at runtime.
For example, if loopback-1 main node Id is `40`, we can disable the filter by For example, if loopback-1 main node Id is `40`, we can disable the filter by
setting its "filter.enabled" metadata key to false using the `pw-metadata` tool: setting its "filter.disabled" metadata key to true using the `pw-metadata` tool:
.. code-block:: .. code-block::
$ pw-metadata -n filters 40 "filter.enabled" false Spa:String:JSON $ pw-metadata -n filters 40 "filter.disabled" true Spa:String:JSON
We can also change the target of a filter at runtime: We can also change the target of a filter at runtime:

View File

@@ -37,11 +37,11 @@ local function getFilterName (metadata, node)
return node.properties ["node.link-group"] return node.properties ["node.link-group"]
end end
local function getFilterEnabled (metadata, node) local function getFilterDisabled (metadata, node)
-- Check metadata -- Check metadata
if metadata ~= nil then if metadata ~= nil then
local id = node["bound-id"] local id = node["bound-id"]
local value_str = metadata:find (id, "filter.enabled") local value_str = metadata:find (id, "filter.disabled")
if value_str ~= nil then if value_str ~= nil then
local json = Json.Raw (value_str) local json = Json.Raw (value_str)
if json:is_boolean() then if json:is_boolean() then
@@ -51,13 +51,13 @@ local function getFilterEnabled (metadata, node)
end end
-- Check node properties -- Check node properties
local prop_str = node.properties ["filter.enabled"] local prop_str = node.properties ["filter.disabled"]
if prop_str ~= nil then if prop_str ~= nil then
return cutils.parseBool (prop_str) return cutils.parseBool (prop_str)
end end
-- Otherwise enable filter by defaul -- Otherwise consider the filter not disabled by default
return true return false
end end
local function getFilterTarget (metadata, node, om) local function getFilterTarget (metadata, node, om)
@@ -262,7 +262,7 @@ local function rescanFilters (om, metadata_om)
-- Get filter properties -- Get filter properties
filter.name = getFilterName (metadata, n) filter.name = getFilterName (metadata, n)
filter.enabled = getFilterEnabled (metadata, n) filter.disabled = getFilterDisabled (metadata, n)
filter.target = getFilterTarget (metadata, n, om) filter.target = getFilterTarget (metadata, n, om)
filter.before = getFilterBefore (metadata, n) filter.before = getFilterBefore (metadata, n)
filter.after = getFilterAfter (metadata, n) filter.after = getFilterAfter (metadata, n)
@@ -316,7 +316,7 @@ SimpleEventHook {
end end
}:register () }:register ()
function module.is_filter_enabled (direction, link_group) function module.is_filter_disabled (direction, link_group)
-- Make sure direction and link_group is valid -- Make sure direction and link_group is valid
if direction == nil or link_group == nil then if direction == nil or link_group == nil then
return false return false
@@ -324,7 +324,7 @@ function module.is_filter_enabled (direction, link_group)
for i, v in ipairs(module.filters) do for i, v in ipairs(module.filters) do
if v.direction == direction and v.link_group == link_group then if v.direction == direction and v.link_group == link_group then
return v.enabled return v.disabled
end end
end end
@@ -343,7 +343,7 @@ function module.get_filter_target (direction, link_group)
for i, v in ipairs(module.filters) do for i, v in ipairs(module.filters) do
if v.direction == direction and if v.direction == direction and
v.link_group == link_group and v.link_group == link_group and
v.enabled then not v.disabled then
filter = v filter = v
index = i index = i
break break
@@ -358,7 +358,7 @@ function module.get_filter_target (direction, link_group)
if v.direction == direction and if v.direction == direction and
v.name ~= filter.name and v.name ~= filter.name and
v.link_group ~= link_group and v.link_group ~= link_group and
v.enabled and not v.disabled and
((v.target == nil and v.target == filter.target) or ((v.target == nil and v.target == filter.target) or
(v.target.id == filter.target.id)) and (v.target.id == filter.target.id)) and
i > index then i > index then
@@ -379,7 +379,7 @@ function module.get_filter_from_target (direction, si_target)
-- Find the first filter matching target -- Find the first filter matching target
for i, v in ipairs(module.filters) do for i, v in ipairs(module.filters) do
if v.direction == direction and if v.direction == direction and
v.enabled and not v.disabled and
v.target ~= nil and v.target ~= nil and
v.target.id == si_target.id then v.target.id == si_target.id then
return v.main_si return v.main_si
@@ -389,7 +389,7 @@ function module.get_filter_from_target (direction, si_target)
-- If not found, just return the first filter with nil target -- If not found, just return the first filter with nil target
for i, v in ipairs(module.filters) do for i, v in ipairs(module.filters) do
if v.direction == direction and if v.direction == direction and
v.enabled and not v.disabled and
v.target == nil then v.target == nil then
return v.main_si return v.main_si
end end

View File

@@ -29,7 +29,7 @@ function checkFilter (si, om, handle_nonstreams)
end end
local direction = cutils.getTargetDirection (si.properties) local direction = cutils.getTargetDirection (si.properties)
return futils.is_filter_enabled (direction, link_group) return not futils.is_filter_disabled (direction, link_group)
end end
function checkLinkable (si, om, handle_nonstreams) function checkLinkable (si, om, handle_nonstreams)