diff --git a/src/pipewire/client.c b/src/pipewire/client.c index d47d7efc8..7ed71c7b5 100644 --- a/src/pipewire/client.c +++ b/src/pipewire/client.c @@ -42,6 +42,7 @@ struct impl { struct resource_data { struct spa_hook resource_listener; + struct pw_client *client; }; /** find a specific permission for a global or NULL when there is none */ @@ -103,11 +104,13 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions, goto no_mem; data = pw_resource_get_user_data(resource); + data->client = this; pw_resource_add_listener(resource, &data->resource_listener, &resource_events, resource); + pw_resource_set_implementation(resource, &client_methods, resource); pw_log_debug("client %p: bound to %d", this, resource->id); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); this->info.change_mask = ~0; pw_client_resource_info(resource, &this->info); @@ -183,12 +186,10 @@ struct pw_client *pw_client_new(struct pw_core *core, this->properties = properties; this->permission_func = client_permission_func; this->permission_data = impl; - impl->permissions_default = PW_PERM_RWX; if (user_data_size > 0) this->user_data = SPA_MEMBER(impl, sizeof(struct impl), void); - spa_list_init(&this->resource_list); spa_hook_list_init(&this->listener_list); pw_map_init(&this->objects, 0, 32); @@ -294,7 +295,6 @@ static int destroy_resource(void *object, void *data) */ void pw_client_destroy(struct pw_client *client) { - struct pw_resource *resource; struct impl *impl = SPA_CONTAINER_OF(client, struct impl, this); pw_log_debug("client %p: destroy", client); @@ -310,9 +310,6 @@ void pw_client_destroy(struct pw_client *client) pw_global_destroy(client->global); } - spa_list_consume(resource, &client->resource_list, link) - pw_resource_destroy(resource); - pw_map_for_each(&client->objects, destroy_resource, client); pw_client_events_free(client); @@ -367,8 +364,9 @@ int pw_client_update_properties(struct pw_client *client, const struct spa_dict pw_client_events_info_changed(client, &client->info); - spa_list_for_each(resource, &client->resource_list, link) - pw_client_resource_info(resource, &client->info); + if (client->global) + spa_list_for_each(resource, &client->global->resource_list, link) + pw_client_resource_info(resource, &client->info); client->info.change_mask = 0; diff --git a/src/pipewire/core.c b/src/pipewire/core.c index 4a1786a86..eeefd514d 100644 --- a/src/pipewire/core.c +++ b/src/pipewire/core.c @@ -349,7 +349,7 @@ global_bind(void *_data, pw_resource_set_implementation(resource, &core_methods, resource); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); if (resource->id == 0) client->core_resource = resource; @@ -428,7 +428,6 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro spa_list_init(&this->protocol_list); spa_list_init(&this->remote_list); - spa_list_init(&this->resource_list); spa_list_init(&this->registry_resource_list); spa_list_init(&this->global_list); spa_list_init(&this->module_list); @@ -587,8 +586,9 @@ int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict) pw_core_events_info_changed(core, &core->info); - spa_list_for_each(resource, &core->resource_list, link) - pw_core_resource_info(resource, &core->info); + if (core->global) + spa_list_for_each(resource, &core->global->resource_list, link) + pw_core_resource_info(resource, &core->info); core->info.change_mask = 0; diff --git a/src/pipewire/factory.c b/src/pipewire/factory.c index e2ddaf25e..cba492b97 100644 --- a/src/pipewire/factory.c +++ b/src/pipewire/factory.c @@ -41,7 +41,6 @@ struct pw_factory *pw_factory_new(struct pw_core *core, this = calloc(1, sizeof(*this) + user_data_size); this->core = core; this->properties = properties; - spa_list_init(&this->resource_list); this->info.name = strdup(name); this->info.type = type; @@ -106,7 +105,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions, pw_log_debug("factory %p: bound to %d", this, resource->id); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); this->info.change_mask = ~0; pw_factory_resource_info(resource, &this->info); diff --git a/src/pipewire/global.c b/src/pipewire/global.c index 73d17e32e..2c2765968 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -81,6 +81,7 @@ pw_global_new(struct pw_core *core, this->properties = properties; this->id = pw_map_insert_new(&core->globals, this); + spa_list_init(&this->resource_list); spa_hook_list_init(&this->listener_list); pw_log_debug("global %p: new %s %d", this, @@ -257,12 +258,16 @@ pw_global_bind(struct pw_global *global, struct pw_client *client, uint32_t perm void pw_global_destroy(struct pw_global *global) { struct pw_core *core = global->core; + struct pw_resource *resource; pw_log_debug("global %p: destroy %u", global, global->id); global_unregister(global); pw_global_events_destroy(global); + spa_list_consume(resource, &global->resource_list, link) + pw_resource_destroy(resource); + pw_map_remove(&core->globals, global->id); pw_log_debug("global %p: free", global); diff --git a/src/pipewire/link.c b/src/pipewire/link.c index c8ef50140..f19eb334f 100644 --- a/src/pipewire/link.c +++ b/src/pipewire/link.c @@ -114,8 +114,9 @@ static void pw_link_update_state(struct pw_link *link, enum pw_link_state state, link->info.change_mask |= PW_LINK_CHANGE_MASK_STATE; pw_link_events_info_changed(link, &link->info); - spa_list_for_each(resource, &link->resource_list, link) - pw_link_resource_info(resource, &link->info); + if (link->global) + spa_list_for_each(resource, &link->global->resource_list, link) + pw_link_resource_info(resource, &link->info); link->info.change_mask = 0; @@ -312,8 +313,9 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st pw_link_events_info_changed(this, &this->info); - spa_list_for_each(resource, &this->resource_list, link) - pw_link_resource_info(resource, &this->info); + if (this->global) + spa_list_for_each(resource, &this->global->resource_list, link) + pw_link_resource_info(resource, &this->info); this->info.change_mask = 0; } @@ -1187,7 +1189,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions, pw_log_debug("link %p: bound to %d", this, resource->id); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); this->info.change_mask = ~0; pw_link_resource_info(resource, &this->info); @@ -1357,7 +1359,6 @@ struct pw_link *pw_link_new(struct pw_core *core, if (str && pw_properties_parse_bool(str)) impl->passive = true; } - spa_list_init(&this->resource_list); spa_hook_list_init(&this->listener_list); impl->format_filter = format_filter; @@ -1479,7 +1480,6 @@ int pw_link_register(struct pw_link *link, void pw_link_destroy(struct pw_link *link) { struct impl *impl = SPA_CONTAINER_OF(link, struct impl, this); - struct pw_resource *resource; pw_log_debug("link %p: destroy", impl); pw_link_events_destroy(link); @@ -1499,9 +1499,6 @@ void pw_link_destroy(struct pw_link *link) pw_global_destroy(link->global); } - spa_list_consume(resource, &link->resource_list, link) - pw_resource_destroy(resource); - pw_log_debug("link %p: free", impl); pw_link_events_free(link); diff --git a/src/pipewire/module.c b/src/pipewire/module.c index efb7484f3..484700aa0 100644 --- a/src/pipewire/module.c +++ b/src/pipewire/module.c @@ -123,7 +123,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions, pw_log_debug("module %p: bound to %d", this, resource->id); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); this->info.change_mask = ~0; pw_module_resource_info(resource, &this->info); @@ -224,7 +224,6 @@ pw_module_load(struct pw_core *core, this->core = core; this->properties = properties; - spa_list_init(&this->resource_list); spa_hook_list_init(&this->listener_list); pw_properties_set(properties, PW_MODULE_PROP_NAME, name); @@ -288,7 +287,6 @@ pw_module_load(struct pw_core *core, void pw_module_destroy(struct pw_module *module) { struct impl *impl = SPA_CONTAINER_OF(module, struct impl, this); - struct pw_resource *resource; pw_log_debug("module %p: destroy", module); pw_module_events_destroy(module); @@ -299,8 +297,6 @@ void pw_module_destroy(struct pw_module *module) spa_hook_remove(&module->global_listener); pw_global_destroy(module->global); } - spa_list_consume(resource, &module->resource_list, link) - pw_resource_destroy(resource); if (module->info.name) free((char *) module->info.name); @@ -345,8 +341,9 @@ int pw_module_update_properties(struct pw_module *module, const struct spa_dict module->info.props = &module->properties->dict; module->info.change_mask |= PW_MODULE_CHANGE_MASK_PROPS; - spa_list_for_each(resource, &module->resource_list, link) - pw_module_resource_info(resource, &module->info); + if (module->global) + spa_list_for_each(resource, &module->global->resource_list, link) + pw_module_resource_info(resource, &module->info); module->info.change_mask = 0; return changed; diff --git a/src/pipewire/node.c b/src/pipewire/node.c index 148e5229a..cd2a304c0 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -181,8 +181,9 @@ static void node_update_state(struct pw_node *node, enum pw_node_state state, ch node->info.change_mask |= PW_NODE_CHANGE_MASK_STATE; pw_node_events_info_changed(node, &node->info); - spa_list_for_each(resource, &node->resource_list, link) - pw_node_resource_info(resource, &node->info); + if (node->global) + spa_list_for_each(resource, &node->global->resource_list, link) + pw_node_resource_info(resource, &node->info); node->info.change_mask = 0; } @@ -394,7 +395,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions, pw_log_debug("node %p: bound to %d", this, resource->id); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); this->info.change_mask = ~0; pw_node_resource_info(resource, &this->info); @@ -645,7 +646,6 @@ struct pw_node *pw_node_new(struct pw_core *core, this->data_loop = core->data_loop; spa_list_init(&this->driver_list); - spa_list_init(&this->resource_list); spa_hook_list_init(&this->listener_list); @@ -739,8 +739,9 @@ int pw_node_update_properties(struct pw_node *node, const struct spa_dict *dict) node->info.change_mask |= PW_NODE_CHANGE_MASK_PROPS; pw_node_events_info_changed(node, &node->info); - spa_list_for_each(resource, &node->resource_list, link) - pw_node_resource_info(resource, &node->info); + if (node->global) + spa_list_for_each(resource, &node->global->resource_list, link) + pw_node_resource_info(resource, &node->info); node->info.change_mask = 0; @@ -892,7 +893,6 @@ void pw_node_add_listener(struct pw_node *node, void pw_node_destroy(struct pw_node *node) { struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this); - struct pw_resource *resource; struct pw_node *n, *t; struct pw_port *port; @@ -932,8 +932,6 @@ void pw_node_destroy(struct pw_node *node) spa_hook_remove(&node->global_listener); pw_global_destroy(node->global); } - spa_list_consume(resource, &node->resource_list, link) - pw_resource_destroy(resource); pw_log_debug("node %p: free", node); pw_node_events_free(node); diff --git a/src/pipewire/port.c b/src/pipewire/port.c index aaa353765..4fe38dcfc 100644 --- a/src/pipewire/port.c +++ b/src/pipewire/port.c @@ -223,8 +223,6 @@ struct pw_port *pw_port_new(enum pw_direction direction, spa_list_init(&this->control_list[0]); spa_list_init(&this->control_list[1]); - spa_list_init(&this->resource_list); - spa_hook_list_init(&this->listener_list); spa_graph_port_init(&this->rt.port, @@ -296,8 +294,9 @@ int pw_port_update_properties(struct pw_port *port, const struct spa_dict *dict) port->info.change_mask |= PW_PORT_CHANGE_MASK_PROPS; pw_port_events_info_changed(port, &port->info); - spa_list_for_each(resource, &port->resource_list, link) - pw_port_resource_info(resource, &port->info); + if (port->global) + spa_list_for_each(resource, &port->global->resource_list, link) + pw_port_resource_info(resource, &port->info); port->info.change_mask = 0; @@ -428,7 +427,7 @@ global_bind(void *_data, struct pw_client *client, uint32_t permissions, pw_log_debug("port %p: bound to %d", this, resource->id); - spa_list_append(&this->resource_list, &resource->link); + spa_list_append(&global->resource_list, &resource->link); this->info.change_mask = ~0; pw_port_resource_info(resource, &this->info); @@ -659,7 +658,6 @@ static void pw_port_remove(struct pw_port *port) void pw_port_destroy(struct pw_port *port) { struct pw_control *control; - struct pw_resource *resource; pw_log_debug("port %p: destroy", port); @@ -677,8 +675,6 @@ void pw_port_destroy(struct pw_port *port) spa_hook_remove(&port->global_listener); pw_global_destroy(port->global); } - spa_list_consume(resource, &port->resource_list, link) - pw_resource_destroy(resource); pw_log_debug("port %p: free", port); pw_port_events_free(port); diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 602d187f3..d58bb749c 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -106,8 +106,6 @@ struct pw_client { struct pw_map objects; /**< list of resource objects */ - struct spa_list resource_list; /**< The list of resources of this client */ - bool busy; struct spa_hook_list listener_list; @@ -142,6 +140,8 @@ struct pw_global { uint32_t version; /**< version of interface */ void *object; /**< object associated with the interface */ + + struct spa_list resource_list; /**< The list of resources of this global */ }; #define pw_core_events_emit(o,m,v,...) spa_hook_list_call(&o->listener_list, struct pw_core_events, m, v, ##__VA_ARGS__) @@ -163,7 +163,6 @@ struct pw_core { struct spa_list protocol_list; /**< list of protocols */ struct spa_list remote_list; /**< list of remote connections */ - struct spa_list resource_list; /**< list of core resources */ struct spa_list registry_resource_list; /**< list of registry resources */ struct spa_list module_list; /**< list of modules */ struct spa_list global_list; /**< list of globals */ @@ -248,8 +247,6 @@ struct pw_module { struct pw_properties *properties; /**< properties of the module */ struct pw_module_info info; /**< introspectable module info */ - struct spa_list resource_list; /**< list of resources for this module */ - struct spa_hook_list listener_list; void *user_data; /**< module user_data */ @@ -314,7 +311,6 @@ struct pw_node { struct spa_node *node; /**< SPA node implementation */ - struct spa_list resource_list; /**< list of resources for this node */ uint32_t port_user_data_size; /**< extra size for port user data */ struct spa_list input_ports; /**< list of input ports */ @@ -399,8 +395,6 @@ struct pw_port { struct pw_properties *properties; /**< properties of the port */ struct pw_port_info info; - struct spa_list resource_list; /**< list of resources for this port */ - enum pw_port_state state; /**< state of the port */ bool allocated; /**< if buffers are allocated */ @@ -453,8 +447,6 @@ struct pw_link { struct pw_properties *properties; /**< extra link properties */ bool feedback; - struct spa_list resource_list; /**< list of bound resources */ - struct spa_io_buffers *io; /**< link io area */ struct pw_port *output; /**< output port */ @@ -592,8 +584,6 @@ struct pw_factory { const struct pw_factory_implementation *implementation; void *implementation_data; - struct spa_list resource_list; /**< The list of resources of this factory */ - void *user_data; };