mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pulse-server: optimize link finding
When we get a new link object, only check if a pending stream is linked according to the new link instead of iterating all links.
This commit is contained in:
		
							parent
							
								
									6c310cf5e2
								
							
						
					
					
						commit
						258a203d74
					
				
					 3 changed files with 32 additions and 18 deletions
				
			
		| 
						 | 
				
			
			@ -112,29 +112,41 @@ bool collect_is_linked(struct pw_manager *m, uint32_t id, enum pw_direction dire
 | 
			
		|||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct pw_manager_object *find_peer_for_link(struct pw_manager *m,
 | 
			
		||||
		struct pw_manager_object *o, uint32_t id, enum pw_direction direction)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_manager_object *p;
 | 
			
		||||
	uint32_t in_node, out_node;
 | 
			
		||||
 | 
			
		||||
	if (o->props == NULL)
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	if (pw_properties_fetch_uint32(o->props, PW_KEY_LINK_OUTPUT_NODE, &out_node) != 0 ||
 | 
			
		||||
	    pw_properties_fetch_uint32(o->props, PW_KEY_LINK_INPUT_NODE, &in_node) != 0)
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	if (direction == PW_DIRECTION_OUTPUT && id == out_node) {
 | 
			
		||||
		struct selector sel = { .id = in_node, .type = pw_manager_object_is_sink, };
 | 
			
		||||
		if ((p = select_object(m, &sel)) != NULL)
 | 
			
		||||
			return p;
 | 
			
		||||
	}
 | 
			
		||||
	if (direction == PW_DIRECTION_INPUT && id == in_node) {
 | 
			
		||||
		struct selector sel = { .id = out_node, .type = pw_manager_object_is_recordable, };
 | 
			
		||||
		if ((p = select_object(m, &sel)) != NULL)
 | 
			
		||||
			return p;
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_manager_object *o, *p;
 | 
			
		||||
	uint32_t in_node, out_node;
 | 
			
		||||
 | 
			
		||||
	spa_list_for_each(o, &m->object_list, link) {
 | 
			
		||||
		if (o->props == NULL || !pw_manager_object_is_link(o))
 | 
			
		||||
		if (!pw_manager_object_is_link(o))
 | 
			
		||||
			continue;
 | 
			
		||||
 | 
			
		||||
		if (pw_properties_fetch_uint32(o->props, PW_KEY_LINK_OUTPUT_NODE, &out_node) != 0 ||
 | 
			
		||||
                    pw_properties_fetch_uint32(o->props, PW_KEY_LINK_INPUT_NODE, &in_node) != 0)
 | 
			
		||||
                        continue;
 | 
			
		||||
 | 
			
		||||
		if (direction == PW_DIRECTION_OUTPUT && id == out_node) {
 | 
			
		||||
			struct selector sel = { .id = in_node, .type = pw_manager_object_is_sink, };
 | 
			
		||||
			if ((p = select_object(m, &sel)) != NULL)
 | 
			
		||||
				return p;
 | 
			
		||||
		}
 | 
			
		||||
		if (direction == PW_DIRECTION_INPUT && id == in_node) {
 | 
			
		||||
			struct selector sel = { .id = out_node, .type = pw_manager_object_is_recordable, };
 | 
			
		||||
			if ((p = select_object(m, &sel)) != NULL)
 | 
			
		||||
				return p;
 | 
			
		||||
		}
 | 
			
		||||
		if ((p = find_peer_for_link(m, o, id, direction)) != NULL)
 | 
			
		||||
			return p;
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -159,6 +159,8 @@ uint32_t collect_transport_codec_info(struct pw_manager_object *card,
 | 
			
		|||
struct spa_dict *collect_props(struct spa_pod *info, struct spa_dict *dict);
 | 
			
		||||
uint32_t find_profile_index(struct pw_manager_object *card, const char *name);
 | 
			
		||||
uint32_t find_port_index(struct pw_manager_object *card, uint32_t direction, const char *port_name);
 | 
			
		||||
struct pw_manager_object *find_peer_for_link(struct pw_manager *m,
 | 
			
		||||
		struct pw_manager_object *o, uint32_t id, enum pw_direction direction);
 | 
			
		||||
struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction);
 | 
			
		||||
bool collect_is_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -829,7 +829,7 @@ static void manager_added(void *data, struct pw_manager_object *o)
 | 
			
		|||
		struct stream *s;
 | 
			
		||||
		struct pw_manager_object *peer = NULL;
 | 
			
		||||
		spa_list_for_each(s, &client->pending_streams, link) {
 | 
			
		||||
			peer = find_linked(manager, s->id, s->direction);
 | 
			
		||||
			peer = find_peer_for_link(manager, o, s->id, s->direction);
 | 
			
		||||
			if (peer)
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue