| 1 |
#!/usr/bin/wpexec |
| 2 |
-- |
| 3 |
-- WirePlumber |
| 4 |
-- |
| 5 |
-- Copyright © 2021 Collabora Ltd. |
| 6 |
-- @author George Kiagiadakis <[email protected]> |
| 7 |
-- |
| 8 |
-- SPDX-License-Identifier: MIT |
| 9 |
-- |
| 10 |
-- This is an example of an interactive script |
| 11 |
-- |
| 12 |
-- Execute with: |
| 13 |
-- wpexec ./interactive.lua '{ option1 = "value1" , option2 = "value2" }' ... |
| 14 |
-- or: |
| 15 |
-- ./interactive.lua '{ option1 = "value1" , option2 = "value2" }' |
| 16 |
----------------------------------------------------------------------------- |
| 17 |
|
| 18 |
-- |
| 19 |
-- Collects arguments passed in from the command line |
| 20 |
-- Assuming '{ option1 = "value1" , option2 = "value2" }' were passed, |
| 21 |
-- this will be a table like this: |
| 22 |
-- { ["option1"] = "value1", ["option2"] = "value2" } |
| 23 |
-- |
| 24 |
local argv = ... |
| 25 |
if argv then |
| 26 |
argv = argv:parse() |
| 27 |
|
| 28 |
print ("Command-line arguments:") |
| 29 |
Debug.dump_table (argv) |
| 30 |
end |
| 31 |
|
| 32 |
-- |
| 33 |
-- Retrieve remote core info |
| 34 |
-- |
| 35 |
local info = Core.get_info() |
| 36 |
|
| 37 |
print ("\nPipeWire daemon info:") |
| 38 |
for k, v in pairs(info) do |
| 39 |
if k == "properties" then |
| 40 |
print ("\tproperties:") |
| 41 |
for kk, vv in pairs(v) do |
| 42 |
print ("\t\t" .. kk .. ": " .. vv) |
| 43 |
end |
| 44 |
else |
| 45 |
print ("\t" .. k .. ": " .. v) |
| 46 |
end |
| 47 |
end |
| 48 |
|
| 49 |
-- |
| 50 |
-- Retrieve objects using an ObjectManager |
| 51 |
-- |
| 52 |
-- Note: obj_mgr here cannot be a local variable; we need it to stay alive |
| 53 |
-- after the execution has returned to the main loop |
| 54 |
-- |
| 55 |
obj_mgr = ObjectManager { |
| 56 |
Interest { type = "client" }, |
| 57 |
Interest { type = "device" }, |
| 58 |
Interest { type = "node" }, |
| 59 |
} |
| 60 |
|
| 61 |
-- Listen for the 'installed' signal from the ObjectManager |
| 62 |
-- and execute a function when it is fired |
| 63 |
-- This function will be called from the main loop at some point later |
| 64 |
obj_mgr:connect("installed", function (om) |
| 65 |
|
| 66 |
-- |
| 67 |
-- Print connected clients |
| 68 |
-- |
| 69 |
print ("\nClients:") |
| 70 |
for obj in om:iterate { type = "client" } do |
| 71 |
|
| 72 |
-- |
| 73 |
-- 'bound-id' and 'global-properties' are GObject |
| 74 |
-- properties of WpProxy / WpGlobalProxy |
| 75 |
-- |
| 76 |
local id = obj["bound-id"] |
| 77 |
local global_props = obj["global-properties"] |
| 78 |
|
| 79 |
print ("\t" .. id .. ": " .. global_props["application.name"] |
| 80 |
.. " (PID: " .. global_props["pipewire.sec.pid"] .. ")") |
| 81 |
end |
| 82 |
|
| 83 |
-- |
| 84 |
-- Print devices |
| 85 |
-- |
| 86 |
print ("\nDevices:") |
| 87 |
for obj in om:iterate { type = "device" } do |
| 88 |
local id = obj["bound-id"] |
| 89 |
local global_props = obj["global-properties"] |
| 90 |
|
| 91 |
print ("\t" .. id .. ": " .. global_props["device.name"] |
| 92 |
.. " (" .. global_props["device.description"] .. ")") |
| 93 |
end |
| 94 |
|
| 95 |
-- Common function to print nodes |
| 96 |
local function printNode(node) |
| 97 |
local id = node["bound-id"] |
| 98 |
local global_props = node["global-properties"] |
| 99 |
|
| 100 |
-- standard lua string.match() function used here |
| 101 |
if global_props["media.class"]:match("Stream/.*") then |
| 102 |
print ("\t" .. id .. ": " .. global_props["application.name"]) |
| 103 |
else |
| 104 |
print ("\t" .. id .. ": " .. global_props["object.path"] |
| 105 |
.. " (" .. global_props["node.description"] .. ")") |
| 106 |
end |
| 107 |
end |
| 108 |
|
| 109 |
-- |
| 110 |
-- Print device sinks |
| 111 |
-- |
| 112 |
print ("\nSinks:") |
| 113 |
-- |
| 114 |
-- Interest can have additional constraints that can be used to filter |
| 115 |
-- the results. In this case we are only interested in nodes with their |
| 116 |
-- "media.class" global property matching the glob expression "*/Sink" |
| 117 |
-- |
| 118 |
local interest = Interest { type = "node", |
| 119 |
Constraint { "media.class", "matches", "*/Sink" } |
| 120 |
} |
| 121 |
for obj in om:iterate(interest) do |
| 122 |
printNode(obj) |
| 123 |
end |
| 124 |
|
| 125 |
-- |
| 126 |
-- Print device sources |
| 127 |
-- |
| 128 |
print ("\nSources:") |
| 129 |
local interest = Interest { type = "node", |
| 130 |
Constraint { "media.class", "matches", "*/Source" } |
| 131 |
} |
| 132 |
for obj in om:iterate(interest) do |
| 133 |
printNode(obj) |
| 134 |
end |
| 135 |
|
| 136 |
-- |
| 137 |
-- Print client streams |
| 138 |
-- |
| 139 |
print ("\nStreams:") |
| 140 |
local interest = Interest { type = "node", |
| 141 |
Constraint { "media.class", "matches", "Stream/*" } |
| 142 |
} |
| 143 |
for obj in om:iterate(interest) do |
| 144 |
printNode(obj) |
| 145 |
end |
| 146 |
|
| 147 |
-- Disconnect from pipewire and quit wireplumber |
| 148 |
-- This only works in script interactive mode |
| 149 |
Core.quit() |
| 150 |
end) |
| 151 |
|
| 152 |
-- Activate the object manager. This is required to start it, |
| 153 |
-- otherwise it doesn't do anything |
| 154 |
obj_mgr:activate() |