scripts: use log topics

This commit is contained in:
George Kiagiadakis
2023-05-19 20:12:08 +03:00
parent 9e09f4e221
commit 982bebe5aa
37 changed files with 168 additions and 122 deletions

View File

@@ -5,6 +5,8 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
log = Log.open_topic ("s-client")
function getDefaultPermissions (properties) function getDefaultPermissions (properties)
local pw_access = properties["pipewire.access"] local pw_access = properties["pipewire.access"]
local media_category = properties["media.category"] local media_category = properties["media.category"]
@@ -43,7 +45,7 @@ clients_om:connect("object-added", function (om, client)
end end
if perms ~= nil then if perms ~= nil then
Log.info(client, "Granting permissions to client " .. id .. ": " .. perms) log:info(client, "Granting permissions to client " .. id .. ": " .. perms)
client:update_permissions { ["any"] = perms } client:update_permissions { ["any"] = perms }
end end
end) end)

View File

@@ -1,6 +1,8 @@
MEDIA_ROLE_NONE = 0 MEDIA_ROLE_NONE = 0
MEDIA_ROLE_CAMERA = 1 << 0 MEDIA_ROLE_CAMERA = 1 << 0
log = Log.open_topic ("s-client")
function hasPermission (permissions, app_id, lookup) function hasPermission (permissions, app_id, lookup)
if permissions then if permissions then
for key, values in pairs(permissions) do for key, values in pairs(permissions) do
@@ -28,7 +30,7 @@ end
function setPermissions (client, allow_client, allow_nodes) function setPermissions (client, allow_client, allow_nodes)
local client_id = client["bound-id"] local client_id = client["bound-id"]
Log.info(client, "Granting ALL access to client " .. client_id) log:info(client, "Granting ALL access to client " .. client_id)
-- Update permissions on client -- Update permissions on client
client:update_permissions { [client_id] = allow_client and "all" or "-" } client:update_permissions { [client_id] = allow_client and "all" or "-" }
@@ -50,18 +52,18 @@ function updateClientPermissions (client, permissions)
-- Make sure the client is not the portal itself -- Make sure the client is not the portal itself
str_prop = client.properties["pipewire.access.portal.is_portal"] str_prop = client.properties["pipewire.access.portal.is_portal"]
if str_prop == "yes" then if str_prop == "yes" then
Log.info (client, "client is the portal itself") log:info (client, "client is the portal itself")
return return
end end
-- Make sure the client has a portal app Id -- Make sure the client has a portal app Id
str_prop = client.properties["pipewire.access.portal.app_id"] str_prop = client.properties["pipewire.access.portal.app_id"]
if str_prop == nil then if str_prop == nil then
Log.info (client, "Portal managed client did not set app_id") log:info (client, "Portal managed client did not set app_id")
return return
end end
if str_prop == "" then if str_prop == "" then
Log.info (client, "Ignoring portal check for non-sandboxed client") log:info (client, "Ignoring portal check for non-sandboxed client")
setPermissions (client, true, true) setPermissions (client, true, true)
return return
end end
@@ -70,19 +72,19 @@ function updateClientPermissions (client, permissions)
-- Make sure the client has portal media roles -- Make sure the client has portal media roles
str_prop = client.properties["pipewire.access.portal.media_roles"] str_prop = client.properties["pipewire.access.portal.media_roles"]
if str_prop == nil then if str_prop == nil then
Log.info (client, "Portal managed client did not set media_roles") log:info (client, "Portal managed client did not set media_roles")
return return
end end
media_roles = parseMediaRoles (str_prop) media_roles = parseMediaRoles (str_prop)
if (media_roles & MEDIA_ROLE_CAMERA) == 0 then if (media_roles & MEDIA_ROLE_CAMERA) == 0 then
Log.info (client, "Ignoring portal check for clients without camera role") log:info (client, "Ignoring portal check for clients without camera role")
return return
end end
-- Update permissions -- Update permissions
allowed = hasPermission (permissions, app_id, "yes") allowed = hasPermission (permissions, app_id, "yes")
Log.info (client, "setting permissions: " .. tostring(allowed)) log:info (client, "setting permissions: " .. tostring(allowed))
setPermissions (client, allowed, allowed) setPermissions (client, allowed, allowed)
end end
@@ -133,7 +135,7 @@ else
-- Otherwise, just set all permissions to all portal clients -- Otherwise, just set all permissions to all portal clients
clients_om:connect("object-added", function (om, client) clients_om:connect("object-added", function (om, client)
local id = client["bound-id"] local id = client["bound-id"]
Log.info(client, "Granting ALL access to client " .. id) log:info(client, "Granting ALL access to client " .. id)
client:update_permissions { ["any"] = "all" } client:update_permissions { ["any"] = "all" }
end) end)
end end

View File

@@ -4,6 +4,8 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
log = Log.open_topic ("s-default-nodes")
SimpleEventHook { SimpleEventHook {
name = "default-nodes/apply-default-node", name = "default-nodes/apply-default-node",
after = { "default-nodes/find-best-default-node", after = { "default-nodes/find-best-default-node",
@@ -27,7 +29,7 @@ SimpleEventHook {
if selected_node then if selected_node then
local key = "default." .. def_node_type local key = "default." .. def_node_type
Log.info ("set default node for " .. key .. " " .. selected_node) log:info ("set default node for " .. key .. " " .. selected_node)
metadata:set (0, key, "Spa:String:JSON", metadata:set (0, key, "Spa:String:JSON",
Json.Object { ["name"] = selected_node }:to_string ()) Json.Object { ["name"] = selected_node }:to_string ())

View File

@@ -4,6 +4,8 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
log = Log.open_topic ("s-default-nodes")
SimpleEventHook { SimpleEventHook {
name = "default-nodes/find-best-default-node", name = "default-nodes/find-best-default-node",
interests = { interests = {

View File

@@ -6,6 +6,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
config = require ("device-config") config = require ("device-config")
log = Log.open_topic ("s-default-nodes")
enabled = false enabled = false

View File

@@ -7,6 +7,8 @@
-- hook to make sure the user prefered device(default.configured.*) is higher -- hook to make sure the user prefered device(default.configured.*) is higher
-- priority. -- priority.
log = Log.open_topic ("s-default-nodes")
SimpleEventHook { SimpleEventHook {
name = "default-nodes/find-selected-default-node", name = "default-nodes/find-selected-default-node",
interests = { interests = {

View File

@@ -4,6 +4,8 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
log = Log.open_topic ("s-default-nodes")
SimpleEventHook { SimpleEventHook {
name = "default-nodes/rescan-trigger", name = "default-nodes/rescan-trigger",
interests = { interests = {
@@ -43,7 +45,7 @@ SimpleEventHook {
local si_om = source:call ("get-object-manager", "session-item") local si_om = source:call ("get-object-manager", "session-item")
local devices_om = source:call ("get-object-manager", "device") local devices_om = source:call ("get-object-manager", "device")
Log.trace ("re-evaluating default nodes") log:trace ("re-evaluating default nodes")
-- Audio Sink -- Audio Sink
pushSelectDefaultNodeEvent (source, si_om, devices_om, "audio.sink", "in", { pushSelectDefaultNodeEvent (source, si_om, devices_om, "audio.sink", "in", {

View File

@@ -6,6 +6,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
config = require ("device-config") config = require ("device-config")
log = Log.open_topic ("s-default-nodes")
-- the state storage -- the state storage
state = nil state = nil

View File

@@ -5,6 +5,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
cutils = require ("common-utils") cutils = require ("common-utils")
log = Log.open_topic ("s-device")
AsyncEventHook { AsyncEventHook {
name = "device/apply-profile", name = "device/apply-profile",
@@ -23,7 +24,7 @@ AsyncEventHook {
local dev_name = device.properties ["device.name"] local dev_name = device.properties ["device.name"]
if not profile then if not profile then
Log.info (device, "No profile found to set on " .. dev_name) log:info (device, "No profile found to set on " .. dev_name)
transition:advance () transition:advance ()
return return
end end
@@ -31,7 +32,7 @@ AsyncEventHook {
for p in device:iterate_params ("Profile") do for p in device:iterate_params ("Profile") do
local active_profile = cutils.parseParam (p, "Profile") local active_profile = cutils.parseParam (p, "Profile")
if active_profile.index == profile.index then if active_profile.index == profile.index then
Log.info (device, "Profile " .. profile.name .. " is already set on " .. dev_name) log:info (device, "Profile " .. profile.name .. " is already set on " .. dev_name)
transition:advance () transition:advance ()
return return
end end
@@ -41,7 +42,7 @@ AsyncEventHook {
"Spa:Pod:Object:Param:Profile", "Profile", "Spa:Pod:Object:Param:Profile", "Profile",
index = profile.index, index = profile.index,
} }
Log.info (device, "Setting profile " .. profile.name .. " on " .. dev_name) log:info (device, "Setting profile " .. profile.name .. " on " .. dev_name)
device:set_param ("Profile", param) device:set_param ("Profile", param)
-- FIXME: add cancellability -- FIXME: add cancellability

View File

@@ -12,6 +12,7 @@
config = require ("device-config") config = require ("device-config")
devinfo = require ("device-info-cache") devinfo = require ("device-info-cache")
log = Log.open_topic ("s-device")
AsyncEventHook { AsyncEventHook {
name = "device/apply-routes", name = "device/apply-routes",
@@ -34,7 +35,7 @@ AsyncEventHook {
assert (dev_info) assert (dev_info)
if not selected_routes then if not selected_routes then
Log.info (device, "No routes selected to set on " .. dev_info.name) log:info (device, "No routes selected to set on " .. dev_info.name)
transition:advance () transition:advance ()
return return
end end
@@ -85,7 +86,7 @@ AsyncEventHook {
save = route.save, save = route.save,
} }
Log.debug (param, log:debug (param,
string.format ("setting route(%s) on for device(%s)(%s)", string.format ("setting route(%s) on for device(%s)(%s)",
route.name, dev_info.name, tostring (device))) route.name, dev_info.name, tostring (device)))

View File

@@ -8,6 +8,7 @@
-- availability -- availability
cutils = require ("common-utils") cutils = require ("common-utils")
log = Log.open_topic ("s-device")
SimpleEventHook { SimpleEventHook {
name = "device/find-best-profile", name = "device/find-best-profile",
@@ -56,7 +57,7 @@ SimpleEventHook {
end end
if selected_profile then if selected_profile then
Log.info (device, string.format ( log:info (device, string.format (
"Found best profile '%s' (%d) for device '%s'", "Found best profile '%s' (%d) for device '%s'",
selected_profile.name, selected_profile.index, dev_name)) selected_profile.name, selected_profile.index, dev_name))
event:set_data ("selected-profile", selected_profile) event:set_data ("selected-profile", selected_profile)

View File

@@ -12,6 +12,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
devinfo = require ("device-info-cache") devinfo = require ("device-info-cache")
log = Log.open_topic ("s-device")
SimpleEventHook { SimpleEventHook {
name = "device/find-best-routes", name = "device/find-best-routes",

View File

@@ -5,6 +5,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
cutils = require ("common-utils") cutils = require ("common-utils")
log = Log.open_topic ("s-device")
SimpleEventHook { SimpleEventHook {
name = "device/select-profile", name = "device/select-profile",

View File

@@ -15,6 +15,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
config = require ("device-config") config = require ("device-config")
devinfo = require ("device-info-cache") devinfo = require ("device-info-cache")
log = Log.open_topic ("s-device")
SimpleEventHook { SimpleEventHook {
name = "device/select-route", name = "device/select-route",
@@ -60,7 +61,7 @@ SimpleEventHook {
-- update properties -- update properties
route_info.prev_available = route_info.available route_info.prev_available = route_info.available
if route_info.available ~= route.available then if route_info.available ~= route.available then
Log.info (device, "route " .. route.name .. " available changed " .. log:info (device, "route " .. route.name .. " available changed " ..
route_info.available .. " -> " .. route.available) route_info.available .. " -> " .. route.available)
route_info.available = route.available route_info.available = route.available
if profile and cutils.arrayContains (route.profiles, profile.index) then if profile and cutils.arrayContains (route.profiles, profile.index) then
@@ -92,7 +93,7 @@ SimpleEventHook {
-- then try to select a new "best" route for each device and ignore -- then try to select a new "best" route for each device and ignore
-- what was stored -- what was stored
if profile_changed or avail_routes_changed then if profile_changed or avail_routes_changed then
Log.info (device, log:info (device,
string.format ("restore routes for profile(%s) of device(%s)", string.format ("restore routes for profile(%s) of device(%s)",
profile.name, dev_info.name)) profile.name, dev_info.name))

View File

@@ -9,6 +9,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
config = require ("device-config") config = require ("device-config")
log = Log.open_topic ("s-device")
-- the state storage -- the state storage
state = nil state = nil
@@ -32,7 +33,7 @@ find_stored_profile_hook = SimpleEventHook {
end end
if not dev_name then if not dev_name then
Log.critical (device, "invalid device.name") log:critical (device, "invalid device.name")
return return
end end
@@ -49,7 +50,7 @@ find_stored_profile_hook = SimpleEventHook {
end end
if selected_profile then if selected_profile then
Log.info (device, string.format ( log:info (device, string.format (
"Found stored profile '%s' (%d) for device '%s'", "Found stored profile '%s' (%d) for device '%s'",
selected_profile.name, selected_profile.index, dev_name)) selected_profile.name, selected_profile.index, dev_name))
event:set_data ("selected-profile", selected_profile) event:set_data ("selected-profile", selected_profile)
@@ -83,17 +84,17 @@ function updateStoredProfile (device, profile)
local index = nil local index = nil
if not dev_name then if not dev_name then
Log.critical (device, "invalid device.name") log:critical (device, "invalid device.name")
return return
end end
Log.debug (device, string.format ( log:debug (device, string.format (
"update stored profile to '%s' (%d) for device '%s'", "update stored profile to '%s' (%d) for device '%s'",
profile.name, profile.index, dev_name)) profile.name, profile.index, dev_name))
-- check if the new profile is the same as the current one -- check if the new profile is the same as the current one
if state_table[dev_name] == profile.name then if state_table[dev_name] == profile.name then
Log.debug (device, " ... profile is already stored") log:debug (device, " ... profile is already stored")
return return
end end
@@ -107,7 +108,7 @@ function updateStoredProfile (device, profile)
end end
if not index then if not index then
Log.info (device, string.format ( log:info (device, string.format (
"profile '%s' (%d) is not valid on device '%s'", "profile '%s' (%d) is not valid on device '%s'",
profile.name, profile.index, dev_name)) profile.name, profile.index, dev_name))
return return
@@ -116,7 +117,7 @@ function updateStoredProfile (device, profile)
state_table[dev_name] = profile.name state_table[dev_name] = profile.name
cutils.storeAfterTimeout (state, state_table) cutils.storeAfterTimeout (state, state_table)
Log.info (device, string.format ( log:info (device, string.format (
"stored profile '%s' (%d) for device '%s'", "stored profile '%s' (%d) for device '%s'",
profile.name, index, dev_name)) profile.name, index, dev_name))
end end

View File

@@ -16,6 +16,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
config = require ("device-config") config = require ("device-config")
devinfo = require ("device-info-cache") devinfo = require ("device-info-cache")
log = Log.open_topic ("s-device")
-- the state storage -- the state storage
state = nil state = nil
@@ -57,7 +58,7 @@ find_stored_routes_hook = SimpleEventHook {
goto next_device_id goto next_device_id
end end
Log.info (device, "restoring route for device ID " .. tostring (device_id)); log:info (device, "restoring route for device ID " .. tostring (device_id));
local route_info = nil local route_info = nil
@@ -74,11 +75,11 @@ find_stored_routes_hook = SimpleEventHook {
if route_info then if route_info then
-- we found a stored route -- we found a stored route
if route_info.available == "no" then if route_info.available == "no" then
Log.info (device, "stored route '" .. route_info.name .. "' not available") log:info (device, "stored route '" .. route_info.name .. "' not available")
-- not available, try to find next best -- not available, try to find next best
route_info = nil route_info = nil
else else
Log.info (device, "found stored route: " .. route_info.name) log:info (device, "found stored route: " .. route_info.name)
-- make sure we save it again -- make sure we save it again
route_info.save = true route_info.save = true
end end
@@ -117,7 +118,7 @@ apply_route_props_hook = SimpleEventHook {
assert (dev_info) assert (dev_info)
if not selected_routes then if not selected_routes then
Log.info (device, "No routes selected to set on " .. dev_info.name) log:info (device, "No routes selected to set on " .. dev_info.name)
return return
end end
@@ -191,7 +192,7 @@ store_or_restore_routes_hook = SimpleEventHook {
if not route_info.prev_active then if not route_info.prev_active then
-- a new route is now active, restore the volume and -- a new route is now active, restore the volume and
-- make sure we save this as a preferred route -- make sure we save this as a preferred route
Log.info (device, log:info (device,
string.format ("new active route(%s) found of device(%s)", string.format ("new active route(%s) found of device(%s)",
route.name, dev_info.name)) route.name, dev_info.name))
@@ -201,7 +202,7 @@ store_or_restore_routes_hook = SimpleEventHook {
elseif route.save and route.props then elseif route.save and route.props then
-- just save route properties -- just save route properties
Log.info (device, log:info (device,
string.format ("storing route(%s) props of device(%s)", string.format ("storing route(%s) props of device(%s)",
route.name, dev_info.name)) route.name, dev_info.name))

View File

@@ -12,6 +12,7 @@
local putils = require ("policy-utils") local putils = require ("policy-utils")
local config = require ("policy-config") local config = require ("policy-config")
log = Log.open_topic ("s-linking")
function findAssociatedLinkGroupNode (si) function findAssociatedLinkGroupNode (si)
local si_props = si.properties local si_props = si.properties
@@ -49,7 +50,7 @@ function onLinkGroupPortsStateChanged (si, old_state, new_state)
return return
end end
Log.info (si, "ports format changed on " .. si_props ["node.name"]) log:info (si, "ports format changed on " .. si_props ["node.name"])
-- find associated device -- find associated device
local si_device = findAssociatedLinkGroupNode (si) local si_device = findAssociatedLinkGroupNode (si)
@@ -60,19 +61,19 @@ function onLinkGroupPortsStateChanged (si, old_state, new_state)
local f, m = si:get_ports_format () local f, m = si:get_ports_format ()
-- unregister the device -- unregister the device
Log.info (si_device, "unregistering " .. device_node_name) log:info (si_device, "unregistering " .. device_node_name)
si_device:remove () si_device:remove ()
-- set new format in the device -- set new format in the device
Log.info (si_device, "setting new format in " .. device_node_name) log:info (si_device, "setting new format in " .. device_node_name)
si_device:set_ports_format (f, m, function (item, e) si_device:set_ports_format (f, m, function (item, e)
if e ~= nil then if e ~= nil then
Log.warning (item, "failed to configure ports in " .. log:warning (item, "failed to configure ports in " ..
device_node_name .. ": " .. e) device_node_name .. ": " .. e)
end end
-- register back the device -- register back the device
Log.info (item, "registering " .. device_node_name) log:info (item, "registering " .. device_node_name)
item:register () item:register ()
end) end)
end end
@@ -105,7 +106,7 @@ SimpleEventHook {
link_group ~= nil then link_group ~= nil then
si:connect ("adapter-ports-state-changed", onLinkGroupPortsStateChanged) si:connect ("adapter-ports-state-changed", onLinkGroupPortsStateChanged)
si_flags.ports_state_signal = true si_flags.ports_state_signal = true
Log.info (si, "listening ports state changed on " .. si_props ["node.name"]) log:info (si, "listening ports state changed on " .. si_props ["node.name"])
end end
end end
end end

View File

@@ -8,6 +8,7 @@
local putils = require ("policy-utils") local putils = require ("policy-utils")
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook { SimpleEventHook {
name = "linking/find-best-target", name = "linking/find-best-target",
@@ -32,7 +33,7 @@ SimpleEventHook {
local target_priority = 0 local target_priority = 0
local target_plugged = 0 local target_plugged = 0
Log.info (si, string.format ("handling item: %s (%s)", log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
for target in om:iterate { for target in om:iterate {
@@ -45,30 +46,30 @@ SimpleEventHook {
local target_node_id = target_props ["node.id"] local target_node_id = target_props ["node.id"]
local priority = tonumber (target_props ["priority.session"]) or 0 local priority = tonumber (target_props ["priority.session"]) or 0
Log.debug (string.format ("Looking at: %s (%s)", log:debug (string.format ("Looking at: %s (%s)",
tostring (target_props ["node.name"]), tostring (target_props ["node.name"]),
tostring (target_node_id))) tostring (target_node_id)))
if not putils.canLink (si_props, target) then if not putils.canLink (si_props, target) then
Log.debug ("... cannot link, skip linkable") log:debug ("... cannot link, skip linkable")
goto skip_linkable goto skip_linkable
end end
if not putils.haveAvailableRoutes (target_props) then if not putils.haveAvailableRoutes (target_props) then
Log.debug ("... does not have routes, skip linkable") log:debug ("... does not have routes, skip linkable")
goto skip_linkable goto skip_linkable
end end
local passthrough_compatible, can_passthrough = local passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target) putils.checkPassthroughCompatibility (si, target)
if not passthrough_compatible then if not passthrough_compatible then
Log.debug ("... passthrough is not compatible, skip linkable") log:debug ("... passthrough is not compatible, skip linkable")
goto skip_linkable goto skip_linkable
end end
local plugged = tonumber (target_props ["item.plugged.usec"]) or 0 local plugged = tonumber (target_props ["item.plugged.usec"]) or 0
Log.debug ("... priority:" .. tostring (priority) .. ", plugged:" .. tostring (plugged)) log:debug ("... priority:" .. tostring (priority) .. ", plugged:" .. tostring (plugged))
-- (target_picked == NULL) --> make sure atleast one target is picked. -- (target_picked == NULL) --> make sure atleast one target is picked.
-- (priority > target_priority) --> pick the highest priority linkable(node) -- (priority > target_priority) --> pick the highest priority linkable(node)
@@ -78,7 +79,7 @@ SimpleEventHook {
if (target_picked == nil or if (target_picked == nil or
priority > target_priority or priority > target_priority or
(priority == target_priority and plugged > target_plugged)) then (priority == target_priority and plugged > target_plugged)) then
Log.debug ("... picked") log:debug ("... picked")
target_picked = target target_picked = target
target_can_passthrough = can_passthrough target_can_passthrough = can_passthrough
target_priority = priority target_priority = priority
@@ -88,7 +89,7 @@ SimpleEventHook {
end end
if target_picked then if target_picked then
Log.info (si, log:info (si,
string.format ("... best target picked: %s (%s), can_passthrough:%s", string.format ("... best target picked: %s (%s), can_passthrough:%s",
tostring (target_picked.properties ["node.name"]), tostring (target_picked.properties ["node.name"]),
tostring (target_picked.properties ["node.id"]), tostring (target_picked.properties ["node.id"]),

View File

@@ -7,6 +7,7 @@
-- Check if default nodes can be picked up as target node. -- Check if default nodes can be picked up as target node.
local putils = require ("policy-utils") local putils = require ("policy-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook { SimpleEventHook {
name = "linking/find-default-target", name = "linking/find-default-target",
@@ -27,7 +28,7 @@ SimpleEventHook {
local target_picked = false local target_picked = false
Log.info (si, string.format ("handling item: %s (%s)", log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
target = putils.findDefaultLinkable (si) target = putils.findDefaultLinkable (si)
@@ -42,7 +43,7 @@ SimpleEventHook {
end end
if target_picked then if target_picked then
Log.info (si, log:info (si,
string.format ("... default target picked: %s (%s), can_passthrough:%s", string.format ("... default target picked: %s (%s), can_passthrough:%s",
tostring (target.properties ["node.name"]), tostring (target.properties ["node.name"]),
tostring (target.properties ["node.id"]), tostring (target.properties ["node.id"]),

View File

@@ -12,6 +12,7 @@
local putils = require ("policy-utils") local putils = require ("policy-utils")
local cutils = require ("common-utils") local cutils = require ("common-utils")
local config = require ("policy-config") local config = require ("policy-config")
log = Log.open_topic ("s-linking")
SimpleEventHook { SimpleEventHook {
name = "linking/find-defined-target", name = "linking/find-defined-target",
@@ -30,7 +31,7 @@ SimpleEventHook {
return return
end end
Log.info (si, string.format ("handling item: %s (%s)", log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
local metadata = config.move and putils.get_default_metadata_object () local metadata = config.move and putils.get_default_metadata_object ()
@@ -109,12 +110,12 @@ SimpleEventHook {
and not target and not target
and not si_flags.was_handled and not si_flags.was_handled
and not si_flags.done_waiting then and not si_flags.done_waiting then
Log.info(si, "... waiting for target") log:info(si, "... waiting for target")
si_flags.done_waiting = true si_flags.done_waiting = true
event:stop_processing () event:stop_processing ()
elseif target_picked then elseif target_picked then
Log.info (si, log:info (si,
string.format ("... defined target picked: %s (%s), can_passthrough:%s", string.format ("... defined target picked: %s (%s), can_passthrough:%s",
tostring (target.properties ["node.name"]), tostring (target.properties ["node.name"]),
tostring (target.properties ["node.id"]), tostring (target.properties ["node.id"]),

View File

@@ -7,6 +7,7 @@
-- example of a user injectible hook to link a node to a custom target -- example of a user injectible hook to link a node to a custom target
local putils = require ("policy-utils") local putils = require ("policy-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook { SimpleEventHook {
name = "linking/sample-find-user-target", name = "linking/sample-find-user-target",
@@ -25,7 +26,7 @@ SimpleEventHook {
return return
end end
Log.info (si, "in find-user-target") log:info (si, "in find-user-target")
-- implement logic here to find a suitable target -- implement logic here to find a suitable target

View File

@@ -7,6 +7,7 @@
-- Select the virtual target based on roles -- Select the virtual target based on roles
local putils = require ("policy-utils") local putils = require ("policy-utils")
log = Log.open_topic ("s-linking")
local defaults = {} local defaults = {}
defaults.roles = Json.Object {} defaults.roles = Json.Object {}
@@ -76,20 +77,20 @@ SimpleEventHook {
return return
end end
Log.info (si, string.format ("handling item: %s (%s)", log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
-- get target media class -- get target media class
local target_media_class = target_class_assoc[si_props ["media.class"]] local target_media_class = target_class_assoc[si_props ["media.class"]]
if not target_media_class then if not target_media_class then
Log.info (si, "target media class not found") log:info (si, "target media class not found")
return return
end end
-- find highest priority virtual by role -- find highest priority virtual by role
local media_role = findRole (role, target_media_class) local media_role = findRole (role, target_media_class)
if media_role == nil then if media_role == nil then
Log.info (si, "media role not found") log:info (si, "media role not found")
return return
end end

View File

@@ -9,6 +9,7 @@
local putils = require ("policy-utils") local putils = require ("policy-utils")
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-linking")
AsyncEventHook { AsyncEventHook {
name = "linking/link-target", name = "linking/link-target",
@@ -37,7 +38,7 @@ AsyncEventHook {
local si_link = nil local si_link = nil
local passthrough = si_flags.can_passthrough local passthrough = si_flags.can_passthrough
Log.info (si, string.format ("handling item: %s (%s)", log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
local exclusive = cutils.parseBool (si_props ["node.exclusive"]) local exclusive = cutils.parseBool (si_props ["node.exclusive"])
@@ -77,7 +78,7 @@ AsyncEventHook {
local is_virtual_client_link = target_props ["item.factory.name"] == "si-audio-virtual" local is_virtual_client_link = target_props ["item.factory.name"] == "si-audio-virtual"
Log.info (si, log:info (si,
string.format ("link %s <-> %s passive:%s, passthrough:%s, exclusive:%s, virtual-client:%s", string.format ("link %s <-> %s passive:%s, passthrough:%s, exclusive:%s, virtual-client:%s",
tostring (si_props ["node.name"]), tostring (si_props ["node.name"]),
tostring (target_props ["node.name"]), tostring (target_props ["node.name"]),
@@ -122,7 +123,7 @@ AsyncEventHook {
Constraint { "bound-id", "=", client_id, type = "gobject" } Constraint { "bound-id", "=", client_id, type = "gobject" }
} }
if client then if client then
Log.info (node, "sending client error: " .. error_msg) log:info (node, "sending client error: " .. error_msg)
client:send_error (node["bound-id"], -32, error_msg) client:send_error (node["bound-id"], -32, error_msg)
end end
end end
@@ -140,7 +141,7 @@ AsyncEventHook {
end end
si_link:register () si_link:register ()
Log.info (si_link, "registered virtual si-standard-link between " log:info (si_link, "registered virtual si-standard-link between "
.. tostring (si).." and ".. tostring(target)) .. tostring (si).." and ".. tostring(target))
-- only activate non virtual links because virtual links activation is -- only activate non virtual links because virtual links activation is
@@ -162,7 +163,7 @@ AsyncEventHook {
end end
si_flags.failed_count = 0 si_flags.failed_count = 0
Log.info (si_link, "activated si-standard-link between " log:info (si_link, "activated si-standard-link between "
.. tostring (si).." and ".. tostring(target)) .. tostring (si).." and ".. tostring(target))
transition:advance () transition:advance ()

View File

@@ -7,6 +7,7 @@
-- Move & follow settings handlers. If the relevant settings are enabled, -- Move & follow settings handlers. If the relevant settings are enabled,
-- install hooks that will schedule a rescan of the graph when needed -- install hooks that will schedule a rescan of the graph when needed
log = Log.open_topic ("s-linking")
local config = require ("policy-config") local config = require ("policy-config")
local handles = {} local handles = {}

View File

@@ -10,6 +10,7 @@
local putils = require ("policy-utils") local putils = require ("policy-utils")
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-linking")
SimpleEventHook { SimpleEventHook {
name = "linking/prepare-link", name = "linking/prepare-link",
@@ -28,13 +29,13 @@ SimpleEventHook {
local exclusive = cutils.parseBool (si_props ["node.exclusive"]) local exclusive = cutils.parseBool (si_props ["node.exclusive"])
local si_must_passthrough = cutils.parseBool (si_props ["item.node.encoded-only"]) local si_must_passthrough = cutils.parseBool (si_props ["item.node.encoded-only"])
Log.info (si, string.format ("handling item: %s (%s)", log:info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
-- Check if item is linked to proper target, otherwise re-link -- Check if item is linked to proper target, otherwise re-link
if si_flags.peer_id then if si_flags.peer_id then
if target and si_flags.peer_id == target.id then if target and si_flags.peer_id == target.id then
Log.debug (si, "... already linked to proper target") log:debug (si, "... already linked to proper target")
-- Check this also here, in case in default targets changed -- Check this also here, in case in default targets changed
putils.checkFollowDefault (si, target, putils.checkFollowDefault (si, target,
si_flags.has_node_defined_target) si_flags.has_node_defined_target)
@@ -50,15 +51,15 @@ SimpleEventHook {
then then
-- remove also not yet activated links: they might never become -- remove also not yet activated links: they might never become
-- active, and we need not wait for it to become active -- active, and we need not wait for it to become active
Log.warning (link, "Link was not activated before removing") log:warning (link, "Link was not activated before removing")
end end
si_flags.peer_id = nil si_flags.peer_id = nil
link:remove () link:remove ()
Log.info (si, "... moving to new target") log:info (si, "... moving to new target")
end end
else else
if link ~= nil then if link ~= nil then
Log.info (si, "... dont-reconnect, not moving") log:info (si, "... dont-reconnect, not moving")
goto done goto done
end end
end end
@@ -75,13 +76,13 @@ SimpleEventHook {
if target then if target then
local target_is_linked, target_is_exclusive = putils.isLinked (target) local target_is_linked, target_is_exclusive = putils.isLinked (target)
if target_is_exclusive then if target_is_exclusive then
Log.info (si, "... target is linked exclusively") log:info (si, "... target is linked exclusively")
target = nil target = nil
end end
if target_is_linked then if target_is_linked then
if exclusive or si_must_passthrough then if exclusive or si_must_passthrough then
Log.info (si, "... target is already linked, cannot link exclusively") log:info (si, "... target is already linked, cannot link exclusively")
target = nil target = nil
else else
-- disable passthrough, we can live without it -- disable passthrough, we can live without it
@@ -91,14 +92,14 @@ SimpleEventHook {
end end
if not target then if not target then
Log.info (si, "... target not found, reconnect:" .. tostring (reconnect)) log:info (si, "... target not found, reconnect:" .. tostring (reconnect))
local node = si:get_associated_proxy ("node") local node = si:get_associated_proxy ("node")
if not reconnect then if not reconnect then
Log.info (si, "... destroy node") log:info (si, "... destroy node")
node:request_destroy () node:request_destroy ()
elseif si_flags.was_handled then elseif si_flags.was_handled then
Log.info (si, "... waiting reconnect") log:info (si, "... waiting reconnect")
return return
end end

View File

@@ -6,6 +6,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
local putils = require ("policy-utils") local putils = require ("policy-utils")
log = Log.open_topic ("s-linking")
local defaults = {} local defaults = {}
defaults.duck_level = 0.3 defaults.duck_level = 0.3
@@ -65,7 +66,7 @@ function restoreVolume (om, role, media_class)
if si_v then if si_v then
local n = si_v:get_associated_proxy ("node") local n = si_v:get_associated_proxy ("node")
if n then if n then
Log.debug(si_v, "restore role " .. role) log:debug(si_v, "restore role " .. role)
mixer_api:call("set-volume", n["bound-id"], { mixer_api:call("set-volume", n["bound-id"], {
monitorVolume = 1.0, monitorVolume = 1.0,
}) })
@@ -86,7 +87,7 @@ function duckVolume (om, role, media_class)
if si_v then if si_v then
local n = si_v:get_associated_proxy ("node") local n = si_v:get_associated_proxy ("node")
if n then if n then
Log.debug(si_v, "duck role " .. role) log:debug(si_v, "duck role " .. role)
mixer_api:call("set-volume", n["bound-id"], { mixer_api:call("set-volume", n["bound-id"], {
monitorVolume = config.duck_level, monitorVolume = config.duck_level,
}) })
@@ -141,7 +142,7 @@ AsyncEventHook {
} }
-- gather info about links -- gather info about links
Log.info ("Rescanning virtual si-standard-link links...") log:info ("Rescanning virtual si-standard-link links...")
for silink in om:iterate { for silink in om:iterate {
type = "SiLink", type = "SiLink",
Constraint { "is.virtual.client.link", "=", true }, Constraint { "is.virtual.client.link", "=", true },
@@ -174,13 +175,13 @@ AsyncEventHook {
local si_flags = putils:get_flags (si_id) local si_flags = putils:get_flags (si_id)
if e then if e then
Log.warning (l, "failed to activate virtual si-standard-link: " .. e) log:warning (l, "failed to activate virtual si-standard-link: " .. e)
if si_flags ~= nil then if si_flags ~= nil then
si_flags.peer_id = nil si_flags.peer_id = nil
end end
l:remove () l:remove ()
else else
Log.info (l, "virtual si-standard-link activated successfully") log:info (l, "virtual si-standard-link activated successfully")
si_flags.si_link = l si_flags.si_link = l
si_flags.failed_peer_id = nil si_flags.failed_peer_id = nil
if si_flags.peer_id == nil then if si_flags.peer_id == nil then
@@ -192,7 +193,7 @@ AsyncEventHook {
-- advance only when all pending activations are completed -- advance only when all pending activations are completed
pending_activations = pending_activations - 1 pending_activations = pending_activations - 1
if pending_activations <= 0 then if pending_activations <= 0 then
Log.info ("All virtual si-standard-links activated") log:info ("All virtual si-standard-links activated")
transition:advance () transition:advance ()
end end
end end
@@ -230,7 +231,7 @@ AsyncEventHook {
end end
duckVolume (om, v[i].role, media_class) duckVolume (om, v[i].role, media_class)
else else
Log.warning("Unknown action: " .. action) log:warning("Unknown action: " .. action)
end end
end end
@@ -245,7 +246,7 @@ AsyncEventHook {
-- just advance transition if no pending activations are needed -- just advance transition if no pending activations are needed
if pending_activations <= 0 then if pending_activations <= 0 then
Log.info ("All virtual si-standard-links rescanned") log:info ("All virtual si-standard-links rescanned")
transition:advance () transition:advance ()
end end
end, end,

View File

@@ -12,6 +12,7 @@
local putils = require ("policy-utils") local putils = require ("policy-utils")
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-linking")
function checkLinkable (si, om, handle_nonstreams) function checkLinkable (si, om, handle_nonstreams)
local si_props = si.properties local si_props = si.properties
@@ -48,7 +49,7 @@ SimpleEventHook {
return return
end end
Log.info (si, string.format ("unhandling item: %s (%s)", log:info (si, string.format ("unhandling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"]))) tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
-- iterate over all the links in the graph and -- iterate over all the links in the graph and
@@ -68,7 +69,7 @@ SimpleEventHook {
end end
silink:remove () silink:remove ()
Log.info (silink, "... link removed") log:info (silink, "... link removed")
end end
end end
@@ -87,7 +88,7 @@ SimpleEventHook {
local source = event:get_source () local source = event:get_source ()
local om = source:call ("get-object-manager", "session-item") local om = source:call ("get-object-manager", "session-item")
Log.info ("rescanning...") log:info ("rescanning...")
for si in om:iterate { type = "SiLinkable" } do for si in om:iterate { type = "SiLinkable" } do
local valid, si_props = checkLinkable (si, om) local valid, si_props = checkLinkable (si, om)
@@ -98,7 +99,7 @@ SimpleEventHook {
-- check if we need to link this node at all -- check if we need to link this node at all
local autoconnect = cutils.parseBool (si_props ["node.autoconnect"]) local autoconnect = cutils.parseBool (si_props ["node.autoconnect"])
if not autoconnect then if not autoconnect then
Log.debug (si, tostring (si_props ["node.name"]) .. " does not need to be autoconnected") log:debug (si, tostring (si_props ["node.name"]) .. " does not need to be autoconnected")
goto skip_linkable goto skip_linkable
end end

View File

@@ -5,6 +5,8 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
log = Log.open_topic ("s-monitors")
local defaults = {} local defaults = {}
defaults.node_properties = Json.Object {} defaults.node_properties = Json.Object {}
@@ -32,7 +34,7 @@ function CreateMidiNode ()
-- create the midi node -- create the midi node
local node = Node("spa-node-factory", props) local node = Node("spa-node-factory", props)
node:activate(Feature.Proxy.BOUND, function (n) node:activate(Feature.Proxy.BOUND, function (n)
Log.info ("activated Midi bridge") log:info ("activated Midi bridge")
end) end)
return node; return node;

View File

@@ -6,6 +6,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-monitors")
local defaults = {} local defaults = {}
defaults.reserve_priority = -20 defaults.reserve_priority = -20
@@ -192,7 +193,7 @@ function createDevice(parent, id, factory, properties)
device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND) device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND)
parent:store_managed_object(id, device) parent:store_managed_object(id, device)
else else
Log.warning ("Failed to create '" .. factory .. "' device") log:warning ("Failed to create '" .. factory .. "' device")
end end
end end
@@ -279,7 +280,7 @@ function prepareDevice(parent, id, obj_type, factory, properties)
-- override the device factory to use ACP -- override the device factory to use ACP
if properties["api.alsa.use-acp"] then if properties["api.alsa.use-acp"] then
Log.info("Enabling the use of ACP on " .. properties["device.name"]) log:info("Enabling the use of ACP on " .. properties["device.name"])
factory = "api.alsa.acp.device" factory = "api.alsa.acp.device"
end end
@@ -314,7 +315,7 @@ function prepareDevice(parent, id, obj_type, factory, properties)
end) end)
rd:connect("release-requested", function (rd) rd:connect("release-requested", function (rd)
Log.info("release requested") log:info("release requested")
parent:store_managed_object(id, nil) parent:store_managed_object(id, nil)
rd:call("release") rd:call("release")
end) end)
@@ -340,7 +341,7 @@ end
function createMonitor () function createMonitor ()
local m = SpaDevice("api.alsa.enum.udev", config.properties) local m = SpaDevice("api.alsa.enum.udev", config.properties)
if m == nil then if m == nil then
Log.notice("PipeWire's SPA ALSA udev plugin(\"api.alsa.enum.udev\")" log:notice("PipeWire's SPA ALSA udev plugin(\"api.alsa.enum.udev\")"
.. "missing or broken. Sound Cards cannot be enumerated") .. "missing or broken. Sound Cards cannot be enumerated")
return nil return nil
end end
@@ -372,7 +373,7 @@ function createMonitor ()
node_names_table = {} node_names_table = {}
-- activate monitor -- activate monitor
Log.info("Activating ALSA monitor") log:info("Activating ALSA monitor")
m:activate(Feature.SpaDevice.ENABLED) m:activate(Feature.SpaDevice.ENABLED)
return m return m
end end
@@ -391,7 +392,7 @@ end
-- has failed and continue without it -- has failed and continue without it
rd_plugin = Plugin.find("reserve-device") rd_plugin = Plugin.find("reserve-device")
if rd_plugin and rd_plugin:call("get-dbus")["state"] ~= "connected" then if rd_plugin and rd_plugin:call("get-dbus")["state"] ~= "connected" then
Log.notice("reserve-device plugin is not connected to D-Bus, " log:notice("reserve-device plugin is not connected to D-Bus, "
.. "disabling device reservation") .. "disabling device reservation")
rd_plugin = nil rd_plugin = nil
end end
@@ -402,12 +403,12 @@ if rd_plugin then
local dbus = rd_plugin:call("get-dbus") local dbus = rd_plugin:call("get-dbus")
dbus:connect("notify::state", function (b, pspec) dbus:connect("notify::state", function (b, pspec)
local state = b["state"] local state = b["state"]
Log.info ("rd-plugin state changed to " .. state) log:info ("rd-plugin state changed to " .. state)
if state == "connected" then if state == "connected" then
Log.info ("Creating ALSA monitor") log:info ("Creating ALSA monitor")
monitor = createMonitor() monitor = createMonitor()
elseif state == "closed" then elseif state == "closed" then
Log.info ("Destroying ALSA monitor") log:info ("Destroying ALSA monitor")
monitor = nil monitor = nil
end end
end) end)

View File

@@ -6,6 +6,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-monitors")
local defaults = {} local defaults = {}
defaults.properties = Json.Object {} defaults.properties = Json.Object {}
@@ -30,7 +31,7 @@ function setLatencyOffset(node, offset_msec)
props.latencyOffsetNsec = tonumber(offset_msec) * 1000000 props.latencyOffsetNsec = tonumber(offset_msec) * 1000000
local param = Pod.Object(props) local param = Pod.Object(props)
Log.debug(param, "setting latency offset on " .. tostring(node)) log:debug(param, "setting latency offset on " .. tostring(node))
node:set_param("Props", param) node:set_param("Props", param)
end end
@@ -92,7 +93,7 @@ function createMonitor()
id_to_name_table[id] = nil id_to_name_table[id] = nil
end) end)
else else
Log.notice("PipeWire's BlueZ MIDI SPA missing or broken. Bluetooth not supported.") log:notice("PipeWire's BlueZ MIDI SPA missing or broken. Bluetooth not supported.")
return nil return nil
end end
@@ -127,7 +128,7 @@ function createServers()
table.insert(servers, node) table.insert(servers, node)
setLatencyOffset(node, latency_offset) setLatencyOffset(node, latency_offset)
else else
Log.notice("Failed to create BLE MIDI server.") log:notice("Failed to create BLE MIDI server.")
end end
i = i + 1 i = i + 1
end end
@@ -140,7 +141,7 @@ if logind_plugin then
-- if logind support is enabled, activate -- if logind support is enabled, activate
-- the monitor only when the seat is active -- the monitor only when the seat is active
function startStopMonitor(seat_state) function startStopMonitor(seat_state)
Log.info(logind_plugin, "Seat state changed: " .. seat_state) log:info(logind_plugin, "Seat state changed: " .. seat_state)
if seat_state == "active" then if seat_state == "active" then
monitor = createMonitor() monitor = createMonitor()

View File

@@ -8,6 +8,7 @@
local COMBINE_OFFSET = 64 local COMBINE_OFFSET = 64
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-monitors")
local defaults = {} local defaults = {}
defaults.properties = Json.Object {} defaults.properties = Json.Object {}
@@ -109,7 +110,7 @@ function createOffloadScoNode(parent, id, type, factory, properties)
} }
args["playback.props"] = Json.Object(playback_args) args["playback.props"] = Json.Object(playback_args)
else else
Log.warning(parent, "Unsupported factory: " .. factory) log:warning(parent, "Unsupported factory: " .. factory)
return return
end end
@@ -142,7 +143,7 @@ device_set_nodes_om:connect ("object-added", function(_, node)
type = "device", type = "device",
Constraint { "object.id", "=", node.properties["device.id"] } Constraint { "object.id", "=", node.properties["device.id"] }
} }
Log.info("Device set node found: " .. tostring (node["bound-id"])) log:info("Device set node found: " .. tostring (node["bound-id"]))
for device in devices_om:iterate (interest) do for device in devices_om:iterate (interest) do
local device_id = device.properties["api.bluez5.id"] local device_id = device.properties["api.bluez5.id"]
if not device_id then if not device_id then
@@ -156,7 +157,7 @@ device_set_nodes_om:connect ("object-added", function(_, node)
local id = node.properties["card.profile.device"] local id = node.properties["card.profile.device"]
if id ~= nil then if id ~= nil then
Log.info(".. assign to device: " .. tostring (device["bound-id"]) .. " node " .. tostring (id)) log:info(".. assign to device: " .. tostring (device["bound-id"]) .. " node " .. tostring (id))
spa_device:store_managed_object (id, node) spa_device:store_managed_object (id, node)
-- set routes again to update volumes etc. -- set routes again to update volumes etc.
@@ -192,10 +193,10 @@ function createSetNode(parent, id, type, factory, properties)
stream_class = "Stream/Input/Audio/Internal" stream_class = "Stream/Input/Audio/Internal"
end end
Log.info("Device set: " .. properties["node.name"]) log:info("Device set: " .. properties["node.name"])
for _, member in pairs(members) do for _, member in pairs(members) do
Log.info("Device set member:" .. member["object.path"]) log:info("Device set member:" .. member["object.path"])
table.insert(rules, table.insert(rules,
Json.Object { Json.Object {
["matches"] = Json.Array { ["matches"] = Json.Array {
@@ -227,7 +228,7 @@ function createSetNode(parent, id, type, factory, properties)
local args_json = Json.Object(args) local args_json = Json.Object(args)
local args_string = args_json:get_data() local args_string = args_json:get_data()
local combine_properties = {} local combine_properties = {}
Log.info("Device set node: " .. args_string) log:info("Device set node: " .. args_string)
return LocalModule("libpipewire-module-combine-stream", args_string, combine_properties) return LocalModule("libpipewire-module-combine-stream", args_string, combine_properties)
end end
@@ -355,12 +356,12 @@ function createDevice(parent, id, type, factory, properties)
device:connect("object-removed", removeNode) device:connect("object-removed", removeNode)
parent:store_managed_object(id, device) parent:store_managed_object(id, device)
else else
Log.warning ("Failed to create '" .. factory .. "' device") log:warning ("Failed to create '" .. factory .. "' device")
return return
end end
end end
Log.info(parent, string.format("%d, %s (%s): %s", log:info(parent, string.format("%d, %s (%s): %s",
id, properties["device.description"], id, properties["device.description"],
properties["api.bluez5.address"], properties["api.bluez5.connection"])) properties["api.bluez5.address"], properties["api.bluez5.connection"]))
@@ -379,7 +380,7 @@ function createMonitor()
if monitor then if monitor then
monitor:connect("create-object", createDevice) monitor:connect("create-object", createDevice)
else else
Log.notice("PipeWire's BlueZ SPA missing or broken. Bluetooth not supported.") log:notice("PipeWire's BlueZ SPA missing or broken. Bluetooth not supported.")
return nil return nil
end end
monitor:activate(Feature.SpaDevice.ENABLED) monitor:activate(Feature.SpaDevice.ENABLED)
@@ -392,7 +393,7 @@ if logind_plugin then
-- if logind support is enabled, activate -- if logind support is enabled, activate
-- the monitor only when the seat is active -- the monitor only when the seat is active
function startStopMonitor(seat_state) function startStopMonitor(seat_state)
Log.info(logind_plugin, "Seat state changed: " .. seat_state) log:info(logind_plugin, "Seat state changed: " .. seat_state)
if seat_state == "active" then if seat_state == "active" then
monitor = createMonitor() monitor = createMonitor()

View File

@@ -6,6 +6,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-monitors")
local defaults = {} local defaults = {}
defaults.properties = Json.Object {} defaults.properties = Json.Object {}
@@ -139,7 +140,7 @@ function createDevice(parent, id, type, factory, properties)
device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND) device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND)
parent:store_managed_object(id, device) parent:store_managed_object(id, device)
else else
Log.warning ("Failed to create '" .. factory .. "' device") log:warning ("Failed to create '" .. factory .. "' device")
end end
end end
@@ -148,5 +149,5 @@ if monitor then
monitor:connect("create-object", createDevice) monitor:connect("create-object", createDevice)
monitor:activate(Feature.SpaDevice.ENABLED) monitor:activate(Feature.SpaDevice.ENABLED)
else else
Log.notice("PipeWire's libcamera SPA missing or broken. libcamera not supported.") log:notice("PipeWire's libcamera SPA missing or broken. libcamera not supported.")
end end

View File

@@ -6,6 +6,7 @@
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
local cutils = require ("common-utils") local cutils = require ("common-utils")
log = Log.open_topic ("s-monitors")
local defaults = {} local defaults = {}
defaults.properties = Json.Object {} defaults.properties = Json.Object {}
@@ -129,7 +130,7 @@ function createDevice(parent, id, type, factory, properties)
device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND) device:activate(Feature.SpaDevice.ENABLED | Feature.Proxy.BOUND)
parent:store_managed_object(id, device) parent:store_managed_object(id, device)
else else
Log.warning ("Failed to create '" .. factory .. "' device") log:warning ("Failed to create '" .. factory .. "' device")
end end
end end
@@ -138,5 +139,5 @@ if monitor then
monitor:connect("create-object", createDevice) monitor:connect("create-object", createDevice)
monitor:activate(Feature.SpaDevice.ENABLED) monitor:activate(Feature.SpaDevice.ENABLED)
else else
Log.notice("PipeWire's V4L SPA missing or broken. Video4Linux not supported.") log:notice("PipeWire's V4L SPA missing or broken. Video4Linux not supported.")
end end

View File

@@ -9,6 +9,7 @@
-- linkable) objects out of them. -- linkable) objects out of them.
config = require ("policy-config") config = require ("policy-config")
log = Log.open_topic ("s-node")
items = {} items = {}
@@ -122,7 +123,7 @@ AsyncEventHook {
local bound_id = node ["bound-id"] local bound_id = node ["bound-id"]
local item = items [node.id] local item = items [node.id]
Log.info (item, "activated item for node " .. tostring (bound_id)) log:info (item, "activated item for node " .. tostring (bound_id))
item:register () item:register ()
transition:advance () transition:advance ()
end, end,

View File

@@ -7,6 +7,8 @@
-- Receive script arguments from config.lua -- Receive script arguments from config.lua
log = Log.open_topic ("s-node")
local defaults = {} local defaults = {}
defaults.virtual_items = Json.Object {} defaults.virtual_items = Json.Object {}
@@ -18,20 +20,20 @@ function createVirtualItem (factory_name, properties)
-- create virtual item -- create virtual item
local si_v = SessionItem ( factory_name ) local si_v = SessionItem ( factory_name )
if not si_v then if not si_v then
Log.warning (si_v, "could not create virtual item of type " .. factory_name) log:warning (si_v, "could not create virtual item of type " .. factory_name)
return return
end end
-- configure virtual item -- configure virtual item
if not si_v:configure(properties) then if not si_v:configure(properties) then
Log.warning(si_v, "failed to configure virtual item " .. properties.name) log:warning(si_v, "failed to configure virtual item " .. properties.name)
return return
end end
-- activate and register virtual item -- activate and register virtual item
si_v:activate (Features.ALL, function (item) si_v:activate (Features.ALL, function (item)
item:register () item:register ()
Log.info(item, "registered virtual item " .. properties.name) log:info(item, "registered virtual item " .. properties.name)
end) end)
end end

View File

@@ -10,6 +10,7 @@
cutils = require ("common-utils") cutils = require ("common-utils")
config = require ("stream-config") config = require ("stream-config")
log = Log.open_topic ("s-node")
-- the state storage -- the state storage
state = nil state = nil
@@ -77,10 +78,10 @@ restore_stream_hook = SimpleEventHook {
if props.volume or (props.mute ~= nil) or props.channelVolumes or props.channelMap if props.volume or (props.mute ~= nil) or props.channelVolumes or props.channelMap
then then
Log.info (node, "restore values from " .. key) log:info (node, "restore values from " .. key)
local param = Pod.Object (props) local param = Pod.Object (props)
Log.debug (param, "setting props on " .. tostring (stream_props ["node.name"])) log:debug (param, "setting props on " .. tostring (stream_props ["node.name"]))
node:set_param ("Props", param) node:set_param ("Props", param)
end end
end end
@@ -111,7 +112,7 @@ restore_stream_hook = SimpleEventHook {
target_node.properties ["object.serial"]) target_node.properties ["object.serial"])
end end
else else
Log.debug (node, log:debug (node,
"Not restoring the target for " .. "Not restoring the target for " ..
tostring (stream_props ["node.name"]) .. tostring (stream_props ["node.name"]) ..
" because it is already set to " .. target_in_props) " because it is already set to " .. target_in_props)
@@ -161,7 +162,7 @@ store_stream_props_hook = SimpleEventHook {
local stored_values = getStoredStreamProps (key) or {} local stored_values = getStoredStreamProps (key) or {}
local hasChanges = false local hasChanges = false
Log.info (node, "saving stream props for " .. log:info (node, "saving stream props for " ..
tostring (stream_props ["node.name"])) tostring (stream_props ["node.name"]))
for p in node:iterate_params ("Props") do for p in node:iterate_params ("Props") do
@@ -252,7 +253,7 @@ store_stream_target_hook = SimpleEventHook {
end end
end end
Log.info (node, "saving stream target for " .. log:info (node, "saving stream target for " ..
tostring (stream_props ["node.name"]) .. " -> " .. tostring (target_name)) tostring (stream_props ["node.name"]) .. " -> " .. tostring (target_name))
local stored_values = getStoredStreamProps (key) or {} local stored_values = getStoredStreamProps (key) or {}
@@ -417,7 +418,7 @@ function toggleState (enable)
rs_metadata = ImplMetadata ("route-settings") rs_metadata = ImplMetadata ("route-settings")
rs_metadata:activate (Features.ALL, function (m, e) rs_metadata:activate (Features.ALL, function (m, e)
if e then if e then
Log.warning ("failed to activate route-settings metadata: " .. tostring (e)) log:warning ("failed to activate route-settings metadata: " .. tostring (e))
end end
end) end)

View File

@@ -5,6 +5,8 @@
-- --
-- SPDX-License-Identifier: MIT -- SPDX-License-Identifier: MIT
log = Log.open_topic ("s-node")
sources = {} sources = {}
SimpleEventHook { SimpleEventHook {
@@ -23,7 +25,7 @@ SimpleEventHook {
local node = event:get_subject () local node = event:get_subject ()
local new_state = event:get_properties ()["event.subject.new-state"] local new_state = event:get_properties ()["event.subject.new-state"]
Log.debug (node, "changed state to " .. new_state) log:debug (node, "changed state to " .. new_state)
-- Always clear the current source if any -- Always clear the current source if any
local id = node["bound-id"] local id = node["bound-id"]
@@ -45,7 +47,7 @@ SimpleEventHook {
-- add idle timeout; multiply by 1000, timeout_add() expects ms -- add idle timeout; multiply by 1000, timeout_add() expects ms
sources[id] = Core.timeout_add(timeout * 1000, function() sources[id] = Core.timeout_add(timeout * 1000, function()
-- Suspend the node -- Suspend the node
Log.info(node, "was idle for a while; suspending ...") log:info(node, "was idle for a while; suspending ...")
node:send_command("Suspend") node:send_command("Suspend")
-- Unref the source -- Unref the source