1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* PipeWire
* Copyright (C) 2016 Axis Communications <dev-gstreamer@axis.com>
* @author Linus Svensson <linus.svensson@axis.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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <getopt.h>
#include <limits.h>
#include <pipewire/core.h>
#include <pipewire/log.h>
#include <pipewire/module.h>
#include <pipewire/utils.h>
#include "spa-monitor.h"
#include "spa-node.h"
struct node_data {
struct pw_node *this;
struct pw_core *core;
struct pw_properties *properties;
struct spa_hook module_listener;
};
static void module_destroy(void *_data)
{
struct node_data *data = _data;
pw_node_destroy(data->this);
}
static const struct pw_module_events module_events = {
PW_VERSION_MODULE_EVENTS,
.destroy = module_destroy,
};
int pipewire__module_init(struct pw_module *module, const char *args)
{
struct pw_properties *props = NULL;
char **argv;
int i, n_tokens;
struct pw_core *core = pw_module_get_core(module);
struct pw_node *node;
struct node_data *data;
if (args == NULL)
goto wrong_arguments;
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
if (n_tokens < 3)
goto not_enough_arguments;
props = pw_properties_new(NULL, NULL);
if (props == NULL)
return -ENOMEM;
for (i = 3; i < n_tokens; i++) {
char **prop;
int n_props;
prop = pw_split_strv(argv[i], "=", INT_MAX, &n_props);
if (n_props >= 2)
pw_properties_set(props, prop[0], prop[1]);
pw_free_strv(prop);
}
node = pw_spa_node_load(core,
NULL,
pw_module_get_global(module),
argv[0], argv[1], argv[2],
PW_SPA_NODE_FLAG_ACTIVATE,
props,
sizeof(struct node_data));
pw_free_strv(argv);
if (node == NULL)
return -ENOMEM;
data = pw_spa_node_get_user_data(node);
data->this = node;
data->core = core;
data->properties = props;
pw_log_debug("module %p: new", module);
pw_module_add_listener(module, &data->module_listener, &module_events, data);
return 0;
not_enough_arguments:
pw_free_strv(argv);
wrong_arguments:
pw_log_error("usage: module-spa-node <plugin> <factory> <name> [key=value ...]");
return -EINVAL;
}
|