mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	media-session: add info logging to profile restore logic
This commit is contained in:
		
							parent
							
								
									b2e4f1358d
								
							
						
					
					
						commit
						b8bac95dad
					
				
					 1 changed files with 42 additions and 12 deletions
				
			
		| 
						 | 
					@ -69,6 +69,7 @@ struct device {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t id;
 | 
						uint32_t id;
 | 
				
			||||||
	struct impl *impl;
 | 
						struct impl *impl;
 | 
				
			||||||
 | 
						char *name;
 | 
				
			||||||
	char *key;
 | 
						char *key;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct spa_hook listener;
 | 
						struct spa_hook listener;
 | 
				
			||||||
| 
						 | 
					@ -213,7 +214,7 @@ static int find_saved_profile(struct device *dev, struct profile *pr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	json = pw_properties_get(impl->properties, dev->key);
 | 
						json = pw_properties_get(impl->properties, dev->key);
 | 
				
			||||||
	if (json == NULL)
 | 
						if (json == NULL)
 | 
				
			||||||
		return -ENOENT;
 | 
							return -ENODEV;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_json_init(&it[0], json, strlen(json));
 | 
						spa_json_init(&it[0], json, strlen(json));
 | 
				
			||||||
	if (spa_json_enter_object(&it[0], &it[1]) <= 0)
 | 
						if (spa_json_enter_object(&it[0], &it[1]) <= 0)
 | 
				
			||||||
| 
						 | 
					@ -228,7 +229,7 @@ static int find_saved_profile(struct device *dev, struct profile *pr)
 | 
				
			||||||
                                break;
 | 
					                                break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	pw_log_debug("device %d: find profile '%s'", dev->id, name);
 | 
						pw_log_debug("device '%s': find profile '%s'", dev->name, name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_for_each(p, &dev->obj->param_list, link) {
 | 
						spa_list_for_each(p, &dev->obj->param_list, link) {
 | 
				
			||||||
		if (p->id != SPA_PARAM_EnumProfile ||
 | 
							if (p->id != SPA_PARAM_EnumProfile ||
 | 
				
			||||||
| 
						 | 
					@ -246,9 +247,6 @@ static int set_profile(struct device *dev, struct profile *pr)
 | 
				
			||||||
	char buf[1024];
 | 
						char buf[1024];
 | 
				
			||||||
	struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
 | 
						struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_log_info("device %d: restore profile '%s' index %d",
 | 
					 | 
				
			||||||
			dev->id, pr->name, pr->index);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pw_device_set_param((struct pw_device*)dev->obj->obj.proxy,
 | 
						pw_device_set_param((struct pw_device*)dev->obj->obj.proxy,
 | 
				
			||||||
			SPA_PARAM_Profile, 0,
 | 
								SPA_PARAM_Profile, 0,
 | 
				
			||||||
			spa_pod_builder_add_object(&b,
 | 
								spa_pod_builder_add_object(&b,
 | 
				
			||||||
| 
						 | 
					@ -267,22 +265,52 @@ static int handle_profile(struct device *dev)
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (dev->active_profile != SPA_ID_INVALID) {
 | 
						if (dev->active_profile != SPA_ID_INVALID) {
 | 
				
			||||||
		/* we had a profile but it is now gone or not available,
 | 
							/* we have a profile, find it */
 | 
				
			||||||
		 * try to restore a new profile */
 | 
					 | 
				
			||||||
		res = find_profile(dev, dev->active_profile, &pr);
 | 
							res = find_profile(dev, dev->active_profile, &pr);
 | 
				
			||||||
		if (res < 0 || pr.available == SPA_PARAM_AVAILABILITY_no)
 | 
							if (res < 0 || pr.available == SPA_PARAM_AVAILABILITY_no) {
 | 
				
			||||||
 | 
								/* we had a profile but it is now gone or not available,
 | 
				
			||||||
 | 
								 * try to restore a new profile */
 | 
				
			||||||
 | 
								if (res < 0)
 | 
				
			||||||
 | 
									pw_log_info("device '%s': active profile index %d removed",
 | 
				
			||||||
 | 
										dev->name, dev->active_profile);
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									pw_log_info("device '%s': active profile '%s' unavailable",
 | 
				
			||||||
 | 
										dev->name, pr.name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			dev->restored = false;
 | 
								dev->restored = false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (!dev->restored) {
 | 
						if (!dev->restored) {
 | 
				
			||||||
		/* first try to restore our saved profile */
 | 
							/* first try to restore our saved profile */
 | 
				
			||||||
		res = find_saved_profile(dev, &pr);
 | 
							res = find_saved_profile(dev, &pr);
 | 
				
			||||||
		if (res < 0 || pr.available == SPA_PARAM_AVAILABILITY_no)
 | 
							if (res < 0 || pr.available == SPA_PARAM_AVAILABILITY_no) {
 | 
				
			||||||
			/* it's not found or not available, try to find
 | 
								/* no saved profile found or it is not available */
 | 
				
			||||||
			 * the next best profile */
 | 
								if (res < 0)
 | 
				
			||||||
 | 
									pw_log_info("device '%s': no saved profile: %s",
 | 
				
			||||||
 | 
										dev->name, spa_strerror(res));
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									pw_log_info("device '%s': saved profile '%s' unavailable",
 | 
				
			||||||
 | 
										dev->name, pr.name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* try to find the next best profile */
 | 
				
			||||||
			res = find_best_profile(dev, &pr);
 | 
								res = find_best_profile(dev, &pr);
 | 
				
			||||||
 | 
								if (res < 0)
 | 
				
			||||||
 | 
									pw_log_info("device '%s': can't find best profile: %s",
 | 
				
			||||||
 | 
											dev->name, spa_strerror(res));
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									pw_log_info("device '%s': found best profile '%s'",
 | 
				
			||||||
 | 
											dev->name, pr.name);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								pw_log_info("device '%s': found saved profile '%s'",
 | 
				
			||||||
 | 
											dev->name, pr.name);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if (res >= 0) {
 | 
							if (res >= 0) {
 | 
				
			||||||
 | 
								pw_log_info("device '%s': restore profile '%s' index %d",
 | 
				
			||||||
 | 
										dev->name, pr.name, pr.index);
 | 
				
			||||||
			if (set_profile(dev, &pr) >= 0)
 | 
								if (set_profile(dev, &pr) >= 0)
 | 
				
			||||||
				dev->restored = true;
 | 
									dev->restored = true;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								pw_log_warn("device '%s': can't restore profile", dev->name);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if ((res = find_current_profile(dev, &pr)) < 0)
 | 
							if ((res = find_current_profile(dev, &pr)) < 0)
 | 
				
			||||||
| 
						 | 
					@ -292,7 +320,7 @@ static int handle_profile(struct device *dev)
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		dev->active_profile = pr.index;
 | 
							dev->active_profile = pr.index;
 | 
				
			||||||
		pw_log_info("device %d: current profile %d %s", dev->id, pr.index, pr.name);
 | 
							pw_log_info("device '%s': active profile changed to '%s'", dev->name, pr.name);
 | 
				
			||||||
		pw_properties_setf(impl->properties, dev->key, "{ \"name\": \"%s\" }", pr.name);
 | 
							pw_properties_setf(impl->properties, dev->key, "{ \"name\": \"%s\" }", pr.name);
 | 
				
			||||||
		add_idle_timeout(impl);
 | 
							add_idle_timeout(impl);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -339,6 +367,7 @@ static void session_create(void *data, struct sm_object *object)
 | 
				
			||||||
	dev->obj = (struct sm_device*)object;
 | 
						dev->obj = (struct sm_device*)object;
 | 
				
			||||||
	dev->id = object->id;
 | 
						dev->id = object->id;
 | 
				
			||||||
	dev->impl = impl;
 | 
						dev->impl = impl;
 | 
				
			||||||
 | 
						dev->name = strdup(name);
 | 
				
			||||||
	dev->key = spa_aprintf(PREFIX"%s", name);
 | 
						dev->key = spa_aprintf(PREFIX"%s", name);
 | 
				
			||||||
	dev->active_profile = SPA_ID_INVALID;
 | 
						dev->active_profile = SPA_ID_INVALID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -349,6 +378,7 @@ static void session_create(void *data, struct sm_object *object)
 | 
				
			||||||
static void destroy_device(struct impl *impl, struct device *dev)
 | 
					static void destroy_device(struct impl *impl, struct device *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	spa_hook_remove(&dev->listener);
 | 
						spa_hook_remove(&dev->listener);
 | 
				
			||||||
 | 
						free(dev->name);
 | 
				
			||||||
	free(dev->key);
 | 
						free(dev->key);
 | 
				
			||||||
	sm_object_remove_data((struct sm_object*)dev->obj, SESSION_KEY);
 | 
						sm_object_remove_data((struct sm_object*)dev->obj, SESSION_KEY);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue