pulse-server: Implement module-loopback

Implements all modargs other than rate adjustment and max latency
related ones, which do not make sense in our context.

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/543
This commit is contained in:
Arun Raghavan 2021-03-31 18:18:08 -04:00
parent 63281413bd
commit e7b04bca2c
3 changed files with 385 additions and 5 deletions

View file

@ -56,9 +56,19 @@ struct module {
struct impl *impl;
const struct module_methods *methods;
struct spa_hook_list hooks;
struct spa_source *unload;
void *user_data;
};
static int module_unload(struct client *client, struct module *module);
static void on_module_unload(void *data, uint64_t count)
{
struct module *module = data;
module_unload(NULL, module);
}
static struct module *module_new(struct impl *impl, const struct module_methods *methods, size_t user_data)
{
struct module *module;
@ -70,6 +80,7 @@ static struct module *module_new(struct impl *impl, const struct module_methods
module->impl = impl;
module->methods = methods;
spa_hook_list_init(&module->hooks);
module->unload = pw_loop_add_event(impl->loop, on_module_unload, module);
module->user_data = SPA_MEMBER(module, sizeof(struct module), void);
return module;
@ -87,6 +98,8 @@ 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;
/* subscription event is sent when the module does a
* module_emit_loaded() */
return module->methods->load(client, module);
}
@ -100,19 +113,32 @@ static void module_free(struct module *module)
free((char*)module->args);
if (module->props)
pw_properties_free(module->props);
pw_loop_destroy_source(impl->loop, module->unload);
free(module);
}
static int module_unload(struct client *client, struct module *module)
{
struct impl *impl = module->impl;
uint32_t module_idx = module->idx;
int res = 0;
/* Note that client can be NULL (when the module is being unloaded
* internally and not by a client request */
pw_log_info("unload module id:%u name:%s", module->idx, module->name);
if (module->methods->unload)
res = module->methods->unload(client, module);
module_free(module);
broadcast_subscribe_event(impl,
SUBSCRIPTION_MASK_MODULE,
SUBSCRIPTION_EVENT_REMOVE | SUBSCRIPTION_EVENT_MODULE,
module_idx);
return res;
}
@ -152,9 +178,11 @@ static void add_props(struct pw_properties *props, const char *str)
}
#include "module-null-sink.c"
#include "module-loopback.c"
static const struct module_info module_list[] = {
{ "module-null-sink", create_module_null_sink, },
{ "module-loopback", create_module_loopback, },
{ NULL, }
};