Skip to content
Snippets Groups Projects
Commit b88ff157 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

m-lua-scripting: add bindings required for device monitors

WpDevice, WpSpaDevice, WpNode, WpImplNode, WpObject and object features
parent c678cbed
No related branches found
No related tags found
No related merge requests found
...@@ -6,12 +6,29 @@ ...@@ -6,12 +6,29 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "wp/global-proxy.h"
#include <wp/wp.h> #include <wp/wp.h>
#include <wplua/wplua.h> #include <wplua/wplua.h>
#define URI_API "resource:///org/freedesktop/pipewire/wireplumber/m-lua-scripting/api.lua" #define URI_API "resource:///org/freedesktop/pipewire/wireplumber/m-lua-scripting/api.lua"
/* helpers */
static WpCore *
get_wp_core (lua_State *L)
{
lua_pushliteral (L, "wireplumber_core");
lua_gettable (L, LUA_REGISTRYINDEX);
return lua_touserdata (L, -1);
}
static WpCore *
get_wp_export_core (lua_State *L)
{
lua_pushliteral (L, "wireplumber_export_core");
lua_gettable (L, LUA_REGISTRYINDEX);
return lua_touserdata (L, -1);
}
/* WpDebug */ /* WpDebug */
static int static int
...@@ -68,6 +85,39 @@ static const luaL_Reg log_funcs[] = { ...@@ -68,6 +85,39 @@ static const luaL_Reg log_funcs[] = {
{ NULL, NULL } { NULL, NULL }
}; };
/* WpObject */
static void
object_activate_done (WpObject *o, GAsyncResult *res, gpointer data)
{
g_autoptr (GError) error = NULL;
if (!wp_object_activate_finish (o, res, &error)) {
wp_warning_object (o, "failed to activate: %s", error->message);
}
}
static int
object_activate (lua_State *L)
{
WpObject *o = wplua_checkobject (L, 1, WP_TYPE_OBJECT);
WpObjectFeatures features = 0;
if (lua_type (L, 2) != LUA_TNONE) {
features = luaL_checkinteger (L, 2);
} else {
features = WP_OBJECT_FEATURES_ALL;
}
wp_object_activate (o, features, NULL,
(GAsyncReadyCallback) object_activate_done, NULL);
return 0;
}
static const luaL_Reg object_methods[] = {
{ "activate", object_activate },
{ NULL, NULL }
};
/* WpGlobalProxy */ /* WpGlobalProxy */
static int static int
...@@ -326,13 +376,7 @@ static int ...@@ -326,13 +376,7 @@ static int
object_manager_activate (lua_State *L) object_manager_activate (lua_State *L)
{ {
WpObjectManager *om = wplua_checkobject (L, 1, WP_TYPE_OBJECT_MANAGER); WpObjectManager *om = wplua_checkobject (L, 1, WP_TYPE_OBJECT_MANAGER);
WpCore *core; wp_core_install_object_manager (get_wp_core (L), om);
lua_pushliteral (L, "wireplumber_core");
lua_gettable (L, LUA_REGISTRYINDEX);
core = lua_touserdata (L, -1);
wp_core_install_object_manager (core, om);
return 0; return 0;
} }
...@@ -494,6 +538,115 @@ static const luaL_Reg endpoint_link_methods[] = { ...@@ -494,6 +538,115 @@ static const luaL_Reg endpoint_link_methods[] = {
{ NULL, NULL } { NULL, NULL }
}; };
/* Device */
static int
device_new (lua_State *L)
{
const char *factory = luaL_checkstring (L, 1);
WpProperties *properties = NULL;
if (lua_type (L, 2) != LUA_TNONE) {
luaL_checktype (L, 2, LUA_TTABLE);
properties = wplua_table_to_properties (L, 2);
}
WpDevice *d = wp_device_new_from_factory (get_wp_export_core (L),
factory, properties);
wplua_pushobject (L, d);
return 1;
}
/* WpSpaDevice */
static int
spa_device_new (lua_State *L)
{
const char *factory = luaL_checkstring (L, 1);
WpProperties *properties = NULL;
if (lua_type (L, 2) != LUA_TNONE) {
luaL_checktype (L, 2, LUA_TTABLE);
properties = wplua_table_to_properties (L, 2);
}
WpSpaDevice *d = wp_spa_device_new_from_spa_factory (get_wp_export_core (L),
factory, properties);
wplua_pushobject (L, d);
return 1;
}
static int
spa_device_get_managed_object (lua_State *L)
{
WpSpaDevice *device = wplua_checkobject (L, 1, WP_TYPE_SPA_DEVICE);
guint id = luaL_checkinteger (L, 2);
GObject *obj = wp_spa_device_get_managed_object (device, id);
if (obj)
wplua_pushobject (L, obj);
return obj ? 1 : 0;
}
static int
spa_device_store_managed_object (lua_State *L)
{
WpSpaDevice *device = wplua_checkobject (L, 1, WP_TYPE_SPA_DEVICE);
guint id = luaL_checkinteger (L, 2);
GObject *obj = (lua_type (L, 3) != LUA_TNIL) ?
g_object_ref (wplua_checkobject (L, 3, G_TYPE_OBJECT)) : NULL;
wp_spa_device_store_managed_object (device, id, obj);
return 0;
}
static const luaL_Reg spa_device_methods[] = {
{ "get_managed_object", spa_device_get_managed_object },
{ "store_managed_object", spa_device_store_managed_object },
{ NULL, NULL }
};
/* Node */
static int
node_new (lua_State *L)
{
const char *factory = luaL_checkstring (L, 1);
WpProperties *properties = NULL;
if (lua_type (L, 2) != LUA_TNONE) {
luaL_checktype (L, 2, LUA_TTABLE);
properties = wplua_table_to_properties (L, 2);
}
WpNode *d = wp_node_new_from_factory (get_wp_export_core (L),
factory, properties);
wplua_pushobject (L, d);
return 1;
}
static const luaL_Reg node_methods[] = {
{ NULL, NULL }
};
/* ImplNode */
static int
impl_node_new (lua_State *L)
{
const char *factory = luaL_checkstring (L, 1);
WpProperties *properties = NULL;
if (lua_type (L, 2) != LUA_TNONE) {
luaL_checktype (L, 2, LUA_TTABLE);
properties = wplua_table_to_properties (L, 2);
}
WpImplNode *d = wp_impl_node_new_from_pw_factory (get_wp_export_core (L),
factory, properties);
wplua_pushobject (L, d);
return 1;
}
void void
wp_lua_scripting_api_init (lua_State *L) wp_lua_scripting_api_init (lua_State *L)
{ {
...@@ -502,6 +655,8 @@ wp_lua_scripting_api_init (lua_State *L) ...@@ -502,6 +655,8 @@ wp_lua_scripting_api_init (lua_State *L)
luaL_newlib (L, log_funcs); luaL_newlib (L, log_funcs);
lua_setglobal (L, "WpDebug"); lua_setglobal (L, "WpDebug");
wplua_register_type_methods (L, WP_TYPE_OBJECT,
NULL, object_methods);
wplua_register_type_methods (L, WP_TYPE_GLOBAL_PROXY, wplua_register_type_methods (L, WP_TYPE_GLOBAL_PROXY,
NULL, global_proxy_methods); NULL, global_proxy_methods);
wplua_register_type_methods (L, WP_TYPE_OBJECT_INTEREST, wplua_register_type_methods (L, WP_TYPE_OBJECT_INTEREST,
...@@ -516,6 +671,14 @@ wp_lua_scripting_api_init (lua_State *L) ...@@ -516,6 +671,14 @@ wp_lua_scripting_api_init (lua_State *L)
NULL, endpoint_methods); NULL, endpoint_methods);
wplua_register_type_methods (L, WP_TYPE_ENDPOINT_LINK, wplua_register_type_methods (L, WP_TYPE_ENDPOINT_LINK,
NULL, endpoint_link_methods); NULL, endpoint_link_methods);
wplua_register_type_methods (L, WP_TYPE_DEVICE,
device_new, NULL);
wplua_register_type_methods (L, WP_TYPE_SPA_DEVICE,
spa_device_new, spa_device_methods);
wplua_register_type_methods (L, WP_TYPE_NODE,
node_new, node_methods);
wplua_register_type_methods (L, WP_TYPE_IMPL_NODE,
impl_node_new, NULL);
wplua_load_uri (L, URI_API, &error); wplua_load_uri (L, URI_API, &error);
if (G_UNLIKELY (error)) if (G_UNLIKELY (error))
......
...@@ -69,9 +69,52 @@ local function Constraint (spec) ...@@ -69,9 +69,52 @@ local function Constraint (spec)
return debug.setmetatable(spec, { __name = "Constraint" }) return debug.setmetatable(spec, { __name = "Constraint" })
end end
local Features = {
PipewireObject = {
MINIMAL = 0x11,
},
ALL = 0xffffffff,
}
local Feature = {
Proxy = {
BOUND = 1,
},
PipewireObject = {
INFO = (1 << 4),
PARAM_PROPS = (1 << 5),
PARAM_FORMAT = (1 << 6),
PARAM_PROFILE = (1 << 7),
PARAM_PORT_CONFIG = (1 << 8),
PARAM_ROUTE = (1 << 9),
},
SpaDevice = {
ENABLED = (1 << 16),
},
Node = {
PORTS = (1 << 16),
},
Session = {
ENDPOINTS = (1 << 16),
LINKS = (1 << 17),
},
Endpoint = {
STREAMS = (1 << 16),
},
Metadata = {
DATA = (1 << 16),
},
}
SANDBOX_EXPORT = { SANDBOX_EXPORT = {
Features = Features,
Feature = Feature,
Log = WpDebug, Log = WpDebug,
ObjectManager = WpObjectManager_new, ObjectManager = WpObjectManager_new,
Interest = WpObjectInterest_new, Interest = WpObjectInterest_new,
Constraint = Constraint, Constraint = Constraint,
Device = WpDevice_new,
SpaDevice = WpSpaDevice_new,
Node = WpNode_new,
LocalNode = WpImplNode_new,
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment