policy-node.lua: fix the session items unhandling

This commit is contained in:
Ashok Sidipotu 2022-08-26 12:22:02 +05:30 committed by Julian Bouzas
parent 0983326433
commit a5a6300662
6 changed files with 50 additions and 24 deletions

View file

@ -69,6 +69,11 @@ get_object_type_and_priority (gpointer obj, const gchar **type, gint *priority)
*type = "endpoint";
*priority = 60;
}
else if (WP_IS_SI_LINKABLE (obj))
{
*type = "linkable";
*priority = 50;
}
else if (WP_IS_METADATA (obj))
{
*type = "metadata";
@ -250,6 +255,7 @@ wp_standard_event_source_enable (WpPlugin * plugin, WpTransition * transition)
self->om = wp_object_manager_new ();
wp_object_manager_add_interest (self->om, WP_TYPE_GLOBAL_PROXY, NULL);
wp_object_manager_add_interest (self->om, WP_TYPE_SI_LINKABLE, NULL);
wp_object_manager_request_object_features (self->om,
WP_TYPE_GLOBAL_PROXY, WP_OBJECT_FEATURES_ALL);
g_signal_connect_object (self->om, "object-added",

View file

@ -129,11 +129,6 @@ AsyncEventHook {
Log.info (item, "activated item for node " .. tostring (bound_id))
item:register ()
transition:advance ()
props = {}
props ["event.subject.type"] = "linkable"
EventDispatcher.push_event { type = "object-added",
priority = 50, properties = props, subject = item }
end,
},
},
@ -169,9 +164,5 @@ SimpleEventHook {
items [id] = nil
end
props = {}
props ["event.subject.type"] = "linkable"
EventDispatcher.push_event { type = "object-removed",
priority = 50, properties = props, subject = item }
end
}:register ()

View file

@ -13,6 +13,15 @@ function cutils.parseBool (var)
return var and (var:lower () == "true" or var == "1")
end
function cutils.parseParam (param, id)
local route = param:parse ()
if route.pod_type == "Object" and route.object_id == id then
return route.properties
else
return nil
end
end
function cutils.getTargetDirection (properties)
local target_direction = nil
if properties ["item.node.direction"] == "output" or

View file

@ -230,7 +230,7 @@ function putils.haveAvailableRoutes (si_props)
-- First check "SPA_PARAM_Route" if there are any active devices
-- in an active profile.
for p in device:iterate_params ("Route") do
local route = parseParam (p, "Route")
local route = cutils.parseParam (p, "Route")
if not route then
goto skip_route
end
@ -251,7 +251,7 @@ function putils.haveAvailableRoutes (si_props)
-- Second check "SPA_PARAM_EnumRoute" if there is any route that
-- is available if not active.
for p in device:iterate_params ("EnumRoute") do
local route = parseParam (p, "EnumRoute")
local route = cutils.parseParam (p, "EnumRoute")
if not route then
goto skip_enum_route
end
@ -276,6 +276,10 @@ function putils.haveAvailableRoutes (si_props)
return false
end
devices_om = ObjectManager { Interest { type = "device" } }
devices_om:activate ()
linkables_om = ObjectManager {
Interest {
type = "SiLinkable",

View file

@ -38,6 +38,9 @@ function findDefinedTarget (event)
local node_defined = false
local target_picked = nil
si_flags.node_name = si_props ["node.name"]
si_flags.node_id = si_props ["node.id"]
if si_props ["target.object"] ~= nil then
target_value = si_props ["target.object"]
target_key = "object.serial"
@ -186,7 +189,7 @@ function findBestTarget (event)
end
local si_props = si.properties
local target_direction = putils.getTargetDirection (si_props)
local target_direction = cutils.getTargetDirection (si_props)
local target_picked = nil
local target_can_passthrough = false
local target_priority = 0
@ -273,8 +276,8 @@ function prepareLink (event)
local exclusive = parseBool (si_props ["node.exclusive"])
local si_must_passthrough = parseBool (si_props ["item.node.encoded-only"])
Log.info(si, string.format("handling item: %s (%s)",
tostring(si_props["node.name"]), tostring(si_props["node.id"])))
Log.info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
-- Check if item is linked to proper target, otherwise re-link
if si_flags.peer_id then
@ -465,7 +468,7 @@ function createLink (event)
-- activate
si_link:activate (Feature.SessionItem.ACTIVE, function (l, e)
if e then
Log.info(l, "failed to activate si-standard-link: "..tostring(si).." error:".. tostring(e))
Log.info (l, "failed to activate si-standard-link: " .. tostring (si) .. " error:" .. tostring (e))
if si_flags ~= nil then
si_flags.peer_id = nil
end
@ -473,15 +476,20 @@ function createLink (event)
else
if si_flags ~= nil then
si_flags.failed_peer_id = nil
if si_flags.peer_id == nil then
si_flags.peer_id = si_target.id
end
si_flags.failed_count = 0
end
Log.info (l, "activated si-standard-link "..tostring(si))
Log.info (l, "activated si-standard-link " .. tostring (si))
end
putils.set_flags (si_id, si_flags)
end)
::done::
si_flags.was_handled = true
putils.set_flags (si_id, si_flags)
putils.checkFollowDefault (si, si_target, si_flags.has_node_defined_target)
end
linkables_om = ObjectManager {

View file

@ -16,9 +16,9 @@
-- settings file: policy.conf
local move = Settings.get ("default-policy-move"):parse() or false
local follow = Settings.get ("default-policy-follow"):parse() or false
local filter_forward_format = Settings.get ("filter.forward-format"):parse() or false
local move = Settings.get ("default-policy-move"):parse () or false
local follow = Settings.get ("default-policy-follow"):parse () or false
local filter_forward_format = Settings.get ("filter.forward-format"):parse () or false
local putils = require ("policy-utils")
local cutils = require ("common-utils")
@ -30,6 +30,7 @@ function parseBool (var)
end
function unhandleLinkable (si)
local si_id = si.id
local si_flags = putils.get_flags (si_id)
local valid, si_props = checkLinkable (si, true)
if not valid then
@ -37,7 +38,7 @@ function unhandleLinkable (si)
end
Log.info (si, string.format ("unhandling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
tostring (si_flags.node_name), tostring (si_flags.node_id)))
-- remove any links associated with this item
for silink in links_om:iterate () do
@ -86,7 +87,8 @@ function handleLinkable (si)
end
find_target_events [si_id] = EventDispatcher.push_event {
type = "find-target-si-and-link", priority = 10, subject = si }
type = "find-target-si-and-link", priority = 10, subject = si
}
end
function rescan ()
@ -231,9 +233,6 @@ SimpleEventHook {
EventInterest {
Constraint { "event.type", "=", "object-removed" },
Constraint { "event.subject.type", "=", "linkable" },
Constraint { "item.factory.name", "c", "si-audio-adapter", "si-node" },
Constraint { "media.class", "#", "Stream/*", type = "pw-global" },
Constraint { "active-features", "!", 0, type = "gobject" },
},
},
execute = function (event)
@ -369,6 +368,15 @@ pending_linkables_om = ObjectManager {
}
}
links_om = ObjectManager {
Interest {
type = "SiLink",
-- only handle links created by this policy
Constraint { "is.policy.item.link", "=", true },
}
}
endpoints_om:activate ()
linkables_om:activate ()
pending_linkables_om:activate ()
links_om:activate ()