pipewire/src/modules/module-client-node.c

158 lines
4.3 KiB
C
Raw Normal View History

2017-06-05 10:53:54 +02:00
/* PipeWire
*
* Copyright © 2018 Wim Taymans
2017-06-05 10:53:54 +02:00
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
2017-06-05 10:53:54 +02:00
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
2017-06-05 10:53:54 +02:00
*/
#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"
#include "module-client-node/client-node.h"
#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 },
};
struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core);
struct factory_data {
struct pw_factory *this;
2017-06-05 10:53:54 +02:00
struct pw_properties *properties;
struct pw_module *module;
struct spa_hook module_listener;
2017-06-05 10:53:54 +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
{
void *result;
struct pw_resource *node_resource;
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);
if (node_resource == NULL)
goto no_mem;
2018-10-03 20:09:47 +02:00
parent = pw_client_get_global(client);
if (properties && pw_properties_get(properties, "node.stream") != NULL) {
result = pw_client_stream_new(node_resource, parent, properties);
}
else {
result = pw_client_node_new(node_resource, parent, properties, true);
}
if (result == NULL)
2017-06-05 10:53:54 +02:00
goto no_mem;
return result;
2017-06-05 10:53:54 +02:00
no_mem:
pw_log_error("can't create node");
pw_resource_error(resource, new_id, -ENOMEM, "no memory");
goto done;
done:
if (properties)
pw_properties_free(properties);
2017-06-05 10:53:54 +02:00
return NULL;
}
static const struct pw_factory_implementation impl_factory = {
PW_VERSION_FACTORY_IMPLEMENTATION,
.create_object = create_object,
};
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);
pw_factory_destroy(d->this);
}
static const struct pw_module_events module_events = {
PW_VERSION_MODULE_EVENTS,
.destroy = module_destroy,
};
static int module_init(struct pw_module *module, struct pw_properties *properties)
2017-06-05 10:53:54 +02:00
{
struct pw_core *core = pw_module_get_core(module);
struct pw_factory *factory;
struct factory_data *data;
2017-06-05 10:53:54 +02:00
factory = pw_factory_new(core,
"client-node",
PW_TYPE_INTERFACE_ClientNode,
PW_VERSION_CLIENT_NODE,
NULL,
sizeof(*data));
if (factory == NULL)
return -ENOMEM;
data = pw_factory_get_user_data(factory);
data->this = factory;
data->module = module;
data->properties = properties;
2017-06-05 10:53:54 +02:00
pw_log_debug("module %p: new", module);
2017-06-05 10:53:54 +02:00
pw_factory_set_implementation(factory,
&impl_factory,
data);
2017-06-05 10:53:54 +02:00
pw_protocol_native_ext_client_node_init(core);
pw_factory_register(factory, NULL, pw_module_get_global(module), NULL);
2017-06-05 10:53:54 +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));
return 0;
2017-06-05 10:53:54 +02:00
}
int pipewire__module_init(struct pw_module *module, const char *args)
2017-06-05 10:53:54 +02:00
{
return module_init(module, NULL);
2017-06-05 10:53:54 +02:00
}