mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-05 19:28:01 +02:00
src: scripts: add create-item.lua and remove create-endpoint.lua
This commit is contained in:
parent
0d71565d63
commit
f6ed14f997
3 changed files with 58 additions and 102 deletions
|
|
@ -25,8 +25,8 @@ function endpoint_support.enable()
|
|||
-- Create sessions statically at startup
|
||||
load_script("static-sessions.lua", endpoint_support.sessions)
|
||||
|
||||
-- Create endpoints for nodes that appear in the graph
|
||||
load_script("create-endpoint.lua")
|
||||
-- Create items for nodes that appear in the graph
|
||||
load_script("create-item.lua")
|
||||
|
||||
-- Link endpoints to each other to make media flow in the graph
|
||||
load_script("policy-endpoint.lua", endpoint_support.policy)
|
||||
|
|
|
|||
|
|
@ -1,100 +0,0 @@
|
|||
-- WirePlumber
|
||||
--
|
||||
-- Copyright © 2021 Collabora Ltd.
|
||||
-- @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
--
|
||||
-- SPDX-License-Identifier: MIT
|
||||
|
||||
session_items = {
|
||||
endpoints = {},
|
||||
monitors = {},
|
||||
}
|
||||
|
||||
function addEndpoint (node, session_name, endpoint_type, priority)
|
||||
local id = node["bound-id"]
|
||||
local media_class = node.properties['media.class']
|
||||
local session = nil
|
||||
local name = nil
|
||||
|
||||
-- find the session
|
||||
session = sessions_om:lookup {
|
||||
Constraint { "session.name", "=", session_name }
|
||||
}
|
||||
if session == nil then
|
||||
Log.warning(node, "could not find session");
|
||||
return
|
||||
end
|
||||
|
||||
-- get the endpoint name
|
||||
name = node.properties['node.name'] or "endpoint.node." .. id
|
||||
|
||||
-- create endpoint
|
||||
session_items.endpoints[id] = SessionItem ( endpoint_type )
|
||||
|
||||
-- configure endpoint
|
||||
if not session_items.endpoints[id]:configure {
|
||||
["node"] = node,
|
||||
["name"] = name,
|
||||
["media-class"] = media_class,
|
||||
["priority"] = priority,
|
||||
["session"] = session,
|
||||
} then
|
||||
Log.warning(node, "failed to configure endpoint");
|
||||
return
|
||||
end
|
||||
|
||||
-- activate and export endpoint
|
||||
session_items.endpoints[id]:activate (Feature.Object.ALL, function (activated_ep)
|
||||
Log.info(activated_ep, "activated and exported endpoint " .. name);
|
||||
|
||||
-- only use monitor audio sinks
|
||||
if media_class == "Audio/Sink" then
|
||||
-- create monitor
|
||||
local monitor = SessionItem ( "si-monitor" )
|
||||
|
||||
-- configure monitor
|
||||
if not monitor:configure {
|
||||
["endpoint"] = session_items.endpoints[id],
|
||||
["name"] = "Monitor." .. name,
|
||||
["session"] = session,
|
||||
} then
|
||||
Log.warning(monitor, "failed to configure monitor " .. name);
|
||||
return
|
||||
end
|
||||
|
||||
session_items.monitors[id] = monitor
|
||||
|
||||
-- activate and export monitor
|
||||
monitor:activate (Feature.Object.ALL, function (activated_mon)
|
||||
Log.info(activated_mon, "activated and exported monitor " .. name);
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
sessions_om = ObjectManager { Interest { type = "session" } }
|
||||
nodes_om = ObjectManager { Interest { type = "node" } }
|
||||
|
||||
nodes_om:connect("object-added", function (om, node)
|
||||
local media_class = node.properties['media.class']
|
||||
|
||||
-- skip nodes without media class
|
||||
if media_class == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if string.find (media_class, "Audio") then
|
||||
addEndpoint (node, "audio", "si-audio-adapter", 1)
|
||||
else
|
||||
addEndpoint (node, "video", "si-node", 1)
|
||||
end
|
||||
end)
|
||||
|
||||
nodes_om:connect("object-removed", function (om, node)
|
||||
local id = node["bound-id"]
|
||||
session_items.monitors[id] = nil
|
||||
session_items.endpoints[id] = nil
|
||||
end)
|
||||
|
||||
sessions_om:activate()
|
||||
nodes_om:activate()
|
||||
56
src/scripts/create-item.lua
Normal file
56
src/scripts/create-item.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
-- WirePlumber
|
||||
--
|
||||
-- Copyright © 2021 Collabora Ltd.
|
||||
-- @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
--
|
||||
-- SPDX-License-Identifier: MIT
|
||||
|
||||
items = {}
|
||||
|
||||
function addItem (node, item_type)
|
||||
local id = node["bound-id"]
|
||||
|
||||
-- create item
|
||||
items[id] = SessionItem ( item_type )
|
||||
|
||||
-- configure item
|
||||
if not items[id]:configure {
|
||||
["node"] = node,
|
||||
} then
|
||||
Log.warning(items[id], "failed to configure item for node " .. tostring(id))
|
||||
return
|
||||
end
|
||||
|
||||
-- activate item
|
||||
items[id]:activate (Feature.SessionItem.ACTIVE, function (item)
|
||||
Log.info(item, "activated item for node " .. tostring(id))
|
||||
item:register ()
|
||||
end)
|
||||
end
|
||||
|
||||
nodes_om = ObjectManager { Interest { type = "node" } }
|
||||
|
||||
nodes_om:connect("object-added", function (om, node)
|
||||
local media_class = node.properties['media.class']
|
||||
|
||||
-- skip nodes without media class
|
||||
if media_class == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if string.find (media_class, "Audio") then
|
||||
addItem (node, "si-audio-adapter")
|
||||
else
|
||||
addItem (node, "si-node")
|
||||
end
|
||||
end)
|
||||
|
||||
nodes_om:connect("object-removed", function (om, node)
|
||||
local id = node["bound-id"]
|
||||
if items[id] then
|
||||
items[id]:remove ()
|
||||
items[id] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
nodes_om:activate()
|
||||
Loading…
Add table
Reference in a new issue