mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
pulse-server: improve module handling
Make a registry of modules Assign an unique number to each module with the MODULE_FLAG bit set so that we can also enumerate them Implement enumerating our internally loaded modules Implement unloading of the module using the module id Move module-null-sink into a separate file Use Audio/Sink if no other media.class was given, so that it works just like the pulseaudio module Enable linger=true in all cases.
This commit is contained in:
parent
15e6a825f2
commit
e19263140a
4 changed files with 404 additions and 200 deletions
|
|
@ -54,6 +54,7 @@
|
||||||
#define INDEX_MASK 0xffffu
|
#define INDEX_MASK 0xffffu
|
||||||
#define MONITOR_FLAG (1u << 16)
|
#define MONITOR_FLAG (1u << 16)
|
||||||
#define EXTENSION_FLAG (1u << 17)
|
#define EXTENSION_FLAG (1u << 17)
|
||||||
|
#define MODULE_FLAG (1u << 18)
|
||||||
|
|
||||||
#define DEFAULT_SINK "@DEFAULT_SINK@"
|
#define DEFAULT_SINK "@DEFAULT_SINK@"
|
||||||
#define DEFAULT_SOURCE "@DEFAULT_SOURCE@"
|
#define DEFAULT_SOURCE "@DEFAULT_SOURCE@"
|
||||||
|
|
|
||||||
194
src/modules/module-protocol-pulse/module-null-sink.c
Normal file
194
src/modules/module-protocol-pulse/module-null-sink.c
Normal file
|
|
@ -0,0 +1,194 @@
|
||||||
|
/* PipeWire
|
||||||
|
*
|
||||||
|
* Copyright © 2021 Georges Basile Stavracas Neto
|
||||||
|
*
|
||||||
|
* 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:
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct module_null_sink_data {
|
||||||
|
struct pw_proxy *proxy;
|
||||||
|
struct spa_hook listener;
|
||||||
|
uint32_t global_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void module_null_sink_proxy_removed(void *data)
|
||||||
|
{
|
||||||
|
struct module *module = data;
|
||||||
|
struct module_null_sink_data *d = module->user_data;
|
||||||
|
pw_proxy_destroy(d->proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void module_null_sink_proxy_destroy(void *data)
|
||||||
|
{
|
||||||
|
struct module *module = data;
|
||||||
|
struct module_null_sink_data *d = module->user_data;
|
||||||
|
pw_log_info(NAME" %p: proxy %p destroy", module, d->proxy);
|
||||||
|
spa_hook_remove(&d->listener);
|
||||||
|
d->proxy = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void module_null_sink_proxy_bound(void *data, uint32_t global_id)
|
||||||
|
{
|
||||||
|
struct module *module = data;
|
||||||
|
struct module_null_sink_data *d = module->user_data;
|
||||||
|
|
||||||
|
pw_log_info(NAME" module %p proxy %p bound", module, d->proxy);
|
||||||
|
d->global_id = global_id;
|
||||||
|
module_emit_loaded(module, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void module_null_sink_proxy_error(void *data, int seq, int res, const char *message)
|
||||||
|
{
|
||||||
|
struct module *module = data;
|
||||||
|
struct module_null_sink_data *d = module->user_data;
|
||||||
|
struct impl *impl = module->impl;
|
||||||
|
|
||||||
|
pw_log_info(NAME" %p module %p error %d", impl, module, res);
|
||||||
|
pw_proxy_destroy(d->proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int module_null_sink_load(struct client *client, struct module *module)
|
||||||
|
{
|
||||||
|
struct module_null_sink_data *d = module->user_data;
|
||||||
|
static const struct pw_proxy_events proxy_events = {
|
||||||
|
.removed = module_null_sink_proxy_removed,
|
||||||
|
.bound = module_null_sink_proxy_bound,
|
||||||
|
.error = module_null_sink_proxy_error,
|
||||||
|
.destroy = module_null_sink_proxy_destroy,
|
||||||
|
};
|
||||||
|
|
||||||
|
d->proxy = pw_core_create_object(client->core,
|
||||||
|
"adapter",
|
||||||
|
PW_TYPE_INTERFACE_Node,
|
||||||
|
PW_VERSION_NODE,
|
||||||
|
module->props ? &module->props->dict : NULL, 0);
|
||||||
|
if (d->proxy == NULL)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
pw_log_info("loaded module %p id:%u name:%s %p", module, module->idx, module->name, d->proxy);
|
||||||
|
pw_proxy_add_listener(d->proxy, &d->listener, &proxy_events, module);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int module_null_sink_unload(struct client *client, struct module *module)
|
||||||
|
{
|
||||||
|
struct module_null_sink_data *d = module->user_data;
|
||||||
|
pw_log_info("unload module %p id:%u name:%s %p", module, module->idx, module->name, d->proxy);
|
||||||
|
if (d->proxy != NULL)
|
||||||
|
pw_proxy_destroy(d->proxy);
|
||||||
|
if (d->global_id != SPA_ID_INVALID)
|
||||||
|
pw_registry_destroy(client->manager->registry, d->global_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct module_methods module_null_sink_methods = {
|
||||||
|
VERSION_MODULE_METHODS,
|
||||||
|
.load = module_null_sink_load,
|
||||||
|
.unload = module_null_sink_unload,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct module *create_module_null_sink(struct impl *impl, const char *argument)
|
||||||
|
{
|
||||||
|
struct module *module;
|
||||||
|
struct module_null_sink_data *d;
|
||||||
|
struct pw_properties *props = NULL;
|
||||||
|
const char *str;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
if (argument == NULL) {
|
||||||
|
res = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
props = pw_properties_new(NULL, NULL);
|
||||||
|
if (props == NULL) {
|
||||||
|
res = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
add_props(props, argument);
|
||||||
|
|
||||||
|
if ((str = pw_properties_get(props, "sink_name")) != NULL) {
|
||||||
|
pw_properties_set(props, PW_KEY_NODE_NAME, str);
|
||||||
|
pw_properties_set(props, "sink_name", NULL);
|
||||||
|
} else {
|
||||||
|
pw_properties_set(props, PW_KEY_NODE_NAME, "null");
|
||||||
|
}
|
||||||
|
if ((str = pw_properties_get(props, "sink_properties")) != NULL) {
|
||||||
|
add_props(props, str);
|
||||||
|
pw_properties_set(props, "sink_properties", NULL);
|
||||||
|
}
|
||||||
|
if ((str = pw_properties_get(props, "channels")) != NULL) {
|
||||||
|
pw_properties_set(props, SPA_KEY_AUDIO_CHANNELS, str);
|
||||||
|
pw_properties_set(props, "channels", NULL);
|
||||||
|
}
|
||||||
|
if ((str = pw_properties_get(props, "rate")) != NULL) {
|
||||||
|
pw_properties_set(props, SPA_KEY_AUDIO_RATE, str);
|
||||||
|
pw_properties_set(props, "rate", NULL);
|
||||||
|
}
|
||||||
|
if ((str = pw_properties_get(props, "channel_map")) != NULL) {
|
||||||
|
struct channel_map map = CHANNEL_MAP_INIT;
|
||||||
|
uint32_t i;
|
||||||
|
char *s, *p;
|
||||||
|
|
||||||
|
channel_map_parse(str, &map);
|
||||||
|
p = s = alloca(map.channels * 6);
|
||||||
|
|
||||||
|
for (i = 0; i < map.channels; i++)
|
||||||
|
p += snprintf(p, 6, "%s%s", i == 0 ? "" : ",",
|
||||||
|
channel_id2name(map.map[i]));
|
||||||
|
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
|
||||||
|
pw_properties_set(props, "channel_map", NULL);
|
||||||
|
} else if (pw_properties_get(props, SPA_KEY_AUDIO_POSITION) == NULL) {
|
||||||
|
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, "FL,FR");
|
||||||
|
}
|
||||||
|
if ((str = pw_properties_get(props, PW_KEY_MEDIA_CLASS)) == NULL)
|
||||||
|
pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Audio/Sink");
|
||||||
|
|
||||||
|
if ((str = pw_properties_get(props, "device.description")) != NULL) {
|
||||||
|
pw_properties_set(props, PW_KEY_NODE_DESCRIPTION, str);
|
||||||
|
pw_properties_set(props, "device.description", NULL);
|
||||||
|
} else {
|
||||||
|
const char *name, *class;
|
||||||
|
|
||||||
|
name = pw_properties_get(props, PW_KEY_NODE_NAME);
|
||||||
|
class = pw_properties_get(props, PW_KEY_MEDIA_CLASS);
|
||||||
|
pw_properties_setf(props, PW_KEY_NODE_DESCRIPTION,
|
||||||
|
"%s%s%s%ssink",
|
||||||
|
name, (name[0] == '\0') ? "" : " ",
|
||||||
|
class ? class : "", (class && class[0] != '\0') ? " " : "");
|
||||||
|
}
|
||||||
|
pw_properties_set(props, PW_KEY_FACTORY_NAME, "support.null-audio-sink");
|
||||||
|
pw_properties_set(props, PW_KEY_OBJECT_LINGER, "true");
|
||||||
|
|
||||||
|
module = module_new(impl, &module_null_sink_methods, sizeof(*d));
|
||||||
|
if (module == NULL) {
|
||||||
|
res = -errno;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
module->props = props;
|
||||||
|
d = module->user_data;
|
||||||
|
d->global_id = SPA_ID_INVALID;
|
||||||
|
|
||||||
|
return module;
|
||||||
|
out:
|
||||||
|
if (props)
|
||||||
|
pw_properties_free(props);
|
||||||
|
errno = -res;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
/* PipeWire
|
/* PipeWire
|
||||||
*
|
*
|
||||||
* Copyright © 2020 Georges Basile Stavracas Neto
|
* Copyright © 2020 Georges Basile Stavracas Neto
|
||||||
|
* Copyright © 2021 Wim Taymans <wim.taymans@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
|
@ -24,95 +25,98 @@
|
||||||
|
|
||||||
struct module;
|
struct module;
|
||||||
|
|
||||||
typedef void (*module_loaded_cb)(struct module *module, int error, void *userdata);
|
struct module_info {
|
||||||
|
const char *name;
|
||||||
|
struct module *(*create) (struct impl *impl, const char *args);
|
||||||
|
};
|
||||||
|
|
||||||
struct module_events {
|
struct module_events {
|
||||||
void (*removed) (void *data, struct module *module);
|
#define VERSION_MODULE_EVENTS 0
|
||||||
void (*error) (void *data);
|
uint32_t version;
|
||||||
|
|
||||||
|
void (*loaded) (void *data, int res);
|
||||||
|
};
|
||||||
|
|
||||||
|
#define module_emit_loaded(m,r) spa_hook_list_call(&m->hooks, struct module_events, loaded, 0, r)
|
||||||
|
|
||||||
|
struct module_methods {
|
||||||
|
#define VERSION_MODULE_METHODS 0
|
||||||
|
uint32_t version;
|
||||||
|
|
||||||
|
int (*load) (struct client *client, struct module *module);
|
||||||
|
int (*unload) (struct client *client, struct module *module);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct module {
|
struct module {
|
||||||
struct spa_list link; /**< link in client modules */
|
|
||||||
struct pw_proxy *proxy;
|
|
||||||
struct spa_hook listener;
|
|
||||||
struct client *client;
|
|
||||||
struct message *reply;
|
|
||||||
|
|
||||||
module_loaded_cb cb;
|
|
||||||
void *cb_data;
|
|
||||||
|
|
||||||
struct module_events *events;
|
|
||||||
void *events_data;
|
|
||||||
|
|
||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
|
const char *name;
|
||||||
|
const char *args;
|
||||||
|
struct pw_properties *props;
|
||||||
|
struct spa_list link; /**< link in client modules */
|
||||||
|
struct impl *impl;
|
||||||
|
const struct module_methods *methods;
|
||||||
|
struct spa_hook_list hooks;
|
||||||
|
void *user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void module_proxy_removed(void *data)
|
static struct module *module_new(struct impl *impl, const struct module_methods *methods, size_t user_data)
|
||||||
{
|
{
|
||||||
struct module *module = data;
|
struct module *module;
|
||||||
|
|
||||||
if (module->events)
|
module = calloc(1, sizeof(struct module) + user_data);
|
||||||
module->events->removed(module->events_data, module);
|
if (module == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
pw_proxy_destroy(module->proxy);
|
module->impl = impl;
|
||||||
|
module->methods = methods;
|
||||||
|
spa_hook_list_init(&module->hooks);
|
||||||
|
module->user_data = SPA_MEMBER(module, sizeof(struct module), void);
|
||||||
|
|
||||||
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void module_proxy_destroy(void *data)
|
static void module_add_listener(struct module *module,
|
||||||
|
struct spa_hook *listener,
|
||||||
|
const struct module_events *events, void *data)
|
||||||
{
|
{
|
||||||
struct module *module = data;
|
spa_hook_list_append(&module->hooks, listener, events, data);
|
||||||
pw_log_info(NAME" %p: proxy %p destroy", module, module->proxy);
|
}
|
||||||
spa_hook_remove(&module->listener);
|
|
||||||
|
static int module_load(struct client *client, struct module *module)
|
||||||
|
{
|
||||||
|
pw_log_info("load module id:%u name:%s", module->idx, module->name);
|
||||||
|
if (module->methods->load == NULL)
|
||||||
|
return -ENOTSUP;
|
||||||
|
return module->methods->load(client, module);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void module_free(struct module *module)
|
||||||
|
{
|
||||||
|
struct impl *impl = module->impl;
|
||||||
|
if (module->idx != SPA_ID_INVALID)
|
||||||
|
pw_map_remove(&impl->modules, module->idx & INDEX_MASK);
|
||||||
|
|
||||||
|
free((char*)module->name);
|
||||||
|
free((char*)module->args);
|
||||||
|
if (module->props)
|
||||||
|
pw_properties_free(module->props);
|
||||||
free(module);
|
free(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void module_proxy_bound(void *data, uint32_t global_id)
|
static int module_unload(struct client *client, struct module *module)
|
||||||
{
|
{
|
||||||
struct module *module = data;
|
int res = 0;
|
||||||
|
|
||||||
pw_log_info(NAME" module %p proxy %p bound", module, module->proxy);
|
pw_log_info("unload module id:%u name:%s", module->idx, module->name);
|
||||||
|
|
||||||
module->idx = global_id;
|
if (module->methods->unload)
|
||||||
|
res = module->methods->unload(client, module);
|
||||||
|
|
||||||
if (module->cb)
|
module_free(module);
|
||||||
module->cb(module, 0, module->cb_data);
|
return res;
|
||||||
}
|
|
||||||
|
|
||||||
static void module_proxy_error(void *data, int seq, int res, const char *message)
|
|
||||||
{
|
|
||||||
struct module *module = data;
|
|
||||||
struct impl *impl = module->client->impl;
|
|
||||||
|
|
||||||
pw_log_info(NAME" %p module %p error %d", impl, module, res);
|
|
||||||
|
|
||||||
module->idx = 0;
|
|
||||||
|
|
||||||
if (module->cb)
|
|
||||||
module->cb(module, res, module->cb_data);
|
|
||||||
|
|
||||||
pw_proxy_destroy(module->proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int load_null_sink_module(struct client *client, struct module *module, struct pw_properties *props)
|
|
||||||
{
|
|
||||||
static const struct pw_proxy_events proxy_events = {
|
|
||||||
.removed = module_proxy_removed,
|
|
||||||
.bound = module_proxy_bound,
|
|
||||||
.error = module_proxy_error,
|
|
||||||
.destroy = module_proxy_destroy,
|
|
||||||
};
|
|
||||||
|
|
||||||
module->proxy = pw_core_create_object(client->core,
|
|
||||||
"adapter",
|
|
||||||
PW_TYPE_INTERFACE_Node,
|
|
||||||
PW_VERSION_NODE,
|
|
||||||
props ? &props->dict : NULL, 0);
|
|
||||||
if (module->proxy == NULL)
|
|
||||||
return -errno;
|
|
||||||
|
|
||||||
pw_proxy_add_listener(module->proxy, &module->listener, &proxy_events, module);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** utils */
|
||||||
static void add_props(struct pw_properties *props, const char *str)
|
static void add_props(struct pw_properties *props, const char *str)
|
||||||
{
|
{
|
||||||
char *s = strdup(str), *p = s, *e, f;
|
char *s = strdup(str), *p = s, *e, f;
|
||||||
|
|
@ -147,99 +151,45 @@ static void add_props(struct pw_properties *props, const char *str)
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_module(struct client *client, const char *name, const char *argument, module_loaded_cb cb, void *data)
|
#include "module-null-sink.c"
|
||||||
|
|
||||||
|
static const struct module_info module_list[] = {
|
||||||
|
{ "module-null-sink", create_module_null_sink, },
|
||||||
|
{ NULL, }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct module_info *find_module_info(const char *name)
|
||||||
{
|
{
|
||||||
struct module *module = NULL;
|
int i;
|
||||||
int res = -ENOENT;
|
for (i = 0; module_list[i].name != NULL; i++) {
|
||||||
|
if (strcmp(module_list[i].name, name) == 0)
|
||||||
if (strcmp(name, "module-null-sink") == 0) {
|
return &module_list[i];
|
||||||
struct pw_properties *props = NULL;
|
|
||||||
const char *str;
|
|
||||||
|
|
||||||
if (argument == NULL) {
|
|
||||||
res = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
props = pw_properties_new(NULL, NULL);
|
|
||||||
if (props == NULL) {
|
|
||||||
res = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
add_props(props, argument);
|
|
||||||
|
|
||||||
if ((str = pw_properties_get(props, "sink_name")) != NULL) {
|
|
||||||
pw_properties_set(props, PW_KEY_NODE_NAME, str);
|
|
||||||
pw_properties_set(props, "sink_name", NULL);
|
|
||||||
} else {
|
|
||||||
pw_properties_set(props, PW_KEY_NODE_NAME, "null");
|
|
||||||
}
|
|
||||||
if ((str = pw_properties_get(props, "sink_properties")) != NULL) {
|
|
||||||
add_props(props, str);
|
|
||||||
pw_properties_set(props, "sink_properties", NULL);
|
|
||||||
}
|
|
||||||
if ((str = pw_properties_get(props, "channels")) != NULL) {
|
|
||||||
pw_properties_set(props, SPA_KEY_AUDIO_CHANNELS, str);
|
|
||||||
pw_properties_set(props, "channels", NULL);
|
|
||||||
}
|
|
||||||
if ((str = pw_properties_get(props, "rate")) != NULL) {
|
|
||||||
pw_properties_set(props, SPA_KEY_AUDIO_RATE, str);
|
|
||||||
pw_properties_set(props, "rate", NULL);
|
|
||||||
}
|
|
||||||
if ((str = pw_properties_get(props, "channel_map")) != NULL) {
|
|
||||||
struct channel_map map = CHANNEL_MAP_INIT;
|
|
||||||
uint32_t i;
|
|
||||||
char *s, *p;
|
|
||||||
|
|
||||||
channel_map_parse(str, &map);
|
|
||||||
p = s = alloca(map.channels * 6);
|
|
||||||
|
|
||||||
for (i = 0; i < map.channels; i++)
|
|
||||||
p += snprintf(p, 6, "%s%s", i == 0 ? "" : ",",
|
|
||||||
channel_id2name(map.map[i]));
|
|
||||||
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, s);
|
|
||||||
pw_properties_set(props, "channel_map", NULL);
|
|
||||||
} else if (pw_properties_get(props, SPA_KEY_AUDIO_POSITION) == NULL) {
|
|
||||||
pw_properties_set(props, SPA_KEY_AUDIO_POSITION, "FL,FR");
|
|
||||||
}
|
|
||||||
if ((str = pw_properties_get(props, "device.description")) != NULL) {
|
|
||||||
pw_properties_set(props, PW_KEY_NODE_DESCRIPTION, str);
|
|
||||||
pw_properties_set(props, "device.description", NULL);
|
|
||||||
} else {
|
|
||||||
const char *name, *class;
|
|
||||||
|
|
||||||
name = pw_properties_get(props, PW_KEY_NODE_NAME);
|
|
||||||
class = pw_properties_get(props, PW_KEY_MEDIA_CLASS);
|
|
||||||
pw_properties_setf(props, PW_KEY_NODE_DESCRIPTION,
|
|
||||||
"%s%s%s%ssink",
|
|
||||||
name, (name[0] == '\0') ? "" : " ",
|
|
||||||
class ? class : "", (class && class[0] != '\0') ? " " : "");
|
|
||||||
}
|
|
||||||
pw_properties_set(props, PW_KEY_FACTORY_NAME, "support.null-audio-sink");
|
|
||||||
|
|
||||||
module = calloc(1, sizeof(struct module));
|
|
||||||
module->client = client;
|
|
||||||
module->cb = cb;
|
|
||||||
module->cb_data = data;
|
|
||||||
|
|
||||||
if ((res = load_null_sink_module(client, module, props)) < 0)
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
out:
|
return NULL;
|
||||||
if (res < 0) {
|
}
|
||||||
free(module);
|
|
||||||
module = NULL;
|
static struct module *create_module(struct client *client, const char *name, const char *args)
|
||||||
|
{
|
||||||
|
struct impl *impl = client->impl;
|
||||||
|
const struct module_info *info;
|
||||||
|
struct module *module;
|
||||||
|
|
||||||
|
info = find_module_info(name);
|
||||||
|
if (info == NULL) {
|
||||||
|
errno = -ENOENT;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
module = info->create(impl, args);
|
||||||
|
if (module == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return res;
|
module->idx = pw_map_insert_new(&impl->modules, module);
|
||||||
}
|
if (module->idx == SPA_ID_INVALID) {
|
||||||
|
module_unload(client, module);
|
||||||
static void module_add_listener(struct module *module, struct module_events *events, void *userdata)
|
return NULL;
|
||||||
{
|
}
|
||||||
module->events = events;
|
module->name = strdup(name);
|
||||||
module->events_data = userdata;
|
module->args = strdup(args);
|
||||||
}
|
module->idx |= MODULE_FLAG;
|
||||||
|
return module;
|
||||||
static void unload_module(struct module *module)
|
|
||||||
{
|
|
||||||
pw_proxy_destroy(module->proxy);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ struct client {
|
||||||
struct spa_list out_messages;
|
struct spa_list out_messages;
|
||||||
|
|
||||||
struct spa_list operations;
|
struct spa_list operations;
|
||||||
struct spa_list modules;
|
struct spa_list loading_modules;
|
||||||
|
|
||||||
struct spa_list pending_samples;
|
struct spa_list pending_samples;
|
||||||
|
|
||||||
|
|
@ -265,6 +265,7 @@ struct impl {
|
||||||
struct spa_list cleanup_clients;
|
struct spa_list cleanup_clients;
|
||||||
|
|
||||||
struct pw_map samples;
|
struct pw_map samples;
|
||||||
|
struct pw_map modules;
|
||||||
|
|
||||||
struct spa_list free_messages;
|
struct spa_list free_messages;
|
||||||
struct defs defs;
|
struct defs defs;
|
||||||
|
|
@ -3693,6 +3694,29 @@ static int fill_module_info(struct client *client, struct message *m,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int fill_ext_module_info(struct client *client, struct message *m,
|
||||||
|
struct module *module)
|
||||||
|
{
|
||||||
|
message_put(m,
|
||||||
|
TAG_U32, module->idx, /* module index */
|
||||||
|
TAG_STRING, module->name,
|
||||||
|
TAG_STRING, module->args,
|
||||||
|
TAG_U32, -1, /* n_used */
|
||||||
|
TAG_INVALID);
|
||||||
|
|
||||||
|
if (client->version < 15) {
|
||||||
|
message_put(m,
|
||||||
|
TAG_BOOLEAN, false, /* auto unload deprecated */
|
||||||
|
TAG_INVALID);
|
||||||
|
}
|
||||||
|
if (client->version >= 15) {
|
||||||
|
message_put(m,
|
||||||
|
TAG_PROPLIST, module->props,
|
||||||
|
TAG_INVALID);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int64_t get_port_latency_offset(struct client *client, struct pw_manager_object *card, struct port_info *pi)
|
static int64_t get_port_latency_offset(struct client *client, struct pw_manager_object *card, struct port_info *pi)
|
||||||
{
|
{
|
||||||
struct pw_manager *m = client->manager;
|
struct pw_manager *m = client->manager;
|
||||||
|
|
@ -4297,6 +4321,17 @@ static int do_get_info(struct client *client, uint32_t command, uint32_t tag, st
|
||||||
TAG_INVALID)) < 0)
|
TAG_INVALID)) < 0)
|
||||||
goto error_protocol;
|
goto error_protocol;
|
||||||
|
|
||||||
|
reply = reply_new(client, tag);
|
||||||
|
|
||||||
|
if (command == COMMAND_GET_MODULE_INFO && (sel.id & MODULE_FLAG) != 0) {
|
||||||
|
struct module *module;
|
||||||
|
module = pw_map_lookup(&impl->modules, sel.id & INDEX_MASK);
|
||||||
|
if (module == NULL)
|
||||||
|
goto error_noentity;
|
||||||
|
fill_ext_module_info(client, reply, module);
|
||||||
|
return send_message(client, reply);
|
||||||
|
}
|
||||||
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case COMMAND_GET_CLIENT_INFO:
|
case COMMAND_GET_CLIENT_INFO:
|
||||||
sel.type = object_is_client;
|
sel.type = object_is_client;
|
||||||
|
|
@ -4365,7 +4400,6 @@ static int do_get_info(struct client *client, uint32_t command, uint32_t tag, st
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
goto error_noentity;
|
goto error_noentity;
|
||||||
|
|
||||||
reply = reply_new(client, tag);
|
|
||||||
if ((res = fill_func(client, reply, o)) < 0)
|
if ((res = fill_func(client, reply, o)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
@ -4491,6 +4525,14 @@ static int do_list_info(void *data, struct pw_manager_object *object)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_info_list_module(void *item, void *data)
|
||||||
|
{
|
||||||
|
struct module *m = item;
|
||||||
|
struct info_list_data *info = data;
|
||||||
|
fill_ext_module_info(info->client, info->reply, m);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_get_info_list(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
static int do_get_info_list(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
||||||
{
|
{
|
||||||
struct impl *impl = client->impl;
|
struct impl *impl = client->impl;
|
||||||
|
|
@ -4533,6 +4575,9 @@ static int do_get_info_list(struct client *client, uint32_t command, uint32_t ta
|
||||||
if (info.fill_func)
|
if (info.fill_func)
|
||||||
pw_manager_for_each_object(manager, do_list_info, &info);
|
pw_manager_for_each_object(manager, do_list_info, &info);
|
||||||
|
|
||||||
|
if (command == COMMAND_GET_MODULE_INFO_LIST)
|
||||||
|
pw_map_for_each(&impl->modules, do_info_list_module, &info);
|
||||||
|
|
||||||
return send_message(client, info.reply);
|
return send_message(client, info.reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4896,7 +4941,10 @@ static int do_kill(struct client *client, uint32_t command, uint32_t tag, struct
|
||||||
}
|
}
|
||||||
|
|
||||||
struct load_module_data {
|
struct load_module_data {
|
||||||
|
struct spa_list link;
|
||||||
struct client *client;
|
struct client *client;
|
||||||
|
struct module *module;
|
||||||
|
struct spa_hook listener;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -4908,38 +4956,24 @@ static struct load_module_data *load_module_data_new(struct client *client, uint
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_module_removed(void *data, struct module *module)
|
static void load_module_data_free(struct load_module_data *d)
|
||||||
{
|
{
|
||||||
struct client *client = data;
|
spa_hook_remove(&d->listener);
|
||||||
|
free(d);
|
||||||
pw_log_info(NAME" %p: [%s] module %d unloaded", client->impl, client->name, module->idx);
|
|
||||||
|
|
||||||
spa_list_remove(&module->link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_module_error(void *data)
|
static void on_module_loaded(void *data, int error)
|
||||||
{
|
|
||||||
struct client *client = data;
|
|
||||||
|
|
||||||
pw_log_info(NAME" %p: [%s] error loading module", client->impl, client->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void on_module_loaded(struct module *module, int error, void *data)
|
|
||||||
{
|
{
|
||||||
struct load_module_data *d = data;
|
struct load_module_data *d = data;
|
||||||
|
struct module *module = d->module;
|
||||||
|
struct impl *impl = module->impl;
|
||||||
struct message *reply;
|
struct message *reply;
|
||||||
struct client *client;
|
struct client *client;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
int res;
|
|
||||||
|
|
||||||
struct module_events listener = {
|
|
||||||
on_module_removed,
|
|
||||||
on_module_error,
|
|
||||||
};
|
|
||||||
|
|
||||||
client = d->client;
|
client = d->client;
|
||||||
tag = d->tag;
|
tag = d->tag;
|
||||||
free(d);
|
load_module_data_free(d);
|
||||||
|
|
||||||
if (error < 0) {
|
if (error < 0) {
|
||||||
pw_log_warn(NAME" %p: [%s] error loading module", client->impl, client->name);
|
pw_log_warn(NAME" %p: [%s] error loading module", client->impl, client->name);
|
||||||
|
|
@ -4947,25 +4981,31 @@ static void on_module_loaded(struct module *module, int error, void *data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spa_list_append(&client->modules, &module->link);
|
|
||||||
module_add_listener(module, &listener, client);
|
|
||||||
|
|
||||||
pw_log_info(NAME" %p: [%s] module %d loaded", client->impl, client->name, module->idx);
|
pw_log_info(NAME" %p: [%s] module %d loaded", client->impl, client->name, module->idx);
|
||||||
|
|
||||||
|
broadcast_subscribe_event(impl,
|
||||||
|
SUBSCRIPTION_MASK_MODULE,
|
||||||
|
SUBSCRIPTION_EVENT_NEW | SUBSCRIPTION_EVENT_MODULE,
|
||||||
|
module->idx);
|
||||||
|
|
||||||
reply = reply_new(client, tag);
|
reply = reply_new(client, tag);
|
||||||
message_put(reply,
|
message_put(reply,
|
||||||
TAG_U32, module->idx,
|
TAG_U32, module->idx,
|
||||||
TAG_INVALID);
|
TAG_INVALID);
|
||||||
if ((res = send_message(client, reply)) < 0)
|
send_message(client, reply);
|
||||||
reply_error(client, COMMAND_LOAD_MODULE, tag, res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_load_module(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
static int do_load_module(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
||||||
{
|
{
|
||||||
struct load_module_data *data;
|
struct module *module;
|
||||||
struct impl *impl = client->impl;
|
struct impl *impl = client->impl;
|
||||||
|
struct load_module_data *d;
|
||||||
const char *name, *argument;
|
const char *name, *argument;
|
||||||
int res;
|
int res;
|
||||||
|
static struct module_events listener = {
|
||||||
|
VERSION_MODULE_EVENTS,
|
||||||
|
.loaded = on_module_loaded,
|
||||||
|
};
|
||||||
|
|
||||||
if ((res = message_get(m,
|
if ((res = message_get(m,
|
||||||
TAG_STRING, &name,
|
TAG_STRING, &name,
|
||||||
|
|
@ -4976,9 +5016,15 @@ static int do_load_module(struct client *client, uint32_t command, uint32_t tag,
|
||||||
pw_log_info(NAME" %p: [%s] %s name:%s argument:%s", impl,
|
pw_log_info(NAME" %p: [%s] %s name:%s argument:%s", impl,
|
||||||
client->name, commands[command].name, name, argument);
|
client->name, commands[command].name, name, argument);
|
||||||
|
|
||||||
data = load_module_data_new(client, tag);
|
module = create_module(client, name, argument);
|
||||||
res = load_module(client, name, argument, on_module_loaded, data);
|
if (module == NULL)
|
||||||
return res;
|
return -errno;
|
||||||
|
|
||||||
|
d = load_module_data_new(client, tag);
|
||||||
|
d->module = module;
|
||||||
|
module_add_listener(module, &d->listener, &listener, d);
|
||||||
|
|
||||||
|
return module_load(client, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_unload_module(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
static int do_unload_module(struct client *client, uint32_t command, uint32_t tag, struct message *m)
|
||||||
|
|
@ -4996,14 +5042,22 @@ static int do_unload_module(struct client *client, uint32_t command, uint32_t ta
|
||||||
pw_log_info(NAME" %p: [%s] %s tag:%u id:%u", impl, client->name,
|
pw_log_info(NAME" %p: [%s] %s tag:%u id:%u", impl, client->name,
|
||||||
commands[command].name, tag, module_idx);
|
commands[command].name, tag, module_idx);
|
||||||
|
|
||||||
spa_list_for_each(module, &client->modules, link) {
|
if (module_idx == SPA_ID_INVALID)
|
||||||
if (module->idx == module_idx)
|
return -EINVAL;
|
||||||
break;
|
if ((module_idx & MODULE_FLAG) == 0)
|
||||||
}
|
return -EPERM;
|
||||||
if (spa_list_is_end(module, &client->modules, link))
|
|
||||||
|
module = pw_map_lookup(&impl->modules, module_idx & INDEX_MASK);
|
||||||
|
if (module == NULL)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
unload_module(module);
|
module_unload(client, module);
|
||||||
|
|
||||||
|
broadcast_subscribe_event(impl,
|
||||||
|
SUBSCRIPTION_MASK_MODULE,
|
||||||
|
SUBSCRIPTION_EVENT_REMOVE | SUBSCRIPTION_EVENT_MODULE,
|
||||||
|
module_idx);
|
||||||
|
|
||||||
return reply_simple_ack(client, tag);
|
return reply_simple_ack(client, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5208,7 +5262,6 @@ static void client_free(struct client *client)
|
||||||
{
|
{
|
||||||
struct impl *impl = client->impl;
|
struct impl *impl = client->impl;
|
||||||
struct message *msg;
|
struct message *msg;
|
||||||
struct module *module, *tmp;
|
|
||||||
struct pending_sample *p;
|
struct pending_sample *p;
|
||||||
|
|
||||||
pw_log_info(NAME" %p: client %p free", impl, client);
|
pw_log_info(NAME" %p: client %p free", impl, client);
|
||||||
|
|
@ -5220,9 +5273,6 @@ static void client_free(struct client *client)
|
||||||
spa_list_consume(p, &client->pending_samples, link)
|
spa_list_consume(p, &client->pending_samples, link)
|
||||||
pending_sample_free(p);
|
pending_sample_free(p);
|
||||||
|
|
||||||
spa_list_for_each_safe(module, tmp, &client->modules, link)
|
|
||||||
unload_module(module);
|
|
||||||
|
|
||||||
spa_list_consume(msg, &client->out_messages, link)
|
spa_list_consume(msg, &client->out_messages, link)
|
||||||
message_free(impl, msg, true, false);
|
message_free(impl, msg, true, false);
|
||||||
|
|
||||||
|
|
@ -5607,7 +5657,6 @@ on_connect(void *data, int fd, uint32_t mask)
|
||||||
pw_map_init(&client->streams, 16, 16);
|
pw_map_init(&client->streams, 16, 16);
|
||||||
spa_list_init(&client->out_messages);
|
spa_list_init(&client->out_messages);
|
||||||
spa_list_init(&client->operations);
|
spa_list_init(&client->operations);
|
||||||
spa_list_init(&client->modules);
|
|
||||||
spa_list_init(&client->pending_samples);
|
spa_list_init(&client->pending_samples);
|
||||||
|
|
||||||
client->props = pw_properties_new(
|
client->props = pw_properties_new(
|
||||||
|
|
@ -5953,6 +6002,13 @@ static int impl_free_sample(void *item, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int impl_free_module(void *item, void *data)
|
||||||
|
{
|
||||||
|
struct module *m = item;
|
||||||
|
module_free(m);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void impl_free(struct impl *impl)
|
static void impl_free(struct impl *impl)
|
||||||
{
|
{
|
||||||
struct server *s;
|
struct server *s;
|
||||||
|
|
@ -5966,6 +6022,8 @@ static void impl_free(struct impl *impl)
|
||||||
server_free(s);
|
server_free(s);
|
||||||
pw_map_for_each(&impl->samples, impl_free_sample, impl);
|
pw_map_for_each(&impl->samples, impl_free_sample, impl);
|
||||||
pw_map_clear(&impl->samples);
|
pw_map_clear(&impl->samples);
|
||||||
|
pw_map_for_each(&impl->modules, impl_free_module, impl);
|
||||||
|
pw_map_clear(&impl->modules);
|
||||||
if (impl->cleanup != NULL)
|
if (impl->cleanup != NULL)
|
||||||
pw_loop_destroy_source(impl->loop, impl->cleanup);
|
pw_loop_destroy_source(impl->loop, impl->cleanup);
|
||||||
pw_properties_free(impl->props);
|
pw_properties_free(impl->props);
|
||||||
|
|
@ -6065,6 +6123,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
|
||||||
impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC;
|
impl->rate_limit.interval = 2 * SPA_NSEC_PER_SEC;
|
||||||
impl->rate_limit.burst = 1;
|
impl->rate_limit.burst = 1;
|
||||||
pw_map_init(&impl->samples, 16, 16);
|
pw_map_init(&impl->samples, 16, 16);
|
||||||
|
pw_map_init(&impl->modules, 16, 16);
|
||||||
spa_list_init(&impl->cleanup_clients);
|
spa_list_init(&impl->cleanup_clients);
|
||||||
spa_list_init(&impl->free_messages);
|
spa_list_init(&impl->free_messages);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue