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"
property as filter name if this property is not set.
- filter.enabled:
Boolean indicating whether the filter should be used at all or not. If it is
not set, wireplumber will consider the filter enabled by default.
- filter.disabled:
Boolean indicating whether the filter should be disabled at all or not. A
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:
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 ]
media.class = Audio/Sink
filter.name = loopback-1
filter.enabled = true
filter.disabled = false
filter.before = [ loopback-2 ]
}
playback.props = {
@@ -187,7 +188,7 @@ The PipeWire configuration files for the 2 filters should be like this:
audio.position = [ FL FR ]
media.class = Audio/Sink
filter.name = loopback-2
filter.enabled = true
filter.disabled = false
}
playback.props = {
audio.position = [ FL FR ]
@@ -255,7 +256,7 @@ define the filters like this:
audio.position = [ FL FR ]
media.class = Audio/Sink
filter.name = loopback-1
filter.enabled = true
filter.disabled = false
filter.before = [ loopback-2 ]
filter.target = { node.name = "not-default-audio-device-name" }
}
@@ -281,7 +282,7 @@ define the filters like this:
audio.position = [ FL FR ]
media.class = Audio/Sink
filter.name = loopback-2
filter.enabled = true
filter.disabled = false
}
playback.props = {
audio.position = [ FL FR ]
@@ -321,11 +322,11 @@ properties by using the "filters" metadata. This allow users to change the filte
policy at runtime.
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::
$ 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:

View File

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

View File

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