mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-04-22 20:00:41 +02:00
scripts: add new 'filter.smart' property
This allows users to enable/disable smart filter policy per filter. The property is considered false by default, meaning that smart filter policy is disabled for all filters by default.
This commit is contained in:
parent
7044226f66
commit
4ad263b16c
4 changed files with 65 additions and 2 deletions
|
|
@ -117,6 +117,14 @@ are automatically linked by the wirepluber policy in any way we want.
|
|||
Currently, if a filter node is created, wireplumber will check the following
|
||||
optional node properties on the main node:
|
||||
|
||||
- filter.smart:
|
||||
Boolean indicating whether smart policy will be used in the filter nodes or
|
||||
not. This is disabled by default, therefore filter nodes will be treated as
|
||||
regular nodes, without applying any kid of extra logic. On the other hand, if
|
||||
this property is set to true, automatic (smart) filter policy will be used
|
||||
when linking filters. The properties below will instruct the smart policy how
|
||||
to link the filters automatically.
|
||||
|
||||
- filter.smart.name:
|
||||
The unique name of the filter. WirePlumber will use the "node.link-group"
|
||||
property as filter name if this property is not set.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,29 @@ local module = {
|
|||
filters = {},
|
||||
}
|
||||
|
||||
local function getFilterSmart (metadata, node)
|
||||
-- Check metadata
|
||||
if metadata ~= nil then
|
||||
local id = node["bound-id"]
|
||||
local value_str = metadata:find (id, "filter.smart")
|
||||
if value_str ~= nil then
|
||||
local json = Json.Raw (value_str)
|
||||
if json:is_boolean() then
|
||||
return json:parse()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check node properties
|
||||
local prop_str = node.properties ["filter.smart"]
|
||||
if prop_str ~= nil then
|
||||
return cutils.parseBool (prop_str)
|
||||
end
|
||||
|
||||
-- Otherwise consider the filter not smart by default
|
||||
return false
|
||||
end
|
||||
|
||||
local function getFilterSmartName (metadata, node)
|
||||
-- Check metadata
|
||||
if metadata ~= nil then
|
||||
|
|
@ -261,6 +284,7 @@ local function rescanFilters (om, metadata_om)
|
|||
end
|
||||
|
||||
-- Get filter properties
|
||||
filter.smart = getFilterSmart (metadata, n)
|
||||
filter.name = getFilterSmartName (metadata, n)
|
||||
filter.disabled = getFilterSmartDisabled (metadata, n)
|
||||
filter.target = getFilterSmartTarget (metadata, n, om)
|
||||
|
|
@ -316,6 +340,21 @@ SimpleEventHook {
|
|||
end
|
||||
}:register ()
|
||||
|
||||
function module.is_filter_smart (direction, link_group)
|
||||
-- Make sure direction and link_group is valid
|
||||
if direction == nil or link_group == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
for i, v in ipairs(module.filters) do
|
||||
if v.direction == direction and v.link_group == link_group then
|
||||
return v.smart
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function module.is_filter_disabled (direction, link_group)
|
||||
-- Make sure direction and link_group is valid
|
||||
if direction == nil or link_group == nil then
|
||||
|
|
@ -343,7 +382,8 @@ 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
|
||||
not v.disabled then
|
||||
not v.disabled and
|
||||
v.smart then
|
||||
filter = v
|
||||
index = i
|
||||
break
|
||||
|
|
@ -359,6 +399,7 @@ function module.get_filter_target (direction, link_group)
|
|||
v.name ~= filter.name and
|
||||
v.link_group ~= link_group and
|
||||
not v.disabled and
|
||||
v.smart and
|
||||
((v.target == nil and v.target == filter.target) or
|
||||
(v.target.id == filter.target.id)) and
|
||||
i > index then
|
||||
|
|
@ -380,6 +421,7 @@ function module.get_filter_from_target (direction, si_target)
|
|||
for i, v in ipairs(module.filters) do
|
||||
if v.direction == direction and
|
||||
not v.disabled and
|
||||
v.smart and
|
||||
v.target ~= nil and
|
||||
v.target.id == si_target.id then
|
||||
return v.main_si
|
||||
|
|
@ -390,6 +432,7 @@ function module.get_filter_from_target (direction, si_target)
|
|||
for i, v in ipairs(module.filters) do
|
||||
if v.direction == direction and
|
||||
not v.disabled and
|
||||
v.smart and
|
||||
v.target == nil then
|
||||
return v.main_si
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,11 +17,16 @@ function findFilterTarget (si, om)
|
|||
local link_group = node.properties ["node.link-group"]
|
||||
local target_id = -1
|
||||
|
||||
-- return nil if si is not a filter node
|
||||
-- return nil if session item is not a filter node
|
||||
if link_group == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- return nil if filter is not smart
|
||||
if not futils.is_filter_smart (direction, link_group) then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- get the filter target
|
||||
return futils.get_filter_target (direction, link_group)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ function checkFilter (si, om, handle_nonstreams)
|
|||
end
|
||||
|
||||
local direction = cutils.getTargetDirection (si.properties)
|
||||
|
||||
-- always handle filters that are not smart
|
||||
if not futils.is_filter_smart (direction, link_group) then
|
||||
return true
|
||||
end
|
||||
|
||||
-- dont handle smart filters that are disabled
|
||||
return not futils.is_filter_disabled (direction, link_group)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue