policy-node: use default-nodes-api plugin

This commit is contained in:
George Kiagiadakis
2021-03-31 13:09:24 +03:00
parent 0bc257b6c3
commit 0ecefcb55d
5 changed files with 25 additions and 18 deletions

View File

@@ -82,6 +82,8 @@ on_metadata_changed (WpMetadata *m, guint32 subject,
self->defaults[node_t] = g_strdup (name);
}
wp_debug_object (m, "changed '%s' -> '%s'", key, self->defaults[node_t]);
schedule_changed_notification (self);
}
}

View File

@@ -192,6 +192,9 @@ on_metadata_changed (WpMetadata *m, guint32 subject,
self->defaults[node_t].config_value = g_strdup (name);
}
wp_debug_object (m, "changed '%s' -> '%s'", key,
self->defaults[node_t].config_value);
/* re-evaluate the default, taking into account the new configured default;
block recursive calls to this handler as an optimization */
g_signal_handlers_block_by_func (m, on_metadata_changed, d);

View File

@@ -69,6 +69,11 @@ local function Constraint (spec)
return debug.setmetatable(spec, { __name = "Constraint" })
end
local Id = {
INVALID = 0xffffffff,
ANY = 0xffffffff,
}
local Features = {
PipewireObject = {
MINIMAL = 0x11,
@@ -111,6 +116,7 @@ local Feature = {
}
SANDBOX_EXPORT = {
Id = Id,
Features = Features,
Feature = Feature,
Log = WpDebug,

View File

@@ -60,3 +60,6 @@ load_module("metadata")
-- Enables saving and restoring default nodes
load_module("default-nodes")
-- API to access default nodes from scripts
load_module("default-nodes-api")

View File

@@ -9,12 +9,6 @@ target_class_assoc = {
["Stream/Input/Audio"] = "Audio/Source",
["Stream/Output/Audio"] = "Audio/Sink",
["Stream/Input/Video"] = "Video/Source",
["Stream/Output/Video"] = "Video/Sink",
}
default_audio_node_key = {
["Audio/Sink"] = "default.configured.audio.sink",
["Audio/Source"] = "default.configured.audio.source",
}
function createLink (si, si_target)
@@ -44,6 +38,10 @@ function createLink (si, si_target)
end
end
Log.info (string.format("link %s <-> %s",
node.properties["node.name"],
target_node.properties["node.name"]))
-- create and configure link
local si_link = SessionItem ( "si-standard-link" )
if not si_link:configure {
@@ -80,22 +78,18 @@ function findTarget (node, target_media_class)
-- try to find the best target
if target == nil then
local metadata = metadatas_om:lookup()
local def_id = default_nodes:call("get-default-node", target_media_class)
for candidate_si in siportinfos_om:iterate() do
local n = candidate_si:get_associated_proxy ("node")
if n and n.properties["media.class"] == target_media_class then
-- honor default node, if present
if metadata then
local key = default_audio_node_key[target_media_class]
local value = metadata:find(0, key)
local n_id = n["bound-id"]
if value and n_id == tonumber(value) then
if def_id ~= Id.INVALID and n_id == def_id then
target = candidate_si
Log.debug (node, "choosing default node " .. n_id)
break
end
end
-- otherwise just use this candidate
if target == nil then
@@ -164,7 +158,7 @@ function reevaulateSiLinks ()
end
end
metadatas_om = ObjectManager { Interest { type = "metadata" } }
default_nodes = Plugin("default-nodes-api")
siportinfos_om = ObjectManager { Interest { type = "SiPortInfo" } }
silinks_om = ObjectManager { Interest { type = "SiLink" } }
@@ -173,6 +167,5 @@ siportinfos_om:connect("objects-changed", function (om)
reevaulateSiLinks ()
end)
metadatas_om:activate()
siportinfos_om:activate()
silinks_om:activate()