diff --git a/spa/include/spa/graph-scheduler3.h b/spa/include/spa/graph-scheduler3.h index 5ddaceca5..1b09bb5ed 100644 --- a/spa/include/spa/graph-scheduler3.h +++ b/spa/include/spa/graph-scheduler3.h @@ -60,7 +60,7 @@ static const struct spa_graph_node_methods spa_graph_node_scheduler_default = { static inline int spa_graph_port_scheduler_reuse_buffer(struct spa_graph_port *port, uint32_t buffer_id, void *user_data) { - printf("port %p reuse buffer %d\n", port, buffer_id); + debug("port %p reuse buffer %d\n", port, buffer_id); struct spa_node *node = port->node->user_data; return spa_node_port_reuse_buffer(node, port->port_id, buffer_id); } diff --git a/spa/include/spa/loop.h b/spa/include/spa/loop.h index 43bdcf51d..8a0fd4de1 100644 --- a/spa/include/spa/loop.h +++ b/spa/include/spa/loop.h @@ -100,10 +100,10 @@ struct spa_loop { #define spa_loop_remove_source(l,...) (l)->remove_source(__VA_ARGS__) #define spa_loop_invoke(l,...) (l)->invoke((l),__VA_ARGS__) -#define SPA_VERSION_LOOP_CONTROL_HOOKS 0 /** Control hooks */ struct spa_loop_control_hooks { +#define SPA_VERSION_LOOP_CONTROL_HOOKS 0 uint32_t version; struct spa_list link; @@ -114,7 +114,6 @@ struct spa_loop_control_hooks { void (*after) (const struct spa_loop_control_hooks *hooks); }; -#define SPA_VERSION_LOOP_CONTROL 0 /** * spa_loop_control: @@ -124,14 +123,14 @@ struct spa_loop_control_hooks { struct spa_loop_control { /* the version of this structure. This can be used to expand this * structure in the future */ +#define SPA_VERSION_LOOP_CONTROL 0 uint32_t version; int (*get_fd) (struct spa_loop_control *ctrl); /** Add a hook * \param ctrl the control to change - * \param hooks the new hooks - * \param old location to store previous hooks */ + * \param hooks the hooks to add */ void (*add_hooks) (struct spa_loop_control *ctrl, struct spa_loop_control_hooks *hooks); diff --git a/spa/include/spa/pod-builder.h b/spa/include/spa/pod-builder.h index 4dc3aa33f..f3d2443ac 100644 --- a/spa/include/spa/pod-builder.h +++ b/spa/include/spa/pod-builder.h @@ -25,7 +25,6 @@ extern "C" { #endif #include -#include #include struct spa_pod_frame { diff --git a/spa/include/spa/pod-utils.h b/spa/include/spa/pod-utils.h index 7858ee0ff..d7e2202c5 100644 --- a/spa/include/spa/pod-utils.h +++ b/spa/include/spa/pod-utils.h @@ -24,7 +24,6 @@ extern "C" { #endif -#include #include #include diff --git a/spa/plugins/support/plugin.c b/spa/plugins/support/plugin.c index 3cebdfd1f..5cc043c2c 100644 --- a/spa/plugins/support/plugin.c +++ b/spa/plugins/support/plugin.c @@ -17,6 +17,8 @@ * Boston, MA 02110-1301, USA. */ +#include + #include #include diff --git a/src/daemon/daemon-config.c b/src/daemon/daemon-config.c index 290639a34..e6156f4f2 100644 --- a/src/daemon/daemon-config.c +++ b/src/daemon/daemon-config.c @@ -23,6 +23,7 @@ #endif #include +#include #include #include diff --git a/src/extensions/client-node.h b/src/extensions/client-node.h index 445d9de32..869a06c7d 100644 --- a/src/extensions/client-node.h +++ b/src/extensions/client-node.h @@ -30,8 +30,8 @@ extern "C" { #include #include -#define PIPEWIRE_TYPE__ClientNode PIPEWIRE_TYPE_NODE_BASE "Client" -#define PIPEWIRE_TYPE_CLIENT_NODE_BASE PIPEWIRE_TYPE__ClientNode ":" +#define PW_TYPE__ClientNode PW_TYPE_NODE_BASE "Client" +#define PW_TYPE_CLIENT_NODE_BASE PW_TYPE__ClientNode ":" /** information about a buffer */ struct pw_client_node_buffer { diff --git a/src/extensions/protocol-native.h b/src/extensions/protocol-native.h new file mode 100644 index 000000000..232d7db26 --- /dev/null +++ b/src/extensions/protocol-native.h @@ -0,0 +1,75 @@ +/* PipeWire + * Copyright (C) 2017 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __PIPEWIRE_EXT_PROTOCOL_NATIVE_H__ +#define __PIPEWIRE_EXT_PROTOCOL_NATIVE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include + +#define PW_TYPE_PROTOCOL__Native PW_TYPE_PROTOCOL_BASE "Native" +#define PW_TYPE_PROTOCOL_NATIVE_BASE PW_TYPE_PROTOCOL__Native ":" + +/** \ref pw_protocol_native_ext methods */ +struct pw_protocol_native_ext { +#define PW_VERSION_PROTOCOL_NATIVE_EXT 0 + uint32_t version; + + struct spa_pod_builder * (*begin_proxy) (struct pw_proxy *proxy, + uint8_t opcode); + + uint32_t (*add_proxy_fd) (struct pw_proxy *proxy, int fd); + int (*get_proxy_fd) (struct pw_proxy *proxy, uint32_t index); + + void (*end_proxy) (struct pw_proxy *proxy, + struct spa_pod_builder *builder); + + struct spa_pod_builder * (*begin_resource) (struct pw_resource *resource, + uint8_t opcode); + + uint32_t (*add_resource_fd) (struct pw_resource *resource, int fd); + int (*get_resource_fd) (struct pw_resource *resource, uint32_t index); + + void (*end_resource) (struct pw_resource *resource, + struct spa_pod_builder *builder); + +}; + +#define pw_protocol_native_begin_proxy(p,...) pw_protocol_ext((p)->remote->conn->protocol,struct pw_protocol_native_ext,begin_proxy,p,__VA_ARGS__) +#define pw_protocol_native_add_proxy_fd(p,...) pw_protocol_ext((p)->remote->conn->protocol,struct pw_protocol_native_ext,add_proxy_fd,p,__VA_ARGS__) +#define pw_protocol_native_get_proxy_fd(p,...) pw_protocol_ext((p)->remote->conn->protocol,struct pw_protocol_native_ext,get_proxy_fd,p,__VA_ARGS__) +#define pw_protocol_native_end_proxy(p,...) pw_protocol_ext((p)->remote->conn->protocol,struct pw_protocol_native_ext,end_proxy,p,__VA_ARGS__) + +#define pw_protocol_native_begin_resource(r,...) pw_protocol_ext((r)->client->protocol,struct pw_protocol_native_ext,begin_resource,r,__VA_ARGS__) +#define pw_protocol_native_add_resource_fd(r,...) pw_protocol_ext((r)->client->protocol,struct pw_protocol_native_ext,add_resource_fd,r,__VA_ARGS__) +#define pw_protocol_native_get_resource_fd(r,...) pw_protocol_ext((r)->client->protocol,struct pw_protocol_native_ext,get_resource_fd,r,__VA_ARGS__) +#define pw_protocol_native_end_resource(r,...) pw_protocol_ext((r)->client->protocol,struct pw_protocol_native_ext,end_resource,r,__VA_ARGS__) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __PIPEWIRE_EXT_PROTOCOL_NATIVE_H__ */ diff --git a/src/modules/module-client-node.c b/src/modules/module-client-node.c index d1505068e..b0f887294 100644 --- a/src/modules/module-client-node.c +++ b/src/modules/module-client-node.c @@ -30,7 +30,7 @@ #include "module-client-node/client-node.h" -struct pw_protocol *pw_protocol_native_ext_client_node_init(void); +struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core); struct impl { struct pw_node_factory this; @@ -68,11 +68,11 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope impl->this.core = core; impl->this.name = "client-node"; - impl->this.type = spa_type_map_get_id(core->type.map, PIPEWIRE_TYPE__ClientNode); + impl->this.type = spa_type_map_get_id(core->type.map, PW_TYPE__ClientNode); pw_signal_init(&impl->this.destroy_signal); impl->this.create_node = create_node; - pw_protocol_native_ext_client_node_init(); + pw_protocol_native_ext_client_node_init(core); spa_list_insert(core->node_factory_list.prev, &impl->this.link); diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index 2db5c53ba..295826f17 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -1150,7 +1150,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource, impl->fds[0] = impl->fds[1] = -1; pw_log_debug("client-node %p: new", impl); - impl->type_client_node = spa_type_map_get_id(core->type.map, PIPEWIRE_TYPE__ClientNode); + impl->type_client_node = spa_type_map_get_id(core->type.map, PW_TYPE__ClientNode); pw_signal_init(&this->destroy_signal); diff --git a/src/modules/module-client-node/protocol-native.c b/src/modules/module-client-node/protocol-native.c index d7933f770..0c2bd03e6 100644 --- a/src/modules/module-client-node/protocol-native.c +++ b/src/modules/module-client-node/protocol-native.c @@ -25,9 +25,9 @@ #include "pipewire/interfaces.h" #include "pipewire/protocol.h" #include "pipewire/client.h" -#include "extensions/client-node.h" -#include "modules/module-protocol-native/connection.h" +#include "extensions/protocol-native.h" +#include "extensions/client-node.h" /** \cond */ @@ -39,17 +39,16 @@ static void client_node_marshal_done(void *object, int seq, int res) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_DONE); + b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_DONE); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_INT, res); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } @@ -60,18 +59,17 @@ client_node_marshal_update(void *object, uint32_t max_output_ports, const struct spa_props *props) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_UPDATE); + b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_UPDATE); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, change_mask, SPA_POD_TYPE_INT, max_input_ports, SPA_POD_TYPE_INT, max_output_ports, SPA_POD_TYPE_POD, props); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void @@ -86,12 +84,11 @@ client_node_marshal_port_update(void *object, const struct spa_param **params, const struct spa_port_info *info) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f[2]; int i; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_PORT_UPDATE); + b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_PORT_UPDATE); spa_pod_builder_add(b, SPA_POD_TYPE_STRUCT, &f[0], @@ -119,35 +116,33 @@ client_node_marshal_port_update(void *object, } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f[0], 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void client_node_marshal_event_method(void *object, struct spa_event *event) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_EVENT); + b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_EVENT); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_POD, event); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void client_node_marshal_destroy(void *object) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CLIENT_NODE_METHOD_DESTROY); + b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_METHOD_DESTROY); spa_pod_builder_struct(b, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static bool client_node_demarshal_set_props(void *object, void *data, size_t size) @@ -264,7 +259,6 @@ static bool client_node_demarshal_add_mem(void *object, void *data, size_t size) { struct pw_proxy *proxy = object; struct spa_pod_iter it; - struct pw_connection *connection = proxy->remote->protocol_private; uint32_t direction, port_id, mem_id, type, memfd_idx, flags, offset, sz; int memfd; @@ -280,7 +274,7 @@ static bool client_node_demarshal_add_mem(void *object, void *data, size_t size) SPA_POD_TYPE_INT, &offset, SPA_POD_TYPE_INT, &sz, 0)) return false; - memfd = pw_connection_get_fd(connection, memfd_idx); + memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx); ((struct pw_client_node_events *) proxy->implementation)->add_mem(proxy, direction, @@ -396,7 +390,6 @@ static bool client_node_demarshal_transport(void *object, void *data, size_t siz { struct pw_proxy *proxy = object; struct spa_pod_iter it; - struct pw_connection *connection = proxy->remote->protocol_private; uint32_t node_id, ridx, widx, memfd_idx, offset, sz; int readfd, writefd, memfd; @@ -410,9 +403,9 @@ static bool client_node_demarshal_transport(void *object, void *data, size_t siz SPA_POD_TYPE_INT, &sz, 0)) return false; - readfd = pw_connection_get_fd(connection, ridx); - writefd = pw_connection_get_fd(connection, widx); - memfd = pw_connection_get_fd(connection, memfd_idx); + readfd = pw_protocol_native_get_proxy_fd(proxy, ridx); + writefd = pw_protocol_native_get_proxy_fd(proxy, widx); + memfd = pw_protocol_native_get_proxy_fd(proxy, memfd_idx); if (readfd == -1 || writefd == -1 || memfd_idx == -1) return false; @@ -426,31 +419,29 @@ static void client_node_marshal_set_props(void *object, uint32_t seq, const struct spa_props *props) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_SET_PROPS); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_SET_PROPS); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_POD, props); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void client_node_marshal_event_event(void *object, const struct spa_event *event) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_EVENT); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_EVENT); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_POD, event); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -458,17 +449,16 @@ client_node_marshal_add_port(void *object, uint32_t seq, enum spa_direction direction, uint32_t port_id) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_ADD_PORT); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_ADD_PORT); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -476,17 +466,16 @@ client_node_marshal_remove_port(void *object, uint32_t seq, enum spa_direction direction, uint32_t port_id) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_REMOVE_PORT); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_REMOVE_PORT); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -498,11 +487,10 @@ client_node_marshal_set_format(void *object, const struct spa_format *format) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_SET_FORMAT); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_SET_FORMAT); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, @@ -511,7 +499,7 @@ client_node_marshal_set_format(void *object, SPA_POD_TYPE_INT, flags, SPA_POD_TYPE_POD, format); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -522,11 +510,10 @@ client_node_marshal_set_param(void *object, const struct spa_param *param) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_SET_PARAM); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_SET_PARAM); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, @@ -534,7 +521,7 @@ client_node_marshal_set_param(void *object, SPA_POD_TYPE_INT, port_id, SPA_POD_TYPE_POD, param); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -546,22 +533,21 @@ client_node_marshal_add_mem(void *object, int memfd, uint32_t flags, uint32_t offset, uint32_t size) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_ADD_MEM); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_ADD_MEM); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id, SPA_POD_TYPE_INT, mem_id, SPA_POD_TYPE_ID, type, - SPA_POD_TYPE_INT, pw_connection_add_fd(connection, memfd), + SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, memfd), SPA_POD_TYPE_INT, flags, SPA_POD_TYPE_INT, offset, SPA_POD_TYPE_INT, size); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -572,12 +558,11 @@ client_node_marshal_use_buffers(void *object, uint32_t n_buffers, struct pw_client_node_buffer *buffers) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, j; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_USE_BUFFERS); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_USE_BUFFERS); spa_pod_builder_add(b, SPA_POD_TYPE_STRUCT, &f, @@ -612,22 +597,21 @@ client_node_marshal_use_buffers(void *object, } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void client_node_marshal_node_command(void *object, uint32_t seq, const struct spa_command *command) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_NODE_COMMAND); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_NODE_COMMAND); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq, SPA_POD_TYPE_POD, command); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void @@ -637,38 +621,36 @@ client_node_marshal_port_command(void *object, const struct spa_command *command) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_PORT_COMMAND); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_PORT_COMMAND); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, direction, SPA_POD_TYPE_INT, port_id, SPA_POD_TYPE_POD, command); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd, int memfd, uint32_t offset, uint32_t size) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_NODE_EVENT_TRANSPORT); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_EVENT_TRANSPORT); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, node_id, - SPA_POD_TYPE_INT, pw_connection_add_fd(connection, readfd), - SPA_POD_TYPE_INT, pw_connection_add_fd(connection, writefd), - SPA_POD_TYPE_INT, pw_connection_add_fd(connection, memfd), + SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, readfd), + SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, writefd), + SPA_POD_TYPE_INT, pw_protocol_native_add_resource_fd(resource, memfd), SPA_POD_TYPE_INT, offset, SPA_POD_TYPE_INT, size); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } @@ -818,7 +800,7 @@ static const demarshal_func_t pw_protocol_native_client_client_node_demarshal[] }; static const struct pw_interface pw_protocol_native_client_client_node_interface = { - PIPEWIRE_TYPE_NODE_BASE "Client", + PW_TYPE__ClientNode, PW_VERSION_CLIENT_NODE, PW_CLIENT_NODE_METHOD_NUM, &pw_protocol_native_client_client_node_methods, PW_CLIENT_NODE_EVENT_NUM, pw_protocol_native_client_client_node_demarshal, @@ -847,27 +829,24 @@ static const struct pw_client_node_events pw_protocol_native_server_client_node_ }; const struct pw_interface pw_protocol_native_server_client_node_interface = { - PIPEWIRE_TYPE_NODE_BASE "Client", + PW_TYPE__ClientNode, PW_VERSION_CLIENT_NODE, PW_CLIENT_NODE_METHOD_NUM, &pw_protocol_native_server_client_node_demarshal, PW_CLIENT_NODE_EVENT_NUM, &pw_protocol_native_server_client_node_events, }; -struct pw_protocol *pw_protocol_native_ext_client_node_init(void) +struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core) { - static bool init = false; struct pw_protocol *protocol; - protocol = pw_protocol_get(PW_TYPE_PROTOCOL__Native); + protocol = pw_core_find_protocol(core, PW_TYPE_PROTOCOL__Native); - if (init) - return protocol; + if (protocol == NULL) + return NULL; pw_protocol_add_interfaces(protocol, &pw_protocol_native_client_client_node_interface, &pw_protocol_native_server_client_node_interface); - init = true; - return protocol; } diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 17d332f37..3c59af2d2 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -42,6 +42,7 @@ #include "pipewire/data-loop.h" #include "pipewire/main-loop.h" +#include "extensions/protocol-native.h" #include "modules/module-protocol-native/connection.h" #ifndef UNIX_PATH_MAX @@ -51,7 +52,7 @@ #define LOCK_SUFFIX ".lock" #define LOCK_SUFFIXLEN 5 -struct pw_protocol *pw_protocol_native_init(void); +void pw_protocol_native_init(struct pw_protocol *protocol); typedef bool(*demarshal_func_t) (void *object, void *data, size_t size); @@ -61,7 +62,7 @@ struct connection { int fd; struct spa_source *source; - struct pw_connection *connection; + struct pw_protocol_native_connection *connection; bool disconnecting; struct pw_listener need_flush; @@ -78,79 +79,57 @@ struct listener { struct pw_loop *loop; struct spa_source *source; -}; - -struct impl { - struct pw_core *core; - struct spa_list link; - - struct pw_protocol *protocol; - struct pw_properties *properties; - - struct spa_list client_list; - struct spa_loop_control_hooks hooks; }; -struct native_client { - struct impl *impl; - struct spa_list link; - struct pw_client *client; +struct protocol_data { + void *unused; +}; + +struct client_data { int fd; struct spa_source *source; - struct pw_connection *connection; + struct pw_protocol_native_connection *connection; struct pw_listener busy_changed; }; -static void client_destroy(void *data) -{ - struct pw_client *client = data; - struct native_client *this = client->user_data; - - pw_loop_destroy_source(this->impl->core->main_loop, this->source); - spa_list_remove(&this->link); - - pw_connection_destroy(this->connection); - close(this->fd); -} - static void -process_messages(struct native_client *client) +process_messages(struct pw_client *client) { - struct pw_connection *conn = client->connection; + struct client_data *data = client->user_data; + struct pw_protocol_native_connection *conn = data->connection; uint8_t opcode; uint32_t id; uint32_t size; - struct pw_client *c = client->client; void *message; - while (pw_connection_get_next(conn, &opcode, &id, &message, &size)) { + while (pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size)) { struct pw_resource *resource; const demarshal_func_t *demarshal; - pw_log_trace("protocol-native %p: got message %d from %u", client->impl, + pw_log_trace("protocol-native %p: got message %d from %u", client->protocol, opcode, id); - resource = pw_map_lookup(&c->objects, id); + resource = pw_map_lookup(&client->objects, id); if (resource == NULL) { pw_log_error("protocol-native %p: unknown resource %u", - client->impl, id); + client->protocol, id); continue; } if (opcode >= resource->iface->n_methods) { - pw_log_error("protocol-native %p: invalid method %u %u", client->impl, + pw_log_error("protocol-native %p: invalid method %u %u", client->protocol, id, opcode); - pw_client_destroy(c); + pw_client_destroy(client); break; } demarshal = resource->iface->methods; if (!demarshal[opcode] || !demarshal[opcode] (resource, message, size)) { pw_log_error("protocol-native %p: invalid message received %u %u", - client->impl, id, opcode); - pw_client_destroy(c); + client->protocol, id, opcode); + pw_client_destroy(client); break; } - if (c->busy) { + if (client->busy) { break; } } @@ -160,37 +139,41 @@ static void on_busy_changed(struct pw_listener *listener, struct pw_client *client) { - struct native_client *c = SPA_CONTAINER_OF(listener, struct native_client, busy_changed); + struct client_data *data = SPA_CONTAINER_OF(listener, struct client_data, busy_changed); enum spa_io mask = SPA_IO_ERR | SPA_IO_HUP; if (!client->busy) mask |= SPA_IO_IN; - pw_loop_update_io(c->impl->core->main_loop, c->source, mask); + pw_loop_update_io(client->core->main_loop, data->source, mask); if (!client->busy) - process_messages(c); + process_messages(client); } static void on_before_hook(const struct spa_loop_control_hooks *hooks) { - struct impl *this = SPA_CONTAINER_OF(hooks, struct impl, hooks); - struct native_client *client, *tmp; + struct listener *listener = SPA_CONTAINER_OF(hooks, struct listener, hooks); + struct pw_protocol_listener *this = &listener->this; + struct pw_client *client, *tmp; + struct client_data *data; - spa_list_for_each_safe(client, tmp, &this->client_list, link) - pw_connection_flush(client->connection); + spa_list_for_each_safe(client, tmp, &this->client_list, protocol_link) { + data = client->user_data; + pw_protocol_native_connection_flush(data->connection); + } } static void connection_data(struct spa_loop_utils *utils, struct spa_source *source, int fd, enum spa_io mask, void *data) { - struct native_client *client = data; + struct pw_client *client = data; if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { - pw_log_error("protocol-native %p: got connection error", client->impl); - pw_client_destroy(client->client); + pw_log_error("protocol-native %p: got connection error", client->protocol); + pw_client_destroy(client); return; } @@ -198,10 +181,23 @@ connection_data(struct spa_loop_utils *utils, process_messages(client); } -static struct native_client *client_new(struct impl *impl, int fd) +static void client_destroy(void *data) { - struct native_client *this; + struct pw_client *client = data; + struct client_data *this = client->user_data; + + pw_loop_destroy_source(client->protocol->core->main_loop, this->source); + spa_list_remove(&client->protocol_link); + + pw_protocol_native_connection_destroy(this->connection); + close(this->fd); +} + +static struct pw_client *client_new(struct listener *l, int fd) +{ + struct client_data *this; struct pw_client *client; + struct pw_protocol *protocol = l->this.protocol; socklen_t len; struct ucred ucred, *ucredp; @@ -213,61 +209,41 @@ static struct native_client *client_new(struct impl *impl, int fd) ucredp = &ucred; } - client = pw_client_new(impl->core, ucredp, NULL, sizeof(struct native_client)); + client = pw_client_new(protocol->core, ucredp, NULL, sizeof(struct client_data)); if (client == NULL) goto no_client; client->destroy = client_destroy; this = client->user_data; - this->impl = impl; this->fd = fd; - this->source = pw_loop_add_io(impl->core->main_loop, + this->source = pw_loop_add_io(protocol->core->main_loop, this->fd, - SPA_IO_ERR | SPA_IO_HUP, false, connection_data, this); + SPA_IO_ERR | SPA_IO_HUP, false, connection_data, client); if (this->source == NULL) goto no_source; - this->connection = pw_connection_new(fd); + this->connection = pw_protocol_native_connection_new(fd); if (this->connection == NULL) goto no_connection; - client->protocol = impl->protocol; - client->protocol_private = this->connection; - - this->client = client; - - spa_list_insert(impl->client_list.prev, &this->link); + client->protocol = protocol; + spa_list_insert(l->this.client_list.prev, &client->protocol_link); pw_signal_add(&client->busy_changed, &this->busy_changed, on_busy_changed); - pw_global_bind(impl->core->global, client, 0, 0); + pw_global_bind(protocol->core->global, client, PW_VERSION_CORE, 0); - return this; + return client; no_connection: - pw_loop_destroy_source(impl->core->main_loop, this->source); + pw_loop_destroy_source(protocol->core->main_loop, this->source); no_source: - free(this); + pw_client_destroy(client); no_client: return NULL; } -static void destroy_listener(struct listener *l) -{ - if (l->source) - pw_loop_destroy_source(l->loop, l->source); - if (l->addr.sun_path[0]) - unlink(l->addr.sun_path); - if (l->fd >= 0) - close(l->fd); - if (l->lock_addr[0]) - unlink(l->lock_addr); - if (l->fd_lock >= 0) - close(l->fd_lock); - free(l); -} - static bool init_socket_name(struct listener *l, const char *name) { int name_size; @@ -334,8 +310,9 @@ static void socket_data(struct spa_loop_utils *utils, struct spa_source *source, int fd, enum spa_io mask, void *data) { - struct impl *impl = data; - struct native_client *client; + struct listener *l = data; + struct pw_client *client; + struct client_data *c; struct sockaddr_un name; socklen_t length; int client_fd; @@ -347,18 +324,19 @@ socket_data(struct spa_loop_utils *utils, return; } - client = client_new(impl, client_fd); + client = client_new(l, client_fd); if (client == NULL) { pw_log_error("failed to create client"); close(client_fd); return; } + c = client->user_data; - pw_loop_update_io(impl->core->main_loop, - client->source, SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP); + pw_loop_update_io(client->protocol->core->main_loop, + c->source, SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP); } -static bool add_socket(struct impl *impl, struct listener *l) +static bool add_socket(struct pw_protocol *protocol, struct listener *l) { socklen_t size; @@ -376,8 +354,8 @@ static bool add_socket(struct impl *impl, struct listener *l) return false; } - l->loop = impl->core->main_loop; - l->source = pw_loop_add_io(l->loop, l->fd, SPA_IO_IN, false, socket_data, impl); + l->loop = protocol->core->main_loop; + l->source = pw_loop_add_io(l->loop, l->fd, SPA_IO_IN, false, socket_data, l); if (l->source == NULL) return false; @@ -441,11 +419,11 @@ static int impl_connect(struct pw_protocol_connection *conn) static void on_remote_data(struct spa_loop_utils *utils, - struct spa_source *source, int fd, enum spa_io mask, void *data) + struct spa_source *source, int fd, enum spa_io mask, void *data) { struct connection *impl = data; struct pw_remote *this = impl->this.remote; - struct pw_connection *conn = impl->connection; + struct pw_protocol_native_connection *conn = impl->connection; if (mask & (SPA_IO_ERR | SPA_IO_HUP)) { pw_log_error("protocol-native %p: got connection error", impl); @@ -460,7 +438,7 @@ on_remote_data(struct spa_loop_utils *utils, void *message; while (!impl->disconnecting - && pw_connection_get_next(conn, &opcode, &id, &message, &size)) { + && pw_protocol_native_connection_get_next(conn, &opcode, &id, &message, &size)) { struct pw_proxy *proxy; const demarshal_func_t *demarshal; @@ -496,11 +474,11 @@ static void do_flush_event(struct spa_loop_utils *utils, struct spa_source *sour { struct connection *impl = data; if (impl->connection) - if (!pw_connection_flush(impl->connection)) + if (!pw_protocol_native_connection_flush(impl->connection)) impl->this.disconnect(&impl->this); } -static void on_need_flush(struct pw_listener *listener, struct pw_connection *connection) +static void on_need_flush(struct pw_listener *listener, struct pw_protocol_native_connection *connection) { struct connection *impl = SPA_CONTAINER_OF(listener, struct connection, need_flush); struct pw_remote *remote = impl->this.remote; @@ -510,14 +488,12 @@ static void on_need_flush(struct pw_listener *listener, struct pw_connection *co static int impl_connect_fd(struct pw_protocol_connection *conn, int fd) { struct connection *impl = SPA_CONTAINER_OF(conn, struct connection, this); - struct pw_remote *remote = impl->this.remote; + struct pw_remote *remote = conn->remote; - impl->connection = pw_connection_new(fd); + impl->connection = pw_protocol_native_connection_new(fd); if (impl->connection == NULL) goto error_close; - conn->remote->protocol_private = impl->connection; - pw_signal_add(&impl->connection->need_flush, &impl->need_flush, on_need_flush); impl->fd = fd; @@ -533,10 +509,10 @@ static int impl_connect_fd(struct pw_protocol_connection *conn, int fd) return -1; } -static int impl_disconnect(struct pw_protocol_connection *conn) +static void impl_disconnect(struct pw_protocol_connection *conn) { struct connection *impl = SPA_CONTAINER_OF(conn, struct connection, this); - struct pw_remote *remote = impl->this.remote; + struct pw_remote *remote = conn->remote; impl->disconnecting = true; @@ -545,17 +521,15 @@ static int impl_disconnect(struct pw_protocol_connection *conn) impl->source = NULL; if (impl->connection) - pw_connection_destroy(impl->connection); + pw_protocol_native_connection_destroy(impl->connection); impl->connection = NULL; if (impl->fd != -1) close(impl->fd); impl->fd = -1; - - return 0; } -static int impl_destroy(struct pw_protocol_connection *conn) +static void impl_destroy(struct pw_protocol_connection *conn) { struct connection *impl = SPA_CONTAINER_OF(conn, struct connection, this); struct pw_remote *remote = conn->remote; @@ -564,8 +538,6 @@ static int impl_destroy(struct pw_protocol_connection *conn) spa_list_remove(&conn->link); free(impl); - - return 0; } static struct pw_protocol_connection * @@ -573,14 +545,14 @@ impl_new_connection(struct pw_protocol *protocol, struct pw_remote *remote, struct pw_properties *properties) { - struct impl *impl = protocol->protocol_private; - struct connection *c; + struct connection *impl; struct pw_protocol_connection *this; - if ((c = calloc(1, sizeof(struct connection))) == NULL) + if ((impl = calloc(1, sizeof(struct connection))) == NULL) return NULL; - this = &c->this; + this = &impl->this; + this->protocol = protocol; this->remote = remote; this->connect = impl_connect; @@ -588,19 +560,36 @@ impl_new_connection(struct pw_protocol *protocol, this->disconnect = impl_disconnect; this->destroy = impl_destroy; - c->flush_event = pw_loop_add_event(remote->core->main_loop, do_flush_event, c); + impl->flush_event = pw_loop_add_event(remote->core->main_loop, do_flush_event, impl); - spa_list_insert(impl->protocol->connection_list.prev, &c->this.link); + spa_list_insert(protocol->connection_list.prev, &this->link); return this; } +static void destroy_listener(struct pw_protocol_listener *listener) +{ + struct listener *l = SPA_CONTAINER_OF(listener, struct listener, this); + + if (l->source) + pw_loop_destroy_source(l->loop, l->source); + if (l->addr.sun_path[0]) + unlink(l->addr.sun_path); + if (l->fd >= 0) + close(l->fd); + if (l->lock_addr[0]) + unlink(l->lock_addr); + if (l->fd_lock >= 0) + close(l->fd_lock); + free(l); +} + static struct pw_protocol_listener * impl_add_listener(struct pw_protocol *protocol, struct pw_core *core, struct pw_properties *properties) { - struct impl *impl = protocol->protocol_private; + struct pw_protocol_listener *this; struct listener *l; const char *name; @@ -610,6 +599,11 @@ impl_add_listener(struct pw_protocol *protocol, l->fd = -1; l->fd_lock = -1; + this = &l->this; + this->protocol = protocol; + spa_list_init(&this->client_list); + this->destroy = destroy_listener; + name = get_name(core->properties); if (!init_socket_name(l, name)) @@ -618,46 +612,113 @@ impl_add_listener(struct pw_protocol *protocol, if (!lock_socket(l)) goto error; - if (!add_socket(impl, l)) + if (!add_socket(protocol, l)) goto error; - spa_list_insert(impl->protocol->listener_list.prev, &l->this.link); + spa_list_insert(protocol->listener_list.prev, &this->link); - impl->hooks.before = on_before_hook; - pw_loop_add_hooks(impl->core->main_loop, &impl->hooks); + l->hooks.before = on_before_hook; + pw_loop_add_hooks(protocol->core->main_loop, &l->hooks); - pw_log_info("protocol-native %p: Added listener", protocol); + pw_log_info("protocol-native %p: Added listener %p", protocol, this); - return &l->this; + return this; error: - destroy_listener(l); + destroy_listener(this); return NULL; } +const static struct pw_protocol_implementaton protocol_impl = { + PW_VERSION_PROTOCOL_IMPLEMENTATION, + impl_new_connection, + impl_add_listener, +}; -static struct impl *pw_protocol_native_new(struct pw_core *core, struct pw_properties *properties) +static struct spa_pod_builder * +impl_ext_begin_proxy(struct pw_proxy *proxy, uint8_t opcode) { - struct impl *impl; + struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this); + return pw_protocol_native_connection_begin_proxy(impl->connection, proxy, opcode); +} + +static uint32_t impl_ext_add_proxy_fd(struct pw_proxy *proxy, int fd) +{ + struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this); + return pw_protocol_native_connection_add_fd(impl->connection, fd); +} + +static int impl_ext_get_proxy_fd(struct pw_proxy *proxy, uint32_t index) +{ + struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this); + return pw_protocol_native_connection_get_fd(impl->connection, index); +} + +static void impl_ext_end_proxy(struct pw_proxy *proxy, + struct spa_pod_builder *builder) +{ + struct connection *impl = SPA_CONTAINER_OF(proxy->remote->conn, struct connection, this); + pw_protocol_native_connection_end(impl->connection, builder); +} + +static struct spa_pod_builder * +impl_ext_begin_resource(struct pw_resource *resource, uint8_t opcode) +{ + struct client_data *data = resource->client->user_data; + return pw_protocol_native_connection_begin_resource(data->connection, resource, opcode); +} + +static uint32_t impl_ext_add_resource_fd(struct pw_resource *resource, int fd) +{ + struct client_data *data = resource->client->user_data; + return pw_protocol_native_connection_add_fd(data->connection, fd); +} +static int impl_ext_get_resource_fd(struct pw_resource *resource, uint32_t index) +{ + struct client_data *data = resource->client->user_data; + return pw_protocol_native_connection_get_fd(data->connection, index); +} + +static void impl_ext_end_resource(struct pw_resource *resource, + struct spa_pod_builder *builder) +{ + struct client_data *data = resource->client->user_data; + pw_protocol_native_connection_end(data->connection, builder); +} + +const static struct pw_protocol_native_ext protocol_ext_impl = { + PW_VERSION_PROTOCOL_NATIVE_EXT, + impl_ext_begin_proxy, + impl_ext_add_proxy_fd, + impl_ext_get_proxy_fd, + impl_ext_end_proxy, + impl_ext_begin_resource, + impl_ext_add_resource_fd, + impl_ext_get_resource_fd, + impl_ext_end_resource, +}; + +static struct pw_protocol *pw_protocol_native_new(struct pw_core *core, struct pw_properties *properties) +{ + struct pw_protocol *this; const char *val; - impl = calloc(1, sizeof(struct impl)); + this = pw_protocol_new(core, PW_TYPE_PROTOCOL__Native, sizeof(struct protocol_data)); + if (this == NULL) + return NULL; - impl->core = core; - impl->properties = properties; - impl->protocol = pw_protocol_native_init(); - impl->protocol->new_connection = impl_new_connection; - impl->protocol->add_listener = impl_add_listener; - impl->protocol->protocol_private = impl; - pw_log_debug("protocol-native %p: new %p", impl, impl->protocol); + this->implementation = &protocol_impl; + this->extension = &protocol_ext_impl; - spa_list_init(&impl->client_list); + pw_protocol_native_init(this); + + pw_log_debug("protocol-native %p: new", this); if ((val = pw_properties_get(core->properties, "pipewire.daemon"))) { if (atoi(val) == 1) - impl_add_listener(impl->protocol, core, properties); + impl_add_listener(this, core, properties); } - return impl; + return this; } #if 0 diff --git a/src/modules/module-protocol-native/connection.c b/src/modules/module-protocol-native/connection.c index 073cc836d..cbd257e4e 100644 --- a/src/modules/module-protocol-native/connection.c +++ b/src/modules/module-protocol-native/connection.c @@ -53,7 +53,7 @@ struct buffer { }; struct impl { - struct pw_connection this; + struct pw_protocol_native_connection this; struct buffer in, out; @@ -70,9 +70,9 @@ struct impl { * \param index the index of the fd to get * \return the fd at \a index or -1 when no such fd exists * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ -int pw_connection_get_fd(struct pw_connection *conn, uint32_t index) +int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *conn, uint32_t index) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); @@ -88,9 +88,9 @@ int pw_connection_get_fd(struct pw_connection *conn, uint32_t index) * \param fd the fd to add * \return the index of the fd or -1 when an error occured * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ -uint32_t pw_connection_add_fd(struct pw_connection *conn, int fd) +uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connection *conn, int fd) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); uint32_t index, i; @@ -112,7 +112,7 @@ uint32_t pw_connection_add_fd(struct pw_connection *conn, int fd) return index; } -static void *connection_ensure_size(struct pw_connection *conn, struct buffer *buf, size_t size) +static void *connection_ensure_size(struct pw_protocol_native_connection *conn, struct buffer *buf, size_t size) { if (buf->buffer_size + size > buf->buffer_maxsize) { buf->buffer_maxsize = SPA_ROUND_UP_N(buf->buffer_size + size, MAX_BUFFER_SIZE); @@ -124,7 +124,7 @@ static void *connection_ensure_size(struct pw_connection *conn, struct buffer *b return (uint8_t *) buf->buffer_data + buf->buffer_size; } -static bool refill_buffer(struct pw_connection *conn, struct buffer *buf) +static bool refill_buffer(struct pw_protocol_native_connection *conn, struct buffer *buf) { ssize_t len; struct cmsghdr *cmsg; @@ -186,12 +186,12 @@ static void clear_buffer(struct buffer *buf) * \param fd the socket * \returns a newly allocated connection object * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ -struct pw_connection *pw_connection_new(int fd) +struct pw_protocol_native_connection *pw_protocol_native_connection_new(int fd) { struct impl *impl; - struct pw_connection *this; + struct pw_protocol_native_connection *this; impl = calloc(1, sizeof(struct impl)); if (impl == NULL) @@ -229,9 +229,9 @@ struct pw_connection *pw_connection_new(int fd) * * \param conn the connection to destroy * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ -void pw_connection_destroy(struct pw_connection *conn) +void pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); @@ -256,10 +256,10 @@ void pw_connection_destroy(struct pw_connection *conn) * Get the next packet in \a conn and store the opcode and destination * id as well as the packet data and size. * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ bool -pw_connection_get_next(struct pw_connection *conn, +pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *conn, uint8_t *opcode, uint32_t *dest_id, void **dt, @@ -330,7 +330,7 @@ pw_connection_get_next(struct pw_connection *conn, return true; } -static inline void *begin_write(struct pw_connection *conn, uint32_t size) +static inline void *begin_write(struct pw_protocol_native_connection *conn, uint32_t size) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); uint32_t *p; @@ -357,9 +357,9 @@ static uint32_t write_pod(struct spa_pod_builder *b, uint32_t ref, const void *d } struct spa_pod_builder * -pw_connection_begin_write_resource(struct pw_connection *conn, - struct pw_resource *resource, - uint8_t opcode) +pw_protocol_native_connection_begin_resource(struct pw_protocol_native_connection *conn, + struct pw_resource *resource, + uint8_t opcode) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); uint32_t diff, base, i, b; @@ -386,9 +386,9 @@ pw_connection_begin_write_resource(struct pw_connection *conn, } struct spa_pod_builder * -pw_connection_begin_write_proxy(struct pw_connection *conn, - struct pw_proxy *proxy, - uint8_t opcode) +pw_protocol_native_connection_begin_proxy(struct pw_protocol_native_connection *conn, + struct pw_proxy *proxy, + uint8_t opcode) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); uint32_t diff, base, i, b; @@ -415,8 +415,8 @@ pw_connection_begin_write_proxy(struct pw_connection *conn, } void -pw_connection_end_write(struct pw_connection *conn, - struct spa_pod_builder *builder) +pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn, + struct spa_pod_builder *builder) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); uint32_t *p, size = builder->offset; @@ -443,9 +443,9 @@ pw_connection_end_write(struct pw_connection *conn, * * Write the queued messages on the connection to the socket * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ -bool pw_connection_flush(struct pw_connection *conn) +bool pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); ssize_t len; @@ -515,9 +515,9 @@ bool pw_connection_flush(struct pw_connection *conn) * * Remove all queued messages from \a conn * - * \memberof pw_connection + * \memberof pw_protocol_native_connection */ -bool pw_connection_clear(struct pw_connection *conn) +bool pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn) { struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this); diff --git a/src/modules/module-protocol-native/connection.h b/src/modules/module-protocol-native/connection.h index 7f2134495..7960fd42b 100644 --- a/src/modules/module-protocol-native/connection.h +++ b/src/modules/module-protocol-native/connection.h @@ -17,8 +17,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PIPEWIRE_CONNECTION_H__ -#define __PIPEWIRE_CONNECTION_H__ +#ifndef __PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H__ +#define __PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H__ #ifdef __cplusplus extern "C" { @@ -27,63 +27,61 @@ extern "C" { #include #include -/** \class pw_connection +/** \class pw_protocol_native_connection * * \brief Manages the connection between client and server * - * The \ref pw_connection handles the connection between client + * The \ref pw_protocol_native_connection handles the connection between client * and server on a given socket. */ -struct pw_connection { +struct pw_protocol_native_connection { int fd; /**< the socket */ /** Emited when data has been written that needs to be flushed */ - PW_SIGNAL(need_flush, (struct pw_listener *listener, struct pw_connection *conn)); + PW_SIGNAL(need_flush, (struct pw_listener *listener, + struct pw_protocol_native_connection *conn)); /** Emited when the connection is destroyed */ - PW_SIGNAL(destroy_signal, (struct pw_listener *listener, struct pw_connection *conn)); + PW_SIGNAL(destroy_signal, (struct pw_listener *listener, + struct pw_protocol_native_connection *conn)); }; -struct pw_connection * -pw_connection_new(int fd); +struct pw_protocol_native_connection * +pw_protocol_native_connection_new(int fd); void -pw_connection_destroy(struct pw_connection *conn); - -uint32_t -pw_connection_add_fd(struct pw_connection *conn, int fd); - -int -pw_connection_get_fd(struct pw_connection *conn, uint32_t index); +pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn); bool -pw_connection_get_next(struct pw_connection *conn, - uint8_t *opcode, - uint32_t *dest_id, - void **data, uint32_t *size); +pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *conn, + uint8_t *opcode, + uint32_t *dest_id, + void **data, uint32_t *size); + +uint32_t pw_protocol_native_connection_add_fd(struct pw_protocol_native_connection *conn, int fd); + +int pw_protocol_native_connection_get_fd(struct pw_protocol_native_connection *conn, uint32_t index); struct spa_pod_builder * -pw_connection_begin_write_resource(struct pw_connection *conn, - struct pw_resource *resource, - uint8_t opcode); +pw_protocol_native_connection_begin_resource(struct pw_protocol_native_connection *conn, + struct pw_resource *resource, + uint8_t opcode); struct spa_pod_builder * -pw_connection_begin_write_proxy(struct pw_connection *conn, - struct pw_proxy *proxy, - uint8_t opcode); - - +pw_protocol_native_connection_begin_proxy(struct pw_protocol_native_connection *conn, + struct pw_proxy *proxy, + uint8_t opcode); void -pw_connection_end_write(struct pw_connection *conn, - struct spa_pod_builder *builder); +pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn, + struct spa_pod_builder *builder); bool -pw_connection_flush(struct pw_connection *conn); +pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn); bool -pw_connection_clear(struct pw_connection *conn); +pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* __PIPEWIRE_CONNECTION_H__ */ +#endif /* __PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H__ */ diff --git a/src/modules/module-protocol-native/protocol-native.c b/src/modules/module-protocol-native/protocol-native.c index a8a950bc9..a4467c88c 100644 --- a/src/modules/module-protocol-native/protocol-native.c +++ b/src/modules/module-protocol-native/protocol-native.c @@ -17,6 +17,7 @@ * Boston, MA 02110-1301, USA. */ +#include #include #include "spa/pod-iter.h" @@ -25,6 +26,7 @@ #include "pipewire/protocol.h" #include "pipewire/interfaces.h" #include "pipewire/resource.h" +#include "extensions/protocol-native.h" #include "connection.h" @@ -37,12 +39,11 @@ typedef bool(*demarshal_func_t) (void *object, void *data, size_t size); static void core_marshal_client_update(void *object, const struct spa_dict *props) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; int i, n_items; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_CLIENT_UPDATE); + b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CLIENT_UPDATE); n_items = props ? props->n_items : 0; @@ -55,37 +56,35 @@ static void core_marshal_client_update(void *object, const struct spa_dict *prop } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void core_marshal_sync(void *object, uint32_t seq) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_SYNC); + b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_SYNC); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void core_marshal_get_registry(void *object, uint32_t version, uint32_t new_id) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_GET_REGISTRY); + b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_GET_REGISTRY); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, version, SPA_POD_TYPE_INT, new_id); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void @@ -95,12 +94,11 @@ core_marshal_create_node(void *object, uint32_t version, uint32_t new_id) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, n_items; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_CREATE_NODE); + b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CREATE_NODE); n_items = props ? props->n_items : 0; @@ -119,7 +117,7 @@ core_marshal_create_node(void *object, SPA_POD_TYPE_INT, new_id, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void @@ -133,12 +131,11 @@ core_marshal_create_link(void *object, uint32_t new_id) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, n_items; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_CREATE_LINK); + b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CREATE_LINK); n_items = props ? props->n_items : 0; @@ -160,19 +157,18 @@ core_marshal_create_link(void *object, SPA_POD_TYPE_INT, new_id, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static void core_marshal_update_types_client(void *object, uint32_t first_id, uint32_t n_types, const char **types) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i; - b = pw_connection_begin_write_proxy(connection, proxy, PW_CORE_METHOD_UPDATE_TYPES); + b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_UPDATE_TYPES); spa_pod_builder_add(b, SPA_POD_TYPE_STRUCT, &f, @@ -183,7 +179,7 @@ core_marshal_update_types_client(void *object, uint32_t first_id, uint32_t n_typ } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static bool core_demarshal_info(void *object, void *data, size_t size) @@ -286,12 +282,11 @@ static bool core_demarshal_update_types_client(void *object, void *data, size_t static void core_marshal_info(void *object, struct pw_core_info *info) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, n_items; - b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_INFO); + b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_INFO); n_items = info->props ? info->props->n_items : 0; @@ -312,33 +307,31 @@ static void core_marshal_info(void *object, struct pw_core_info *info) } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void core_marshal_done(void *object, uint32_t seq) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_DONE); + b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_DONE); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, seq); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void core_marshal_error(void *object, uint32_t id, int res, const char *error, ...) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; char buffer[128]; struct spa_pod_builder *b; struct spa_pod_frame f; va_list ap; - b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_ERROR); + b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_ERROR); va_start(ap, error); vsnprintf(buffer, sizeof(buffer), error, ap); @@ -349,33 +342,31 @@ static void core_marshal_error(void *object, uint32_t id, int res, const char *e SPA_POD_TYPE_INT, res, SPA_POD_TYPE_STRING, buffer); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void core_marshal_remove_id(void *object, uint32_t id) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_REMOVE_ID); + b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_REMOVE_ID); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, id); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void core_marshal_update_types_server(void *object, uint32_t first_id, uint32_t n_types, const char **types) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i; - b = pw_connection_begin_write_resource(connection, resource, PW_CORE_EVENT_UPDATE_TYPES); + b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_UPDATE_TYPES); spa_pod_builder_add(b, SPA_POD_TYPE_STRUCT, &f, @@ -386,7 +377,7 @@ core_marshal_update_types_server(void *object, uint32_t first_id, uint32_t n_typ } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static bool core_demarshal_client_update(void *object, void *data, size_t size) @@ -537,32 +528,30 @@ static bool core_demarshal_update_types_server(void *object, void *data, size_t static void registry_marshal_global(void *object, uint32_t id, uint32_t type, uint32_t version) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_REGISTRY_EVENT_GLOBAL); + b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_EVENT_GLOBAL); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, id, SPA_POD_TYPE_ID, type, SPA_POD_TYPE_INT, version); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static void registry_marshal_global_remove(void *object, uint32_t id) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_REGISTRY_EVENT_GLOBAL_REMOVE); + b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_EVENT_GLOBAL_REMOVE); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, id); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static bool registry_demarshal_bind(void *object, void *data, size_t size) @@ -585,12 +574,11 @@ static bool registry_demarshal_bind(void *object, void *data, size_t size) static void module_marshal_info(void *object, struct pw_module_info *info) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, n_items; - b = pw_connection_begin_write_resource(connection, resource, PW_MODULE_EVENT_INFO); + b = pw_protocol_native_begin_resource(resource, PW_MODULE_EVENT_INFO); n_items = info->props ? info->props->n_items : 0; @@ -609,7 +597,7 @@ static void module_marshal_info(void *object, struct pw_module_info *info) } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static bool module_demarshal_info(void *object, void *data, size_t size) @@ -644,12 +632,11 @@ static bool module_demarshal_info(void *object, void *data, size_t size) static void node_marshal_info(void *object, struct pw_node_info *info) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, n_items; - b = pw_connection_begin_write_resource(connection, resource, PW_NODE_EVENT_INFO); + b = pw_protocol_native_begin_resource(resource, PW_NODE_EVENT_INFO); spa_pod_builder_add(b, SPA_POD_TYPE_STRUCT, &f, @@ -684,7 +671,7 @@ static void node_marshal_info(void *object, struct pw_node_info *info) } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static bool node_demarshal_info(void *object, void *data, size_t size) @@ -743,12 +730,11 @@ static bool node_demarshal_info(void *object, void *data, size_t size) static void client_marshal_info(void *object, struct pw_client_info *info) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; uint32_t i, n_items; - b = pw_connection_begin_write_resource(connection, resource, PW_CLIENT_EVENT_INFO); + b = pw_protocol_native_begin_resource(resource, PW_CLIENT_EVENT_INFO); n_items = info->props ? info->props->n_items : 0; @@ -764,7 +750,7 @@ static void client_marshal_info(void *object, struct pw_client_info *info) } spa_pod_builder_add(b, -SPA_POD_TYPE_STRUCT, &f, 0); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static bool client_demarshal_info(void *object, void *data, size_t size) @@ -797,11 +783,10 @@ static bool client_demarshal_info(void *object, void *data, size_t size) static void link_marshal_info(void *object, struct pw_link_info *info) { struct pw_resource *resource = object; - struct pw_connection *connection = resource->client->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_resource(connection, resource, PW_LINK_EVENT_INFO); + b = pw_protocol_native_begin_resource(resource, PW_LINK_EVENT_INFO); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, info->id, @@ -812,7 +797,7 @@ static void link_marshal_info(void *object, struct pw_link_info *info) SPA_POD_TYPE_INT, info->input_port_id, SPA_POD_TYPE_POD, info->format); - pw_connection_end_write(connection, b); + pw_protocol_native_end_resource(resource, b); } static bool link_demarshal_info(void *object, void *data, size_t size) @@ -872,18 +857,17 @@ static bool registry_demarshal_global_remove(void *object, void *data, size_t si static void registry_marshal_bind(void *object, uint32_t id, uint32_t version, uint32_t new_id) { struct pw_proxy *proxy = object; - struct pw_connection *connection = proxy->remote->protocol_private; struct spa_pod_builder *b; struct spa_pod_frame f; - b = pw_connection_begin_write_proxy(connection, proxy, PW_REGISTRY_METHOD_BIND); + b = pw_protocol_native_begin_proxy(proxy, PW_REGISTRY_METHOD_BIND); spa_pod_builder_struct(b, &f, SPA_POD_TYPE_INT, id, SPA_POD_TYPE_INT, version, SPA_POD_TYPE_INT, new_id); - pw_connection_end_write(connection, b); + pw_protocol_native_end_proxy(proxy, b); } static const struct pw_core_methods pw_protocol_native_client_core_methods = { @@ -904,7 +888,7 @@ static const demarshal_func_t pw_protocol_native_client_core_demarshal[PW_CORE_E }; static const struct pw_interface pw_protocol_native_client_core_interface = { - PIPEWIRE_TYPE__Core, + PW_TYPE__Core, PW_VERSION_CORE, PW_CORE_METHOD_NUM, &pw_protocol_native_client_core_methods, PW_CORE_EVENT_NUM, pw_protocol_native_client_core_demarshal @@ -920,7 +904,7 @@ static const demarshal_func_t pw_protocol_native_client_registry_demarshal[] = { }; static const struct pw_interface pw_protocol_native_client_registry_interface = { - PIPEWIRE_TYPE__Registry, + PW_TYPE__Registry, PW_VERSION_REGISTRY, PW_REGISTRY_METHOD_NUM, &pw_protocol_native_client_registry_methods, PW_REGISTRY_EVENT_NUM, pw_protocol_native_client_registry_demarshal, @@ -931,7 +915,7 @@ static const demarshal_func_t pw_protocol_native_client_module_demarshal[] = { }; static const struct pw_interface pw_protocol_native_client_module_interface = { - PIPEWIRE_TYPE__Module, + PW_TYPE__Module, PW_VERSION_MODULE, 0, NULL, PW_MODULE_EVENT_NUM, pw_protocol_native_client_module_demarshal, @@ -942,7 +926,7 @@ static const demarshal_func_t pw_protocol_native_client_node_demarshal[] = { }; static const struct pw_interface pw_protocol_native_client_node_interface = { - PIPEWIRE_TYPE__Node, + PW_TYPE__Node, PW_VERSION_NODE, 0, NULL, PW_NODE_EVENT_NUM, pw_protocol_native_client_node_demarshal, @@ -953,7 +937,7 @@ static const demarshal_func_t pw_protocol_native_client_client_demarshal[] = { }; static const struct pw_interface pw_protocol_native_client_client_interface = { - PIPEWIRE_TYPE__Client, + PW_TYPE__Client, PW_VERSION_CLIENT, 0, NULL, PW_CLIENT_EVENT_NUM, pw_protocol_native_client_client_demarshal, @@ -964,7 +948,7 @@ static const demarshal_func_t pw_protocol_native_client_link_demarshal[] = { }; static const struct pw_interface pw_protocol_native_client_link_interface = { - PIPEWIRE_TYPE__Link, + PW_TYPE__Link, PW_VERSION_LINK, 0, NULL, PW_LINK_EVENT_NUM, pw_protocol_native_client_link_demarshal, @@ -988,7 +972,7 @@ static const struct pw_core_events pw_protocol_native_server_core_events = { }; const struct pw_interface pw_protocol_native_server_core_interface = { - PIPEWIRE_TYPE__Core, + PW_TYPE__Core, PW_VERSION_CORE, PW_CORE_METHOD_NUM, pw_protocol_native_server_core_demarshal, PW_CORE_EVENT_NUM, &pw_protocol_native_server_core_events, @@ -1004,7 +988,7 @@ static const struct pw_registry_events pw_protocol_native_server_registry_events }; const struct pw_interface pw_protocol_native_server_registry_interface = { - PIPEWIRE_TYPE__Registry, + PW_TYPE__Registry, PW_VERSION_REGISTRY, PW_REGISTRY_METHOD_NUM, pw_protocol_native_server_registry_demarshal, PW_REGISTRY_EVENT_NUM, &pw_protocol_native_server_registry_events, @@ -1015,7 +999,7 @@ static const struct pw_module_events pw_protocol_native_server_module_events = { }; const struct pw_interface pw_protocol_native_server_module_interface = { - PIPEWIRE_TYPE__Module, + PW_TYPE__Module, PW_VERSION_MODULE, 0, NULL, PW_MODULE_EVENT_NUM, &pw_protocol_native_server_module_events, @@ -1026,7 +1010,7 @@ static const struct pw_node_events pw_protocol_native_server_node_events = { }; const struct pw_interface pw_protocol_native_server_node_interface = { - PIPEWIRE_TYPE__Node, + PW_TYPE__Node, PW_VERSION_NODE, 0, NULL, PW_NODE_EVENT_NUM, &pw_protocol_native_server_node_events, @@ -1037,7 +1021,7 @@ static const struct pw_client_events pw_protocol_native_server_client_events = { }; const struct pw_interface pw_protocol_native_server_client_interface = { - PIPEWIRE_TYPE__Client, + PW_TYPE__Client, PW_VERSION_CLIENT, 0, NULL, PW_CLIENT_EVENT_NUM, &pw_protocol_native_server_client_events, @@ -1048,22 +1032,14 @@ static const struct pw_link_events pw_protocol_native_server_link_events = { }; const struct pw_interface pw_protocol_native_server_link_interface = { - PIPEWIRE_TYPE__Link, + PW_TYPE__Link, PW_VERSION_LINK, 0, NULL, PW_LINK_EVENT_NUM, &pw_protocol_native_server_link_events, }; -struct pw_protocol *pw_protocol_native_init(void) +void pw_protocol_native_init(struct pw_protocol *protocol) { - static bool init = false; - struct pw_protocol *protocol; - - protocol = pw_protocol_get(PW_TYPE_PROTOCOL__Native); - - if (init) - return protocol; - pw_protocol_add_interfaces(protocol, &pw_protocol_native_client_core_interface, &pw_protocol_native_server_core_interface); @@ -1083,7 +1059,4 @@ struct pw_protocol *pw_protocol_native_init(void) &pw_protocol_native_client_link_interface, &pw_protocol_native_server_link_interface); - init = true; - - return protocol; } diff --git a/src/modules/spa/spa-monitor.c b/src/modules/spa/spa-monitor.c index e8850a6c8..d037b1715 100644 --- a/src/modules/spa/spa-monitor.c +++ b/src/modules/spa/spa-monitor.c @@ -17,6 +17,7 @@ * Boston, MA 02110-1301, USA. */ +#include #include #include #include diff --git a/src/pipewire/client.h b/src/pipewire/client.h index 9de1388d5..0d6827ad0 100644 --- a/src/pipewire/client.h +++ b/src/pipewire/client.h @@ -36,6 +36,9 @@ extern "C" { #include #include +#define PW_TYPE__Client PW_TYPE_OBJECT_BASE "Client" +#define PW_TYPE_CLIENT_BASE PW_TYPE__Client ":" + /** \page page_client Client * * \section sec_page_client_overview Overview @@ -115,6 +118,7 @@ struct pw_client { PW_SIGNAL(destroy_signal, (struct pw_listener *listener, struct pw_client *client)); struct pw_protocol *protocol; /**< protocol in use */ + struct spa_list protocol_link; /**< link in the protocol client_list */ void *protocol_private; /**< private data for the protocol */ void *user_data; /**< extra user data */ diff --git a/src/pipewire/command.c b/src/pipewire/command.c index a3b6d8359..2422ea822 100644 --- a/src/pipewire/command.c +++ b/src/pipewire/command.c @@ -19,6 +19,7 @@ */ #include +#include #include #include diff --git a/src/pipewire/core.c b/src/pipewire/core.c index 52e5ded19..63e588d47 100644 --- a/src/pipewire/core.c +++ b/src/pipewire/core.c @@ -18,12 +18,14 @@ */ #include #include +#include #include #include #include #include +#include #include #include @@ -326,6 +328,7 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro pw_data_loop_start(impl->data_loop); + 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); @@ -727,3 +730,14 @@ struct pw_node_factory *pw_core_find_node_factory(struct pw_core *core, const ch } return NULL; } + +struct pw_protocol *pw_core_find_protocol(struct pw_core *core, const char *name) +{ + struct pw_protocol *protocol; + + spa_list_for_each(protocol, &core->protocol_list, link) { + if (strcmp(protocol->name, name) == 0) + return protocol; + } + return NULL; +} diff --git a/src/pipewire/core.h b/src/pipewire/core.h index 0cccc764a..1bd214979 100644 --- a/src/pipewire/core.h +++ b/src/pipewire/core.h @@ -30,15 +30,19 @@ extern "C" { struct pw_global; #include -#include - -#include -#include -#include +#include +#include +#include +#include #include -#include #include +#define PW_TYPE__Core PW_TYPE_OBJECT_BASE "Core" +#define PW_TYPE_CORE_BASE PW_TYPE__Core ":" + +#define PW_TYPE__Registry PW_TYPE_OBJECT_BASE "Registry" +#define PW_TYPE_REGISTRY_BASE PW_TYPE__Registry ":" + /** \page page_server_api Server API * * \section page_server_overview Overview @@ -160,6 +164,7 @@ struct pw_core { struct pw_map objects; /**< map of known objects */ + 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 */ @@ -236,6 +241,9 @@ pw_core_find_port(struct pw_core *core, struct pw_node_factory * pw_core_find_node_factory(struct pw_core *core, const char *name); +struct pw_protocol * +pw_core_find_protocol(struct pw_core *core, const char *name); + #ifdef __cplusplus } #endif diff --git a/src/pipewire/link.c b/src/pipewire/link.c index ab3cfb8a9..b9279ffdf 100644 --- a/src/pipewire/link.c +++ b/src/pipewire/link.c @@ -18,6 +18,7 @@ */ #include +#include #include #include diff --git a/src/pipewire/link.h b/src/pipewire/link.h index 276e53766..dbd6e564b 100644 --- a/src/pipewire/link.h +++ b/src/pipewire/link.h @@ -29,10 +29,14 @@ extern "C" { #include #include +#include #include #include #include +#define PW_TYPE__Link PW_TYPE_OBJECT_BASE "Link" +#define PW_TYPE_LINK_BASE PW_TYPE__Link ":" + /** \page page_link Link * * \section page_link_overview Overview diff --git a/src/pipewire/loop.c b/src/pipewire/loop.c index 4fd3c8b53..39084c3c3 100644 --- a/src/pipewire/loop.c +++ b/src/pipewire/loop.c @@ -17,6 +17,8 @@ * Boston, MA 02110-1301, USA. */ +#include + #include #include diff --git a/src/pipewire/map.h b/src/pipewire/map.h index 0f98c7e61..82553ba40 100644 --- a/src/pipewire/map.h +++ b/src/pipewire/map.h @@ -25,7 +25,6 @@ extern "C" { #endif #include -#include #include #include diff --git a/src/pipewire/module.c b/src/pipewire/module.c index 68edf52fb..f37958d65 100644 --- a/src/pipewire/module.c +++ b/src/pipewire/module.c @@ -22,6 +22,7 @@ #include "config.h" #endif +#include #include #include #include diff --git a/src/pipewire/module.h b/src/pipewire/module.h index fb390ca92..7dab7b4ca 100644 --- a/src/pipewire/module.h +++ b/src/pipewire/module.h @@ -27,6 +27,9 @@ extern "C" { #include +#define PW_TYPE__Module PW_TYPE_OBJECT_BASE "Module" +#define PW_TYPE_MODULE_BASE PW_TYPE__Module ":" + #define PIPEWIRE_SYMBOL_MODULE_INIT "pipewire__module_init" /** \class pw_module diff --git a/src/pipewire/node-factory.h b/src/pipewire/node-factory.h index 20452b2c6..b343e319f 100644 --- a/src/pipewire/node-factory.h +++ b/src/pipewire/node-factory.h @@ -24,8 +24,8 @@ extern "C" { #endif -#define PIPEWIRE_TYPE__NodeFactory "PipeWire:Object:NodeFactory" -#define PIPEWIRE_TYPE_NODE_FACTORY_BASE PIPEWIRE_TYPE__NodeFactory ":" +#define PW_TYPE__NodeFactory "PipeWire:Object:NodeFactory" +#define PW_TYPE_NODE_FACTORY_BASE PW_TYPE__NodeFactory ":" #include #include diff --git a/src/pipewire/node.c b/src/pipewire/node.c index f8e2b1ce7..dc7f1f5d5 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -19,6 +19,7 @@ #include #include +#include #include #include "pipewire/pipewire.h" diff --git a/src/pipewire/node.h b/src/pipewire/node.h index 69eff6f8d..fcca866e0 100644 --- a/src/pipewire/node.h +++ b/src/pipewire/node.h @@ -24,8 +24,8 @@ extern "C" { #endif -#define PIPEWIRE_TYPE__Node "PipeWire:Object:Node" -#define PIPEWIRE_TYPE_NODE_BASE PIPEWIRE_TYPE__Node ":" +#define PW_TYPE__Node PW_TYPE_OBJECT_BASE "Node" +#define PW_TYPE_NODE_BASE PW_TYPE__Node ":" #include #include diff --git a/src/pipewire/pipewire.h b/src/pipewire/pipewire.h index f7894b029..30c91242a 100644 --- a/src/pipewire/pipewire.h +++ b/src/pipewire/pipewire.h @@ -24,17 +24,30 @@ extern "C" { #endif +#include + +#include +#include +#include #include +#include #include #include -#include -#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include #include +#include +#include #include -#include - /** \mainpage * * \section sec_intro Introduction diff --git a/src/pipewire/port.h b/src/pipewire/port.h index b56b27f49..f682a36db 100644 --- a/src/pipewire/port.h +++ b/src/pipewire/port.h @@ -24,11 +24,12 @@ extern "C" { #endif -#define PIPEWIRE_TYPE__Port "PipeWire:Object:Port" -#define PIPEWIRE_TYPE_PORT_BASE PIPEWIRE_TYPE__Port ":" +#define PW_TYPE__Port "PipeWire:Object:Port" +#define PW_TYPE_PORT_BASE PW_TYPE__Port ":" #include +#include #include #include diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index 374d18e90..558e2ea6c 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -17,6 +17,8 @@ * Boston, MA 02110-1301, USA. */ +#include + #include "pipewire/pipewire.h" #include "pipewire/properties.h" diff --git a/src/pipewire/protocol.c b/src/pipewire/protocol.c index 6fcc77d7e..bf2564251 100644 --- a/src/pipewire/protocol.c +++ b/src/pipewire/protocol.c @@ -19,42 +19,68 @@ #include -static struct impl { - bool init; - struct spa_list protocol_list; -} protocols; +struct impl { + struct pw_protocol this; +}; -static struct impl *get_impl(void) +struct pw_protocol *pw_protocol_new(struct pw_core *core, + const char *name, + size_t user_data_size) { - if (!protocols.init) { - spa_list_init(&protocols.protocol_list); - protocols.init = true; - } - return &protocols; -} - -struct pw_protocol *pw_protocol_get(const char *name) -{ - struct impl *impl = get_impl(); struct pw_protocol *protocol; - spa_list_for_each(protocol, &impl->protocol_list, link) { - if (strcmp(protocol->name, name) == 0) - return protocol; - } + if (pw_core_find_protocol(core, name) != NULL) + return NULL; + + protocol = calloc(1, sizeof(struct impl) + user_data_size); + protocol->core = core; + protocol->name = strdup(name); - protocol = calloc(1, sizeof(struct pw_protocol)); - protocol->name = name; spa_list_init(&protocol->iface_list); spa_list_init(&protocol->connection_list); spa_list_init(&protocol->listener_list); - spa_list_insert(impl->protocol_list.prev, &protocol->link); - pw_log_info("Created protocol %s", name); + pw_signal_init(&protocol->destroy_signal); + + if (user_data_size > 0) + protocol->user_data = SPA_MEMBER(protocol, sizeof(struct impl), void); + + spa_list_insert(core->protocol_list.prev, &protocol->link); + + pw_log_info("protocol %p: Created protocol %s", protocol, name); return protocol; } +void pw_protocol_destroy(struct pw_protocol *protocol) +{ + struct impl *impl = SPA_CONTAINER_OF(protocol, struct impl, this); + struct pw_protocol_iface *iface, *t1; + struct pw_protocol_listener *listener, *t2; + struct pw_protocol_connection *connection, *t3; + + pw_log_info("protocol %p: destroy", protocol); + pw_signal_emit(&protocol->destroy_signal, protocol); + + spa_list_remove(&protocol->link); + + spa_list_for_each_safe(iface, t1, &protocol->iface_list, link) + free(iface); + + spa_list_for_each_safe(listener, t2, &protocol->listener_list, link) + pw_protocol_listener_destroy(listener); + + spa_list_for_each_safe(connection, t3, &protocol->connection_list, link) + pw_protocol_connection_destroy(connection); + + free(protocol->name); + + if (protocol->destroy) + protocol->destroy(protocol); + + free(impl); +} + void pw_protocol_add_interfaces(struct pw_protocol *protocol, const struct pw_interface *client_iface, diff --git a/src/pipewire/protocol.h b/src/pipewire/protocol.h index 2c79deb16..8d383c087 100644 --- a/src/pipewire/protocol.h +++ b/src/pipewire/protocol.h @@ -28,50 +28,87 @@ extern "C" { #include #include +#include +#include #include -#define PW_TYPE_PROTOCOL__Native PW_TYPE_PROTOCOL_BASE "Native" +#define PW_TYPE__Protocol "PipeWire:Protocol" +#define PW_TYPE_PROTOCOL_BASE PW_TYPE__Protocol ":" struct pw_protocol_connection { - struct spa_list link; - struct pw_remote *remote; + struct spa_list link; /**< link in protocol connection_list */ + struct pw_protocol *protocol; /**< the owner protocol */ + + struct pw_remote *remote; /**< the associated remote */ int (*connect) (struct pw_protocol_connection *conn); int (*connect_fd) (struct pw_protocol_connection *conn, int fd); - int (*disconnect) (struct pw_protocol_connection *conn); - int (*destroy) (struct pw_protocol_connection *conn); + void (*disconnect) (struct pw_protocol_connection *conn); + void (*destroy) (struct pw_protocol_connection *conn); }; +#define pw_protocol_connection_connect(c) ((c)->connect(c)) +#define pw_protocol_connection_connect_fd(c,fd) ((c)->connect_fd(c,fd)) +#define pw_protocol_connection_disconnect(c) ((c)->disconnect(c)) +#define pw_protocol_connection_destroy(c) ((c)->destroy(c)) + struct pw_protocol_listener { - struct spa_list link; - struct pw_core *core; + struct spa_list link; /**< link in protocol listener_list */ + struct pw_protocol *protocol; /**< the owner protocol */ - int (*destroy) (struct pw_protocol_listener *listen); + struct spa_list client_list; /**< list of client of this protocol */ + + void (*destroy) (struct pw_protocol_listener *listen); }; +#define pw_protocol_listener_destroy(l) ((l)->destroy(l)) + struct pw_protocol_iface { struct spa_list link; const struct pw_interface *client_iface; const struct pw_interface *server_iface; }; -struct pw_protocol { - struct spa_list link; - const char *name; - struct spa_list iface_list; - struct spa_list connection_list; - struct spa_list listener_list; - +struct pw_protocol_implementaton { +#define PW_VERSION_PROTOCOL_IMPLEMENTATION 0 + uint32_t version; struct pw_protocol_connection * (*new_connection) (struct pw_protocol *protocol, struct pw_remote *remote, struct pw_properties *properties); struct pw_protocol_listener * (*add_listener) (struct pw_protocol *protocol, struct pw_core *core, struct pw_properties *properties); - void *protocol_private; }; -struct pw_protocol *pw_protocol_get(const char *name); +struct pw_protocol { + struct spa_list link; /**< link in core protocol_list */ + struct pw_core *core; /**< core for this protocol */ + + char *name; /**< type name of the protocol */ + + struct spa_list iface_list; /**< list of supported interfaces */ + struct spa_list connection_list; /**< list of current connections */ + struct spa_list listener_list; /**< list of current listeners */ + + const struct pw_protocol_implementaton *implementation; /**< implementation of the protocol */ + + /** Emited when the protocol is destroyed */ + PW_SIGNAL(destroy_signal, (struct pw_listener *listener, struct pw_protocol *protocol)); + + const void *extension; /**< extension API */ + + void *user_data; /**< user data for the implementation */ + pw_destroy_t destroy; /**< function to clean up the object */ +}; + +#define pw_protocol_new_connection(p,...) ((p)->implementation->new_connection(p,__VA_ARGS__)) +#define pw_protocol_add_listener(p,...) ((p)->implementation->add_listener(p,__VA_ARGS__)) + +#define pw_protocol_ext(p,type,method,...) ((type*)(p)->extension)->method( __VA_ARGS__) +#define pw_protocol_connection_ext(c,type,method,...) ((type*)(c)->protocol->extension)->method( __VA_ARGS__) +#define pw_protocol_listener_ext(l,type,method,...) ((type*)(l)->protocol->extension)->method( __VA_ARGS__) + +struct pw_protocol *pw_protocol_new(struct pw_core *core, const char *name, size_t user_data_size); /** \class pw_protocol * @@ -83,9 +120,7 @@ pw_protocol_add_interfaces(struct pw_protocol *protocol, const struct pw_interface *server_iface); const struct pw_interface * -pw_protocol_get_interface(struct pw_protocol *protocol, - const char *type, - bool server); +pw_protocol_get_interface(struct pw_protocol *protocol, const char *type, bool server); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/pipewire/proxy.c b/src/pipewire/proxy.c index 6687a8798..db406bb2e 100644 --- a/src/pipewire/proxy.c +++ b/src/pipewire/proxy.c @@ -68,7 +68,7 @@ struct pw_proxy *pw_proxy_new(struct pw_remote *remote, if (user_data_size > 0) this->user_data = SPA_MEMBER(impl, sizeof(struct proxy), void); - this->iface = pw_protocol_get_interface(remote->protocol, + this->iface = pw_protocol_get_interface(remote->conn->protocol, spa_type_map_get_type(remote->core->type.map, type), false); diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index 7236bfeca..222ad090c 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -23,14 +23,17 @@ #include #include +#include + #include "pipewire/pipewire.h" #include "pipewire/introspect.h" #include "pipewire/interfaces.h" #include "pipewire/remote.h" #include "pipewire/core.h" #include "pipewire/module.h" +#include "pipewire/stream.h" -#include +#include "extensions/protocol-native.h" /** \cond */ struct remote { @@ -150,6 +153,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core, { struct remote *impl; struct pw_remote *this; + struct pw_protocol *protocol; impl = calloc(1, sizeof(struct remote)); if (impl == NULL) @@ -183,11 +187,12 @@ struct pw_remote *pw_remote_new(struct pw_core *core, pw_module_load(core, "libpipewire-module-protocol-native", NULL, NULL); pw_module_load(core, "libpipewire-module-client-node", NULL, NULL); - this->protocol = pw_protocol_get(PW_TYPE_PROTOCOL__Native); - if (this->protocol == NULL || this->protocol->new_connection == NULL) + + protocol = pw_core_find_protocol(core, PW_TYPE_PROTOCOL__Native); + if (protocol == NULL) goto no_protocol; - this->conn = this->protocol->new_connection(this->protocol, this, properties); + this->conn = pw_protocol_new_connection(protocol, this, properties); if (this->conn == NULL) goto no_connection; @@ -213,7 +218,7 @@ void pw_remote_destroy(struct pw_remote *remote) if (remote->state != PW_REMOTE_STATE_UNCONNECTED) pw_remote_disconnect(remote); - remote->conn->destroy(remote->conn); + pw_protocol_connection_destroy (remote->conn); spa_list_remove(&remote->link); @@ -238,7 +243,7 @@ static int do_connect(struct pw_remote *remote) return 0; no_proxy: - remote->conn->disconnect(remote->conn); + pw_protocol_connection_disconnect (remote->conn); remote_update_state(remote, PW_REMOTE_STATE_ERROR, "can't connect: no memory"); return -1; } @@ -249,7 +254,7 @@ int pw_remote_connect(struct pw_remote *remote) remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL); - if ((res = remote->conn->connect(remote->conn)) < 0) { + if ((res = pw_protocol_connection_connect (remote->conn)) < 0) { remote_update_state(remote, PW_REMOTE_STATE_ERROR, "connect failed"); return res; } @@ -263,7 +268,7 @@ int pw_remote_connect_fd(struct pw_remote *remote, int fd) remote_update_state(remote, PW_REMOTE_STATE_CONNECTING, NULL); - if ((res = remote->conn->connect_fd(remote->conn, fd)) < 0) { + if ((res = pw_protocol_connection_connect_fd (remote->conn, fd)) < 0) { remote_update_state(remote, PW_REMOTE_STATE_ERROR, "connect_fd failed"); return res; } @@ -277,7 +282,7 @@ void pw_remote_disconnect(struct pw_remote *remote) struct pw_stream *stream, *s2; pw_log_debug("remote %p: disconnect", remote); - remote->conn->disconnect(remote->conn); + pw_protocol_connection_disconnect (remote->conn); spa_list_for_each_safe(stream, s2, &remote->stream_list, link) pw_stream_destroy(stream); diff --git a/src/pipewire/remote.h b/src/pipewire/remote.h index 453292eb0..7046fd77c 100644 --- a/src/pipewire/remote.h +++ b/src/pipewire/remote.h @@ -139,8 +139,6 @@ struct pw_remote { struct spa_list proxy_list; /**< list of \ref pw_proxy objects */ struct spa_list stream_list; /**< list of \ref pw_stream objects */ - struct pw_protocol *protocol; /**< the protocol in use */ - void *protocol_private; /**< private data for the protocol */ struct pw_protocol_connection *conn; /**< the protocol connection */ enum pw_remote_state state; diff --git a/src/pipewire/resource.h b/src/pipewire/resource.h index 3acc35e6a..7a3767f97 100644 --- a/src/pipewire/resource.h +++ b/src/pipewire/resource.h @@ -24,8 +24,8 @@ extern "C" { #endif -#define PIPEWIRE_TYPE__Resource "PipeWire:Object:Resource" -#define PIPEWIRE_TYPE_RESOURCE_BASE PIPEWIRE_TYPE__Resource ":" +#define PW_TYPE__Resource "PipeWire:Object:Resource" +#define PW_TYPE_RESOURCE_BASE PW_TYPE__Resource ":" #include diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index 502bb2020..75e03bbe4 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -204,7 +204,7 @@ struct pw_stream *pw_stream_new(struct pw_remote *remote, this->remote = remote; this->name = strdup(name); - impl->type_client_node = spa_type_map_get_id(remote->core->type.map, PIPEWIRE_TYPE_NODE_BASE "Client"); + impl->type_client_node = spa_type_map_get_id(remote->core->type.map, PW_TYPE__ClientNode); pw_signal_init(&this->destroy_signal); pw_signal_init(&this->state_changed); diff --git a/src/pipewire/transport.h b/src/pipewire/transport.h index 402355c9a..e47918b72 100644 --- a/src/pipewire/transport.h +++ b/src/pipewire/transport.h @@ -89,12 +89,12 @@ pw_transport_next_event(struct pw_transport *trans, struct spa_event *event); int pw_transport_parse_event(struct pw_transport *trans, void *event); -#define PIPEWIRE_TYPE_EVENT__Transport SPA_TYPE_EVENT_BASE "Transport" -#define PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE PIPEWIRE_TYPE_EVENT__Transport ":" +#define PW_TYPE_EVENT__Transport SPA_TYPE_EVENT_BASE "Transport" +#define PW_TYPE_EVENT_TRANSPORT_BASE PW_TYPE_EVENT__Transport ":" -#define PIPEWIRE_TYPE_EVENT_TRANSPORT__HaveOutput PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE "HaveOutput" -#define PIPEWIRE_TYPE_EVENT_TRANSPORT__NeedInput PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE "NeedInput" -#define PIPEWIRE_TYPE_EVENT_TRANSPORT__ReuseBuffer PIPEWIRE_TYPE_EVENT_TRANSPORT_BASE "ReuseBuffer" +#define PW_TYPE_EVENT_TRANSPORT__HaveOutput PW_TYPE_EVENT_TRANSPORT_BASE "HaveOutput" +#define PW_TYPE_EVENT_TRANSPORT__NeedInput PW_TYPE_EVENT_TRANSPORT_BASE "NeedInput" +#define PW_TYPE_EVENT_TRANSPORT__ReuseBuffer PW_TYPE_EVENT_TRANSPORT_BASE "ReuseBuffer" struct pw_type_event_transport { uint32_t HaveOutput; @@ -106,9 +106,9 @@ static inline void pw_type_event_transport_map(struct spa_type_map *map, struct pw_type_event_transport *type) { if (type->HaveOutput == 0) { - type->HaveOutput = spa_type_map_get_id(map, PIPEWIRE_TYPE_EVENT_TRANSPORT__HaveOutput); - type->NeedInput = spa_type_map_get_id(map, PIPEWIRE_TYPE_EVENT_TRANSPORT__NeedInput); - type->ReuseBuffer = spa_type_map_get_id(map, PIPEWIRE_TYPE_EVENT_TRANSPORT__ReuseBuffer); + type->HaveOutput = spa_type_map_get_id(map, PW_TYPE_EVENT_TRANSPORT__HaveOutput); + type->NeedInput = spa_type_map_get_id(map, PW_TYPE_EVENT_TRANSPORT__NeedInput); + type->ReuseBuffer = spa_type_map_get_id(map, PW_TYPE_EVENT_TRANSPORT__ReuseBuffer); } } diff --git a/src/pipewire/type.c b/src/pipewire/type.c index 2ec057cfe..e54df8aa1 100644 --- a/src/pipewire/type.c +++ b/src/pipewire/type.c @@ -26,6 +26,7 @@ #include "pipewire/pipewire.h" #include "pipewire/type.h" +#include "pipewire/module.h" #include "pipewire/node-factory.h" @@ -38,13 +39,13 @@ void pw_type_init(struct pw_type *type) { type->map = pw_get_support_interface(SPA_TYPE__TypeMap); - type->core = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Core); - type->registry = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Registry); - type->node = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Node); - 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->module = spa_type_map_get_id(type->map, PIPEWIRE_TYPE__Module); + type->core = spa_type_map_get_id(type->map, PW_TYPE__Core); + type->registry = spa_type_map_get_id(type->map, PW_TYPE__Registry); + type->node = spa_type_map_get_id(type->map, PW_TYPE__Node); + type->node_factory = spa_type_map_get_id(type->map, PW_TYPE__NodeFactory); + type->link = spa_type_map_get_id(type->map, PW_TYPE__Link); + type->client = spa_type_map_get_id(type->map, PW_TYPE__Client); + type->module = spa_type_map_get_id(type->map, PW_TYPE__Module); type->spa_log = spa_type_map_get_id(type->map, SPA_TYPE__Log); type->spa_node = spa_type_map_get_id(type->map, SPA_TYPE__Node); diff --git a/src/pipewire/type.h b/src/pipewire/type.h index 3486343a3..ac2961b46 100644 --- a/src/pipewire/type.h +++ b/src/pipewire/type.h @@ -33,26 +33,8 @@ extern "C" { #include #include -#define PIPEWIRE_TYPE__Core "PipeWire:Object:Core" -#define PIPEWIRE_TYPE_CORE_BASE PIPEWIRE_TYPE__Core ":" - -#define PIPEWIRE_TYPE__Registry "PipeWire:Object:Registry" -#define PIPEWIRE_TYPE_REGISYRY_BASE PIPEWIRE_TYPE__Registry ":" - -#define PIPEWIRE_TYPE__Node "PipeWire:Object:Node" -#define PIPEWIRE_TYPE_NODE_BASE PIPEWIRE_TYPE__Node ":" - -#define PIPEWIRE_TYPE__Client "PipeWire:Object:Client" -#define PIPEWIRE_TYPE_CLIENT_BASE PIPEWIRE_TYPE__Client ":" - -#define PIPEWIRE_TYPE__Link "PipeWire:Object:Link" -#define PIPEWIRE_TYPE_LINK_BASE PIPEWIRE_TYPE__Link ":" - -#define PIPEWIRE_TYPE__Module "PipeWire:Object:Module" -#define PIPEWIRE_TYPE_MODULE_BASE PIPEWIRE_TYPE__Module ":" - -#define PW_TYPE__Protocol "PipeWire:Protocol" -#define PW_TYPE_PROTOCOL_BASE PW_TYPE__Protocol ":" +#define PW_TYPE__Object "PipeWire:Object" +#define PW_TYPE_OBJECT_BASE PW_TYPE__Object ":" /** \class pw_interface * \brief The interface definition diff --git a/src/tools/pipewire-monitor.c b/src/tools/pipewire-monitor.c index 14415ba38..90ebb7677 100644 --- a/src/tools/pipewire-monitor.c +++ b/src/tools/pipewire-monitor.c @@ -22,6 +22,8 @@ #include #include +#include +#include #include struct data { @@ -60,7 +62,7 @@ static void on_info_changed(struct pw_listener *listener, struct pw_remote *remo bool print_all = true, print_mark = false; printf("\tid: %u\n", info->id); - printf("\ttype: %s\n", PIPEWIRE_TYPE__Core); + printf("\ttype: %s\n", PW_TYPE__Core); if (print_all) { printf("%c\tuser-name: \"%s\"\n", MARK_CHANGE(0), info->user_name); printf("%c\thost-name: \"%s\"\n", MARK_CHANGE(1), info->host_name); @@ -90,7 +92,7 @@ static void module_event_info(void *object, struct pw_module_info *info) info = data->info = pw_module_info_update(data->info, info); printf("\tid: %u\n", info->id); - printf("\ttype: %s\n", PIPEWIRE_TYPE__Module); + printf("\ttype: %s\n", PW_TYPE__Module); if (print_all) { printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name); printf("%c\tfilename: \"%s\"\n", MARK_CHANGE(1), info->filename); @@ -122,7 +124,7 @@ static void node_event_info(void *object, struct pw_node_info *info) info = data->info = pw_node_info_update(data->info, info); printf("\tid: %u\n", info->id); - printf("\ttype: %s\n", PIPEWIRE_TYPE__Node); + printf("\ttype: %s\n", PW_TYPE__Node); if (print_all) { int i; @@ -169,7 +171,7 @@ static void client_event_info(void *object, struct pw_client_info *info) info = data->info = pw_client_info_update(data->info, info); printf("\tid: %u\n", info->id); - printf("\ttype: %s\n", PIPEWIRE_TYPE__Client); + printf("\ttype: %s\n", PW_TYPE__Client); if (print_all) { print_properties(info->props, MARK_CHANGE(0)); } @@ -198,7 +200,7 @@ static void link_event_info(void *object, struct pw_link_info *info) info = data->info = pw_link_info_update(data->info, info); printf("\tid: %u\n", info->id); - printf("\ttype: %s\n", PIPEWIRE_TYPE__Link); + printf("\ttype: %s\n", PW_TYPE__Link); if (print_all) { printf("%c\toutput-node-id: %u\n", MARK_CHANGE(0), info->output_node_id); printf("%c\toutput-port-id: %u\n", MARK_CHANGE(1), info->output_port_id);