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,18 +112,18 @@ bool collect_is_linked(struct pw_manager *m, uint32_t id, enum pw_direction dire
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t id, enum pw_direction direction)
 | 
					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 *o, *p;
 | 
						struct pw_manager_object *p;
 | 
				
			||||||
	uint32_t in_node, out_node;
 | 
						uint32_t in_node, out_node;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_for_each(o, &m->object_list, link) {
 | 
						if (o->props == NULL)
 | 
				
			||||||
		if (o->props == NULL || !pw_manager_object_is_link(o))
 | 
							return NULL;
 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pw_properties_fetch_uint32(o->props, PW_KEY_LINK_OUTPUT_NODE, &out_node) != 0 ||
 | 
						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)
 | 
						    pw_properties_fetch_uint32(o->props, PW_KEY_LINK_INPUT_NODE, &in_node) != 0)
 | 
				
			||||||
                        continue;
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (direction == PW_DIRECTION_OUTPUT && id == out_node) {
 | 
						if (direction == PW_DIRECTION_OUTPUT && id == out_node) {
 | 
				
			||||||
		struct selector sel = { .id = in_node, .type = pw_manager_object_is_sink, };
 | 
							struct selector sel = { .id = in_node, .type = pw_manager_object_is_sink, };
 | 
				
			||||||
| 
						 | 
					@ -135,6 +135,18 @@ struct pw_manager_object *find_linked(struct pw_manager *m, uint32_t id, enum pw
 | 
				
			||||||
		if ((p = select_object(m, &sel)) != NULL)
 | 
							if ((p = select_object(m, &sel)) != NULL)
 | 
				
			||||||
			return p;
 | 
								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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_list_for_each(o, &m->object_list, link) {
 | 
				
			||||||
 | 
							if (!pw_manager_object_is_link(o))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if ((p = find_peer_for_link(m, o, id, direction)) != NULL)
 | 
				
			||||||
 | 
								return p;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return NULL;
 | 
						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);
 | 
					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_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);
 | 
					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);
 | 
					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);
 | 
					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 stream *s;
 | 
				
			||||||
		struct pw_manager_object *peer = NULL;
 | 
							struct pw_manager_object *peer = NULL;
 | 
				
			||||||
		spa_list_for_each(s, &client->pending_streams, link) {
 | 
							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)
 | 
								if (peer)
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue