mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	Revert "default-profile: keep a restore and save list"
This reverts commit de71618b99.
Doesn't work when the device is removed and added again.
			
			
This commit is contained in:
		
							parent
							
								
									d337abf690
								
							
						
					
					
						commit
						e544f82004
					
				
					 1 changed files with 28 additions and 29 deletions
				
			
		| 
						 | 
					@ -59,8 +59,7 @@ struct impl {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct spa_hook meta_listener;
 | 
						struct spa_hook meta_listener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct pw_properties *to_restore;
 | 
						struct pw_properties *properties;
 | 
				
			||||||
	struct pw_properties *to_save;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct device {
 | 
					struct device {
 | 
				
			||||||
| 
						 | 
					@ -71,6 +70,10 @@ struct device {
 | 
				
			||||||
	char *name;
 | 
						char *name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct spa_hook listener;
 | 
						struct spa_hook listener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned int restored:1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t active_profile;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct find_data {
 | 
					struct find_data {
 | 
				
			||||||
| 
						 | 
					@ -85,7 +88,7 @@ static void remove_idle_timeout(struct impl *impl)
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (impl->idle_timeout) {
 | 
						if (impl->idle_timeout) {
 | 
				
			||||||
		if ((res = sm_media_session_save_state(impl->session, SESSION_KEY, impl->to_save)) < 0)
 | 
							if ((res = sm_media_session_save_state(impl->session, SESSION_KEY, impl->properties)) < 0)
 | 
				
			||||||
			pw_log_error("can't save "SESSION_KEY" state: %s", spa_strerror(res));
 | 
								pw_log_error("can't save "SESSION_KEY" state: %s", spa_strerror(res));
 | 
				
			||||||
		pw_loop_destroy_source(main_loop, impl->idle_timeout);
 | 
							pw_loop_destroy_source(main_loop, impl->idle_timeout);
 | 
				
			||||||
		impl->idle_timeout = NULL;
 | 
							impl->idle_timeout = NULL;
 | 
				
			||||||
| 
						 | 
					@ -117,8 +120,7 @@ static void session_destroy(void *data)
 | 
				
			||||||
	struct impl *impl = data;
 | 
						struct impl *impl = data;
 | 
				
			||||||
	remove_idle_timeout(impl);
 | 
						remove_idle_timeout(impl);
 | 
				
			||||||
	spa_hook_remove(&impl->listener);
 | 
						spa_hook_remove(&impl->listener);
 | 
				
			||||||
	pw_properties_free(impl->to_restore);
 | 
						pw_properties_free(impl->properties);
 | 
				
			||||||
	pw_properties_free(impl->to_save);
 | 
					 | 
				
			||||||
	free(impl);
 | 
						free(impl);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -142,10 +144,16 @@ static uint32_t find_profile_id(struct device *dev, const char *name)
 | 
				
			||||||
	return SPA_ID_INVALID;
 | 
						return SPA_ID_INVALID;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int restore_profile(struct device *dev, const char *name)
 | 
					static int restore_profile(struct device *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct impl *impl = dev->impl;
 | 
				
			||||||
 | 
						const char *name;
 | 
				
			||||||
	uint32_t index = SPA_ID_INVALID;
 | 
						uint32_t index = SPA_ID_INVALID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						name = pw_properties_get(impl->properties, dev->name);
 | 
				
			||||||
 | 
						if (name == NULL)
 | 
				
			||||||
 | 
							return -ENOENT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_log_debug("device %d: find profile '%s'", dev->id, name);
 | 
						pw_log_debug("device %d: find profile '%s'", dev->id, name);
 | 
				
			||||||
	index = find_profile_id(dev, name);
 | 
						index = find_profile_id(dev, name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -159,6 +167,7 @@ static int restore_profile(struct device *dev, const char *name)
 | 
				
			||||||
				spa_pod_builder_add_object(&b,
 | 
									spa_pod_builder_add_object(&b,
 | 
				
			||||||
					SPA_TYPE_OBJECT_ParamProfile, SPA_PARAM_Profile,
 | 
										SPA_TYPE_OBJECT_ParamProfile, SPA_PARAM_Profile,
 | 
				
			||||||
					SPA_PARAM_PROFILE_index, SPA_POD_Int(index)));
 | 
										SPA_PARAM_PROFILE_index, SPA_POD_Int(index)));
 | 
				
			||||||
 | 
							dev->active_profile = index;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return -ENOENT;
 | 
						return -ENOENT;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -166,14 +175,12 @@ static int restore_profile(struct device *dev, const char *name)
 | 
				
			||||||
static int handle_profile(struct device *dev, struct sm_param *p)
 | 
					static int handle_profile(struct device *dev, struct sm_param *p)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct impl *impl = dev->impl;
 | 
						struct impl *impl = dev->impl;
 | 
				
			||||||
	const char *name;
 | 
					 | 
				
			||||||
	uint32_t index;
 | 
						uint32_t index;
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	name = pw_properties_get(impl->to_restore, dev->name);
 | 
						if (!dev->restored) {
 | 
				
			||||||
	if (name) {
 | 
							restore_profile(dev);
 | 
				
			||||||
		restore_profile(dev, name);
 | 
							dev->restored = true;
 | 
				
			||||||
		pw_properties_set(impl->to_restore, dev->name, NULL);
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		const char *name;
 | 
							const char *name;
 | 
				
			||||||
		if ((res = spa_pod_parse_object(p->param,
 | 
							if ((res = spa_pod_parse_object(p->param,
 | 
				
			||||||
| 
						 | 
					@ -183,8 +190,12 @@ static int handle_profile(struct device *dev, struct sm_param *p)
 | 
				
			||||||
			pw_log_warn("device %d: can't parse profile: %s", dev->id, spa_strerror(res));
 | 
								pw_log_warn("device %d: can't parse profile: %s", dev->id, spa_strerror(res));
 | 
				
			||||||
			return res;
 | 
								return res;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (dev->active_profile == index)
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							dev->active_profile = index;
 | 
				
			||||||
		pw_log_debug("device %d: current profile %d %s", dev->id, index, name);
 | 
							pw_log_debug("device %d: current profile %d %s", dev->id, index, name);
 | 
				
			||||||
		pw_properties_set(impl->to_save, dev->name, name);
 | 
							pw_properties_set(impl->properties, dev->name, name);
 | 
				
			||||||
		add_idle_timeout(impl);
 | 
							add_idle_timeout(impl);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
| 
						 | 
					@ -284,28 +295,16 @@ int sm_default_profile_start(struct sm_media_session *session)
 | 
				
			||||||
	impl->session = session;
 | 
						impl->session = session;
 | 
				
			||||||
	impl->context = session->context;
 | 
						impl->context = session->context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl->to_restore = pw_properties_new(NULL, NULL);
 | 
						impl->properties = pw_properties_new(NULL, NULL);
 | 
				
			||||||
	if (impl->to_restore == NULL) {
 | 
						if (impl->properties == NULL) {
 | 
				
			||||||
		res = -errno;
 | 
							free(impl);
 | 
				
			||||||
		goto exit_free;
 | 
							return -ENOMEM;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((res = sm_media_session_load_state(impl->session, SESSION_KEY, impl->to_restore)) < 0)
 | 
						if ((res = sm_media_session_load_state(impl->session, SESSION_KEY, impl->properties)) < 0)
 | 
				
			||||||
		pw_log_info("can't load "SESSION_KEY" state: %s", spa_strerror(res));
 | 
							pw_log_info("can't load "SESSION_KEY" state: %s", spa_strerror(res));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl->to_save = pw_properties_copy(impl->to_restore);
 | 
					 | 
				
			||||||
	if (impl->to_save == NULL) {
 | 
					 | 
				
			||||||
		res = -errno;
 | 
					 | 
				
			||||||
		goto exit_free_props;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	sm_media_session_add_listener(impl->session, &impl->listener, &session_events, impl);
 | 
						sm_media_session_add_listener(impl->session, &impl->listener, &session_events, impl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					 | 
				
			||||||
exit_free_props:
 | 
					 | 
				
			||||||
	pw_properties_free(impl->to_restore);
 | 
					 | 
				
			||||||
exit_free:
 | 
					 | 
				
			||||||
	free(impl);
 | 
					 | 
				
			||||||
	return res;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue