mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	module: load and register in one go
Load and register the module in one go because we need to have the global set when calling the init function so that factories and nodes can use this as the parent global. Set the name in the global properties.
This commit is contained in:
		
							parent
							
								
									1ed63e7ba0
								
							
						
					
					
						commit
						5df5afd0a9
					
				
					 7 changed files with 50 additions and 45 deletions
				
			
		| 
						 | 
					@ -138,7 +138,7 @@ int main(int argc, char *argv[])
 | 
				
			||||||
	if (argc > 3)
 | 
						if (argc > 3)
 | 
				
			||||||
		data.path = argv[3];
 | 
							data.path = argv[3];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL);
 | 
						pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, NULL, NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_debug_set_type_map(data.t->map);
 | 
						spa_debug_set_type_map(data.t->map);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -514,7 +514,7 @@ int main(int argc, char *argv[])
 | 
				
			||||||
	data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL);
 | 
						data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL);
 | 
				
			||||||
	data.t = pw_core_get_type(data.core);
 | 
						data.t = pw_core_get_type(data.core);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL);
 | 
						pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, NULL, NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	init_type(&data.type, data.t->map);
 | 
						init_type(&data.type, data.t->map);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,12 +92,11 @@ execute_command_module_load(struct pw_command *command, struct pw_core *core, ch
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct pw_module *module;
 | 
						struct pw_module *module;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	module = pw_module_load(core, command->args[1], command->args[2]);
 | 
						module = pw_module_load(core, command->args[1], command->args[2], NULL, NULL, NULL);
 | 
				
			||||||
	if (module == NULL) {
 | 
						if (module == NULL) {
 | 
				
			||||||
		asprintf(err, "could not load module \"%s\"", command->args[1]);
 | 
							asprintf(err, "could not load module \"%s\"", command->args[1]);
 | 
				
			||||||
		return -ENOMEM;
 | 
							return -ENOMEM;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	pw_module_register(module, NULL, NULL, NULL);
 | 
					 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -158,7 +158,12 @@ struct pw_module * pw_core_find_module(struct pw_core *core, const char *filenam
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \memberof pw_module
 | 
					 * \memberof pw_module
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct pw_module *pw_module_load(struct pw_core *core, const char *name, const char *args)
 | 
					struct pw_module *
 | 
				
			||||||
 | 
					pw_module_load(struct pw_core *core,
 | 
				
			||||||
 | 
						       const char *name, const char *args,
 | 
				
			||||||
 | 
						       struct pw_client *owner,
 | 
				
			||||||
 | 
						       struct pw_global *parent,
 | 
				
			||||||
 | 
						       struct pw_properties *properties)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct pw_module *this;
 | 
						struct pw_module *this;
 | 
				
			||||||
	struct impl *impl;
 | 
						struct impl *impl;
 | 
				
			||||||
| 
						 | 
					@ -205,6 +210,11 @@ struct pw_module *pw_module_load(struct pw_core *core, const char *name, const c
 | 
				
			||||||
	if (impl == NULL)
 | 
						if (impl == NULL)
 | 
				
			||||||
		goto no_mem;
 | 
							goto no_mem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (properties == NULL)
 | 
				
			||||||
 | 
							properties = pw_properties_new(NULL, NULL);
 | 
				
			||||||
 | 
						if (properties == NULL)
 | 
				
			||||||
 | 
							goto no_mem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl->hnd = hnd;
 | 
						impl->hnd = hnd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this = &impl->this;
 | 
						this = &impl->this;
 | 
				
			||||||
| 
						 | 
					@ -218,6 +228,21 @@ struct pw_module *pw_module_load(struct pw_core *core, const char *name, const c
 | 
				
			||||||
	this->info.args = args ? strdup(args) : NULL;
 | 
						this->info.args = args ? strdup(args) : NULL;
 | 
				
			||||||
	this->info.props = NULL;
 | 
						this->info.props = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pw_properties_set(properties, PW_MODULE_PROP_NAME, name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_list_append(&core->module_list, &this->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						this->global = pw_global_new(core,
 | 
				
			||||||
 | 
									     core->type.module, PW_VERSION_MODULE,
 | 
				
			||||||
 | 
									     properties,
 | 
				
			||||||
 | 
									     module_bind_func, this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (this->global == NULL)
 | 
				
			||||||
 | 
							goto no_global;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pw_global_register(this->global, owner, parent);
 | 
				
			||||||
 | 
						this->info.id = this->global->id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((res = init_func(this, args)) < 0)
 | 
						if ((res = init_func(this, args)) < 0)
 | 
				
			||||||
		goto init_failed;
 | 
							goto init_failed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,38 +259,18 @@ struct pw_module *pw_module_load(struct pw_core *core, const char *name, const c
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
      no_mem:
 | 
					      no_mem:
 | 
				
			||||||
      no_pw_module:
 | 
					      no_pw_module:
 | 
				
			||||||
	pw_log_error("\"%s\" is not a pipewire module", filename);
 | 
						pw_log_error("\"%s\": is not a pipewire module", filename);
 | 
				
			||||||
	dlclose(hnd);
 | 
						dlclose(hnd);
 | 
				
			||||||
	free(filename);
 | 
						free(filename);
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
      init_failed:
 | 
					      no_global:
 | 
				
			||||||
	pw_log_error("\"%s\" failed to initialize: %s", filename, spa_strerror(res));
 | 
						pw_log_error("\"%s\": failed to create global", filename);
 | 
				
			||||||
 | 
						pw_module_destroy(this);
 | 
				
			||||||
 | 
						return NULL;
 | 
				
			||||||
 | 
					      init_failed:
 | 
				
			||||||
 | 
						pw_log_error("\"%s\": failed to initialize: %s", filename, spa_strerror(res));
 | 
				
			||||||
	pw_module_destroy(this);
 | 
						pw_module_destroy(this);
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
int pw_module_register(struct pw_module *module,
 | 
					 | 
				
			||||||
		       struct pw_client *owner,
 | 
					 | 
				
			||||||
		       struct pw_global *parent,
 | 
					 | 
				
			||||||
		       struct pw_properties *properties)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct pw_core *core = module->core;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	spa_list_append(&core->module_list, &module->link);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	module->global = pw_global_new(core,
 | 
					 | 
				
			||||||
				       core->type.module, PW_VERSION_MODULE,
 | 
					 | 
				
			||||||
				       properties,
 | 
					 | 
				
			||||||
				       module_bind_func, module);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (module->global == NULL)
 | 
					 | 
				
			||||||
		return -ENOMEM;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pw_global_register(module->global, owner, parent);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	module->info.id = module->global->id;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Destroy a module
 | 
					/** Destroy a module
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,19 +58,20 @@ struct pw_module_events {
 | 
				
			||||||
#define PW_VERSION_MODULE_EVENTS	0
 | 
					#define PW_VERSION_MODULE_EVENTS	0
 | 
				
			||||||
	uint32_t version;
 | 
						uint32_t version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/** The module id destroyed */
 | 
						/** The module is destroyed */
 | 
				
			||||||
	void (*destroy) (void *data);
 | 
						void (*destroy) (void *data);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Load a module by name and arguments and register it */
 | 
					/** The name of the module */
 | 
				
			||||||
struct pw_module *
 | 
					#define PW_MODULE_PROP_NAME	"pipewire.module.name"
 | 
				
			||||||
pw_module_load(struct pw_core *core, const char *name, const char *args);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Finish module configuration and register */
 | 
					struct pw_module *
 | 
				
			||||||
int pw_module_register(struct pw_module *module,	/**< the module to register */
 | 
					pw_module_load(struct pw_core *core,
 | 
				
			||||||
		       struct pw_client *owner,		/**< optional owner */
 | 
						       const char *name,		/**< name of the module */
 | 
				
			||||||
		       struct pw_global *parent,	/**< parent global */
 | 
						       const char *args			/**< arguments of the module */,
 | 
				
			||||||
		       struct pw_properties *properties	/**< extra global properties */);
 | 
						       struct pw_client *owner,		/**< optional owner */
 | 
				
			||||||
 | 
						       struct pw_global *parent,	/**< parent global */
 | 
				
			||||||
 | 
						       struct pw_properties *properties	/**< extra global properties */);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Get the core of a module */
 | 
					/** Get the core of a module */
 | 
				
			||||||
struct pw_core * pw_module_get_core(struct pw_module *module);
 | 
					struct pw_core * pw_module_get_core(struct pw_module *module);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -251,7 +251,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
 | 
				
			||||||
	spa_hook_list_init(&this->listener_list);
 | 
						spa_hook_list_init(&this->listener_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((protocol_name = pw_properties_get(properties, PW_REMOTE_PROP_PROTOCOL)) == NULL) {
 | 
						if ((protocol_name = pw_properties_get(properties, PW_REMOTE_PROP_PROTOCOL)) == NULL) {
 | 
				
			||||||
		if (!pw_module_load(core, "libpipewire-module-protocol-native", NULL))
 | 
							if (!pw_module_load(core, "libpipewire-module-protocol-native", NULL, NULL, NULL, NULL))
 | 
				
			||||||
			goto no_protocol;
 | 
								goto no_protocol;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		protocol_name = PW_TYPE_PROTOCOL__Native;
 | 
							protocol_name = PW_TYPE_PROTOCOL__Native;
 | 
				
			||||||
| 
						 | 
					@ -265,7 +265,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);
 | 
						pw_module_load(core, "libpipewire-module-client-node", NULL, NULL, NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        spa_list_append(&core->remote_list, &this->link);
 | 
					        spa_list_append(&core->remote_list, &this->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -218,7 +218,7 @@ static bool do_load_module(struct data *data, const char *cmd, char *args, char
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	module = pw_module_load(data->core, a[0], n == 2 ? a[1] : NULL);
 | 
						module = pw_module_load(data->core, a[0], n == 2 ? a[1] : NULL, NULL, NULL, NULL);
 | 
				
			||||||
	if (module == NULL) {
 | 
						if (module == NULL) {
 | 
				
			||||||
		asprintf(error, "Could not load module");
 | 
							asprintf(error, "Could not load module");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
| 
						 | 
					@ -1116,7 +1116,7 @@ int main(int argc, char *argv[])
 | 
				
			||||||
	data.t = pw_core_get_type(data.core);
 | 
						data.t = pw_core_get_type(data.core);
 | 
				
			||||||
	info = pw_core_get_info(data.core);
 | 
						info = pw_core_get_info(data.core);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_module_load(data.core, "libpipewire-module-link-factory", NULL);
 | 
						pw_module_load(data.core, "libpipewire-module-link-factory", NULL, NULL, NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_loop_add_io(l, STDIN_FILENO, SPA_IO_IN|SPA_IO_HUP, false, do_input, &data);
 | 
						pw_loop_add_io(l, STDIN_FILENO, SPA_IO_IN|SPA_IO_HUP, false, do_input, &data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue