mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
module: fix registration of modules
Don't fail when protocol-native is already registered.
This commit is contained in:
parent
91d54364fc
commit
589e3d977c
10 changed files with 50 additions and 36 deletions
|
|
@ -492,7 +492,6 @@ static void make_nodes(struct data *data)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct data data = { 0, };
|
||||
char *err;
|
||||
|
||||
pw_init(&argc, &argv);
|
||||
|
||||
|
|
@ -501,7 +500,7 @@ int main(int argc, char *argv[])
|
|||
data.core = pw_core_new(data.loop, NULL);
|
||||
data.path = argc > 1 ? argv[1] : NULL;
|
||||
|
||||
pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, &err);
|
||||
pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL);
|
||||
|
||||
init_type(&data.type, data.core->type.map);
|
||||
|
||||
|
|
|
|||
|
|
@ -715,6 +715,9 @@ static bool module_init(struct pw_module *module, struct pw_properties *properti
|
|||
const char *val;
|
||||
struct protocol_data *d;
|
||||
|
||||
if (pw_core_find_protocol(core, PW_TYPE_PROTOCOL__Native) != NULL)
|
||||
return true;
|
||||
|
||||
this = pw_protocol_new(core, PW_TYPE_PROTOCOL__Native, sizeof(struct protocol_data));
|
||||
if (this == NULL)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -90,7 +90,11 @@ execute_command_module_load(struct pw_command *command, struct pw_core *core, ch
|
|||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(command, struct impl, this);
|
||||
|
||||
return pw_module_load(core, impl->args[1], impl->args[2], err) != NULL;
|
||||
if (pw_module_load(core, impl->args[1], impl->args[2]) == NULL) {
|
||||
asprintf(err, "could not load module \"%s\"", impl->args[1]);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Free command
|
||||
|
|
|
|||
|
|
@ -349,6 +349,7 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
|
|||
spa_list_init(&this->resource_list);
|
||||
spa_list_init(&this->registry_resource_list);
|
||||
spa_list_init(&this->global_list);
|
||||
spa_list_init(&this->module_list);
|
||||
spa_list_init(&this->client_list);
|
||||
spa_list_init(&this->node_list);
|
||||
spa_list_init(&this->node_factory_list);
|
||||
|
|
@ -770,14 +771,3 @@ struct pw_node_factory *pw_core_find_node_factory(struct pw_core *core, const ch
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct pw_protocol *pw_core_find_protocol(struct pw_core *core, const char *name)
|
||||
{
|
||||
struct pw_protocol *protocol;
|
||||
|
||||
spa_list_for_each(protocol, &core->protocol_list, link) {
|
||||
if (strcmp(protocol->name, name) == 0)
|
||||
return protocol;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ struct pw_core {
|
|||
struct spa_list remote_list; /**< list of remote connections */
|
||||
struct spa_list resource_list; /**< list of core resources */
|
||||
struct spa_list registry_resource_list; /**< list of registry resources */
|
||||
struct spa_list module_list; /**< list of modules */
|
||||
struct spa_list global_list; /**< list of globals */
|
||||
struct spa_list client_list; /**< list of clients */
|
||||
struct spa_list node_list; /**< list of nodes */
|
||||
|
|
@ -244,9 +245,6 @@ pw_core_find_port(struct pw_core *core,
|
|||
struct pw_node_factory *
|
||||
pw_core_find_node_factory(struct pw_core *core, const char *name);
|
||||
|
||||
struct pw_protocol *
|
||||
pw_core_find_protocol(struct pw_core *core, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -116,18 +116,27 @@ module_bind_func(struct pw_global *global,
|
|||
return SPA_RESULT_NO_MEMORY;
|
||||
}
|
||||
|
||||
struct pw_module * pw_core_find_module(struct pw_core *core, const char *filename)
|
||||
{
|
||||
struct pw_module *module;
|
||||
spa_list_for_each(module, &core->module_list, link) {
|
||||
if (strcmp(module->info.filename, filename) == 0)
|
||||
return module;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Load a module
|
||||
*
|
||||
* \param core a \ref pw_core
|
||||
* \param name name of the module to load
|
||||
* \param args A string with arguments for the module
|
||||
* \param[out] err Return location for an error string, or NULL
|
||||
* \param[out] error Return location for an error string, or NULL
|
||||
* \return A \ref pw_module if the module could be loaded, or NULL on failure.
|
||||
*
|
||||
* \memberof pw_module
|
||||
*/
|
||||
struct pw_module *pw_module_load(struct pw_core *core,
|
||||
const char *name, const char *args, char **err)
|
||||
struct pw_module *pw_module_load(struct pw_core *core, const char *name, const char *args)
|
||||
{
|
||||
struct pw_module *this;
|
||||
struct impl *impl;
|
||||
|
|
@ -185,6 +194,7 @@ struct pw_module *pw_module_load(struct pw_core *core,
|
|||
this->info.args = args ? strdup(args) : NULL;
|
||||
this->info.props = NULL;
|
||||
|
||||
spa_list_insert(core->module_list.prev, &this->link);
|
||||
this->global = pw_core_add_global(core, NULL, core->global,
|
||||
core->type.module, PW_VERSION_MODULE,
|
||||
module_bind_func, this);
|
||||
|
|
@ -197,24 +207,20 @@ struct pw_module *pw_module_load(struct pw_core *core,
|
|||
return this;
|
||||
|
||||
not_found:
|
||||
if (err)
|
||||
asprintf(err, "No module \"%s\" was found", name);
|
||||
pw_log_error("No module \"%s\" was found", name);
|
||||
return NULL;
|
||||
open_failed:
|
||||
if (err)
|
||||
asprintf(err, "Failed to open module: \"%s\" %s", filename, dlerror());
|
||||
pw_log_error("Failed to open module: \"%s\" %s", filename, dlerror());
|
||||
free(filename);
|
||||
return NULL;
|
||||
no_mem:
|
||||
no_pw_module:
|
||||
if (err)
|
||||
asprintf(err, "\"%s\" is not a pipewire module", name);
|
||||
pw_log_error("\"%s\" is not a pipewire module", filename);
|
||||
dlclose(hnd);
|
||||
free(filename);
|
||||
return NULL;
|
||||
init_failed:
|
||||
if (err)
|
||||
asprintf(err, "\"%s\" failed to initialize", name);
|
||||
pw_log_error("\"%s\" failed to initialize", filename);
|
||||
pw_module_destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -235,6 +241,9 @@ void pw_module_destroy(struct pw_module *module)
|
|||
free((char *) module->info.filename);
|
||||
if (module->info.args)
|
||||
free((char *) module->info.args);
|
||||
|
||||
spa_list_remove(&module->link);
|
||||
pw_global_destroy(module->global);
|
||||
dlclose(impl->hnd);
|
||||
free(impl);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,12 +63,14 @@ struct pw_module {
|
|||
typedef bool (*pw_module_init_func_t) (struct pw_module *module, char *args);
|
||||
|
||||
struct pw_module *
|
||||
pw_module_load(struct pw_core *core,
|
||||
const char *name, const char *args, char **err);
|
||||
pw_module_load(struct pw_core *core, const char *name, const char *args);
|
||||
|
||||
void
|
||||
pw_module_destroy(struct pw_module *module);
|
||||
|
||||
struct pw_module *
|
||||
pw_core_find_module(struct pw_core *core, const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,9 +35,6 @@ struct pw_protocol *pw_protocol_new(struct pw_core *core,
|
|||
{
|
||||
struct pw_protocol *protocol;
|
||||
|
||||
if (pw_core_find_protocol(core, name) != NULL)
|
||||
return NULL;
|
||||
|
||||
protocol = calloc(1, sizeof(struct impl) + user_data_size);
|
||||
protocol->core = core;
|
||||
protocol->name = strdup(name);
|
||||
|
|
@ -116,3 +113,13 @@ pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type)
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct pw_protocol *pw_core_find_protocol(struct pw_core *core, const char *name)
|
||||
{
|
||||
struct pw_protocol *protocol;
|
||||
spa_list_for_each(protocol, &core->protocol_list, link) {
|
||||
if (strcmp(protocol->name, name) == 0)
|
||||
return protocol;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ void pw_protocol_add_marshal(struct pw_protocol *protocol,
|
|||
const struct pw_protocol_marshal *
|
||||
pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type);
|
||||
|
||||
struct pw_protocol * pw_core_find_protocol(struct pw_core *core, const char *name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
|
|||
pw_signal_init(&this->destroy_signal);
|
||||
|
||||
if ((protocol_name = pw_properties_get(properties, "pipewire.protocol")) == NULL) {
|
||||
if (!pw_module_load(core, "libpipewire-module-protocol-native", NULL, NULL))
|
||||
if (!pw_module_load(core, "libpipewire-module-protocol-native", NULL))
|
||||
goto no_protocol;
|
||||
|
||||
protocol_name = PW_TYPE_PROTOCOL__Native;
|
||||
|
|
@ -201,7 +201,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
|
|||
if (this->conn == NULL)
|
||||
goto no_connection;
|
||||
|
||||
pw_module_load(core, "libpipewire-module-client-node", NULL, NULL);
|
||||
pw_module_load(core, "libpipewire-module-client-node", NULL);
|
||||
|
||||
spa_list_insert(core->remote_list.prev, &this->link);
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ static int do_connect(struct pw_remote *remote)
|
|||
if (remote->core_proxy == NULL)
|
||||
goto no_proxy;
|
||||
|
||||
pw_proxy_add_listener((struct pw_proxy*)remote->core_proxy, remote, &core_events);
|
||||
pw_proxy_add_listener(&remote->core_proxy->proxy, remote, &core_events);
|
||||
|
||||
pw_core_proxy_client_update(remote->core_proxy, &remote->properties->dict);
|
||||
pw_core_proxy_sync(remote->core_proxy, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue