mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	avoid including private.h
Expose some more methods to make it possible to build without including the private.h header, especially in modules.
This commit is contained in:
		
							parent
							
								
									8e6a5a1714
								
							
						
					
					
						commit
						df519ee3b3
					
				
					 43 changed files with 349 additions and 372 deletions
				
			
		| 
						 | 
				
			
			@ -26,15 +26,15 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <spa/utils/result.h>
 | 
			
		||||
#include <pipewire/impl.h>
 | 
			
		||||
 | 
			
		||||
#include <extensions/session-manager.h>
 | 
			
		||||
 | 
			
		||||
#include "client-endpoint.h"
 | 
			
		||||
#include "endpoint.h"
 | 
			
		||||
#include "endpoint-stream.h"
 | 
			
		||||
 | 
			
		||||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#define NAME "client-endpoint"
 | 
			
		||||
 | 
			
		||||
struct factory_data {
 | 
			
		||||
| 
						 | 
				
			
			@ -184,8 +184,10 @@ static void *create_object(void *data,
 | 
			
		|||
	if (!properties)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d", owner->global->id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d", factory->global->id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d",
 | 
			
		||||
			pw_impl_client_get_info(owner)->id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d",
 | 
			
		||||
			pw_impl_factory_get_info(factory)->id);
 | 
			
		||||
 | 
			
		||||
	this->resource = pw_resource_new(owner, new_id, PW_PERM_RWX, type, version, 0);
 | 
			
		||||
	if (this->resource == NULL)
 | 
			
		||||
| 
						 | 
				
			
			@ -235,7 +237,7 @@ static void module_registered(void *data)
 | 
			
		|||
	char id[16];
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	snprintf(id, sizeof(id), "%d", module->global->id);
 | 
			
		||||
	snprintf(id, sizeof(id), "%d", pw_impl_module_get_info(module)->id);
 | 
			
		||||
	items[0] = SPA_DICT_ITEM_INIT(PW_KEY_MODULE_ID, id);
 | 
			
		||||
	pw_impl_factory_update_properties(factory, &SPA_DICT_INIT(items, 1));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,8 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <spa/utils/result.h>
 | 
			
		||||
 | 
			
		||||
#include <pipewire/impl.h>
 | 
			
		||||
#include <extensions/session-manager.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -33,8 +35,6 @@
 | 
			
		|||
#include "session.h"
 | 
			
		||||
#include "endpoint-link.h"
 | 
			
		||||
 | 
			
		||||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#define NAME "client-session"
 | 
			
		||||
 | 
			
		||||
struct factory_data {
 | 
			
		||||
| 
						 | 
				
			
			@ -183,8 +183,10 @@ static void *create_object(void *data,
 | 
			
		|||
	if (!properties)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d", owner->global->id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d", factory->global->id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_CLIENT_ID, "%d",
 | 
			
		||||
			pw_impl_client_get_info(owner)->id);
 | 
			
		||||
	pw_properties_setf(properties, PW_KEY_FACTORY_ID, "%d",
 | 
			
		||||
			pw_impl_factory_get_info(factory)->id);
 | 
			
		||||
 | 
			
		||||
	this->resource = pw_resource_new(owner, new_id, PW_PERM_RWX, type, version, 0);
 | 
			
		||||
	if (this->resource == NULL)
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +236,7 @@ static void module_registered(void *data)
 | 
			
		|||
	char id[16];
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	snprintf(id, sizeof(id), "%d", module->global->id);
 | 
			
		||||
	snprintf(id, sizeof(id), "%d", pw_impl_module_get_info(module)->id);
 | 
			
		||||
	items[0] = SPA_DICT_ITEM_INIT(PW_KEY_MODULE_ID, id);
 | 
			
		||||
	pw_impl_factory_update_properties(factory, &SPA_DICT_INIT(items, 1));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <pipewire/pipewire.h>
 | 
			
		||||
#include <pipewire/impl.h>
 | 
			
		||||
#include <extensions/session-manager.h>
 | 
			
		||||
 | 
			
		||||
#include <spa/pod/filter.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -34,13 +34,10 @@
 | 
			
		|||
#include "endpoint-link.h"
 | 
			
		||||
#include "client-session.h"
 | 
			
		||||
 | 
			
		||||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#define NAME "endpoint-link"
 | 
			
		||||
 | 
			
		||||
struct resource_data {
 | 
			
		||||
	struct endpoint_link *link;
 | 
			
		||||
	struct spa_hook resource_listener;
 | 
			
		||||
	struct spa_hook object_listener;
 | 
			
		||||
	uint32_t n_subscribe_ids;
 | 
			
		||||
	uint32_t subscribe_ids[32];
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +101,7 @@ static int endpoint_link_subscribe_params (void *object, uint32_t *ids, uint32_t
 | 
			
		|||
	for (i = 0; i < n_ids; i++) {
 | 
			
		||||
		data->subscribe_ids[i] = ids[i];
 | 
			
		||||
		pw_log_debug(NAME" %p: resource %d subscribe param %u",
 | 
			
		||||
			data->link, resource->id, ids[i]);
 | 
			
		||||
			data->link, pw_resource_get_id(resource), ids[i]);
 | 
			
		||||
		endpoint_link_enum_params(resource, 1, ids[i], 0, UINT32_MAX, NULL);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -143,30 +140,54 @@ static const struct pw_endpoint_link_methods methods = {
 | 
			
		|||
	.request_state = endpoint_link_request_state,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct emit_param_data {
 | 
			
		||||
	struct endpoint_link *this;
 | 
			
		||||
	struct spa_pod *param;
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t index;
 | 
			
		||||
	uint32_t next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int emit_param(void *_data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct emit_param_data *d = _data;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
		if (data->subscribe_ids[i] == d->id) {
 | 
			
		||||
			pw_endpoint_link_resource_param(resource, 1,
 | 
			
		||||
				d->id, d->index, d->next, d->param);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void endpoint_link_notify_subscribed(struct endpoint_link *this,
 | 
			
		||||
					uint32_t index, uint32_t next)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_global *global = this->global;
 | 
			
		||||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	struct emit_param_data data;
 | 
			
		||||
	struct spa_pod *param = this->params[index];
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	if (!param || !spa_pod_is_object (param))
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.this = this;
 | 
			
		||||
	data.param = param;
 | 
			
		||||
	data.id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.index = index;
 | 
			
		||||
	data.next = next;
 | 
			
		||||
 | 
			
		||||
	spa_list_for_each(resource, &global->resource_list, link) {
 | 
			
		||||
		data = pw_resource_get_user_data(resource);
 | 
			
		||||
		for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
			if (data->subscribe_ids[i] == id) {
 | 
			
		||||
				pw_endpoint_link_resource_param(resource, 1,
 | 
			
		||||
					id, index, next, param);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pw_global_for_each_resource(global, emit_param, &data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int emit_info(void *data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct endpoint_link *this = data;
 | 
			
		||||
	pw_endpoint_link_resource_info(resource, &this->info);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int endpoint_link_update(struct endpoint_link *this,
 | 
			
		||||
| 
						 | 
				
			
			@ -197,8 +218,6 @@ int endpoint_link_update(struct endpoint_link *this,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (change_mask & PW_CLIENT_SESSION_UPDATE_INFO) {
 | 
			
		||||
		struct pw_resource *resource;
 | 
			
		||||
 | 
			
		||||
		if (info->change_mask & PW_ENDPOINT_LINK_CHANGE_MASK_STATE) {
 | 
			
		||||
			this->info.state = info->state;
 | 
			
		||||
			free(this->info.error);
 | 
			
		||||
| 
						 | 
				
			
			@ -229,9 +248,7 @@ int endpoint_link_update(struct endpoint_link *this,
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		this->info.change_mask = info->change_mask;
 | 
			
		||||
		spa_list_for_each(resource, &this->global->resource_list, link) {
 | 
			
		||||
			pw_endpoint_link_resource_info(resource, &this->info);
 | 
			
		||||
		}
 | 
			
		||||
		pw_global_for_each_resource(this->global, emit_info, this);
 | 
			
		||||
		this->info.change_mask = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -244,17 +261,6 @@ int endpoint_link_update(struct endpoint_link *this,
 | 
			
		|||
	return -ENOMEM;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void endpoint_link_unbind(void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_resource *resource = data;
 | 
			
		||||
	spa_list_remove(&resource->link);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_resource_events resource_events = {
 | 
			
		||||
	PW_VERSION_RESOURCE_EVENTS,
 | 
			
		||||
	.destroy = endpoint_link_unbind,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int endpoint_link_bind(void *_data, struct pw_impl_client *client,
 | 
			
		||||
			uint32_t permissions, uint32_t version, uint32_t id)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -263,20 +269,18 @@ static int endpoint_link_bind(void *_data, struct pw_impl_client *client,
 | 
			
		|||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions,
 | 
			
		||||
			pw_global_get_type(global), version, sizeof(*data));
 | 
			
		||||
	if (resource == NULL)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	data->link = this;
 | 
			
		||||
	pw_resource_add_listener(resource, &data->resource_listener,
 | 
			
		||||
				&resource_events, resource);
 | 
			
		||||
	pw_resource_add_object_listener(resource, &data->object_listener,
 | 
			
		||||
					&methods, resource);
 | 
			
		||||
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, resource->id);
 | 
			
		||||
 | 
			
		||||
	spa_list_append(&global->resource_list, &resource->link);
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, pw_resource_get_id(resource));
 | 
			
		||||
	pw_global_add_resource(global, resource);
 | 
			
		||||
 | 
			
		||||
	this->info.change_mask = PW_ENDPOINT_LINK_CHANGE_MASK_ALL;
 | 
			
		||||
	pw_endpoint_link_resource_info(resource, &this->info);
 | 
			
		||||
| 
						 | 
				
			
			@ -316,10 +320,11 @@ int endpoint_link_init(struct endpoint_link *this,
 | 
			
		|||
	if (!this->global)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u", this->global->id);
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
 | 
			
		||||
			pw_global_get_id(this->global));
 | 
			
		||||
 | 
			
		||||
	this->info.version = PW_VERSION_ENDPOINT_LINK_INFO;
 | 
			
		||||
	this->info.id = this->global->id;
 | 
			
		||||
	this->info.id = pw_global_get_id(this->global);
 | 
			
		||||
	this->info.session_id = session_id;
 | 
			
		||||
	this->info.props = &this->props->dict;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,13 +34,10 @@
 | 
			
		|||
#include "endpoint-stream.h"
 | 
			
		||||
#include "client-endpoint.h"
 | 
			
		||||
 | 
			
		||||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#define NAME "endpoint-stream"
 | 
			
		||||
 | 
			
		||||
struct resource_data {
 | 
			
		||||
	struct endpoint_stream *stream;
 | 
			
		||||
	struct spa_hook resource_listener;
 | 
			
		||||
	struct spa_hook object_listener;
 | 
			
		||||
	uint32_t n_subscribe_ids;
 | 
			
		||||
	uint32_t subscribe_ids[32];
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +101,7 @@ static int endpoint_stream_subscribe_params (void *object, uint32_t *ids, uint32
 | 
			
		|||
	for (i = 0; i < n_ids; i++) {
 | 
			
		||||
		data->subscribe_ids[i] = ids[i];
 | 
			
		||||
		pw_log_debug(NAME" %p: resource %d subscribe param %u",
 | 
			
		||||
			data->stream, resource->id, ids[i]);
 | 
			
		||||
			data->stream, pw_resource_get_id(resource), ids[i]);
 | 
			
		||||
		endpoint_stream_enum_params(resource, 1, ids[i], 0, UINT32_MAX, NULL);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -130,30 +127,54 @@ static const struct pw_endpoint_stream_methods methods = {
 | 
			
		|||
	.set_param = endpoint_stream_set_param,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct emit_param_data {
 | 
			
		||||
	struct endpoint_stream *this;
 | 
			
		||||
	struct spa_pod *param;
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t index;
 | 
			
		||||
	uint32_t next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int emit_param(void *_data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct emit_param_data *d = _data;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
		if (data->subscribe_ids[i] == d->id) {
 | 
			
		||||
			pw_endpoint_stream_resource_param(resource, 1,
 | 
			
		||||
				d->id, d->index, d->next, d->param);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void endpoint_stream_notify_subscribed(struct endpoint_stream *this,
 | 
			
		||||
					uint32_t index, uint32_t next)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_global *global = this->global;
 | 
			
		||||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	struct emit_param_data data;
 | 
			
		||||
	struct spa_pod *param = this->params[index];
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	if (!param || !spa_pod_is_object (param))
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.this = this;
 | 
			
		||||
	data.param = param;
 | 
			
		||||
	data.id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.index = index;
 | 
			
		||||
	data.next = next;
 | 
			
		||||
 | 
			
		||||
	spa_list_for_each(resource, &global->resource_list, link) {
 | 
			
		||||
		data = pw_resource_get_user_data(resource);
 | 
			
		||||
		for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
			if (data->subscribe_ids[i] == id) {
 | 
			
		||||
				pw_endpoint_stream_resource_param(resource, 1,
 | 
			
		||||
					id, index, next, param);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pw_global_for_each_resource(global, emit_param, &data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int emit_info(void *data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct endpoint_stream *this = data;
 | 
			
		||||
	pw_endpoint_stream_resource_info(resource, &this->info);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int endpoint_stream_update(struct endpoint_stream *this,
 | 
			
		||||
| 
						 | 
				
			
			@ -184,8 +205,6 @@ int endpoint_stream_update(struct endpoint_stream *this,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (change_mask & PW_CLIENT_ENDPOINT_UPDATE_INFO) {
 | 
			
		||||
		struct pw_resource *resource;
 | 
			
		||||
 | 
			
		||||
		if (info->change_mask & PW_ENDPOINT_STREAM_CHANGE_MASK_LINK_PARAMS) {
 | 
			
		||||
			free(this->info.link_params);
 | 
			
		||||
			this->info.link_params = spa_pod_copy(info->link_params);
 | 
			
		||||
| 
						 | 
				
			
			@ -211,9 +230,7 @@ int endpoint_stream_update(struct endpoint_stream *this,
 | 
			
		|||
			this->info.name = info->name ? strdup(info->name) : NULL;
 | 
			
		||||
 | 
			
		||||
		this->info.change_mask = info->change_mask;
 | 
			
		||||
		spa_list_for_each(resource, &this->global->resource_list, link) {
 | 
			
		||||
			pw_endpoint_stream_resource_info(resource, &this->info);
 | 
			
		||||
		}
 | 
			
		||||
		pw_global_for_each_resource(this->global, emit_info, this);
 | 
			
		||||
		this->info.change_mask = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -226,17 +243,6 @@ int endpoint_stream_update(struct endpoint_stream *this,
 | 
			
		|||
	return -ENOMEM;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void endpoint_stream_unbind(void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_resource *resource = data;
 | 
			
		||||
	spa_list_remove(&resource->link);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_resource_events resource_events = {
 | 
			
		||||
	PW_VERSION_RESOURCE_EVENTS,
 | 
			
		||||
	.destroy = endpoint_stream_unbind,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int endpoint_stream_bind(void *_data, struct pw_impl_client *client,
 | 
			
		||||
			uint32_t permissions, uint32_t version, uint32_t id)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -245,20 +251,18 @@ static int endpoint_stream_bind(void *_data, struct pw_impl_client *client,
 | 
			
		|||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions,
 | 
			
		||||
			pw_global_get_type(global), version, sizeof(*data));
 | 
			
		||||
	if (resource == NULL)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	data->stream = this;
 | 
			
		||||
	pw_resource_add_listener(resource, &data->resource_listener,
 | 
			
		||||
				&resource_events, resource);
 | 
			
		||||
	pw_resource_add_object_listener(resource, &data->object_listener,
 | 
			
		||||
					&methods, resource);
 | 
			
		||||
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, resource->id);
 | 
			
		||||
 | 
			
		||||
	spa_list_append(&global->resource_list, &resource->link);
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, pw_resource_get_id(resource));
 | 
			
		||||
	pw_global_add_resource(global, resource);
 | 
			
		||||
 | 
			
		||||
	this->info.change_mask = PW_ENDPOINT_STREAM_CHANGE_MASK_ALL;
 | 
			
		||||
	pw_endpoint_stream_resource_info(resource, &this->info);
 | 
			
		||||
| 
						 | 
				
			
			@ -298,10 +302,11 @@ int endpoint_stream_init(struct endpoint_stream *this,
 | 
			
		|||
	if (!this->global)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u", this->global->id);
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
 | 
			
		||||
			pw_global_get_id(this->global));
 | 
			
		||||
 | 
			
		||||
	this->info.version = PW_VERSION_ENDPOINT_STREAM_INFO;
 | 
			
		||||
	this->info.id = this->global->id;
 | 
			
		||||
	this->info.id = pw_global_get_id(this->global);
 | 
			
		||||
	this->info.endpoint_id = endpoint_id;
 | 
			
		||||
	this->info.props = &this->props->dict;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,13 +34,10 @@
 | 
			
		|||
#include "endpoint.h"
 | 
			
		||||
#include "client-endpoint.h"
 | 
			
		||||
 | 
			
		||||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#define NAME "endpoint"
 | 
			
		||||
 | 
			
		||||
struct resource_data {
 | 
			
		||||
	struct endpoint *endpoint;
 | 
			
		||||
	struct spa_hook resource_listener;
 | 
			
		||||
	struct spa_hook object_listener;
 | 
			
		||||
	uint32_t n_subscribe_ids;
 | 
			
		||||
	uint32_t subscribe_ids[32];
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +103,7 @@ static int endpoint_subscribe_params (void *object, uint32_t *ids, uint32_t n_id
 | 
			
		|||
	for (i = 0; i < n_ids; i++) {
 | 
			
		||||
		data->subscribe_ids[i] = ids[i];
 | 
			
		||||
		pw_log_debug(NAME" %p: resource %d subscribe param %u",
 | 
			
		||||
			data->endpoint, resource->id, ids[i]);
 | 
			
		||||
			data->endpoint, pw_resource_get_id(resource), ids[i]);
 | 
			
		||||
		endpoint_enum_params(resource, 1, ids[i], 0, UINT32_MAX, NULL);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -147,30 +144,54 @@ static const struct pw_endpoint_methods methods = {
 | 
			
		|||
	.create_link = endpoint_create_link,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct emit_param_data {
 | 
			
		||||
	struct endpoint *this;
 | 
			
		||||
	struct spa_pod *param;
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t index;
 | 
			
		||||
	uint32_t next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int emit_param(void *_data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct emit_param_data *d = _data;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
		if (data->subscribe_ids[i] == d->id) {
 | 
			
		||||
			pw_endpoint_resource_param(resource, 1,
 | 
			
		||||
				d->id, d->index, d->next, d->param);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void endpoint_notify_subscribed(struct endpoint *this,
 | 
			
		||||
					uint32_t index, uint32_t next)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_global *global = this->global;
 | 
			
		||||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	struct emit_param_data data;
 | 
			
		||||
	struct spa_pod *param = this->params[index];
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	if (!param || !spa_pod_is_object (param))
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.this = this;
 | 
			
		||||
	data.param = param;
 | 
			
		||||
	data.id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.index = index;
 | 
			
		||||
	data.next = next;
 | 
			
		||||
 | 
			
		||||
	spa_list_for_each(resource, &global->resource_list, link) {
 | 
			
		||||
		data = pw_resource_get_user_data(resource);
 | 
			
		||||
		for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
			if (data->subscribe_ids[i] == id) {
 | 
			
		||||
				pw_endpoint_resource_param(resource, 1, id,
 | 
			
		||||
					index, next, param);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pw_global_for_each_resource(global, emit_param, &data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int emit_info(void *data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct endpoint *this = data;
 | 
			
		||||
	pw_endpoint_resource_info(resource, &this->info);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int endpoint_update(struct endpoint *this,
 | 
			
		||||
| 
						 | 
				
			
			@ -201,8 +222,6 @@ int endpoint_update(struct endpoint *this,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (change_mask & PW_CLIENT_ENDPOINT_UPDATE_INFO) {
 | 
			
		||||
		struct pw_resource *resource;
 | 
			
		||||
 | 
			
		||||
		if (info->change_mask & PW_ENDPOINT_CHANGE_MASK_STREAMS)
 | 
			
		||||
			this->info.n_streams = info->n_streams;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -233,9 +252,7 @@ int endpoint_update(struct endpoint *this,
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		this->info.change_mask = info->change_mask;
 | 
			
		||||
		spa_list_for_each(resource, &this->global->resource_list, link) {
 | 
			
		||||
			pw_endpoint_resource_info(resource, &this->info);
 | 
			
		||||
		}
 | 
			
		||||
		pw_global_for_each_resource(this->global, emit_info, this);
 | 
			
		||||
		this->info.change_mask = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -248,17 +265,6 @@ int endpoint_update(struct endpoint *this,
 | 
			
		|||
	return -ENOMEM;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void endpoint_unbind(void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_resource *resource = data;
 | 
			
		||||
	spa_list_remove(&resource->link);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_resource_events resource_events = {
 | 
			
		||||
	PW_VERSION_RESOURCE_EVENTS,
 | 
			
		||||
	.destroy = endpoint_unbind,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int endpoint_bind(void *_data, struct pw_impl_client *client,
 | 
			
		||||
			uint32_t permissions, uint32_t version, uint32_t id)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -267,20 +273,18 @@ static int endpoint_bind(void *_data, struct pw_impl_client *client,
 | 
			
		|||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions,
 | 
			
		||||
			pw_global_get_type(global), version, sizeof(*data));
 | 
			
		||||
	if (resource == NULL)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	data->endpoint = this;
 | 
			
		||||
	pw_resource_add_listener(resource, &data->resource_listener,
 | 
			
		||||
				&resource_events, resource);
 | 
			
		||||
	pw_resource_add_object_listener(resource, &data->object_listener,
 | 
			
		||||
					&methods, resource);
 | 
			
		||||
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, resource->id);
 | 
			
		||||
 | 
			
		||||
	spa_list_append(&global->resource_list, &resource->link);
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, pw_resource_get_id(resource));
 | 
			
		||||
	pw_global_add_resource(global, resource);
 | 
			
		||||
 | 
			
		||||
	this->info.change_mask = PW_ENDPOINT_CHANGE_MASK_ALL;
 | 
			
		||||
	pw_endpoint_resource_info(resource, &this->info);
 | 
			
		||||
| 
						 | 
				
			
			@ -333,13 +337,14 @@ int endpoint_init(struct endpoint *this,
 | 
			
		|||
	if (!this->global)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u", this->global->id);
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
 | 
			
		||||
			pw_global_get_id(this->global));
 | 
			
		||||
 | 
			
		||||
	this->info.version = PW_VERSION_ENDPOINT_INFO;
 | 
			
		||||
	this->info.id = this->global->id;
 | 
			
		||||
	this->info.id = pw_global_get_id(this->global);
 | 
			
		||||
	this->info.props = &this->props->dict;
 | 
			
		||||
 | 
			
		||||
	pw_resource_set_bound_id(client_ep->resource, this->global->id);
 | 
			
		||||
	pw_resource_set_bound_id(client_ep->resource, this->info.id);
 | 
			
		||||
 | 
			
		||||
	return pw_global_register(this->global);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <pipewire/pipewire.h>
 | 
			
		||||
#include <pipewire/impl.h>
 | 
			
		||||
#include <extensions/session-manager.h>
 | 
			
		||||
 | 
			
		||||
#include <spa/pod/filter.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -34,13 +34,10 @@
 | 
			
		|||
#include "session.h"
 | 
			
		||||
#include "client-session.h"
 | 
			
		||||
 | 
			
		||||
#include <pipewire/private.h>
 | 
			
		||||
 | 
			
		||||
#define NAME "session"
 | 
			
		||||
 | 
			
		||||
struct resource_data {
 | 
			
		||||
	struct session *session;
 | 
			
		||||
	struct spa_hook resource_listener;
 | 
			
		||||
	struct spa_hook object_listener;
 | 
			
		||||
	uint32_t n_subscribe_ids;
 | 
			
		||||
	uint32_t subscribe_ids[32];
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +101,7 @@ static int session_subscribe_params (void *object, uint32_t *ids, uint32_t n_ids
 | 
			
		|||
	for (i = 0; i < n_ids; i++) {
 | 
			
		||||
		data->subscribe_ids[i] = ids[i];
 | 
			
		||||
		pw_log_debug(NAME" %p: resource %d subscribe param %u",
 | 
			
		||||
			data->session, resource->id, ids[i]);
 | 
			
		||||
			data->session, pw_resource_get_id(resource), ids[i]);
 | 
			
		||||
		session_enum_params(resource, 1, ids[i], 0, UINT32_MAX, NULL);
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -130,30 +127,54 @@ static const struct pw_session_methods methods = {
 | 
			
		|||
	.set_param = session_set_param,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct emit_param_data {
 | 
			
		||||
	struct session *this;
 | 
			
		||||
	struct spa_pod *param;
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t index;
 | 
			
		||||
	uint32_t next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int emit_param(void *_data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct emit_param_data *d = _data;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
		if (data->subscribe_ids[i] == d->id) {
 | 
			
		||||
			pw_session_resource_param(resource, 1,
 | 
			
		||||
				d->id, d->index, d->next, d->param);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void session_notify_subscribed(struct session *this,
 | 
			
		||||
					uint32_t index, uint32_t next)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_global *global = this->global;
 | 
			
		||||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
	struct emit_param_data data;
 | 
			
		||||
	struct spa_pod *param = this->params[index];
 | 
			
		||||
	uint32_t id;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
 | 
			
		||||
	if (!param || !spa_pod_is_object (param))
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.this = this;
 | 
			
		||||
	data.param = param;
 | 
			
		||||
	data.id = SPA_POD_OBJECT_ID (param);
 | 
			
		||||
	data.index = index;
 | 
			
		||||
	data.next = next;
 | 
			
		||||
 | 
			
		||||
	spa_list_for_each(resource, &global->resource_list, link) {
 | 
			
		||||
		data = pw_resource_get_user_data(resource);
 | 
			
		||||
		for (i = 0; i < data->n_subscribe_ids; i++) {
 | 
			
		||||
			if (data->subscribe_ids[i] == id) {
 | 
			
		||||
				pw_session_resource_param(resource, 1, id,
 | 
			
		||||
					index, next, param);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	pw_global_for_each_resource(global, emit_param, &data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int emit_info(void *data, struct pw_resource *resource)
 | 
			
		||||
{
 | 
			
		||||
	struct session *this = data;
 | 
			
		||||
	pw_session_resource_info(resource, &this->info);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int session_update(struct session *this,
 | 
			
		||||
| 
						 | 
				
			
			@ -184,8 +205,6 @@ int session_update(struct session *this,
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (change_mask & PW_CLIENT_SESSION_UPDATE_INFO) {
 | 
			
		||||
		struct pw_resource *resource;
 | 
			
		||||
 | 
			
		||||
		if (info->change_mask & PW_SESSION_CHANGE_MASK_PROPS)
 | 
			
		||||
			pw_properties_update(this->props, info->props);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -203,9 +222,7 @@ int session_update(struct session *this,
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		this->info.change_mask = info->change_mask;
 | 
			
		||||
		spa_list_for_each(resource, &this->global->resource_list, link) {
 | 
			
		||||
			pw_session_resource_info(resource, &this->info);
 | 
			
		||||
		}
 | 
			
		||||
		pw_global_for_each_resource(this->global, emit_info, this);
 | 
			
		||||
		this->info.change_mask = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -218,17 +235,6 @@ int session_update(struct session *this,
 | 
			
		|||
	return -ENOMEM;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void session_unbind(void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct pw_resource *resource = data;
 | 
			
		||||
	spa_list_remove(&resource->link);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_resource_events resource_events = {
 | 
			
		||||
	PW_VERSION_RESOURCE_EVENTS,
 | 
			
		||||
	.destroy = session_unbind,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int session_bind(void *_data, struct pw_impl_client *client,
 | 
			
		||||
			uint32_t permissions, uint32_t version, uint32_t id)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -237,20 +243,19 @@ static int session_bind(void *_data, struct pw_impl_client *client,
 | 
			
		|||
	struct pw_resource *resource;
 | 
			
		||||
	struct resource_data *data;
 | 
			
		||||
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions, global->type, version, sizeof(*data));
 | 
			
		||||
	resource = pw_resource_new(client, id, permissions,
 | 
			
		||||
			pw_global_get_type(global), version, sizeof(*data));
 | 
			
		||||
	if (resource == NULL)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	data = pw_resource_get_user_data(resource);
 | 
			
		||||
	data->session = this;
 | 
			
		||||
	pw_resource_add_listener(resource, &data->resource_listener,
 | 
			
		||||
				&resource_events, resource);
 | 
			
		||||
 | 
			
		||||
	pw_resource_add_object_listener(resource, &data->object_listener,
 | 
			
		||||
					&methods, resource);
 | 
			
		||||
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, resource->id);
 | 
			
		||||
 | 
			
		||||
	spa_list_append(&global->resource_list, &resource->link);
 | 
			
		||||
	pw_log_debug(NAME" %p: bound to %d", this, pw_resource_get_id(resource));
 | 
			
		||||
	pw_global_add_resource(global, resource);
 | 
			
		||||
 | 
			
		||||
	this->info.change_mask = PW_SESSION_CHANGE_MASK_ALL;
 | 
			
		||||
	pw_session_resource_info(resource, &this->info);
 | 
			
		||||
| 
						 | 
				
			
			@ -294,13 +299,14 @@ int session_init(struct session *this,
 | 
			
		|||
	if (!this->global)
 | 
			
		||||
		goto no_mem;
 | 
			
		||||
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u", this->global->id);
 | 
			
		||||
	pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
 | 
			
		||||
			pw_global_get_id(this->global));
 | 
			
		||||
 | 
			
		||||
	this->info.version = PW_VERSION_SESSION_INFO;
 | 
			
		||||
	this->info.id = this->global->id;
 | 
			
		||||
	this->info.id = pw_global_get_id(this->global);
 | 
			
		||||
	this->info.props = &this->props->dict;
 | 
			
		||||
 | 
			
		||||
	pw_resource_set_bound_id(client_sess->resource, this->global->id);
 | 
			
		||||
	pw_resource_set_bound_id(client_sess->resource, this->info.id);
 | 
			
		||||
 | 
			
		||||
	return pw_global_register(this->global);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue