mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	core: make pw_core_for_each_global more powerful
Make the for_each function more powerful by allowing more than just a bool return value.
This commit is contained in:
		
							parent
							
								
									1f4d1d071c
								
							
						
					
					
						commit
						ef800581f0
					
				
					 4 changed files with 28 additions and 24 deletions
				
			
		| 
						 | 
					@ -1286,7 +1286,7 @@ make_freewheel_client(struct impl *impl)
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool on_global(void *data, struct pw_global *global)
 | 
					static int on_global(void *data, struct pw_global *global)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl *impl = data;
 | 
						struct impl *impl = data;
 | 
				
			||||||
	struct pw_node *node;
 | 
						struct pw_node *node;
 | 
				
			||||||
| 
						 | 
					@ -1300,21 +1300,21 @@ static bool on_global(void *data, struct pw_global *global)
 | 
				
			||||||
	struct spa_pod *props;
 | 
						struct spa_pod *props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pw_global_get_type(global) != impl->t->node)
 | 
						if (pw_global_get_type(global) != impl->t->node)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	node = pw_global_get_object(global);
 | 
						node = pw_global_get_object(global);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	properties = pw_node_get_properties(node);
 | 
						properties = pw_node_get_properties(node);
 | 
				
			||||||
	if ((str = pw_properties_get(properties, "media.class")) == NULL)
 | 
						if ((str = pw_properties_get(properties, "media.class")) == NULL)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcmp(str, "Audio/Sink") != 0)
 | 
						if (strcmp(str, "Audio/Sink") != 0)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	out_port = pw_node_get_free_port(impl->server.audio_node->node, PW_DIRECTION_OUTPUT);
 | 
						out_port = pw_node_get_free_port(impl->server.audio_node->node, PW_DIRECTION_OUTPUT);
 | 
				
			||||||
	in_port = pw_node_get_free_port(node, PW_DIRECTION_INPUT);
 | 
						in_port = pw_node_get_free_port(node, PW_DIRECTION_INPUT);
 | 
				
			||||||
	if (out_port == NULL || in_port == NULL)
 | 
						if (out_port == NULL || in_port == NULL)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl->sink_link = pw_link_new(impl->core,
 | 
						impl->sink_link = pw_link_new(impl->core,
 | 
				
			||||||
		    out_port,
 | 
							    out_port,
 | 
				
			||||||
| 
						 | 
					@ -1326,7 +1326,7 @@ static bool on_global(void *data, struct pw_global *global)
 | 
				
			||||||
	if (impl->sink_link == NULL) {
 | 
						if (impl->sink_link == NULL) {
 | 
				
			||||||
		pw_log_warn("can't link ports: %s", error);
 | 
							pw_log_warn("can't link ports: %s", error);
 | 
				
			||||||
		free(error);
 | 
							free(error);
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (spa_node_enum_params(node->node, impl->t->param.idProps, &index, NULL, &props, &b) == 1) {
 | 
						if (spa_node_enum_params(node->node, impl->t->param.idProps, &index, NULL, &props, &b) == 1) {
 | 
				
			||||||
| 
						 | 
					@ -1343,7 +1343,7 @@ static bool on_global(void *data, struct pw_global *global)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_link_register(impl->sink_link, NULL, pw_module_get_global(impl->module));
 | 
						pw_link_register(impl->sink_link, NULL, pw_module_get_global(impl->module));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return false;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool init_nodes(struct impl *impl)
 | 
					static bool init_nodes(struct impl *impl)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -138,7 +138,7 @@ static struct pw_node *make_node(struct impl *impl)
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool on_global(void *data, struct pw_global *global)
 | 
					static int on_global(void *data, struct pw_global *global)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl *impl = data;
 | 
						struct impl *impl = data;
 | 
				
			||||||
	struct pw_node *n, *node;
 | 
						struct pw_node *n, *node;
 | 
				
			||||||
| 
						 | 
					@ -149,24 +149,24 @@ static bool on_global(void *data, struct pw_global *global)
 | 
				
			||||||
	struct pw_link *link;
 | 
						struct pw_link *link;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pw_global_get_type(global) != impl->t->node)
 | 
						if (pw_global_get_type(global) != impl->t->node)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	n = pw_global_get_object(global);
 | 
						n = pw_global_get_object(global);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	properties = pw_node_get_properties(n);
 | 
						properties = pw_node_get_properties(n);
 | 
				
			||||||
	if ((str = pw_properties_get(properties, "media.class")) == NULL)
 | 
						if ((str = pw_properties_get(properties, "media.class")) == NULL)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (strcmp(str, "Audio/Sink") != 0)
 | 
						if (strcmp(str, "Audio/Sink") != 0)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((ip = pw_node_get_free_port(n, PW_DIRECTION_INPUT)) == NULL)
 | 
						if ((ip = pw_node_get_free_port(n, PW_DIRECTION_INPUT)) == NULL)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	node = make_node(impl);
 | 
						node = make_node(impl);
 | 
				
			||||||
	op = pw_node_get_free_port(node, PW_DIRECTION_OUTPUT);
 | 
						op = pw_node_get_free_port(node, PW_DIRECTION_OUTPUT);
 | 
				
			||||||
	if (op == NULL)
 | 
						if (op == NULL)
 | 
				
			||||||
		return true;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	link = pw_link_new(impl->core,
 | 
						link = pw_link_new(impl->core,
 | 
				
			||||||
			   op,
 | 
								   op,
 | 
				
			||||||
| 
						 | 
					@ -176,7 +176,7 @@ static bool on_global(void *data, struct pw_global *global)
 | 
				
			||||||
			   &error, 0);
 | 
								   &error, 0);
 | 
				
			||||||
	pw_link_register(link, NULL, pw_module_get_global(impl->module));
 | 
						pw_link_register(link, NULL, pw_module_get_global(impl->module));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void module_destroy(void *data)
 | 
					static void module_destroy(void *data)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -596,16 +596,17 @@ void pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict
 | 
				
			||||||
	core->info.change_mask = 0;
 | 
						core->info.change_mask = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool pw_core_for_each_global(struct pw_core *core,
 | 
					int pw_core_for_each_global(struct pw_core *core,
 | 
				
			||||||
			     bool (*callback) (void *data, struct pw_global *global),
 | 
								    int (*callback) (void *data, struct pw_global *global),
 | 
				
			||||||
			    void *data)
 | 
								    void *data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct pw_global *g, *t;
 | 
						struct pw_global *g, *t;
 | 
				
			||||||
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_for_each_safe(g, t, &core->global_list, link)
 | 
						spa_list_for_each_safe(g, t, &core->global_list, link)
 | 
				
			||||||
		if (!callback(data, g))
 | 
							if ((res = callback(data, g)) != 0)
 | 
				
			||||||
			return false;
 | 
								return res;
 | 
				
			||||||
	return true;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct pw_global *pw_core_find_global(struct pw_core *core, uint32_t id)
 | 
					struct pw_global *pw_core_find_global(struct pw_core *core, uint32_t id)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,9 +151,12 @@ const struct spa_support *pw_core_get_support(struct pw_core *core, uint32_t *n_
 | 
				
			||||||
/** get the core main loop */
 | 
					/** get the core main loop */
 | 
				
			||||||
struct pw_loop *pw_core_get_main_loop(struct pw_core *core);
 | 
					struct pw_loop *pw_core_get_main_loop(struct pw_core *core);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** iterate the globals */
 | 
					/** Iterate the globals of the core. The callback should return
 | 
				
			||||||
bool pw_core_for_each_global(struct pw_core *core,
 | 
					 * 0 to fetch the next item, any other value stops the iteration and returns
 | 
				
			||||||
			     bool (*callback) (void *data, struct pw_global *global),
 | 
					 * the value. When all callbacks return 0, this function returns 0 when all
 | 
				
			||||||
 | 
					 * globals are iterated. */
 | 
				
			||||||
 | 
					int pw_core_for_each_global(struct pw_core *core,
 | 
				
			||||||
 | 
								    int (*callback) (void *data, struct pw_global *global),
 | 
				
			||||||
			    void *data);
 | 
								    void *data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Find a core global by id */
 | 
					/** Find a core global by id */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue