2023-02-08 18:12:00 +01:00
|
|
|
/* PipeWire */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2016 Axis Communications <dev-gstreamer@axis.com> */
|
|
|
|
|
/* @author Linus Svensson <linus.svensson@axis.com> */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2017-06-19 15:49:13 +02:00
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
#include <errno.h>
|
2017-06-19 15:49:13 +02:00
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
2019-12-11 10:57:10 +01:00
|
|
|
#include <pipewire/impl.h>
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2025-01-28 12:33:47 +01:00
|
|
|
#include "spa/spa-node.h"
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2025-01-28 10:33:05 +01:00
|
|
|
/** \page page_module_spa_node SPA Node
|
|
|
|
|
*
|
|
|
|
|
* Load and manage an SPA node.
|
|
|
|
|
*/
|
2021-09-16 15:35:10 +10:00
|
|
|
#define NAME "spa-node"
|
|
|
|
|
|
|
|
|
|
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
|
|
|
|
|
#define PW_LOG_TOPIC_DEFAULT mod_topic
|
|
|
|
|
|
2019-08-12 14:47:16 +02:00
|
|
|
#define MODULE_USAGE "<factory> [key=value ...]"
|
2019-05-31 16:06:14 +02:00
|
|
|
|
2018-06-01 11:23:02 +02:00
|
|
|
static const struct spa_dict_item module_props[] = {
|
2019-05-24 15:47:48 +02:00
|
|
|
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
|
|
|
|
|
{ PW_KEY_MODULE_DESCRIPTION, "Load and manage an SPA node" },
|
2019-05-31 16:06:14 +02:00
|
|
|
{ PW_KEY_MODULE_USAGE, MODULE_USAGE },
|
2019-05-24 15:47:48 +02:00
|
|
|
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
|
2018-06-01 11:23:02 +02:00
|
|
|
};
|
|
|
|
|
|
2017-11-24 17:01:30 +01:00
|
|
|
struct node_data {
|
2019-12-11 12:41:45 +01:00
|
|
|
struct pw_impl_node *this;
|
2019-12-10 18:19:56 +01:00
|
|
|
struct pw_context *context;
|
2017-11-24 17:01:30 +01:00
|
|
|
struct pw_properties *properties;
|
|
|
|
|
|
|
|
|
|
struct spa_hook module_listener;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void module_destroy(void *_data)
|
|
|
|
|
{
|
|
|
|
|
struct node_data *data = _data;
|
2019-06-20 11:04:34 +02:00
|
|
|
spa_hook_remove(&data->module_listener);
|
2019-12-11 12:41:45 +01:00
|
|
|
pw_impl_node_destroy(data->this);
|
2017-11-24 17:01:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 11:57:56 +01:00
|
|
|
static const struct pw_impl_module_events module_events = {
|
|
|
|
|
PW_VERSION_IMPL_MODULE_EVENTS,
|
2017-11-24 17:01:30 +01:00
|
|
|
.destroy = module_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-06 13:24:41 +01:00
|
|
|
SPA_EXPORT
|
2019-12-11 11:57:56 +01:00
|
|
|
int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
2017-06-19 15:49:13 +02:00
|
|
|
{
|
|
|
|
|
struct pw_properties *props = NULL;
|
2023-07-03 20:53:08 +02:00
|
|
|
spa_auto(pw_strv) argv = NULL;
|
|
|
|
|
int n_tokens;
|
2019-12-11 11:57:56 +01:00
|
|
|
struct pw_context *context = pw_impl_module_get_context(module);
|
2019-12-11 12:41:45 +01:00
|
|
|
struct pw_impl_node *node;
|
2017-11-24 17:01:30 +01:00
|
|
|
struct node_data *data;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2021-09-16 15:35:10 +10:00
|
|
|
PW_LOG_TOPIC_INIT(mod_topic);
|
|
|
|
|
|
2017-06-19 15:49:13 +02:00
|
|
|
if (args == NULL)
|
2019-06-20 11:04:34 +02:00
|
|
|
goto error_arguments;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2019-08-12 14:47:16 +02:00
|
|
|
argv = pw_split_strv(args, " \t", 2, &n_tokens);
|
|
|
|
|
if (n_tokens < 1)
|
2019-06-20 11:04:34 +02:00
|
|
|
goto error_arguments;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2019-08-12 14:47:16 +02:00
|
|
|
if (n_tokens == 2) {
|
|
|
|
|
props = pw_properties_new_string(argv[1]);
|
2023-07-03 20:53:08 +02:00
|
|
|
if (props == NULL)
|
|
|
|
|
return -errno;
|
2017-06-19 15:49:13 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-10 18:19:56 +01:00
|
|
|
node = pw_spa_node_load(context,
|
2019-08-12 14:47:16 +02:00
|
|
|
argv[0],
|
2017-11-24 17:01:30 +01:00
|
|
|
PW_SPA_NODE_FLAG_ACTIVATE,
|
|
|
|
|
props,
|
|
|
|
|
sizeof(struct node_data));
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2023-07-03 20:53:08 +02:00
|
|
|
if (node == NULL)
|
|
|
|
|
return -errno;
|
2017-11-24 17:01:30 +01:00
|
|
|
|
|
|
|
|
data = pw_spa_node_get_user_data(node);
|
|
|
|
|
data->this = node;
|
2019-12-10 18:19:56 +01:00
|
|
|
data->context = context;
|
2017-11-24 17:01:30 +01:00
|
|
|
data->properties = props;
|
|
|
|
|
|
|
|
|
|
pw_log_debug("module %p: new", module);
|
2019-12-11 11:57:56 +01:00
|
|
|
pw_impl_module_add_listener(module, &data->module_listener, &module_events, data);
|
2017-11-24 17:01:30 +01:00
|
|
|
|
2019-12-11 11:57:56 +01:00
|
|
|
pw_impl_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_props));
|
2018-06-01 11:23:02 +02:00
|
|
|
|
2017-12-18 11:38:30 +01:00
|
|
|
return 0;
|
2017-06-19 15:49:13 +02:00
|
|
|
|
2019-06-20 11:04:34 +02:00
|
|
|
error_arguments:
|
2019-05-31 16:06:14 +02:00
|
|
|
pw_log_error("usage: module-spa-node " MODULE_USAGE);
|
2023-07-03 20:53:08 +02:00
|
|
|
return -EINVAL;
|
2017-06-19 15:49:13 +02:00
|
|
|
}
|