mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	module-metadata: allow create without client
Which will create a new impl-metadata object.
This commit is contained in:
		
							parent
							
								
									afa0f9305d
								
							
						
					
					
						commit
						d19ab798be
					
				
					 2 changed files with 45 additions and 21 deletions
				
			
		| 
						 | 
					@ -74,43 +74,70 @@ static void *create_object(void *_data,
 | 
				
			||||||
			   uint32_t new_id)
 | 
								   uint32_t new_id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct factory_data *data = _data;
 | 
						struct factory_data *data = _data;
 | 
				
			||||||
 | 
						struct pw_context *context = pw_impl_module_get_context(data->module);
 | 
				
			||||||
	void *result;
 | 
						void *result;
 | 
				
			||||||
	struct pw_resource *metadata_resource;
 | 
						struct pw_resource *metadata_resource = NULL;
 | 
				
			||||||
	struct pw_impl_client *client = pw_resource_get_client(resource);
 | 
						struct pw_impl_client *client = resource ? pw_resource_get_client(resource) : NULL;
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	metadata_resource = pw_resource_new(client, new_id, PW_PERM_ALL, type, version, 0);
 | 
						if (properties == NULL)
 | 
				
			||||||
	if (metadata_resource == NULL) {
 | 
							properties = pw_properties_new(NULL, NULL);
 | 
				
			||||||
		res = -errno;
 | 
						if (properties == NULL)
 | 
				
			||||||
		goto error_resource;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
					
 | 
				
			||||||
 | 
						pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d",
 | 
				
			||||||
 | 
								pw_impl_factory_get_info(data->this)->id);
 | 
				
			||||||
 | 
						pw_properties_setf(properties, PW_KEY_MODULE_ID, "%d",
 | 
				
			||||||
 | 
								pw_impl_module_get_info(data->module)->id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (pw_properties_get(properties, PW_KEY_METADATA_NAME) == NULL)
 | 
				
			||||||
 | 
							pw_properties_set(properties, PW_KEY_METADATA_NAME, "default");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (client) {
 | 
				
			||||||
 | 
							metadata_resource = pw_resource_new(client, new_id, PW_PERM_ALL, type, version, 0);
 | 
				
			||||||
 | 
							if (metadata_resource == NULL) {
 | 
				
			||||||
 | 
								res = -errno;
 | 
				
			||||||
 | 
								goto error_resource;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (properties) {
 | 
					 | 
				
			||||||
		pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d",
 | 
					 | 
				
			||||||
				pw_impl_factory_get_info(data->this)->id);
 | 
					 | 
				
			||||||
		pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d",
 | 
							pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d",
 | 
				
			||||||
				pw_impl_client_get_info(client)->id);
 | 
									pw_impl_client_get_info(client)->id);
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result = pw_metadata_new(pw_impl_client_get_context(client), metadata_resource, properties);
 | 
							result = pw_metadata_new(context, metadata_resource, properties);
 | 
				
			||||||
	if (result == NULL) {
 | 
							if (result == NULL) {
 | 
				
			||||||
		res = -errno;
 | 
								properties = NULL;
 | 
				
			||||||
		goto error_node;
 | 
								res = -errno;
 | 
				
			||||||
 | 
								goto error_node;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							result = pw_context_create_metadata(context, NULL, properties, 0);
 | 
				
			||||||
 | 
							if (result == NULL) {
 | 
				
			||||||
 | 
								properties = NULL;
 | 
				
			||||||
 | 
								res = -errno;
 | 
				
			||||||
 | 
								goto error_node;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							pw_impl_metadata_register(result, NULL);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error_resource:
 | 
					error_resource:
 | 
				
			||||||
	pw_log_error("can't create resource: %s", spa_strerror(res));
 | 
						pw_log_error("can't create resource: %s", spa_strerror(res));
 | 
				
			||||||
	pw_resource_errorf_id(resource, new_id, res, "can't create resource: %s", spa_strerror(res));
 | 
						if (resource)
 | 
				
			||||||
 | 
							pw_resource_errorf_id(resource, new_id, res,
 | 
				
			||||||
 | 
									"can't create resource: %s", spa_strerror(res));
 | 
				
			||||||
	goto error_exit;
 | 
						goto error_exit;
 | 
				
			||||||
error_node:
 | 
					error_node:
 | 
				
			||||||
	pw_log_error("can't create metadata: %s", spa_strerror(res));
 | 
						pw_log_error("can't create metadata: %s", spa_strerror(res));
 | 
				
			||||||
	pw_resource_errorf_id(resource, new_id, res, "can't create metadata: %s", spa_strerror(res));
 | 
						if (resource)
 | 
				
			||||||
 | 
							pw_resource_errorf_id(resource, new_id, res,
 | 
				
			||||||
 | 
									"can't create metadata: %s", spa_strerror(res));
 | 
				
			||||||
	goto error_exit_free;
 | 
						goto error_exit_free;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
error_exit_free:
 | 
					error_exit_free:
 | 
				
			||||||
	pw_resource_remove(metadata_resource);
 | 
						if (metadata_resource)
 | 
				
			||||||
 | 
							pw_resource_remove(metadata_resource);
 | 
				
			||||||
error_exit:
 | 
					error_exit:
 | 
				
			||||||
 | 
						pw_properties_free(properties);
 | 
				
			||||||
	errno = -res;
 | 
						errno = -res;
 | 
				
			||||||
	return NULL;
 | 
						return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -271,9 +271,6 @@ pw_metadata_new(struct pw_context *context, struct pw_resource *resource,
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pw_properties_get(properties, PW_KEY_METADATA_NAME) == NULL)
 | 
					 | 
				
			||||||
		pw_properties_set(properties, PW_KEY_METADATA_NAME, "default");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pw_resource_install_marshal(resource, true);
 | 
						pw_resource_install_marshal(resource, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl->global = pw_global_new(context,
 | 
						impl->global = pw_global_new(context,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue