mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	module-raop: fix deduplication
Also check duplicate entries in the resolve callback because we might not have created a tunnel earlier.
This commit is contained in:
		
							parent
							
								
									6b6f3432fe
								
							
						
					
					
						commit
						14fd7f7bf7
					
				
					 1 changed files with 26 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -171,7 +171,14 @@ static struct tunnel *find_tunnel(struct impl *impl, const struct tunnel_info *i
 | 
			
		|||
 | 
			
		||||
static void free_tunnel(struct tunnel *t)
 | 
			
		||||
{
 | 
			
		||||
	spa_list_remove(&t->link);
 | 
			
		||||
	if (t->module)
 | 
			
		||||
		pw_impl_module_destroy(t->module);
 | 
			
		||||
	free((char *) t->info.name);
 | 
			
		||||
	free((char *) t->info.host_name);
 | 
			
		||||
	free((char *) t->info.ip);
 | 
			
		||||
	free((char *) t->info.port);
 | 
			
		||||
	free(t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void impl_free(struct impl *impl)
 | 
			
		||||
| 
						 | 
				
			
			@ -284,16 +291,8 @@ static void pw_properties_from_avahi_string(const char *key, const char *value,
 | 
			
		|||
static void submodule_destroy(void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct tunnel *t = data;
 | 
			
		||||
 | 
			
		||||
	spa_list_remove(&t->link);
 | 
			
		||||
	spa_hook_remove(&t->module_listener);
 | 
			
		||||
 | 
			
		||||
	free((char *) t->info.name);
 | 
			
		||||
	free((char *) t->info.host_name);
 | 
			
		||||
	free((char *) t->info.ip);
 | 
			
		||||
	free((char *) t->info.port);
 | 
			
		||||
 | 
			
		||||
	free(t);
 | 
			
		||||
	t->module = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_impl_module_events submodule_events = {
 | 
			
		||||
| 
						 | 
				
			
			@ -304,19 +303,18 @@ static const struct pw_impl_module_events submodule_events = {
 | 
			
		|||
struct match_info {
 | 
			
		||||
	struct impl *impl;
 | 
			
		||||
	struct pw_properties *props;
 | 
			
		||||
	struct tunnel_info *tinfo;
 | 
			
		||||
	struct tunnel *tunnel;
 | 
			
		||||
	bool matched;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int create_stream(struct impl *impl, struct pw_properties *props,
 | 
			
		||||
		struct tunnel_info *tinfo)
 | 
			
		||||
		struct tunnel *t)
 | 
			
		||||
{
 | 
			
		||||
	FILE *f;
 | 
			
		||||
	char *args;
 | 
			
		||||
	size_t size;
 | 
			
		||||
	int res = 0;
 | 
			
		||||
	struct pw_impl_module *mod;
 | 
			
		||||
	struct tunnel *t;
 | 
			
		||||
 | 
			
		||||
	if ((f = open_memstream(&args, &size)) == NULL) {
 | 
			
		||||
		res = -errno;
 | 
			
		||||
| 
						 | 
				
			
			@ -341,16 +339,7 @@ static int create_stream(struct impl *impl, struct pw_properties *props,
 | 
			
		|||
                goto done;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	t = make_tunnel(impl, tinfo);
 | 
			
		||||
	if (t == NULL) {
 | 
			
		||||
		res = -errno;
 | 
			
		||||
		pw_log_error("Can't make tunnel: %m");
 | 
			
		||||
		pw_impl_module_destroy(mod);
 | 
			
		||||
		goto done;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pw_impl_module_add_listener(mod, &t->module_listener, &submodule_events, t);
 | 
			
		||||
 | 
			
		||||
	t->module = mod;
 | 
			
		||||
done:
 | 
			
		||||
	return res;
 | 
			
		||||
| 
						 | 
				
			
			@ -365,7 +354,7 @@ static int rule_matched(void *data, const char *location, const char *action,
 | 
			
		|||
	i->matched = true;
 | 
			
		||||
	if (spa_streq(action, "create-stream")) {
 | 
			
		||||
		pw_properties_update_string(i->props, str, len);
 | 
			
		||||
		create_stream(i->impl, i->props, i->tinfo);
 | 
			
		||||
		create_stream(i->impl, i->props, i->tunnel);
 | 
			
		||||
	}
 | 
			
		||||
	return res;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -377,6 +366,7 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
 | 
			
		|||
{
 | 
			
		||||
	struct impl *impl = userdata;
 | 
			
		||||
	struct tunnel_info tinfo;
 | 
			
		||||
	struct tunnel *t;
 | 
			
		||||
	const char *str, *port_str;
 | 
			
		||||
	AvahiStringList *l;
 | 
			
		||||
	struct pw_properties *props = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -419,6 +409,17 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
 | 
			
		|||
			.host_name = host_name,
 | 
			
		||||
			.ip = at,
 | 
			
		||||
			.port = port_str);
 | 
			
		||||
	t = find_tunnel(impl, &tinfo);
 | 
			
		||||
	if (t == NULL)
 | 
			
		||||
		t = make_tunnel(impl, &tinfo);
 | 
			
		||||
	if (t == NULL) {
 | 
			
		||||
		pw_log_error("Can't make tunnel: %m");
 | 
			
		||||
		goto done;
 | 
			
		||||
	}
 | 
			
		||||
	if (t->module != NULL) {
 | 
			
		||||
		pw_log_info("found duplicate mdns entry - skipping tunnel creation");
 | 
			
		||||
		goto done;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if ((str = pw_properties_get(impl->properties, "stream.rules")) == NULL)
 | 
			
		||||
		str = DEFAULT_CREATE_RULES;
 | 
			
		||||
| 
						 | 
				
			
			@ -426,7 +427,7 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
 | 
			
		|||
		struct match_info minfo = {
 | 
			
		||||
			.impl = impl,
 | 
			
		||||
			.props = props,
 | 
			
		||||
			.tinfo = &tinfo,
 | 
			
		||||
			.tunnel = t,
 | 
			
		||||
		};
 | 
			
		||||
		pw_conf_match_rules(str, strlen(str), NAME, &props->dict,
 | 
			
		||||
				rule_matched, &minfo);
 | 
			
		||||
| 
						 | 
				
			
			@ -459,7 +460,7 @@ static void browser_cb(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProt
 | 
			
		|||
	switch (event) {
 | 
			
		||||
	case AVAHI_BROWSER_NEW:
 | 
			
		||||
		if (t != NULL) {
 | 
			
		||||
			pw_log_debug("found duplicate mdns entry - skipping tunnel creation");
 | 
			
		||||
			pw_log_info("found duplicate mdns entry - skipping tunnel creation");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		if (!(avahi_service_resolver_new(impl->client,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue