2017-06-05 10:53:54 +02:00
|
|
|
/* PipeWire
|
|
|
|
|
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
#include "pipewire/core.h"
|
2017-08-08 19:55:14 +02:00
|
|
|
#include "pipewire/interfaces.h"
|
|
|
|
|
#include "pipewire/log.h"
|
2017-07-11 15:57:20 +02:00
|
|
|
#include "pipewire/module.h"
|
|
|
|
|
|
2017-06-21 09:03:29 +02:00
|
|
|
#include "module-client-node/client-node.h"
|
2018-04-13 20:06:37 +02:00
|
|
|
#include "module-client-node/client-stream.h"
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2018-06-01 11:23:02 +02:00
|
|
|
static const struct spa_dict_item module_props[] = {
|
|
|
|
|
{ PW_MODULE_PROP_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
|
|
|
|
|
{ PW_MODULE_PROP_DESCRIPTION, "Allow clients to create and control remote nodes" },
|
|
|
|
|
{ PW_MODULE_PROP_VERSION, PACKAGE_VERSION },
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-12 18:04:00 +02:00
|
|
|
struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core);
|
2017-06-21 12:11:54 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
struct factory_data {
|
2017-09-17 16:47:03 +02:00
|
|
|
struct pw_factory *this;
|
2017-06-05 10:53:54 +02:00
|
|
|
struct pw_properties *properties;
|
2017-08-22 18:30:10 +02:00
|
|
|
|
2018-07-03 21:43:21 +02:00
|
|
|
struct pw_module *module;
|
2017-08-22 18:30:10 +02:00
|
|
|
struct spa_hook module_listener;
|
2017-06-05 10:53:54 +02:00
|
|
|
};
|
|
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
static void *create_object(void *_data,
|
|
|
|
|
struct pw_resource *resource,
|
|
|
|
|
uint32_t type,
|
|
|
|
|
uint32_t version,
|
|
|
|
|
struct pw_properties *properties,
|
|
|
|
|
uint32_t new_id)
|
2017-06-05 10:53:54 +02:00
|
|
|
{
|
2018-04-13 20:06:37 +02:00
|
|
|
void *result;
|
2017-09-17 16:47:03 +02:00
|
|
|
struct pw_resource *node_resource;
|
2018-07-03 21:43:21 +02:00
|
|
|
struct pw_global *parent;
|
2018-10-03 20:09:47 +02:00
|
|
|
struct pw_client *client = pw_resource_get_client(resource);
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2018-10-03 20:09:47 +02:00
|
|
|
node_resource = pw_resource_new(client, new_id, PW_PERM_RWX, type, version, 0);
|
2017-09-17 16:47:03 +02:00
|
|
|
if (node_resource == NULL)
|
|
|
|
|
goto no_mem;
|
|
|
|
|
|
2018-10-03 20:09:47 +02:00
|
|
|
parent = pw_client_get_global(client);
|
2018-07-03 21:43:21 +02:00
|
|
|
|
2018-04-13 20:06:37 +02:00
|
|
|
if (properties && pw_properties_get(properties, "node.stream") != NULL) {
|
2018-07-03 21:43:21 +02:00
|
|
|
result = pw_client_stream_new(node_resource, parent, properties);
|
2018-04-13 20:06:37 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2018-07-03 21:43:21 +02:00
|
|
|
result = pw_client_node_new(node_resource, parent, properties, true);
|
2018-04-13 20:06:37 +02:00
|
|
|
}
|
|
|
|
|
if (result == NULL)
|
2017-06-05 10:53:54 +02:00
|
|
|
goto no_mem;
|
|
|
|
|
|
2018-04-13 20:06:37 +02:00
|
|
|
return result;
|
2017-06-05 10:53:54 +02:00
|
|
|
|
|
|
|
|
no_mem:
|
|
|
|
|
pw_log_error("can't create node");
|
2018-10-03 19:24:53 +02:00
|
|
|
pw_resource_error(resource, new_id, -ENOMEM, "no memory");
|
2017-09-17 16:47:03 +02:00
|
|
|
goto done;
|
|
|
|
|
done:
|
2017-07-13 15:21:52 +02:00
|
|
|
if (properties)
|
|
|
|
|
pw_properties_free(properties);
|
2017-06-05 10:53:54 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
static const struct pw_factory_implementation impl_factory = {
|
|
|
|
|
PW_VERSION_FACTORY_IMPLEMENTATION,
|
|
|
|
|
.create_object = create_object,
|
2017-08-04 10:18:54 +02:00
|
|
|
};
|
|
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
static void module_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct factory_data *d = data;
|
|
|
|
|
|
|
|
|
|
spa_hook_remove(&d->module_listener);
|
|
|
|
|
|
|
|
|
|
if (d->properties)
|
|
|
|
|
pw_properties_free(d->properties);
|
|
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
pw_factory_destroy(d->this);
|
2017-08-22 18:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:28:03 +01:00
|
|
|
static const struct pw_module_events module_events = {
|
2017-08-22 18:30:10 +02:00
|
|
|
PW_VERSION_MODULE_EVENTS,
|
|
|
|
|
.destroy = module_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
static int module_init(struct pw_module *module, struct pw_properties *properties)
|
2017-06-05 10:53:54 +02:00
|
|
|
{
|
2017-08-06 06:42:26 +02:00
|
|
|
struct pw_core *core = pw_module_get_core(module);
|
2017-09-17 16:47:03 +02:00
|
|
|
struct pw_factory *factory;
|
2017-08-04 10:18:54 +02:00
|
|
|
struct factory_data *data;
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
factory = pw_factory_new(core,
|
|
|
|
|
"client-node",
|
2018-08-27 15:03:11 +02:00
|
|
|
PW_TYPE_INTERFACE_ClientNode,
|
2017-09-17 16:47:03 +02:00
|
|
|
PW_VERSION_CLIENT_NODE,
|
|
|
|
|
NULL,
|
|
|
|
|
sizeof(*data));
|
2017-08-04 10:18:54 +02:00
|
|
|
if (factory == NULL)
|
2017-12-18 11:38:30 +01:00
|
|
|
return -ENOMEM;
|
2017-07-18 14:58:14 +02:00
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
data = pw_factory_get_user_data(factory);
|
2017-08-04 10:18:54 +02:00
|
|
|
data->this = factory;
|
2018-07-03 21:43:21 +02:00
|
|
|
data->module = module;
|
2017-08-04 10:18:54 +02:00
|
|
|
data->properties = properties;
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
pw_log_debug("module %p: new", module);
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2017-09-17 16:47:03 +02:00
|
|
|
pw_factory_set_implementation(factory,
|
|
|
|
|
&impl_factory,
|
|
|
|
|
data);
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2017-07-12 18:04:00 +02:00
|
|
|
pw_protocol_native_ext_client_node_init(core);
|
2017-06-21 12:11:54 +02:00
|
|
|
|
2018-01-19 11:18:17 +01:00
|
|
|
pw_factory_register(factory, NULL, pw_module_get_global(module), NULL);
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2017-08-22 18:30:10 +02:00
|
|
|
pw_module_add_listener(module, &data->module_listener, &module_events, data);
|
2017-06-05 10:53:54 +02:00
|
|
|
|
2018-06-01 11:23:02 +02:00
|
|
|
pw_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
|
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
return 0;
|
2017-06-05 10:53:54 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
int pipewire__module_init(struct pw_module *module, const char *args)
|
2017-06-05 10:53:54 +02:00
|
|
|
{
|
2017-07-18 14:58:14 +02:00
|
|
|
return module_init(module, NULL);
|
2017-06-05 10:53:54 +02:00
|
|
|
}
|