diff --git a/modules/module-default-nodes-api.c b/modules/module-default-nodes-api.c index 485456f3..c5df4909 100644 --- a/modules/module-default-nodes-api.c +++ b/modules/module-default-nodes-api.c @@ -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); } } diff --git a/modules/module-default-nodes.c b/modules/module-default-nodes.c index c82a4e3a..8b625ee2 100644 --- a/modules/module-default-nodes.c +++ b/modules/module-default-nodes.c @@ -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); diff --git a/modules/module-lua-scripting/api.lua b/modules/module-lua-scripting/api.lua index 952ac1d1..0a82c344 100644 --- a/modules/module-lua-scripting/api.lua +++ b/modules/module-lua-scripting/api.lua @@ -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, diff --git a/src/config/config.lua b/src/config/config.lua index 2fe30c0b..6f1faf35 100644 --- a/src/config/config.lua +++ b/src/config/config.lua @@ -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") diff --git a/src/scripts/policy-node.lua b/src/scripts/policy-node.lua index 45d50ba1..5d8ded15 100644 --- a/src/scripts/policy-node.lua +++ b/src/scripts/policy-node.lua @@ -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,21 +78,17 @@ 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 - target = candidate_si - Log.debug (node, "choosing default node " .. n_id) - break - end + local n_id = n["bound-id"] + if def_id ~= Id.INVALID and n_id == def_id then + target = candidate_si + Log.debug (node, "choosing default node " .. n_id) + break end -- otherwise just use this candidate @@ -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()