diff --git a/pipewire/client/stream.c b/pipewire/client/stream.c index cdd968a8e..370708674 100644 --- a/pipewire/client/stream.c +++ b/pipewire/client/stream.c @@ -63,6 +63,8 @@ struct buffer_id { struct stream { struct pw_stream this; + uint32_t type_client_node; + uint32_t n_possible_formats; struct spa_format **possible_formats; @@ -203,6 +205,7 @@ struct pw_stream *pw_stream_new(struct pw_context *context, this->context = context; this->name = strdup(name); + impl->type_client_node = spa_type_map_get_id(context->type.map, PIPEWIRE_TYPE_NODE_BASE "Client"); pw_signal_init(&this->destroy_signal); pw_signal_init(&this->state_changed); @@ -904,7 +907,9 @@ pw_stream_connect(struct pw_stream *stream, pw_properties_set(stream->properties, "pipewire.autoconnect", "1"); impl->node_proxy = pw_proxy_new(stream->context, - SPA_ID_INVALID, stream->context->type.client_node, 0); + SPA_ID_INVALID, + impl->type_client_node, + 0); if (impl->node_proxy == NULL) return false; @@ -918,7 +923,8 @@ pw_stream_connect(struct pw_stream *stream, pw_core_do_create_node(stream->context->core_proxy, "client-node", "client-node", - &stream->properties->dict, impl->node_proxy->id); + &stream->properties->dict, + impl->node_proxy->id); do_node_init(stream); diff --git a/pipewire/client/type.c b/pipewire/client/type.c index 152d24480..889238dd3 100644 --- a/pipewire/client/type.c +++ b/pipewire/client/type.c @@ -28,7 +28,6 @@ #include "pipewire/client/type.h" #include "pipewire/server/node-factory.h" -#include "pipewire/server/client-node.h" /** Initializes the type system @@ -45,7 +44,6 @@ void pw_type_init(struct pw_type *type) type->node_factory = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__NodeFactory); type->link = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Link); type->client = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Client); - type->client_node = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__ClientNode); type->module = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Module); type->spa_log = spa_type_map_get_id(type->map, SPA_TYPE__Log); diff --git a/pipewire/client/type.h b/pipewire/client/type.h index 70f3f8bec..5527e47cc 100644 --- a/pipewire/client/type.h +++ b/pipewire/client/type.h @@ -66,7 +66,6 @@ struct pw_type { uint32_t node_factory; uint32_t link; uint32_t client; - uint32_t client_node; uint32_t module; uint32_t spa_log; diff --git a/pipewire/modules/meson.build b/pipewire/modules/meson.build index 05104a850..35153aadf 100644 --- a/pipewire/modules/meson.build +++ b/pipewire/modules/meson.build @@ -32,7 +32,8 @@ pipewire_module_mixer = shared_library('pipewire-module-mixer', [ 'module-mixer. dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep], ) -pipewire_module_client_node = shared_library('pipewire-module-client-node', [ 'module-client-node.c' ], +pipewire_module_client_node = shared_library('pipewire-module-client-node', + [ 'module-client-node.c', 'module-client-node/client-node.c' ], c_args : pipewire_module_c_args, include_directories : [configinc, spa_inc], link_with : spalib, diff --git a/pipewire/modules/module-autolink.c b/pipewire/modules/module-autolink.c index 78c0bb3a6..f4cb6132e 100644 --- a/pipewire/modules/module-autolink.c +++ b/pipewire/modules/module-autolink.c @@ -26,7 +26,6 @@ #include "pipewire/client/interfaces.h" #include "pipewire/server/core.h" #include "pipewire/server/module.h" -#include "pipewire/server/client-node.h" struct impl { struct pw_core *core; @@ -35,23 +34,12 @@ struct impl { struct pw_listener global_added; struct pw_listener global_removed; - struct spa_list client_list; -}; - -struct client_info { - struct impl *impl; - struct pw_client *client; - struct spa_list link; - struct pw_listener resource_impl; - struct pw_listener resource_removed; struct spa_list node_list; }; struct node_info { struct impl *impl; - struct client_info *info; struct pw_node *node; - struct pw_resource *resource; struct spa_list link; struct pw_listener state_changed; struct pw_listener port_added; @@ -60,28 +48,17 @@ struct node_info { struct pw_listener link_state_changed; }; -static struct node_info *find_node_info(struct client_info *cinfo, struct pw_node *node) +static struct node_info *find_node_info(struct impl *impl, struct pw_node *node) { struct node_info *info; - spa_list_for_each(info, &cinfo->node_list, link) { + spa_list_for_each(info, &impl->node_list, link) { if (info->node == node) return info; } return NULL; } -static struct client_info *find_client_info(struct impl *impl, struct pw_client *client) -{ - struct client_info *info; - - spa_list_for_each(info, &impl->client_list, link) { - if (info->client == client) - return info; - } - return NULL; -} - static void node_info_free(struct node_info *info) { spa_list_remove(&info->link); @@ -93,20 +70,6 @@ static void node_info_free(struct node_info *info) free(info); } -static void client_info_free(struct client_info *cinfo) -{ - struct node_info *info, *tmp; - - spa_list_remove(&cinfo->link); - pw_signal_remove(&cinfo->resource_impl); - pw_signal_remove(&cinfo->resource_removed); - - spa_list_for_each_safe(info, tmp, &cinfo->node_list, link) - node_info_free(info); - - free(cinfo); -} - static void try_link_port(struct pw_node *node, struct pw_port *port, struct node_info *info); static void @@ -139,14 +102,15 @@ on_link_state_changed(struct pw_listener *listener, pw_core_notify_error(resource->client->core_resource, resource->id, SPA_RESULT_ERROR, link->error); } - if (info->info->client) { - pw_core_notify_error(info->info->client->core_resource, - info->resource->id, + if (info->node->owner) { + pw_core_notify_error(info->node->owner->client->core_resource, + info->node->owner->id, SPA_RESULT_ERROR, link->error); } break; } + case PW_LINK_STATE_UNLINKED: pw_log_debug("module %p: link %p: unlinked", impl, link); break; @@ -211,9 +175,9 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod error: pw_log_error("module %p: can't link node '%s'", impl, error); - if (info->info->client && info->info->client->core_resource) { - pw_core_notify_error(info->info->client->core_resource, - info->resource->id, SPA_RESULT_ERROR, error); + if (info->node->owner && info->node->owner->client->core_resource) { + pw_core_notify_error(info->node->owner->client->core_resource, + info->node->owner->id, SPA_RESULT_ERROR, error); } free(error); return; @@ -252,84 +216,30 @@ on_state_changed(struct pw_listener *listener, on_node_created(node, info); } -static void -on_node_added(struct impl *impl, - struct pw_node *node, struct pw_resource *resource, struct client_info *cinfo) -{ - struct node_info *info; - - info = calloc(1, sizeof(struct node_info)); - info->impl = impl; - info->node = node; - info->resource = resource; - info->info = cinfo; - spa_list_insert(cinfo->node_list.prev, &info->link); - - spa_list_init(&info->port_unlinked.link); - spa_list_init(&info->link_state_changed.link); - pw_signal_add(&node->port_added, &info->port_added, on_port_added); - pw_signal_add(&node->port_removed, &info->port_removed, on_port_removed); - pw_signal_add(&node->state_changed, &info->state_changed, on_state_changed); - - pw_log_debug("module %p: node %p added", impl, node); - - if (node->info.state > PW_NODE_STATE_CREATING) - on_node_created(node, info); -} - -static void -on_resource_impl(struct pw_listener *listener, - struct pw_client *client, struct pw_resource *resource) -{ - struct client_info *cinfo = SPA_CONTAINER_OF(listener, struct client_info, resource_impl); - struct impl *impl = cinfo->impl; - - if (resource->type == impl->core->type.client_node) { - struct pw_client_node *cnode = resource->object; - on_node_added(impl, cnode->node, resource, cinfo); - } -} - -static void -on_resource_removed(struct pw_listener *listener, - struct pw_client *client, struct pw_resource *resource) -{ - struct client_info *cinfo = - SPA_CONTAINER_OF(listener, struct client_info, resource_removed); - struct impl *impl = cinfo->impl; - - if (resource->type == impl->core->type.client_node) { - struct pw_client_node *cnode = resource->object; - struct node_info *ninfo; - - if ((ninfo = find_node_info(cinfo, cnode->node))) - node_info_free(ninfo); - - pw_log_debug("module %p: node %p removed", impl, cnode->node); - } -} - static void on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_global *global) { struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_added); - if (global->type == impl->core->type.client) { - struct pw_client *client = global->object; - struct client_info *cinfo; + if (global->type == impl->core->type.node) { + struct pw_node *node = global->object; + struct node_info *ninfo; - cinfo = calloc(1, sizeof(struct client_info)); - cinfo->impl = impl; - cinfo->client = global->object; - spa_list_init(&cinfo->node_list); + ninfo = calloc(1, sizeof(struct node_info)); + ninfo->impl = impl; + ninfo->node = node; + spa_list_insert(impl->node_list.prev, &ninfo->link); + spa_list_init(&ninfo->port_unlinked.link); + spa_list_init(&ninfo->link_state_changed.link); - spa_list_insert(impl->client_list.prev, &cinfo->link); + pw_signal_add(&node->port_added, &ninfo->port_added, on_port_added); + pw_signal_add(&node->port_removed, &ninfo->port_removed, on_port_removed); + pw_signal_add(&node->state_changed, &ninfo->state_changed, on_state_changed); - pw_signal_add(&client->resource_impl, &cinfo->resource_impl, on_resource_impl); - pw_signal_add(&client->resource_removed, &cinfo->resource_removed, - on_resource_removed); + pw_log_debug("module %p: node %p added", impl, node); - pw_log_debug("module %p: client %p added", impl, cinfo->client); + if (node->info.state > PW_NODE_STATE_CREATING) + on_node_created(node, ninfo); } } @@ -338,14 +248,14 @@ on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_ { struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_removed); - if (global->type == impl->core->type.client) { - struct pw_client *client = global->object; - struct client_info *cinfo; + if (global->type == impl->core->type.node) { + struct pw_node *node = global->object; + struct node_info *ninfo; - if ((cinfo = find_client_info(impl, client))) - client_info_free(cinfo); + if ((ninfo = find_node_info(impl, node))) + node_info_free(ninfo); - pw_log_debug("module %p: client %p removed", impl, client); + pw_log_debug("module %p: node %p removed", impl, node); } } @@ -368,7 +278,7 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope impl->core = core; impl->properties = properties; - spa_list_init(&impl->client_list); + spa_list_init(&impl->node_list); pw_signal_add(&core->global_added, &impl->global_added, on_global_added); pw_signal_add(&core->global_removed, &impl->global_removed, on_global_removed); diff --git a/pipewire/modules/module-client-node.c b/pipewire/modules/module-client-node.c index 2e753734d..a9cef8682 100644 --- a/pipewire/modules/module-client-node.c +++ b/pipewire/modules/module-client-node.c @@ -27,9 +27,7 @@ #include "pipewire/client/interfaces.h" #include "pipewire/server/core.h" #include "pipewire/server/module.h" -#include "pipewire/server/client-node.h" - -#define AUDIOMIXER_LIB "build/spa/plugins/audiomixer/libspa-audiomixer.so" +#include "module-client-node/client-node.h" struct impl { struct pw_node_factory this; diff --git a/pipewire/server/client-node.c b/pipewire/modules/module-client-node/client-node.c similarity index 98% rename from pipewire/server/client-node.c rename to pipewire/modules/module-client-node/client-node.c index f6d4bdc88..1b03ddcfb 100644 --- a/pipewire/server/client-node.c +++ b/pipewire/modules/module-client-node/client-node.c @@ -37,7 +37,7 @@ #include "pipewire/client/transport.h" #include "pipewire/server/core.h" -#include "pipewire/server/client-node.h" +#include "client-node.h" /** \cond */ @@ -117,6 +117,8 @@ struct proxy { struct impl { struct pw_client_node this; + uint32_t type_client_node; + struct pw_core *core; struct proxy proxy; @@ -1064,7 +1066,7 @@ on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_gl struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_added); if (global->object == impl->this.node) - global->owner = impl->this.client; + global->owner = impl->this.resource; } static int proxy_clear(struct proxy *this) @@ -1152,24 +1154,26 @@ struct pw_client_node *pw_client_node_new(struct pw_client *client, impl->fds[0] = impl->fds[1] = -1; pw_log_debug("client-node %p: new", impl); + impl->type_client_node = spa_type_map_get_id(client->core->type.map, PIPEWIRE_TYPE__ClientNode); + pw_signal_init(&this->destroy_signal); proxy_init(&impl->proxy, NULL, client->core->support, client->core->n_support); - - this->node = pw_node_new(client->core, - client, name, true, &impl->proxy.node, NULL, properties); - if (this->node == NULL) - goto error_no_node; - impl->proxy.impl = impl; this->resource = pw_resource_new(client, id, - client->core->type.client_node, 0); + impl->type_client_node, + 0); if (this->resource == NULL) goto error_no_resource; + this->node = pw_node_new(client->core, + this->resource, name, true, &impl->proxy.node, NULL, properties); + if (this->node == NULL) + goto error_no_node; + pw_resource_set_implementation(this->resource, this, PW_VERSION_CLIENT_NODE, @@ -1184,9 +1188,9 @@ struct pw_client_node *pw_client_node_new(struct pw_client *client, return this; - error_no_resource: - pw_node_destroy(this->node); error_no_node: + pw_resource_destroy(this->resource); + error_no_resource: proxy_clear(&impl->proxy); free(impl); return NULL; diff --git a/pipewire/server/client-node.h b/pipewire/modules/module-client-node/client-node.h similarity index 100% rename from pipewire/server/client-node.h rename to pipewire/modules/module-client-node/client-node.h diff --git a/pipewire/modules/module-flatpak.c b/pipewire/modules/module-flatpak.c index 69fe6299d..0ad8f2f19 100644 --- a/pipewire/modules/module-flatpak.c +++ b/pipewire/modules/module-flatpak.c @@ -208,7 +208,7 @@ check_global_owner(struct pw_core *core, struct pw_client *client, struct pw_glo if (global->owner == NULL) return true; - if (global->owner->ucred.uid == client->ucred.uid) + if (global->owner->client->ucred.uid == client->ucred.uid) return true; return false; diff --git a/pipewire/modules/module-protocol-native.c b/pipewire/modules/module-protocol-native.c index e9b408425..2c1ae94b6 100644 --- a/pipewire/modules/module-protocol-native.c +++ b/pipewire/modules/module-protocol-native.c @@ -37,7 +37,6 @@ #include "pipewire/server/protocol-native.h" #include "pipewire/server/node.h" #include "pipewire/server/module.h" -#include "pipewire/server/client-node.h" #include "pipewire/server/client.h" #include "pipewire/server/resource.h" #include "pipewire/server/link.h" diff --git a/pipewire/server/client.c b/pipewire/server/client.c index e1b034947..a6cc641d6 100644 --- a/pipewire/server/client.c +++ b/pipewire/server/client.c @@ -110,7 +110,7 @@ struct pw_client *pw_client_new(struct pw_core *core, spa_list_insert(core->client_list.prev, &this->link); - pw_core_add_global(core, this, core->type.client, 0, this, client_bind_func, &this->global); + pw_core_add_global(core, NULL, core->type.client, 0, this, client_bind_func, &this->global); this->info.id = this->global->id; this->info.props = this->properties ? &this->properties->dict : NULL; diff --git a/pipewire/server/core.c b/pipewire/server/core.c index 35103f81f..2aed3bafc 100644 --- a/pipewire/server/core.c +++ b/pipewire/server/core.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -369,7 +368,7 @@ void pw_core_destroy(struct pw_core *core) */ bool pw_core_add_global(struct pw_core *core, - struct pw_client *owner, + struct pw_resource *owner, uint32_t type, uint32_t version, void *object, diff --git a/pipewire/server/core.h b/pipewire/server/core.h index 304c3a723..cd9a076cb 100644 --- a/pipewire/server/core.h +++ b/pipewire/server/core.h @@ -33,6 +33,7 @@ struct pw_global; #include #include +#include #include #include #include @@ -120,7 +121,7 @@ typedef bool (*pw_global_filter_func_t) (struct pw_global *global, */ struct pw_global { struct pw_core *core; /**< the core */ - struct pw_client *owner; /**< the owner of this object, NULL when the + struct pw_resource *owner; /**< the owner of this object, NULL when the * PipeWire server is the owner */ struct spa_list link; /**< link in core list of globals */ @@ -192,7 +193,7 @@ pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict); bool pw_core_add_global(struct pw_core *core, - struct pw_client *owner, + struct pw_resource *owner, uint32_t type, uint32_t version, void *object, pw_bind_func_t bind, diff --git a/pipewire/server/meson.build b/pipewire/server/meson.build index 2f63bc895..3e73224e7 100644 --- a/pipewire/server/meson.build +++ b/pipewire/server/meson.build @@ -1,6 +1,5 @@ pipewirecore_headers = [ 'client.h', - 'client-node.h', 'command.h', 'core.h', 'data-loop.h', @@ -17,7 +16,6 @@ pipewirecore_headers = [ pipewirecore_sources = [ 'client.c', - 'client-node.c', 'command.c', 'core.c', 'data-loop.c', diff --git a/pipewire/server/node.c b/pipewire/server/node.c index fb42d117a..585c421fe 100644 --- a/pipewire/server/node.c +++ b/pipewire/server/node.c @@ -519,7 +519,7 @@ static const struct spa_node_callbacks node_callbacks = { }; struct pw_node *pw_node_new(struct pw_core *core, - struct pw_client *owner, + struct pw_resource *owner, const char *name, bool async, struct spa_node *node, diff --git a/pipewire/server/node.h b/pipewire/server/node.h index f67747b91..c8ca05526 100644 --- a/pipewire/server/node.h +++ b/pipewire/server/node.h @@ -58,7 +58,7 @@ struct pw_node { struct spa_list link; /**< link in core node_list */ struct pw_global *global; /**< global for this node */ - struct pw_client *owner; /**< owner client if any */ + struct pw_resource *owner; /**< owner resource if any */ struct pw_properties *properties; /**< properties of the node */ struct pw_node_info info; /**< introspectable node info */ @@ -111,7 +111,7 @@ struct pw_node { /** Create a new node \memberof pw_node */ struct pw_node * pw_node_new(struct pw_core *core, /**< the core */ - struct pw_client *owner, /**< optional owner */ + struct pw_resource *owner, /**< optional owner */ const char *name, /**< node name */ bool async, /**< if the node will initialize async */ struct spa_node *node, /**< the node */