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[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct data data = { 0, };
 | 
						struct data data = { 0, };
 | 
				
			||||||
	char *err;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_init(&argc, &argv);
 | 
						pw_init(&argc, &argv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -501,7 +500,7 @@ int main(int argc, char *argv[])
 | 
				
			||||||
	data.core = pw_core_new(data.loop, NULL);
 | 
						data.core = pw_core_new(data.loop, NULL);
 | 
				
			||||||
	data.path = argc > 1 ? argv[1] : 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);
 | 
						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;
 | 
						const char *val;
 | 
				
			||||||
	struct protocol_data *d;
 | 
						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));
 | 
						this = pw_protocol_new(core, PW_TYPE_PROTOCOL__Native, sizeof(struct protocol_data));
 | 
				
			||||||
	if (this == NULL)
 | 
						if (this == NULL)
 | 
				
			||||||
		return false;
 | 
							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);
 | 
						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
 | 
					/** 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->resource_list);
 | 
				
			||||||
	spa_list_init(&this->registry_resource_list);
 | 
						spa_list_init(&this->registry_resource_list);
 | 
				
			||||||
	spa_list_init(&this->global_list);
 | 
						spa_list_init(&this->global_list);
 | 
				
			||||||
 | 
						spa_list_init(&this->module_list);
 | 
				
			||||||
	spa_list_init(&this->client_list);
 | 
						spa_list_init(&this->client_list);
 | 
				
			||||||
	spa_list_init(&this->node_list);
 | 
						spa_list_init(&this->node_list);
 | 
				
			||||||
	spa_list_init(&this->node_factory_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;
 | 
						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 remote_list;		/**< list of remote connections */
 | 
				
			||||||
	struct spa_list resource_list;		/**< list of core resources */
 | 
						struct spa_list resource_list;		/**< list of core resources */
 | 
				
			||||||
	struct spa_list registry_resource_list;	/**< list of registry 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 global_list;		/**< list of globals */
 | 
				
			||||||
	struct spa_list client_list;		/**< list of clients */
 | 
						struct spa_list client_list;		/**< list of clients */
 | 
				
			||||||
	struct spa_list node_list;		/**< list of nodes */
 | 
						struct spa_list node_list;		/**< list of nodes */
 | 
				
			||||||
| 
						 | 
					@ -244,9 +245,6 @@ pw_core_find_port(struct pw_core *core,
 | 
				
			||||||
struct pw_node_factory *
 | 
					struct pw_node_factory *
 | 
				
			||||||
pw_core_find_node_factory(struct pw_core *core, const char *name);
 | 
					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
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,18 +116,27 @@ module_bind_func(struct pw_global *global,
 | 
				
			||||||
	return SPA_RESULT_NO_MEMORY;
 | 
						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
 | 
					/** Load a module
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \param core a \ref pw_core
 | 
					 * \param core a \ref pw_core
 | 
				
			||||||
 * \param name name of the module to load
 | 
					 * \param name name of the module to load
 | 
				
			||||||
 * \param args A string with arguments for the module
 | 
					 * \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.
 | 
					 * \return A \ref pw_module if the module could be loaded, or NULL on failure.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \memberof pw_module
 | 
					 * \memberof pw_module
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct pw_module *pw_module_load(struct pw_core *core,
 | 
					struct pw_module *pw_module_load(struct pw_core *core, const char *name, const char *args)
 | 
				
			||||||
				 const char *name, const char *args, char **err)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct pw_module *this;
 | 
						struct pw_module *this;
 | 
				
			||||||
	struct impl *impl;
 | 
						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.args = args ? strdup(args) : NULL;
 | 
				
			||||||
	this->info.props = NULL;
 | 
						this->info.props = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_list_insert(core->module_list.prev, &this->link);
 | 
				
			||||||
	this->global = pw_core_add_global(core, NULL, core->global,
 | 
						this->global = pw_core_add_global(core, NULL, core->global,
 | 
				
			||||||
					  core->type.module, PW_VERSION_MODULE,
 | 
										  core->type.module, PW_VERSION_MODULE,
 | 
				
			||||||
					  module_bind_func, this);
 | 
										  module_bind_func, this);
 | 
				
			||||||
| 
						 | 
					@ -197,24 +207,20 @@ struct pw_module *pw_module_load(struct pw_core *core,
 | 
				
			||||||
	return this;
 | 
						return this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      not_found:
 | 
					      not_found:
 | 
				
			||||||
	if (err)
 | 
						pw_log_error("No module \"%s\" was found", name);
 | 
				
			||||||
		asprintf(err, "No module \"%s\" was found", name);
 | 
					 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
      open_failed:
 | 
					      open_failed:
 | 
				
			||||||
	if (err)
 | 
						pw_log_error("Failed to open module: \"%s\" %s", filename, dlerror());
 | 
				
			||||||
		asprintf(err, "Failed to open module: \"%s\" %s", filename, dlerror());
 | 
					 | 
				
			||||||
	free(filename);
 | 
						free(filename);
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
      no_mem:
 | 
					      no_mem:
 | 
				
			||||||
      no_pw_module:
 | 
					      no_pw_module:
 | 
				
			||||||
	if (err)
 | 
						pw_log_error("\"%s\" is not a pipewire module", filename);
 | 
				
			||||||
		asprintf(err, "\"%s\" is not a pipewire module", name);
 | 
					 | 
				
			||||||
	dlclose(hnd);
 | 
						dlclose(hnd);
 | 
				
			||||||
	free(filename);
 | 
						free(filename);
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
      init_failed:
 | 
					      init_failed:
 | 
				
			||||||
	if (err)
 | 
						pw_log_error("\"%s\" failed to initialize", filename);
 | 
				
			||||||
		asprintf(err, "\"%s\" failed to initialize", name);
 | 
					 | 
				
			||||||
	pw_module_destroy(this);
 | 
						pw_module_destroy(this);
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -235,6 +241,9 @@ void pw_module_destroy(struct pw_module *module)
 | 
				
			||||||
		free((char *) module->info.filename);
 | 
							free((char *) module->info.filename);
 | 
				
			||||||
	if (module->info.args)
 | 
						if (module->info.args)
 | 
				
			||||||
		free((char *) module->info.args);
 | 
							free((char *) module->info.args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_list_remove(&module->link);
 | 
				
			||||||
 | 
						pw_global_destroy(module->global);
 | 
				
			||||||
	dlclose(impl->hnd);
 | 
						dlclose(impl->hnd);
 | 
				
			||||||
	free(impl);
 | 
						free(impl);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,12 +63,14 @@ struct pw_module {
 | 
				
			||||||
typedef bool (*pw_module_init_func_t) (struct pw_module *module, char *args);
 | 
					typedef bool (*pw_module_init_func_t) (struct pw_module *module, char *args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct pw_module *
 | 
					struct pw_module *
 | 
				
			||||||
pw_module_load(struct pw_core *core,
 | 
					pw_module_load(struct pw_core *core, const char *name, const char *args);
 | 
				
			||||||
	       const char *name, const char *args, char **err);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
pw_module_destroy(struct pw_module *module);
 | 
					pw_module_destroy(struct pw_module *module);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct pw_module *
 | 
				
			||||||
 | 
					pw_core_find_module(struct pw_core *core, const char *filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,9 +35,6 @@ struct pw_protocol *pw_protocol_new(struct pw_core *core,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct pw_protocol *protocol;
 | 
						struct pw_protocol *protocol;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pw_core_find_protocol(core, name) != NULL)
 | 
					 | 
				
			||||||
		return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	protocol = calloc(1, sizeof(struct impl) + user_data_size);
 | 
						protocol = calloc(1, sizeof(struct impl) + user_data_size);
 | 
				
			||||||
	protocol->core = core;
 | 
						protocol->core = core;
 | 
				
			||||||
	protocol->name = strdup(name);
 | 
						protocol->name = strdup(name);
 | 
				
			||||||
| 
						 | 
					@ -116,3 +113,13 @@ pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
	return NULL;
 | 
						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 *
 | 
					const struct pw_protocol_marshal *
 | 
				
			||||||
pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type);
 | 
					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
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}  /* extern "C" */
 | 
					}  /* extern "C" */
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -187,7 +187,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
 | 
				
			||||||
	pw_signal_init(&this->destroy_signal);
 | 
						pw_signal_init(&this->destroy_signal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((protocol_name = pw_properties_get(properties, "pipewire.protocol")) == NULL) {
 | 
						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;
 | 
								goto no_protocol;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		protocol_name = PW_TYPE_PROTOCOL__Native;
 | 
							protocol_name = PW_TYPE_PROTOCOL__Native;
 | 
				
			||||||
| 
						 | 
					@ -201,7 +201,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
 | 
				
			||||||
	if (this->conn == NULL)
 | 
						if (this->conn == NULL)
 | 
				
			||||||
		goto no_connection;
 | 
							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);
 | 
					        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)
 | 
						if (remote->core_proxy == NULL)
 | 
				
			||||||
		goto no_proxy;
 | 
							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_client_update(remote->core_proxy, &remote->properties->dict);
 | 
				
			||||||
	pw_core_proxy_sync(remote->core_proxy, 0);
 | 
						pw_core_proxy_sync(remote->core_proxy, 0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue