summaryrefslogtreecommitdiffstats
path: root/src/modules/module-protocol-native
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/module-protocol-native')
-rw-r--r--src/modules/module-protocol-native/connection.c866
-rw-r--r--src/modules/module-protocol-native/connection.h112
-rw-r--r--src/modules/module-protocol-native/defs.h49
-rw-r--r--src/modules/module-protocol-native/local-socket.c169
-rw-r--r--src/modules/module-protocol-native/portal-screencast.c41
-rw-r--r--src/modules/module-protocol-native/protocol-footer.c152
-rw-r--r--src/modules/module-protocol-native/protocol-footer.h59
-rw-r--r--src/modules/module-protocol-native/protocol-native.c2236
-rw-r--r--src/modules/module-protocol-native/test-connection.c225
-rw-r--r--src/modules/module-protocol-native/v0/interfaces.h534
-rw-r--r--src/modules/module-protocol-native/v0/protocol-native.c1371
-rw-r--r--src/modules/module-protocol-native/v0/typemap.h282
12 files changed, 6096 insertions, 0 deletions
diff --git a/src/modules/module-protocol-native/connection.c b/src/modules/module-protocol-native/connection.c
new file mode 100644
index 0000000..1ba256c
--- /dev/null
+++ b/src/modules/module-protocol-native/connection.c
@@ -0,0 +1,866 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+
+#include <spa/utils/result.h>
+#include <spa/pod/builder.h>
+
+#include <pipewire/pipewire.h>
+
+PW_LOG_TOPIC_EXTERN(mod_topic);
+#define PW_LOG_TOPIC_DEFAULT mod_topic
+PW_LOG_TOPIC_EXTERN(mod_topic_connection);
+
+#undef spa_debug
+#define spa_debug(...) pw_logt_debug(mod_topic_connection, __VA_ARGS__)
+#include <spa/debug/pod.h>
+
+#include "connection.h"
+#include "defs.h"
+
+#define MAX_BUFFER_SIZE (1024 * 32)
+#define MAX_FDS 1024u
+#define MAX_FDS_MSG 28
+
+#define HDR_SIZE_V0 8
+#define HDR_SIZE 16
+
+struct buffer {
+ uint8_t *buffer_data;
+ size_t buffer_size;
+ size_t buffer_maxsize;
+ int fds[MAX_FDS];
+ uint32_t n_fds;
+
+ uint32_t seq;
+ size_t offset;
+ size_t fds_offset;
+ struct pw_protocol_native_message msg;
+};
+
+struct reenter_item {
+ void *old_buffer_data;
+ struct pw_protocol_native_message return_msg;
+ struct spa_list link;
+};
+
+struct impl {
+ struct pw_protocol_native_connection this;
+ struct pw_context *context;
+
+ struct buffer in, out;
+ struct spa_pod_builder builder;
+
+ struct spa_list reenter_stack;
+ uint32_t pending_reentering;
+
+ uint32_t version;
+ size_t hdr_size;
+};
+
+/** \endcond */
+
+/** Get an fd from a connection
+ *
+ * \param conn the connection
+ * \param index the index of the fd to get
+ * \return the fd at \a index or -ENOENT when no such fd exists
+ *
+ * \memberof pw_protocol_native_connection
+ */
+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);
+ struct buffer *buf = &impl->in;
+
+ if (index == SPA_ID_INVALID)
+ return -1;
+
+ if (index >= buf->msg.n_fds)
+ return -ENOENT;
+
+ return buf->msg.fds[index];
+}
+
+/** Add an fd to a connection
+ *
+ * \param conn the connection
+ * \param fd the fd to add
+ * \return the index of the fd or SPA_IDX_INVALID when an error occurred
+ *
+ * \memberof pw_protocol_native_connection
+ */
+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);
+ struct buffer *buf = &impl->out;
+ uint32_t index, i;
+
+ if (fd < 0)
+ return SPA_IDX_INVALID;
+
+ for (i = 0; i < buf->msg.n_fds; i++) {
+ if (buf->msg.fds[i] == fd)
+ return i;
+ }
+
+ index = buf->msg.n_fds;
+ if (index + buf->n_fds >= MAX_FDS) {
+ pw_log_error("connection %p: too many fds (%d)", conn, MAX_FDS);
+ return SPA_IDX_INVALID;
+ }
+
+ buf->msg.fds[index] = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+ if (buf->msg.fds[index] == -1) {
+ pw_log_error("connection %p: can't DUP fd:%d %m", conn, fd);
+ return SPA_IDX_INVALID;
+ }
+ buf->msg.n_fds++;
+ pw_log_debug("connection %p: add fd %d (new fd:%d) at index %d",
+ conn, fd, buf->msg.fds[index], index);
+
+ return index;
+}
+
+static void *connection_ensure_size(struct pw_protocol_native_connection *conn, struct buffer *buf, size_t size)
+{
+ int res;
+
+ if (buf->buffer_size + size > buf->buffer_maxsize) {
+ void *np;
+ size_t ns;
+
+ ns = SPA_ROUND_UP_N(buf->buffer_size + size, MAX_BUFFER_SIZE);
+ np = realloc(buf->buffer_data, ns);
+ if (np == NULL) {
+ res = -errno;
+ free(buf->buffer_data);
+ buf->buffer_maxsize = 0;
+ spa_hook_list_call(&conn->listener_list,
+ struct pw_protocol_native_connection_events,
+ error, 0, res);
+ errno = -res;
+ return NULL;
+ }
+ buf->buffer_maxsize = ns;
+ buf->buffer_data = np;
+ pw_log_debug("connection %p: resize buffer to %zd %zd %zd",
+ conn, buf->buffer_size, size, buf->buffer_maxsize);
+ }
+ return (uint8_t *) buf->buffer_data + buf->buffer_size;
+}
+
+static void handle_connection_error(struct pw_protocol_native_connection *conn, int res)
+{
+ if (res == EPIPE || res == ECONNRESET)
+ pw_log_info("connection %p: could not recvmsg on fd:%d: %s", conn, conn->fd, strerror(res));
+ else
+ pw_log_error("connection %p: could not recvmsg on fd:%d: %s", conn, conn->fd, strerror(res));
+}
+
+static size_t cmsg_data_length(const struct cmsghdr *cmsg)
+{
+ const void *begin = CMSG_DATA(cmsg);
+ const void *end = SPA_PTROFF(cmsg, cmsg->cmsg_len, void);
+
+ spa_assert(begin <= end);
+
+ return SPA_PTRDIFF(end, begin);
+}
+
+static void close_all_fds(struct msghdr *msg, struct cmsghdr *from)
+{
+ for (; from != NULL; from = CMSG_NXTHDR(msg, from)) {
+ if (from->cmsg_level != SOL_SOCKET || from->cmsg_type != SCM_RIGHTS)
+ continue;
+
+ size_t n_fds = cmsg_data_length(from) / sizeof(int);
+ for (size_t i = 0; i < n_fds; i++) {
+ const void *p = SPA_PTROFF(CMSG_DATA(from), sizeof(int) * i, void);
+ int fd;
+
+ memcpy(&fd, p, sizeof(fd));
+ pw_log_debug("%p: close fd:%d", msg, fd);
+ close(fd);
+ }
+ }
+}
+
+static int refill_buffer(struct pw_protocol_native_connection *conn, struct buffer *buf)
+{
+ ssize_t len;
+ struct cmsghdr *cmsg = NULL;
+ struct msghdr msg = { 0 };
+ struct iovec iov[1];
+ union {
+ char cmsgbuf[CMSG_SPACE(MAX_FDS_MSG * sizeof(int))];
+ struct cmsghdr align;
+ } cmsgbuf;
+ int n_fds = 0;
+ size_t avail;
+
+ avail = buf->buffer_maxsize - buf->buffer_size;
+
+ iov[0].iov_base = buf->buffer_data + buf->buffer_size;
+ iov[0].iov_len = avail;
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = &cmsgbuf;
+ msg.msg_controllen = sizeof(cmsgbuf);
+ msg.msg_flags = MSG_CMSG_CLOEXEC | MSG_DONTWAIT;
+
+ while (true) {
+ len = recvmsg(conn->fd, &msg, msg.msg_flags);
+ if (msg.msg_flags & MSG_CTRUNC)
+ goto cmsgs_truncated;
+ if (len == 0 && avail != 0)
+ return -EPIPE;
+ else if (len < 0) {
+ if (errno == EINTR)
+ continue;
+ if (errno != EAGAIN && errno != EWOULDBLOCK)
+ goto recv_error;
+ return -EAGAIN;
+ }
+ break;
+ }
+
+ buf->buffer_size += len;
+
+ /* handle control messages */
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
+ continue;
+
+ n_fds = cmsg_data_length(cmsg) / sizeof(int);
+ if (n_fds + buf->n_fds > MAX_FDS)
+ goto too_many_fds;
+ memcpy(&buf->fds[buf->n_fds], CMSG_DATA(cmsg), n_fds * sizeof(int));
+ buf->n_fds += n_fds;
+ }
+ pw_log_trace("connection %p: %d read %zd bytes and %d fds", conn, conn->fd, len,
+ n_fds);
+
+ return 0;
+
+ /* ERRORS */
+recv_error:
+ handle_connection_error(conn, errno);
+ return -errno;
+
+cmsgs_truncated:
+ close_all_fds(&msg, CMSG_FIRSTHDR(&msg));
+ return -EPROTO;
+
+too_many_fds:
+ close_all_fds(&msg, cmsg);
+ return -EPROTO;
+}
+
+static void clear_buffer(struct buffer *buf, bool fds)
+{
+ uint32_t i;
+ if (fds) {
+ for (i = 0; i < buf->n_fds; i++) {
+ pw_log_debug("%p: close fd:%d", buf, buf->fds[i]);
+ close(buf->fds[i]);
+ }
+ }
+ buf->n_fds = 0;
+ buf->buffer_size = 0;
+ buf->offset = 0;
+ buf->fds_offset = 0;
+}
+
+/** Prepare connection for calling from reentered context.
+ *
+ * This ensures that message buffers returned by get_next are not invalidated by additional
+ * calls made after enter. Leave invalidates the buffers at the higher stack level.
+ *
+ * \memberof pw_protocol_native_connection
+ */
+void pw_protocol_native_connection_enter(struct pw_protocol_native_connection *conn)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+
+ /* Postpone processing until get_next is actually called */
+ ++impl->pending_reentering;
+}
+
+static void pop_reenter_stack(struct impl *impl, uint32_t count)
+{
+ while (count > 0) {
+ struct reenter_item *item;
+
+ item = spa_list_last(&impl->reenter_stack, struct reenter_item, link);
+ spa_list_remove(&item->link);
+
+ free(item->return_msg.fds);
+ free(item->old_buffer_data);
+ free(item);
+
+ --count;
+ }
+}
+
+void pw_protocol_native_connection_leave(struct pw_protocol_native_connection *conn)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+
+ if (impl->pending_reentering > 0) {
+ --impl->pending_reentering;
+ } else {
+ pw_log_trace("connection %p: reenter: pop", impl);
+ pop_reenter_stack(impl, 1);
+ }
+}
+
+static int ensure_stack_level(struct impl *impl, struct pw_protocol_native_message **msg)
+{
+ void *data;
+ struct buffer *buf = &impl->in;
+ struct reenter_item *item, *new_item = NULL;
+
+ item = spa_list_last(&impl->reenter_stack, struct reenter_item, link);
+
+ if (SPA_LIKELY(impl->pending_reentering == 0)) {
+ new_item = item;
+ } else {
+ uint32_t new_count;
+
+ pw_log_trace("connection %p: reenter: push %d levels",
+ impl, impl->pending_reentering);
+
+ /* Append empty item(s) to the reenter stack */
+ for (new_count = 0; new_count < impl->pending_reentering; ++new_count) {
+ new_item = calloc(1, sizeof(struct reenter_item));
+ if (new_item == NULL) {
+ pop_reenter_stack(impl, new_count);
+ return -ENOMEM;
+ }
+ spa_list_append(&impl->reenter_stack, &new_item->link);
+ }
+
+ /*
+ * Stack level increased: we have to switch to a new message data buffer, because
+ * data of returned messages is contained in the buffer and might still be in
+ * use on the lower stack levels.
+ *
+ * We stash the buffer for the previous stack level, and allocate a new one for
+ * the new stack level. If there was a previous buffer for the previous level, we
+ * know its contents are no longer in use (the only active buffer at that stack
+ * level is buf->buffer_data), and we can recycle it as the new buffer (realloc
+ * instead of calloc).
+ *
+ * The current data contained in the buffer needs to be copied to the new buffer.
+ */
+
+ data = realloc(item->old_buffer_data, buf->buffer_maxsize);
+ if (data == NULL) {
+ pop_reenter_stack(impl, new_count);
+ return -ENOMEM;
+ }
+
+ item->old_buffer_data = buf->buffer_data;
+
+ memcpy(data, buf->buffer_data, buf->buffer_size);
+ buf->buffer_data = data;
+
+ impl->pending_reentering = 0;
+ }
+ if (new_item == NULL)
+ return -EIO;
+
+ /* Ensure fds buffer is allocated */
+ if (SPA_UNLIKELY(new_item->return_msg.fds == NULL)) {
+ data = calloc(MAX_FDS, sizeof(int));
+ if (data == NULL)
+ return -ENOMEM;
+ new_item->return_msg.fds = data;
+ }
+
+ *msg = &new_item->return_msg;
+
+ return 0;
+}
+
+/** Make a new connection object for the given socket
+ *
+ * \param fd the socket
+ * \returns a newly allocated connection object
+ *
+ * \memberof pw_protocol_native_connection
+ */
+struct pw_protocol_native_connection *pw_protocol_native_connection_new(struct pw_context *context, int fd)
+{
+ struct impl *impl;
+ struct pw_protocol_native_connection *this;
+ struct reenter_item *reenter_item;
+
+ impl = calloc(1, sizeof(struct impl));
+ if (impl == NULL)
+ return NULL;
+
+ impl->context = context;
+
+ this = &impl->this;
+
+ pw_log_debug("connection %p: new fd:%d", this, fd);
+
+ this->fd = fd;
+ spa_hook_list_init(&this->listener_list);
+
+ impl->hdr_size = HDR_SIZE;
+ impl->version = 3;
+
+ impl->out.buffer_data = calloc(1, MAX_BUFFER_SIZE);
+ impl->out.buffer_maxsize = MAX_BUFFER_SIZE;
+ impl->in.buffer_data = calloc(1, MAX_BUFFER_SIZE);
+ impl->in.buffer_maxsize = MAX_BUFFER_SIZE;
+
+ reenter_item = calloc(1, sizeof(struct reenter_item));
+
+ if (impl->out.buffer_data == NULL || impl->in.buffer_data == NULL || reenter_item == NULL)
+ goto no_mem;
+
+ spa_list_init(&impl->reenter_stack);
+ spa_list_append(&impl->reenter_stack, &reenter_item->link);
+
+ return this;
+
+no_mem:
+ free(impl->out.buffer_data);
+ free(impl->in.buffer_data);
+ free(reenter_item);
+ free(impl);
+ return NULL;
+}
+
+int pw_protocol_native_connection_set_fd(struct pw_protocol_native_connection *conn, int fd)
+{
+ pw_log_debug("connection %p: fd:%d", conn, fd);
+ conn->fd = fd;
+ return 0;
+}
+
+/** Destroy a connection
+ *
+ * \param conn the connection to destroy
+ *
+ * \memberof pw_protocol_native_connection
+ */
+void pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+
+ pw_log_debug("connection %p: destroy", conn);
+
+ spa_hook_list_call(&conn->listener_list, struct pw_protocol_native_connection_events, destroy, 0);
+
+ spa_hook_list_clean(&conn->listener_list);
+
+ clear_buffer(&impl->out, true);
+ clear_buffer(&impl->in, true);
+ free(impl->out.buffer_data);
+ free(impl->in.buffer_data);
+
+ while (!spa_list_is_empty(&impl->reenter_stack))
+ pop_reenter_stack(impl, 1);
+
+ free(impl);
+}
+
+static int prepare_packet(struct pw_protocol_native_connection *conn, struct buffer *buf)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+ uint8_t *data;
+ size_t size, len;
+ uint32_t *p;
+
+ data = buf->buffer_data + buf->offset;
+ size = buf->buffer_size - buf->offset;
+
+ if (size < impl->hdr_size)
+ return impl->hdr_size;
+
+ p = (uint32_t *) data;
+
+ buf->msg.id = p[0];
+ buf->msg.opcode = p[1] >> 24;
+ len = p[1] & 0xffffff;
+
+ if (buf->msg.id == 0 && buf->msg.opcode == 1) {
+ if (p[3] >= 4) {
+ pw_log_warn("old version detected");
+ impl->version = 0;
+ impl->hdr_size = HDR_SIZE_V0;
+ } else {
+ impl->version = 3;
+ impl->hdr_size = HDR_SIZE;
+ }
+ spa_hook_list_call(&conn->listener_list,
+ struct pw_protocol_native_connection_events,
+ start, 0, impl->version);
+ }
+ if (impl->version >= 3) {
+ buf->msg.seq = p[2];
+ buf->msg.n_fds = p[3];
+ } else {
+ buf->msg.seq = 0;
+ buf->msg.n_fds = 0;
+ }
+
+ data += impl->hdr_size;
+ size -= impl->hdr_size;
+ buf->msg.fds = &buf->fds[buf->fds_offset];
+
+ if (buf->msg.n_fds + buf->fds_offset > MAX_FDS)
+ return -EPROTO;
+
+ if (size < len)
+ return len;
+
+ buf->msg.size = len;
+ buf->msg.data = data;
+
+ buf->offset += impl->hdr_size + len;
+ buf->fds_offset += buf->msg.n_fds;
+
+ if (buf->offset >= buf->buffer_size)
+ clear_buffer(buf, false);
+
+ return 0;
+}
+
+/** Move to the next packet in the connection
+ *
+ * \param conn the connection
+ * \param opcode address of result opcode
+ * \param dest_id address of result destination id
+ * \param dt pointer to packet data
+ * \param sz size of packet data
+ * \return true on success
+ *
+ * Get the next packet in \a conn and store the opcode and destination
+ * id as well as the packet data and size.
+ *
+ * \memberof pw_protocol_native_connection
+ */
+int
+pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *conn,
+ const struct pw_protocol_native_message **msg)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+ int len, res;
+ struct buffer *buf;
+ struct pw_protocol_native_message *return_msg;
+ int *fds;
+
+ if ((res = ensure_stack_level(impl, &return_msg)) < 0)
+ return res;
+
+ buf = &impl->in;
+
+ while (1) {
+ len = prepare_packet(conn, buf);
+ if (len < 0)
+ return len;
+ if (len == 0)
+ break;
+
+ if (connection_ensure_size(conn, buf, len) == NULL)
+ return -errno;
+ if ((res = refill_buffer(conn, buf)) < 0)
+ return res;
+ }
+
+ /* Returned msg struct should be safe vs. reentering */
+ fds = return_msg->fds;
+ *return_msg = buf->msg;
+ if (buf->msg.n_fds > 0) {
+ memcpy(fds, buf->msg.fds, buf->msg.n_fds * sizeof(int));
+ }
+ return_msg->fds = fds;
+
+ *msg = return_msg;
+
+ return 1;
+}
+
+/** Get footer data from the tail of the current packet.
+ *
+ * \param conn the connection
+ * \param msg current message
+ * \return footer POD, or NULL if no valid footer present
+ *
+ * \memberof pw_protocol_native_connection
+ */
+struct spa_pod *pw_protocol_native_connection_get_footer(struct pw_protocol_native_connection *conn,
+ const struct pw_protocol_native_message *msg)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+ struct spa_pod *pod;
+
+ if (impl->version != 3)
+ return NULL;
+
+ /*
+ * Protocol version 3 footer: a single SPA POD
+ */
+
+ /* Footer immediately follows the message POD, if it is present */
+ if ((pod = get_first_pod_from_data(msg->data, msg->size, 0)) == NULL)
+ return NULL;
+ pod = get_first_pod_from_data(msg->data, msg->size, SPA_POD_SIZE(pod));
+ if (pod == NULL)
+ return NULL;
+ pw_log_trace("connection %p: recv message footer, size:%zu",
+ conn, (size_t)SPA_POD_SIZE(pod));
+ return pod;
+}
+
+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;
+ struct buffer *buf = &impl->out;
+ /* header and size for payload */
+ if ((p = connection_ensure_size(conn, buf, impl->hdr_size + size)) == NULL)
+ return NULL;
+
+ return SPA_PTROFF(p, impl->hdr_size, void);
+}
+
+static int builder_overflow(void *data, uint32_t size)
+{
+ struct impl *impl = data;
+ struct spa_pod_builder *b = &impl->builder;
+
+ b->size = SPA_ROUND_UP_N(size, 4096);
+ if ((b->data = begin_write(&impl->this, b->size)) == NULL)
+ return -errno;
+ return 0;
+}
+
+static const struct spa_pod_builder_callbacks builder_callbacks = {
+ SPA_VERSION_POD_BUILDER_CALLBACKS,
+ .overflow = builder_overflow
+};
+
+struct spa_pod_builder *
+pw_protocol_native_connection_begin(struct pw_protocol_native_connection *conn,
+ uint32_t id, uint8_t opcode,
+ struct pw_protocol_native_message **msg)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+ struct buffer *buf = &impl->out;
+
+ buf->msg.id = id;
+ buf->msg.opcode = opcode;
+ impl->builder = SPA_POD_BUILDER_INIT(NULL, 0);
+ spa_pod_builder_set_callbacks(&impl->builder, &builder_callbacks, impl);
+ if (impl->version >= 3) {
+ buf->msg.n_fds = 0;
+ buf->msg.fds = &buf->fds[buf->n_fds];
+ } else {
+ buf->msg.n_fds = buf->n_fds;
+ buf->msg.fds = &buf->fds[0];
+ }
+
+ buf->msg.seq = buf->seq;
+ if (msg)
+ *msg = &buf->msg;
+ return &impl->builder;
+}
+
+int
+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->state.offset;
+ struct buffer *buf = &impl->out;
+ int res;
+
+ if ((p = connection_ensure_size(conn, buf, impl->hdr_size + size)) == NULL)
+ return -errno;
+
+ p[0] = buf->msg.id;
+ p[1] = (buf->msg.opcode << 24) | (size & 0xffffff);
+ if (impl->version >= 3) {
+ p[2] = buf->msg.seq;
+ p[3] = buf->msg.n_fds;
+ }
+
+ buf->buffer_size += impl->hdr_size + size;
+ if (impl->version >= 3)
+ buf->n_fds += buf->msg.n_fds;
+ else
+ buf->n_fds = buf->msg.n_fds;
+
+ if (mod_topic_connection->level >= SPA_LOG_LEVEL_DEBUG) {
+ pw_logt_debug(mod_topic_connection,
+ ">>>>>>>>> out: id:%d op:%d size:%d seq:%d",
+ buf->msg.id, buf->msg.opcode, size, buf->msg.seq);
+ spa_debug_pod(0, NULL, SPA_PTROFF(p, impl->hdr_size, struct spa_pod));
+ pw_logt_debug(mod_topic_connection,
+ ">>>>>>>>> out: done");
+ }
+
+ buf->seq = (buf->seq + 1) & SPA_ASYNC_SEQ_MASK;
+ res = SPA_RESULT_RETURN_ASYNC(buf->msg.seq);
+
+ spa_hook_list_call(&conn->listener_list,
+ struct pw_protocol_native_connection_events, need_flush, 0);
+
+ return res;
+}
+
+/** Flush the connection object
+ *
+ * \param conn the connection object
+ * \return 0 on success < 0 error code on error
+ *
+ * Write the queued messages on the connection to the socket
+ *
+ * \memberof pw_protocol_native_connection
+ */
+int pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+ ssize_t sent, outsize;
+ struct msghdr msg = { 0 };
+ struct iovec iov[1];
+ struct cmsghdr *cmsg;
+ union {
+ char cmsgbuf[CMSG_SPACE(MAX_FDS_MSG * sizeof(int))];
+ struct cmsghdr align;
+ } cmsgbuf;
+ int res = 0, *fds;
+ uint32_t fds_len, to_close, n_fds, outfds, i;
+ struct buffer *buf;
+ void *data;
+ size_t size;
+
+ buf = &impl->out;
+ data = buf->buffer_data;
+ size = buf->buffer_size;
+ fds = buf->fds;
+ n_fds = buf->n_fds;
+ to_close = 0;
+
+ while (size > 0) {
+ if (n_fds > MAX_FDS_MSG) {
+ outfds = MAX_FDS_MSG;
+ outsize = SPA_MIN(sizeof(uint32_t), size);
+ } else {
+ outfds = n_fds;
+ outsize = size;
+ }
+
+ fds_len = outfds * sizeof(int);
+
+ iov[0].iov_base = data;
+ iov[0].iov_len = outsize;
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+
+ if (outfds > 0) {
+ msg.msg_control = &cmsgbuf;
+ msg.msg_controllen = CMSG_SPACE(fds_len);
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(fds_len);
+ memcpy(CMSG_DATA(cmsg), fds, fds_len);
+ msg.msg_controllen = cmsg->cmsg_len;
+ } else {
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ }
+
+ while (true) {
+ sent = sendmsg(conn->fd, &msg, MSG_NOSIGNAL | MSG_DONTWAIT);
+ if (sent < 0) {
+ if (errno == EINTR)
+ continue;
+ else {
+ res = -errno;
+ goto exit;
+ }
+ }
+ break;
+ }
+ pw_log_trace("connection %p: %d written %zd bytes and %u fds", conn, conn->fd, sent,
+ outfds);
+
+ size -= sent;
+ data = SPA_PTROFF(data, sent, void);
+ n_fds -= outfds;
+ fds += outfds;
+ to_close += outfds;
+ }
+
+ res = 0;
+
+exit:
+ if (size > 0)
+ memmove(buf->buffer_data, data, size);
+ buf->buffer_size = size;
+ for (i = 0; i < to_close; i++) {
+ pw_log_debug("%p: close fd:%d", conn, buf->fds[i]);
+ close(buf->fds[i]);
+ }
+ if (n_fds > 0)
+ memmove(buf->fds, fds, n_fds * sizeof(int));
+ buf->n_fds = n_fds;
+ return res;
+}
+
+/** Clear the connection object
+ *
+ * \param conn the connection object
+ * \return 0 on success
+ *
+ * Remove all queued messages from \a conn
+ *
+ * \memberof pw_protocol_native_connection
+ */
+int pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn)
+{
+ struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
+
+ clear_buffer(&impl->out, true);
+ clear_buffer(&impl->in, true);
+
+ return 0;
+}
diff --git a/src/modules/module-protocol-native/connection.h b/src/modules/module-protocol-native/connection.h
new file mode 100644
index 0000000..d93829c
--- /dev/null
+++ b/src/modules/module-protocol-native/connection.h
@@ -0,0 +1,112 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H
+#define PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <spa/utils/defs.h>
+#include <spa/utils/hook.h>
+
+#include <pipewire/extensions/protocol-native.h>
+
+struct pw_protocol_native_connection_events {
+#define PW_VERSION_PROTOCOL_NATIVE_CONNECTION_EVENTS 0
+ uint32_t version;
+
+ void (*destroy) (void *data);
+
+ void (*error) (void *data, int error);
+
+ void (*need_flush) (void *data);
+
+ void (*start) (void *data, uint32_t version);
+};
+
+/** \class pw_protocol_native_connection
+ *
+ * \brief Manages the connection between client and server
+ *
+ * The \ref pw_protocol_native_connection handles the connection between client
+ * and server on a given socket.
+ */
+struct pw_protocol_native_connection {
+ int fd; /**< the socket */
+
+ struct spa_hook_list listener_list;
+};
+
+static inline void
+pw_protocol_native_connection_add_listener(struct pw_protocol_native_connection *conn,
+ struct spa_hook *listener,
+ const struct pw_protocol_native_connection_events *events,
+ void *data)
+{
+ spa_hook_list_append(&conn->listener_list, listener, events, data);
+}
+
+struct pw_protocol_native_connection *
+pw_protocol_native_connection_new(struct pw_context *context, int fd);
+
+int pw_protocol_native_connection_set_fd(struct pw_protocol_native_connection *conn, int fd);
+
+void
+pw_protocol_native_connection_destroy(struct pw_protocol_native_connection *conn);
+
+int
+pw_protocol_native_connection_get_next(struct pw_protocol_native_connection *conn,
+ const struct pw_protocol_native_message **msg);
+
+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_protocol_native_connection_begin(struct pw_protocol_native_connection *conn,
+ uint32_t id, uint8_t opcode,
+ struct pw_protocol_native_message **msg);
+
+int
+pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
+ struct spa_pod_builder *builder);
+
+int
+pw_protocol_native_connection_flush(struct pw_protocol_native_connection *conn);
+
+int
+pw_protocol_native_connection_clear(struct pw_protocol_native_connection *conn);
+
+void pw_protocol_native_connection_enter(struct pw_protocol_native_connection *conn);
+void pw_protocol_native_connection_leave(struct pw_protocol_native_connection *conn);
+
+struct spa_pod *pw_protocol_native_connection_get_footer(struct pw_protocol_native_connection *conn,
+ const struct pw_protocol_native_message *msg);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* PIPEWIRE_PROTOCOL_NATIVE_CONNECTION_H */
diff --git a/src/modules/module-protocol-native/defs.h b/src/modules/module-protocol-native/defs.h
new file mode 100644
index 0000000..dc3c625
--- /dev/null
+++ b/src/modules/module-protocol-native/defs.h
@@ -0,0 +1,49 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
+ const struct spa_dict *props,
+ void (*done_callback) (void *data, int res),
+ void *data);
+int pw_protocol_native_connect_portal_screencast(struct pw_protocol_client *client,
+ const struct spa_dict *props,
+ void (*done_callback) (void *data, int res),
+ void *data);
+
+static inline void *get_first_pod_from_data(void *data, uint32_t maxsize, uint64_t offset)
+{
+ void *pod;
+ if (maxsize <= offset)
+ return NULL;
+
+ /* spa_pod_parser_advance() rounds up, so round down here to compensate */
+ maxsize = SPA_ROUND_DOWN_N(maxsize - offset, 8);
+ if (maxsize < sizeof(struct spa_pod))
+ return NULL;
+
+ pod = SPA_PTROFF(data, offset, void);
+ if (SPA_POD_BODY_SIZE(pod) > maxsize - sizeof(struct spa_pod))
+ return NULL;
+ return pod;
+}
diff --git a/src/modules/module-protocol-native/local-socket.c b/src/modules/module-protocol-native/local-socket.c
new file mode 100644
index 0000000..cbae203
--- /dev/null
+++ b/src/modules/module-protocol-native/local-socket.c
@@ -0,0 +1,169 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+
+#include <pipewire/pipewire.h>
+
+#define DEFAULT_SYSTEM_RUNTIME_DIR "/run/pipewire"
+
+PW_LOG_TOPIC_EXTERN(mod_topic);
+#define PW_LOG_TOPIC_DEFAULT mod_topic
+
+static const char *
+get_remote(const struct spa_dict *props)
+{
+ const char *name;
+
+ name = getenv("PIPEWIRE_REMOTE");
+ if ((name == NULL || name[0] == '\0') && props)
+ name = spa_dict_lookup(props, PW_KEY_REMOTE_NAME);
+ if (name == NULL || name[0] == '\0')
+ name = PW_DEFAULT_REMOTE;
+ return name;
+}
+
+static const char *
+get_runtime_dir(void)
+{
+ const char *runtime_dir;
+
+ runtime_dir = getenv("PIPEWIRE_RUNTIME_DIR");
+ if (runtime_dir == NULL)
+ runtime_dir = getenv("XDG_RUNTIME_DIR");
+ if (runtime_dir == NULL)
+ runtime_dir = getenv("USERPROFILE");
+ return runtime_dir;
+}
+
+static const char *
+get_system_dir(void)
+{
+ return DEFAULT_SYSTEM_RUNTIME_DIR;
+}
+
+static int try_connect(struct pw_protocol_client *client,
+ const char *runtime_dir, const char *name,
+ void (*done_callback) (void *data, int res),
+ void *data)
+{
+ struct sockaddr_un addr;
+ socklen_t size;
+ int res, name_size, fd;
+
+ pw_log_info("connecting to '%s' runtime_dir:%s", name, runtime_dir);
+
+ if ((fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) {
+ res = -errno;
+ goto error;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_LOCAL;
+ if (runtime_dir == NULL)
+ name_size = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", name) + 1;
+ else
+ name_size = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", runtime_dir, name) + 1;
+
+ if (name_size > (int) sizeof addr.sun_path) {
+ if (runtime_dir == NULL)
+ pw_log_error("client %p: socket path \"%s\" plus null terminator exceeds %i bytes",
+ client, name, (int) sizeof(addr.sun_path));
+ else
+ pw_log_error("client %p: socket path \"%s/%s\" plus null terminator exceeds %i bytes",
+ client, runtime_dir, name, (int) sizeof(addr.sun_path));
+ res = -ENAMETOOLONG;
+ goto error_close;
+ };
+
+ size = offsetof(struct sockaddr_un, sun_path) + name_size;
+
+ if (connect(fd, (struct sockaddr *) &addr, size) < 0) {
+ pw_log_debug("connect to '%s' failed: %m", name);
+ if (errno == ENOENT)
+ errno = EHOSTDOWN;
+ if (errno == EAGAIN) {
+ pw_log_info("client %p: connect pending, fd %d", client, fd);
+ } else {
+ res = -errno;
+ goto error_close;
+ }
+ }
+
+ res = pw_protocol_client_connect_fd(client, fd, true);
+
+ if (done_callback)
+ done_callback(data, res);
+
+ return res;
+
+error_close:
+ close(fd);
+error:
+ return res;
+}
+
+int pw_protocol_native_connect_local_socket(struct pw_protocol_client *client,
+ const struct spa_dict *props,
+ void (*done_callback) (void *data, int res),
+ void *data)
+{
+ const char *runtime_dir, *name;
+ int res;
+
+ name = get_remote(props);
+ if (name == NULL)
+ return -EINVAL;
+
+ if (name[0] == '/') {
+ res = try_connect(client, NULL, name, done_callback, data);
+ } else {
+ runtime_dir = get_runtime_dir();
+ if (runtime_dir != NULL) {
+ res = try_connect(client, runtime_dir, name, done_callback, data);
+ if (res >= 0)
+ goto exit;
+ }
+ runtime_dir = get_system_dir();
+ if (runtime_dir != NULL)
+ res = try_connect(client, runtime_dir, name, done_callback, data);
+ }
+exit:
+ return res;
+}
diff --git a/src/modules/module-protocol-native/portal-screencast.c b/src/modules/module-protocol-native/portal-screencast.c
new file mode 100644
index 0000000..7cb6614
--- /dev/null
+++ b/src/modules/module-protocol-native/portal-screencast.c
@@ -0,0 +1,41 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+
+#include <pipewire/pipewire.h>
+
+int pw_protocol_native_connect_portal_screencast(struct pw_protocol_client *client,
+ const struct spa_dict *props,
+ void (*done_callback) (void *data, int res),
+ void *data)
+{
+ return -ENOTSUP;
+}
diff --git a/src/modules/module-protocol-native/protocol-footer.c b/src/modules/module-protocol-native/protocol-footer.c
new file mode 100644
index 0000000..9b6fe62
--- /dev/null
+++ b/src/modules/module-protocol-native/protocol-footer.c
@@ -0,0 +1,152 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <spa/pod/builder.h>
+#include <spa/pod/parser.h>
+#include <spa/utils/result.h>
+
+#include <pipewire/private.h>
+
+#include "connection.h"
+#include "protocol-footer.h"
+#include "defs.h"
+
+PW_LOG_TOPIC_EXTERN(mod_topic);
+#define PW_LOG_TOPIC_DEFAULT mod_topic
+
+struct footer_builder {
+ struct spa_pod_builder *builder;
+ struct spa_pod_frame outer;
+ struct spa_pod_frame inner;
+ unsigned int started:1;
+};
+
+#define FOOTER_BUILDER_INIT(builder) ((struct footer_builder) { (builder) })
+
+static void start_footer_entry(struct footer_builder *fb, uint32_t opcode)
+{
+ if (!fb->started) {
+ spa_pod_builder_push_struct(fb->builder, &fb->outer);
+ fb->started = true;
+ }
+
+ spa_pod_builder_id(fb->builder, opcode);
+ spa_pod_builder_push_struct(fb->builder, &fb->inner);
+}
+
+static void end_footer_entry(struct footer_builder *fb)
+{
+ spa_pod_builder_pop(fb->builder, &fb->inner);
+}
+
+static void end_footer(struct footer_builder *fb)
+{
+ if (!fb->started)
+ return;
+
+ spa_pod_builder_pop(fb->builder, &fb->outer);
+}
+
+void marshal_core_footers(struct footer_core_global_state *state, struct pw_core *core,
+ struct spa_pod_builder *builder)
+{
+ struct footer_builder fb = FOOTER_BUILDER_INIT(builder);
+
+ if (core->recv_generation != state->last_recv_generation) {
+ state->last_recv_generation = core->recv_generation;
+
+ pw_log_trace("core %p: send client registry generation:%"PRIu64,
+ core, core->recv_generation);
+
+ start_footer_entry(&fb, FOOTER_CLIENT_OPCODE_GENERATION);
+ spa_pod_builder_long(fb.builder, core->recv_generation);
+ end_footer_entry(&fb);
+ }
+
+ end_footer(&fb);
+}
+
+void marshal_client_footers(struct footer_client_global_state *state, struct pw_impl_client *client,
+ struct spa_pod_builder *builder)
+{
+ struct footer_builder fb = FOOTER_BUILDER_INIT(builder);
+
+ if (client->context->generation != client->sent_generation) {
+ client->sent_generation = client->context->generation;
+
+ pw_log_trace("impl-client %p: send server registry generation:%"PRIu64,
+ client, client->context->generation);
+
+ start_footer_entry(&fb, FOOTER_CORE_OPCODE_GENERATION);
+ spa_pod_builder_long(fb.builder, client->context->generation);
+ end_footer_entry(&fb);
+ }
+
+ end_footer(&fb);
+}
+
+int demarshal_core_generation(void *object, struct spa_pod_parser *parser)
+{
+ struct pw_core *core = object;
+ int64_t generation;
+
+ if (spa_pod_parser_get_long(parser, &generation) < 0)
+ return -EINVAL;
+
+ core->recv_generation = SPA_MAX(core->recv_generation,
+ (uint64_t)generation);
+
+ pw_log_trace("core %p: recv server registry generation:%"PRIu64,
+ core, generation);
+
+ return 0;
+}
+
+int demarshal_client_generation(void *object, struct spa_pod_parser *parser)
+{
+ struct pw_impl_client *client = object;
+ int64_t generation;
+
+ if (spa_pod_parser_get_long(parser, &generation) < 0)
+ return -EINVAL;
+
+ client->recv_generation = SPA_MAX(client->recv_generation,
+ (uint64_t)generation);
+
+ pw_log_trace("impl-client %p: recv client registry generation:%"PRIu64,
+ client, generation);
+
+ return 0;
+}
+
+const struct footer_demarshal footer_core_demarshal[FOOTER_CORE_OPCODE_LAST] = {
+ [FOOTER_CORE_OPCODE_GENERATION] = (struct footer_demarshal){ .demarshal = demarshal_core_generation },
+};
+
+const struct footer_demarshal footer_client_demarshal[FOOTER_CLIENT_OPCODE_LAST] = {
+ [FOOTER_CLIENT_OPCODE_GENERATION] = (struct footer_demarshal){ .demarshal = demarshal_client_generation },
+};
diff --git a/src/modules/module-protocol-native/protocol-footer.h b/src/modules/module-protocol-native/protocol-footer.h
new file mode 100644
index 0000000..bdbec04
--- /dev/null
+++ b/src/modules/module-protocol-native/protocol-footer.h
@@ -0,0 +1,59 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Protocol footer.
+ *
+ * For passing around general state data that is not associated with
+ * messages sent to objects.
+ */
+
+enum {
+ FOOTER_CORE_OPCODE_GENERATION = 0,
+ FOOTER_CORE_OPCODE_LAST
+};
+
+enum {
+ FOOTER_CLIENT_OPCODE_GENERATION = 0,
+ FOOTER_CLIENT_OPCODE_LAST
+};
+
+struct footer_core_global_state {
+ uint64_t last_recv_generation;
+};
+
+struct footer_client_global_state {
+};
+
+struct footer_demarshal {
+ int (*demarshal)(void *object, struct spa_pod_parser *parser);
+};
+
+extern const struct footer_demarshal footer_core_demarshal[FOOTER_CORE_OPCODE_LAST];
+extern const struct footer_demarshal footer_client_demarshal[FOOTER_CLIENT_OPCODE_LAST];
+
+void marshal_core_footers(struct footer_core_global_state *state, struct pw_core *core,
+ struct spa_pod_builder *builder);
+void marshal_client_footers(struct footer_client_global_state *state, struct pw_impl_client *client,
+ struct spa_pod_builder *builder);
diff --git a/src/modules/module-protocol-native/protocol-native.c b/src/modules/module-protocol-native/protocol-native.c
new file mode 100644
index 0000000..1c2d83e
--- /dev/null
+++ b/src/modules/module-protocol-native/protocol-native.c
@@ -0,0 +1,2236 @@
+/* PipeWire
+ *
+ * Copyright © 2018 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+
+#include <spa/pod/builder.h>
+#include <spa/pod/parser.h>
+#include <spa/utils/result.h>
+
+#include <pipewire/impl.h>
+#include <pipewire/extensions/protocol-native.h>
+
+#include "connection.h"
+
+#define MAX_DICT 1024
+#define MAX_PARAM_INFO 128
+#define MAX_PERMISSIONS 4096
+
+PW_LOG_TOPIC_EXTERN(mod_topic);
+#define PW_LOG_TOPIC_DEFAULT mod_topic
+
+static int core_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_core_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static int core_method_marshal_hello(void *object, uint32_t version)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_HELLO, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(version));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int core_method_marshal_sync(void *object, uint32_t id, int seq)
+{
+ struct pw_protocol_native_message *msg;
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_SYNC, &msg);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq)));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int core_method_marshal_pong(void *object, uint32_t id, int seq)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_PONG, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(seq));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int core_method_marshal_error(void *object, uint32_t id, int seq, int res, const char *error)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_ERROR, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(seq),
+ SPA_POD_Int(res),
+ SPA_POD_String(error));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static struct pw_registry * core_method_marshal_get_registry(void *object,
+ uint32_t version, size_t user_data_size)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+ struct pw_proxy *res;
+ uint32_t new_id;
+
+ res = pw_proxy_new(object, PW_TYPE_INTERFACE_Registry, version, user_data_size);
+ if (res == NULL)
+ return NULL;
+
+ new_id = pw_proxy_get_id(res);
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_GET_REGISTRY, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(version),
+ SPA_POD_Int(new_id));
+
+ pw_protocol_native_end_proxy(proxy, b);
+
+ return (struct pw_registry *) res;
+}
+
+static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_item *item)
+{
+ const char *str;
+ spa_pod_builder_string(b, item->key);
+ str = item->value;
+ if (spa_strstartswith(str, "pointer:"))
+ str = "";
+ spa_pod_builder_string(b, str);
+}
+
+static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict)
+{
+ uint32_t i, n_items;
+ struct spa_pod_frame f;
+
+ n_items = dict ? dict->n_items : 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_int(b, n_items);
+ for (i = 0; i < n_items; i++)
+ push_item(b, &dict->items[i]);
+ spa_pod_builder_pop(b, &f);
+}
+
+static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *item)
+{
+ int res;
+ if ((res = spa_pod_parser_get(prs,
+ SPA_POD_String(&item->key),
+ SPA_POD_String(&item->value),
+ NULL)) < 0)
+ return res;
+ if (spa_strstartswith(item->value, "pointer:"))
+ item->value = "";
+ return 0;
+}
+
+#define parse_dict(prs,d) \
+do { \
+ if (spa_pod_parser_get(prs, \
+ SPA_POD_Int(&(d)->n_items), NULL) < 0) \
+ return -EINVAL; \
+ (d)->items = NULL; \
+ if ((d)->n_items > 0) { \
+ uint32_t i; \
+ if ((d)->n_items > MAX_DICT) \
+ return -ENOSPC; \
+ (d)->items = alloca((d)->n_items * sizeof(struct spa_dict_item)); \
+ for (i = 0; i < (d)->n_items; i++) { \
+ if (parse_item(prs, (struct spa_dict_item *) &(d)->items[i]) < 0) \
+ return -EINVAL; \
+ } \
+ } \
+} while(0)
+
+#define parse_dict_struct(prs,f,dict) \
+do { \
+ if (spa_pod_parser_push_struct(prs, f) < 0) \
+ return -EINVAL; \
+ parse_dict(prs, dict); \
+ spa_pod_parser_pop(prs, f); \
+} while(0)
+
+static void push_params(struct spa_pod_builder *b, uint32_t n_params,
+ const struct spa_param_info *params)
+{
+ uint32_t i;
+ struct spa_pod_frame f;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_int(b, n_params);
+ for (i = 0; i < n_params; i++) {
+ spa_pod_builder_id(b, params[i].id);
+ spa_pod_builder_int(b, params[i].flags);
+ }
+ spa_pod_builder_pop(b, &f);
+}
+
+
+#define parse_params_struct(prs,f,params,n_params) \
+do { \
+ if (spa_pod_parser_push_struct(prs, f) < 0 || \
+ spa_pod_parser_get(prs, \
+ SPA_POD_Int(&(n_params)), NULL) < 0) \
+ return -EINVAL; \
+ (params) = NULL; \
+ if ((n_params) > 0) { \
+ uint32_t i; \
+ if ((n_params) > MAX_PARAM_INFO) \
+ return -ENOSPC; \
+ (params) = alloca((n_params) * sizeof(struct spa_param_info)); \
+ for (i = 0; i < (n_params); i++) { \
+ if (spa_pod_parser_get(prs, \
+ SPA_POD_Id(&(params)[i].id), \
+ SPA_POD_Int(&(params)[i].flags), NULL) < 0) \
+ return -EINVAL; \
+ } \
+ } \
+ spa_pod_parser_pop(prs, f); \
+} while(0)
+
+
+#define parse_permissions_struct(prs,f,n_permissions,permissions) \
+do { \
+ if (spa_pod_parser_push_struct(prs, f) < 0 || \
+ spa_pod_parser_get(prs, \
+ SPA_POD_Int(&(n_permissions)), NULL) < 0) \
+ return -EINVAL; \
+ (permissions) = NULL; \
+ if ((n_permissions) > 0) { \
+ uint32_t i; \
+ if ((n_permissions) > MAX_PERMISSIONS) \
+ return -ENOSPC; \
+ (permissions) = alloca((n_permissions) * sizeof(struct pw_permission)); \
+ for (i = 0; i < (n_permissions); i++) { \
+ if (spa_pod_parser_get(prs, \
+ SPA_POD_Int(&(permissions)[i].id), \
+ SPA_POD_Int(&(permissions)[i].permissions), NULL) < 0) \
+ return -EINVAL; \
+ } \
+ } \
+ spa_pod_parser_pop(prs, f); \
+} while(0)
+
+static void *
+core_method_marshal_create_object(void *object,
+ const char *factory_name,
+ const char *type, uint32_t version,
+ const struct spa_dict *props, size_t user_data_size)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ struct pw_proxy *res;
+ uint32_t new_id;
+
+ res = pw_proxy_new(object, type, version, user_data_size);
+ if (res == NULL)
+ return NULL;
+
+ new_id = pw_proxy_get_id(res);
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_CREATE_OBJECT, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_String(factory_name),
+ SPA_POD_String(type),
+ SPA_POD_Int(version),
+ NULL);
+ push_dict(b, props);
+ spa_pod_builder_int(b, new_id);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_proxy(proxy, b);
+
+ return (void *)res;
+}
+
+static int
+core_method_marshal_destroy(void *object, void *p)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+ uint32_t id = pw_proxy_get_id(p);
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CORE_METHOD_DESTROY, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int core_event_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_core_info info = { .props = &props };
+ struct spa_pod_frame f[2];
+ struct spa_pod_parser prs;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0)
+ return -EINVAL;
+ if (spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_Int(&info.cookie),
+ SPA_POD_String(&info.user_name),
+ SPA_POD_String(&info.host_name),
+ SPA_POD_String(&info.version),
+ SPA_POD_String(&info.name),
+ SPA_POD_Long(&info.change_mask), NULL) < 0)
+ return -EINVAL;
+
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_proxy_notify(proxy, struct pw_core_events, info, 0, &info);
+}
+
+static int core_event_demarshal_done(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, seq;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&seq)) < 0)
+ return -EINVAL;
+
+ if (id == SPA_ID_INVALID)
+ return 0;
+
+ return pw_proxy_notify(proxy, struct pw_core_events, done, 0, id, seq);
+}
+
+static int core_event_demarshal_ping(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, seq;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&seq)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_core_events, ping, 0, id, seq);
+}
+
+static int core_event_demarshal_error(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, res;
+ int seq;
+ const char *error;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&seq),
+ SPA_POD_Int(&res),
+ SPA_POD_String(&error)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_core_events, error, 0, id, seq, res, error);
+}
+
+static int core_event_demarshal_remove_id(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs, SPA_POD_Int(&id)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_core_events, remove_id, 0, id);
+}
+
+static int core_event_demarshal_bound_id(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, global_id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&global_id)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_core_events, bound_id, 0, id, global_id);
+}
+
+static int core_event_demarshal_add_mem(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, type, flags;
+ int64_t idx;
+ int fd;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Id(&type),
+ SPA_POD_Fd(&idx),
+ SPA_POD_Int(&flags)) < 0)
+ return -EINVAL;
+
+ fd = pw_protocol_native_get_proxy_fd(proxy, idx);
+
+ return pw_proxy_notify(proxy, struct pw_core_events, add_mem, 0, id, type, fd, flags);
+}
+
+static int core_event_demarshal_remove_mem(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_core_events, remove_mem, 0, id);
+}
+
+static void core_event_marshal_info(void *data, const struct pw_core_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_Int(info->cookie),
+ SPA_POD_String(info->user_name),
+ SPA_POD_String(info->host_name),
+ SPA_POD_String(info->version),
+ SPA_POD_String(info->name),
+ SPA_POD_Long(info->change_mask),
+ NULL);
+ push_dict(b, info->change_mask & PW_CORE_CHANGE_MASK_PROPS ? info->props : NULL);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_done(void *data, uint32_t id, int seq)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_DONE, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(seq));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_ping(void *data, uint32_t id, int seq)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct pw_protocol_native_message *msg;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_PING, &msg);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq)));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_error(void *data, uint32_t id, int seq, int res, const char *error)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_ERROR, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(seq),
+ SPA_POD_Int(res),
+ SPA_POD_String(error));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_remove_id(void *data, uint32_t id)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_REMOVE_ID, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_bound_id(void *data, uint32_t id, uint32_t global_id)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_BOUND_ID, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(global_id));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_add_mem(void *data, uint32_t id, uint32_t type, int fd, uint32_t flags)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_ADD_MEM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Id(type),
+ SPA_POD_Fd(pw_protocol_native_add_resource_fd(resource, fd)),
+ SPA_POD_Int(flags));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_event_marshal_remove_mem(void *data, uint32_t id)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_EVENT_REMOVE_MEM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int core_method_demarshal_hello(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t version;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&version)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, hello, 0, version);
+}
+
+static int core_method_demarshal_sync(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, seq;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&seq)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, sync, 0, id, seq);
+}
+
+static int core_method_demarshal_pong(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, seq;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&seq)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, pong, 0, id, seq);
+}
+
+static int core_method_demarshal_error(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, res;
+ int seq;
+ const char *error;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&seq),
+ SPA_POD_Int(&res),
+ SPA_POD_String(&error)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, error, 0, id, seq, res, error);
+}
+
+static int core_method_demarshal_get_registry(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ int32_t version, new_id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&version),
+ SPA_POD_Int(&new_id)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, get_registry, 0, version, new_id);
+}
+
+static int core_method_demarshal_create_object(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ uint32_t version, new_id;
+ const char *factory_name, *type;
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_String(&factory_name),
+ SPA_POD_String(&type),
+ SPA_POD_Int(&version),
+ NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ if (spa_pod_parser_get(&prs,
+ SPA_POD_Int(&new_id), NULL) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, create_object, 0, factory_name,
+ type, version,
+ &props, new_id);
+}
+
+static int core_method_demarshal_destroy(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct pw_resource *r;
+ struct spa_pod_parser prs;
+ uint32_t id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id)) < 0)
+ return -EINVAL;
+
+ pw_log_debug("client %p: destroy resource %u", client, id);
+
+ if ((r = pw_impl_client_find_resource(client, id)) == NULL)
+ goto no_resource;
+
+ return pw_resource_notify(resource, struct pw_core_methods, destroy, 0, r);
+
+ no_resource:
+ pw_log_debug("client %p: unknown resource %u op:%u", client, id, msg->opcode);
+ pw_resource_errorf(resource, -ENOENT, "unknown resource %d op:%u", id, msg->opcode);
+ return 0;
+}
+
+static int registry_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_registry_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void registry_marshal_global(void *data, uint32_t id, uint32_t permissions,
+ const char *type, uint32_t version, const struct spa_dict *props)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_EVENT_GLOBAL, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(permissions),
+ SPA_POD_String(type),
+ SPA_POD_Int(version),
+ NULL);
+ push_dict(b, props);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void registry_marshal_global_remove(void *data, uint32_t id)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_EVENT_GLOBAL_REMOVE, NULL);
+
+ spa_pod_builder_add_struct(b, SPA_POD_Int(id));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int registry_demarshal_bind(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, version, new_id;
+ char *type;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_String(&type),
+ SPA_POD_Int(&version),
+ SPA_POD_Int(&new_id)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_registry_methods, bind, 0, id, type, version, new_id);
+}
+
+static int registry_demarshal_destroy(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_registry_methods, destroy, 0, id);
+}
+
+static int module_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_module_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void module_marshal_info(void *data, const struct pw_module_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_MODULE_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_String(info->name),
+ SPA_POD_String(info->filename),
+ SPA_POD_String(info->args),
+ SPA_POD_Long(info->change_mask),
+ NULL);
+ push_dict(b, info->change_mask & PW_MODULE_CHANGE_MASK_PROPS ? info->props : NULL);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int module_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_module_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_String(&info.name),
+ SPA_POD_String(&info.filename),
+ SPA_POD_String(&info.args),
+ SPA_POD_Long(&info.change_mask), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_proxy_notify(proxy, struct pw_module_events, info, 0, &info);
+}
+
+static int device_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_device_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void device_marshal_info(void *data, const struct pw_device_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_DEVICE_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_Long(info->change_mask),
+ NULL);
+ push_dict(b, info->change_mask & PW_DEVICE_CHANGE_MASK_PROPS ? info->props : NULL);
+ push_params(b, info->n_params, info->params);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int device_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_device_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_Long(&info.change_mask), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+ parse_params_struct(&prs, &f[1], info.params, info.n_params);
+
+ return pw_proxy_notify(proxy, struct pw_device_events, info, 0, &info);
+}
+
+static void device_marshal_param(void *data, int seq, uint32_t id, uint32_t index, uint32_t next,
+ const struct spa_pod *param)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_DEVICE_EVENT_PARAM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(seq),
+ SPA_POD_Id(id),
+ SPA_POD_Int(index),
+ SPA_POD_Int(next),
+ SPA_POD_Pod(param));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int device_demarshal_param(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, index, next;
+ int seq;
+ struct spa_pod *param;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&seq),
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&next),
+ SPA_POD_Pod(&param)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_device_events, param, 0,
+ seq, id, index, next, param);
+}
+
+static int device_marshal_subscribe_params(void *object, uint32_t *ids, uint32_t n_ids)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_DEVICE_METHOD_SUBSCRIBE_PARAMS, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, n_ids, ids));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int device_demarshal_subscribe_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t csize, ctype, n_ids;
+ uint32_t *ids;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Array(&csize, &ctype, &n_ids, &ids)) < 0)
+ return -EINVAL;
+
+ if (ctype != SPA_TYPE_Id)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_device_methods, subscribe_params, 0,
+ ids, n_ids);
+}
+
+static int device_marshal_enum_params(void *object, int seq,
+ uint32_t id, uint32_t index, uint32_t num, const struct spa_pod *filter)
+{
+ struct pw_protocol_native_message *msg;
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_DEVICE_METHOD_ENUM_PARAMS, &msg);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq)),
+ SPA_POD_Id(id),
+ SPA_POD_Int(index),
+ SPA_POD_Int(num),
+ SPA_POD_Pod(filter));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int device_demarshal_enum_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, index, num;
+ int seq;
+ struct spa_pod *filter;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&seq),
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&num),
+ SPA_POD_Pod(&filter)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_device_methods, enum_params, 0,
+ seq, id, index, num, filter);
+}
+
+static int device_marshal_set_param(void *object, uint32_t id, uint32_t flags,
+ const struct spa_pod *param)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_DEVICE_METHOD_SET_PARAM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Id(id),
+ SPA_POD_Int(flags),
+ SPA_POD_Pod(param));
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int device_demarshal_set_param(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, flags;
+ struct spa_pod *param;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&flags),
+ SPA_POD_Pod(&param)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_device_methods, set_param, 0, id, flags, param);
+}
+
+static int factory_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_factory_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void factory_marshal_info(void *data, const struct pw_factory_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_FACTORY_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_String(info->name),
+ SPA_POD_String(info->type),
+ SPA_POD_Int(info->version),
+ SPA_POD_Long(info->change_mask),
+ NULL);
+ push_dict(b, info->change_mask & PW_FACTORY_CHANGE_MASK_PROPS ? info->props : NULL);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int factory_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_factory_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_String(&info.name),
+ SPA_POD_String(&info.type),
+ SPA_POD_Int(&info.version),
+ SPA_POD_Long(&info.change_mask), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_proxy_notify(proxy, struct pw_factory_events, info, 0, &info);
+}
+
+static int node_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_node_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void node_marshal_info(void *data, const struct pw_node_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_NODE_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_Int(info->max_input_ports),
+ SPA_POD_Int(info->max_output_ports),
+ SPA_POD_Long(info->change_mask),
+ SPA_POD_Int(info->n_input_ports),
+ SPA_POD_Int(info->n_output_ports),
+ SPA_POD_Id(info->state),
+ SPA_POD_String(info->error),
+ NULL);
+ push_dict(b, info->change_mask & PW_NODE_CHANGE_MASK_PROPS ? info->props : NULL);
+ push_params(b, info->n_params, info->params);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int node_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_node_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_Int(&info.max_input_ports),
+ SPA_POD_Int(&info.max_output_ports),
+ SPA_POD_Long(&info.change_mask),
+ SPA_POD_Int(&info.n_input_ports),
+ SPA_POD_Int(&info.n_output_ports),
+ SPA_POD_Id(&info.state),
+ SPA_POD_String(&info.error), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+ parse_params_struct(&prs, &f[1], info.params, info.n_params);
+
+ return pw_proxy_notify(proxy, struct pw_node_events, info, 0, &info);
+}
+
+static void node_marshal_param(void *data, int seq, uint32_t id,
+ uint32_t index, uint32_t next, const struct spa_pod *param)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_NODE_EVENT_PARAM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(seq),
+ SPA_POD_Id(id),
+ SPA_POD_Int(index),
+ SPA_POD_Int(next),
+ SPA_POD_Pod(param));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int node_demarshal_param(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, index, next;
+ int seq;
+ struct spa_pod *param;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&seq),
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&next),
+ SPA_POD_Pod(&param)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_node_events, param, 0,
+ seq, id, index, next, param);
+}
+
+static int node_marshal_subscribe_params(void *object, uint32_t *ids, uint32_t n_ids)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_NODE_METHOD_SUBSCRIBE_PARAMS, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, n_ids, ids));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int node_demarshal_subscribe_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t csize, ctype, n_ids;
+ uint32_t *ids;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Array(&csize, &ctype, &n_ids, &ids)) < 0)
+ return -EINVAL;
+
+ if (ctype != SPA_TYPE_Id)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_node_methods, subscribe_params, 0,
+ ids, n_ids);
+}
+
+static int node_marshal_enum_params(void *object, int seq, uint32_t id,
+ uint32_t index, uint32_t num, const struct spa_pod *filter)
+{
+ struct pw_protocol_native_message *msg;
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_NODE_METHOD_ENUM_PARAMS, &msg);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq)),
+ SPA_POD_Id(id),
+ SPA_POD_Int(index),
+ SPA_POD_Int(num),
+ SPA_POD_Pod(filter));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int node_demarshal_enum_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, index, num;
+ int seq;
+ struct spa_pod *filter;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&seq),
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&num),
+ SPA_POD_Pod(&filter)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_node_methods, enum_params, 0,
+ seq, id, index, num, filter);
+}
+
+static int node_marshal_set_param(void *object, uint32_t id, uint32_t flags,
+ const struct spa_pod *param)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_NODE_METHOD_SET_PARAM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Id(id),
+ SPA_POD_Int(flags),
+ SPA_POD_Pod(param));
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int node_demarshal_set_param(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, flags;
+ struct spa_pod *param;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&flags),
+ SPA_POD_Pod(&param)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_node_methods, set_param, 0, id, flags, param);
+}
+
+static int node_marshal_send_command(void *object, const struct spa_command *command)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_NODE_METHOD_SEND_COMMAND, NULL);
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Pod(command));
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int node_demarshal_send_command(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ const struct spa_command *command;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Pod(&command)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_node_methods, send_command, 0, command);
+}
+
+static int port_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_port_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void port_marshal_info(void *data, const struct pw_port_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_PORT_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_Int(info->direction),
+ SPA_POD_Long(info->change_mask),
+ NULL);
+ push_dict(b, info->change_mask & PW_PORT_CHANGE_MASK_PROPS ? info->props : NULL);
+ push_params(b, info->n_params, info->params);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int port_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_port_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_Int(&info.direction),
+ SPA_POD_Long(&info.change_mask), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+ parse_params_struct(&prs, &f[1], info.params, info.n_params);
+
+ return pw_proxy_notify(proxy, struct pw_port_events, info, 0, &info);
+}
+
+static void port_marshal_param(void *data, int seq, uint32_t id,
+ uint32_t index, uint32_t next, const struct spa_pod *param)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_PORT_EVENT_PARAM, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(seq),
+ SPA_POD_Id(id),
+ SPA_POD_Int(index),
+ SPA_POD_Int(next),
+ SPA_POD_Pod(param));
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int port_demarshal_param(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id, index, next;
+ int seq;
+ struct spa_pod *param;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&seq),
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&next),
+ SPA_POD_Pod(&param)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_port_events, param, 0,
+ seq, id, index, next, param);
+}
+
+static int port_marshal_subscribe_params(void *object, uint32_t *ids, uint32_t n_ids)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_PORT_METHOD_SUBSCRIBE_PARAMS, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Array(sizeof(uint32_t), SPA_TYPE_Id, n_ids, ids));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int port_demarshal_subscribe_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t csize, ctype, n_ids;
+ uint32_t *ids;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Array(&csize, &ctype, &n_ids, &ids)) < 0)
+ return -EINVAL;
+
+ if (ctype != SPA_TYPE_Id)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_port_methods, subscribe_params, 0,
+ ids, n_ids);
+}
+
+static int port_marshal_enum_params(void *object, int seq, uint32_t id,
+ uint32_t index, uint32_t num, const struct spa_pod *filter)
+{
+ struct pw_protocol_native_message *msg;
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_PORT_METHOD_ENUM_PARAMS, &msg);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(SPA_RESULT_RETURN_ASYNC(msg->seq)),
+ SPA_POD_Id(id),
+ SPA_POD_Int(index),
+ SPA_POD_Int(num),
+ SPA_POD_Pod(filter));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int port_demarshal_enum_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, index, num;
+ int seq;
+ struct spa_pod *filter;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&seq),
+ SPA_POD_Id(&id),
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&num),
+ SPA_POD_Pod(&filter)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_port_methods, enum_params, 0,
+ seq, id, index, num, filter);
+}
+
+static int client_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_client_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void client_marshal_info(void *data, const struct pw_client_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CLIENT_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_Long(info->change_mask),
+ NULL);
+ push_dict(b, info->change_mask & PW_CLIENT_CHANGE_MASK_PROPS ? info->props : NULL);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int client_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_client_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_Long(&info.change_mask), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_proxy_notify(proxy, struct pw_client_events, info, 0, &info);
+}
+
+static void client_marshal_permissions(void *data, uint32_t index, uint32_t n_permissions,
+ const struct pw_permission *permissions)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f[2];
+ uint32_t i, n = 0;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CLIENT_EVENT_PERMISSIONS, NULL);
+
+ for (i = 0; i < n_permissions; i++) {
+ if (permissions[i].permissions != PW_PERM_INVALID)
+ n++;
+ }
+
+ spa_pod_builder_push_struct(b, &f[0]);
+ spa_pod_builder_int(b, index);
+ spa_pod_builder_push_struct(b, &f[1]);
+ spa_pod_builder_int(b, n);
+
+ for (i = 0; i < n_permissions; i++) {
+ if (permissions[i].permissions == PW_PERM_INVALID)
+ continue;
+ spa_pod_builder_int(b, permissions[i].id);
+ spa_pod_builder_int(b, permissions[i].permissions);
+ }
+ spa_pod_builder_pop(b, &f[1]);
+ spa_pod_builder_pop(b, &f[0]);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int client_demarshal_permissions(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct pw_permission *permissions;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ uint32_t index, n_permissions;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&index), NULL) < 0)
+ return -EINVAL;
+
+ parse_permissions_struct(&prs, &f[1], n_permissions, permissions);
+
+ return pw_proxy_notify(proxy, struct pw_client_events, permissions, 0, index, n_permissions, permissions);
+}
+
+static int client_marshal_error(void *object, uint32_t id, int res, const char *error)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_METHOD_ERROR, NULL);
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_Int(res),
+ SPA_POD_String(error));
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int client_demarshal_error(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t id, res;
+ const char *error;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&res),
+ SPA_POD_String(&error)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_client_methods, error, 0, id, res, error);
+}
+
+static int client_marshal_get_permissions(void *object, uint32_t index, uint32_t num)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_METHOD_GET_PERMISSIONS, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(index),
+ SPA_POD_Int(num));
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int client_marshal_update_properties(void *object, const struct spa_dict *props)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_METHOD_UPDATE_PROPERTIES, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ push_dict(b, props);
+ spa_pod_builder_pop(b, &f);
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int client_demarshal_update_properties(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_resource_notify(resource, struct pw_client_methods, update_properties, 0,
+ &props);
+}
+
+static int client_demarshal_get_permissions(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t index, num;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&index),
+ SPA_POD_Int(&num)) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_client_methods, get_permissions, 0, index, num);
+}
+
+static int client_marshal_update_permissions(void *object, uint32_t n_permissions,
+ const struct pw_permission *permissions)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_METHOD_UPDATE_PERMISSIONS, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_int(b, n_permissions);
+ for (i = 0; i < n_permissions; i++) {
+ spa_pod_builder_int(b, permissions[i].id);
+ spa_pod_builder_int(b, permissions[i].permissions);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static int client_demarshal_update_permissions(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_permission *permissions;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[1];
+ uint32_t n_permissions;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+
+ parse_permissions_struct(&prs, &f[0], n_permissions, permissions);
+
+ return pw_resource_notify(resource, struct pw_client_methods, update_permissions, 0,
+ n_permissions, permissions);
+}
+
+static int link_method_marshal_add_listener(void *object,
+ struct spa_hook *listener,
+ const struct pw_link_events *events,
+ void *data)
+{
+ struct pw_proxy *proxy = object;
+ pw_proxy_add_object_listener(proxy, listener, events, data);
+ return 0;
+}
+
+static void link_marshal_info(void *data, const struct pw_link_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_LINK_EVENT_INFO, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ SPA_POD_Int(info->id),
+ SPA_POD_Int(info->output_node_id),
+ SPA_POD_Int(info->output_port_id),
+ SPA_POD_Int(info->input_node_id),
+ SPA_POD_Int(info->input_port_id),
+ SPA_POD_Long(info->change_mask),
+ SPA_POD_Int(info->state),
+ SPA_POD_String(info->error),
+ SPA_POD_Pod(info->format),
+ NULL);
+ push_dict(b, info->change_mask & PW_LINK_CHANGE_MASK_PROPS ? info->props : NULL);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int link_demarshal_info(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+ struct pw_link_info info = { .props = &props };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&info.id),
+ SPA_POD_Int(&info.output_node_id),
+ SPA_POD_Int(&info.output_port_id),
+ SPA_POD_Int(&info.input_node_id),
+ SPA_POD_Int(&info.input_port_id),
+ SPA_POD_Long(&info.change_mask),
+ SPA_POD_Int(&info.state),
+ SPA_POD_String(&info.error),
+ SPA_POD_Pod(&info.format), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_proxy_notify(proxy, struct pw_link_events, info, 0, &info);
+}
+
+static int registry_demarshal_global(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f[2];
+ uint32_t id, permissions, version;
+ char *type;
+ struct spa_dict props = SPA_DICT_INIT(NULL, 0);
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f[0]) < 0 ||
+ spa_pod_parser_get(&prs,
+ SPA_POD_Int(&id),
+ SPA_POD_Int(&permissions),
+ SPA_POD_String(&type),
+ SPA_POD_Int(&version), NULL) < 0)
+ return -EINVAL;
+
+ parse_dict_struct(&prs, &f[1], &props);
+
+ return pw_proxy_notify(proxy, struct pw_registry_events,
+ global, 0, id, permissions, type, version, &props);
+}
+
+static int registry_demarshal_global_remove(void *data, const struct pw_protocol_native_message *msg)
+{
+ struct pw_proxy *proxy = data;
+ struct spa_pod_parser prs;
+ uint32_t id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&id)) < 0)
+ return -EINVAL;
+
+ return pw_proxy_notify(proxy, struct pw_registry_events, global_remove, 0, id);
+}
+
+static void * registry_marshal_bind(void *object, uint32_t id,
+ const char *type, uint32_t version, size_t user_data_size)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+ struct pw_proxy *res;
+ uint32_t new_id;
+
+ res = pw_proxy_new(object, type, version, user_data_size);
+ if (res == NULL)
+ return NULL;
+
+ new_id = pw_proxy_get_id(res);
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_REGISTRY_METHOD_BIND, NULL);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id),
+ SPA_POD_String(type),
+ SPA_POD_Int(version),
+ SPA_POD_Int(new_id));
+
+ pw_protocol_native_end_proxy(proxy, b);
+
+ return (void *) res;
+}
+
+static int registry_marshal_destroy(void *object, uint32_t id)
+{
+ struct pw_proxy *proxy = object;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_proxy(proxy, PW_REGISTRY_METHOD_DESTROY, NULL);
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(id));
+ return pw_protocol_native_end_proxy(proxy, b);
+}
+
+static const struct pw_core_methods pw_protocol_native_core_method_marshal = {
+ PW_VERSION_CORE_METHODS,
+ .add_listener = &core_method_marshal_add_listener,
+ .hello = &core_method_marshal_hello,
+ .sync = &core_method_marshal_sync,
+ .pong = &core_method_marshal_pong,
+ .error = &core_method_marshal_error,
+ .get_registry = &core_method_marshal_get_registry,
+ .create_object = &core_method_marshal_create_object,
+ .destroy = &core_method_marshal_destroy,
+};
+
+static const struct pw_protocol_native_demarshal pw_protocol_native_core_method_demarshal[PW_CORE_METHOD_NUM] = {
+ [PW_CORE_METHOD_ADD_LISTENER] = { NULL, 0, },
+ [PW_CORE_METHOD_HELLO] = { &core_method_demarshal_hello, 0, },
+ [PW_CORE_METHOD_SYNC] = { &core_method_demarshal_sync, 0, },
+ [PW_CORE_METHOD_PONG] = { &core_method_demarshal_pong, 0, },
+ [PW_CORE_METHOD_ERROR] = { &core_method_demarshal_error, 0, },
+ [PW_CORE_METHOD_GET_REGISTRY] = { &core_method_demarshal_get_registry, 0, },
+ [PW_CORE_METHOD_CREATE_OBJECT] = { &core_method_demarshal_create_object, 0, },
+ [PW_CORE_METHOD_DESTROY] = { &core_method_demarshal_destroy, 0, }
+};
+
+static const struct pw_core_events pw_protocol_native_core_event_marshal = {
+ PW_VERSION_CORE_EVENTS,
+ .info = &core_event_marshal_info,
+ .done = &core_event_marshal_done,
+ .ping = &core_event_marshal_ping,
+ .error = &core_event_marshal_error,
+ .remove_id = &core_event_marshal_remove_id,
+ .bound_id = &core_event_marshal_bound_id,
+ .add_mem = &core_event_marshal_add_mem,
+ .remove_mem = &core_event_marshal_remove_mem,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_core_event_demarshal[PW_CORE_EVENT_NUM] =
+{
+ [PW_CORE_EVENT_INFO] = { &core_event_demarshal_info, 0, },
+ [PW_CORE_EVENT_DONE] = { &core_event_demarshal_done, 0, },
+ [PW_CORE_EVENT_PING] = { &core_event_demarshal_ping, 0, },
+ [PW_CORE_EVENT_ERROR] = { &core_event_demarshal_error, 0, },
+ [PW_CORE_EVENT_REMOVE_ID] = { &core_event_demarshal_remove_id, 0, },
+ [PW_CORE_EVENT_BOUND_ID] = { &core_event_demarshal_bound_id, 0, },
+ [PW_CORE_EVENT_ADD_MEM] = { &core_event_demarshal_add_mem, 0, },
+ [PW_CORE_EVENT_REMOVE_MEM] = { &core_event_demarshal_remove_mem, 0, },
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_core_marshal = {
+ PW_TYPE_INTERFACE_Core,
+ PW_VERSION_CORE,
+ 0,
+ PW_CORE_METHOD_NUM,
+ PW_CORE_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_core_method_marshal,
+ .server_demarshal = pw_protocol_native_core_method_demarshal,
+ .server_marshal = &pw_protocol_native_core_event_marshal,
+ .client_demarshal = pw_protocol_native_core_event_demarshal,
+};
+
+static const struct pw_registry_methods pw_protocol_native_registry_method_marshal = {
+ PW_VERSION_REGISTRY_METHODS,
+ .add_listener = &registry_method_marshal_add_listener,
+ .bind = &registry_marshal_bind,
+ .destroy = &registry_marshal_destroy,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_registry_method_demarshal[PW_REGISTRY_METHOD_NUM] =
+{
+ [PW_REGISTRY_METHOD_ADD_LISTENER] = { NULL, 0, },
+ [PW_REGISTRY_METHOD_BIND] = { &registry_demarshal_bind, 0, },
+ [PW_REGISTRY_METHOD_DESTROY] = { &registry_demarshal_destroy, 0, },
+};
+
+static const struct pw_registry_events pw_protocol_native_registry_event_marshal = {
+ PW_VERSION_REGISTRY_EVENTS,
+ .global = &registry_marshal_global,
+ .global_remove = &registry_marshal_global_remove,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_registry_event_demarshal[PW_REGISTRY_EVENT_NUM] =
+{
+ [PW_REGISTRY_EVENT_GLOBAL] = { &registry_demarshal_global, 0, },
+ [PW_REGISTRY_EVENT_GLOBAL_REMOVE] = { &registry_demarshal_global_remove, 0, }
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_registry_marshal = {
+ PW_TYPE_INTERFACE_Registry,
+ PW_VERSION_REGISTRY,
+ 0,
+ PW_REGISTRY_METHOD_NUM,
+ PW_REGISTRY_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_registry_method_marshal,
+ .server_demarshal = pw_protocol_native_registry_method_demarshal,
+ .server_marshal = &pw_protocol_native_registry_event_marshal,
+ .client_demarshal = pw_protocol_native_registry_event_demarshal,
+};
+
+static const struct pw_module_events pw_protocol_native_module_event_marshal = {
+ PW_VERSION_MODULE_EVENTS,
+ .info = &module_marshal_info,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_module_event_demarshal[PW_MODULE_EVENT_NUM] =
+{
+ [PW_MODULE_EVENT_INFO] = { &module_demarshal_info, 0, },
+};
+
+
+static const struct pw_module_methods pw_protocol_native_module_method_marshal = {
+ PW_VERSION_MODULE_METHODS,
+ .add_listener = &module_method_marshal_add_listener,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_module_method_demarshal[PW_MODULE_METHOD_NUM] =
+{
+ [PW_MODULE_METHOD_ADD_LISTENER] = { NULL, 0, },
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_module_marshal = {
+ PW_TYPE_INTERFACE_Module,
+ PW_VERSION_MODULE,
+ 0,
+ PW_MODULE_METHOD_NUM,
+ PW_MODULE_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_module_method_marshal,
+ .server_demarshal = pw_protocol_native_module_method_demarshal,
+ .server_marshal = &pw_protocol_native_module_event_marshal,
+ .client_demarshal = pw_protocol_native_module_event_demarshal,
+};
+
+static const struct pw_factory_events pw_protocol_native_factory_event_marshal = {
+ PW_VERSION_FACTORY_EVENTS,
+ .info = &factory_marshal_info,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_factory_event_demarshal[PW_FACTORY_EVENT_NUM] =
+{
+ [PW_FACTORY_EVENT_INFO] = { &factory_demarshal_info, 0, },
+};
+
+static const struct pw_factory_methods pw_protocol_native_factory_method_marshal = {
+ PW_VERSION_FACTORY_METHODS,
+ .add_listener = &factory_method_marshal_add_listener,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_factory_method_demarshal[PW_FACTORY_METHOD_NUM] =
+{
+ [PW_FACTORY_METHOD_ADD_LISTENER] = { NULL, 0, },
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_factory_marshal = {
+ PW_TYPE_INTERFACE_Factory,
+ PW_VERSION_FACTORY,
+ 0,
+ PW_FACTORY_METHOD_NUM,
+ PW_FACTORY_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_factory_method_marshal,
+ .server_demarshal = pw_protocol_native_factory_method_demarshal,
+ .server_marshal = &pw_protocol_native_factory_event_marshal,
+ .client_demarshal = pw_protocol_native_factory_event_demarshal,
+};
+
+static const struct pw_device_methods pw_protocol_native_device_method_marshal = {
+ PW_VERSION_DEVICE_METHODS,
+ .add_listener = &device_method_marshal_add_listener,
+ .subscribe_params = &device_marshal_subscribe_params,
+ .enum_params = &device_marshal_enum_params,
+ .set_param = &device_marshal_set_param,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_device_method_demarshal[PW_DEVICE_METHOD_NUM] = {
+ [PW_DEVICE_METHOD_ADD_LISTENER] = { NULL, 0, },
+ [PW_DEVICE_METHOD_SUBSCRIBE_PARAMS] = { &device_demarshal_subscribe_params, 0, },
+ [PW_DEVICE_METHOD_ENUM_PARAMS] = { &device_demarshal_enum_params, 0, },
+ [PW_DEVICE_METHOD_SET_PARAM] = { &device_demarshal_set_param, PW_PERM_W, },
+};
+
+static const struct pw_device_events pw_protocol_native_device_event_marshal = {
+ PW_VERSION_DEVICE_EVENTS,
+ .info = &device_marshal_info,
+ .param = &device_marshal_param,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_device_event_demarshal[PW_DEVICE_EVENT_NUM] = {
+ [PW_DEVICE_EVENT_INFO] = { &device_demarshal_info, 0, },
+ [PW_DEVICE_EVENT_PARAM] = { &device_demarshal_param, 0, }
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_device_marshal = {
+ PW_TYPE_INTERFACE_Device,
+ PW_VERSION_DEVICE,
+ 0,
+ PW_DEVICE_METHOD_NUM,
+ PW_DEVICE_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_device_method_marshal,
+ .server_demarshal = pw_protocol_native_device_method_demarshal,
+ .server_marshal = &pw_protocol_native_device_event_marshal,
+ .client_demarshal = pw_protocol_native_device_event_demarshal,
+};
+
+static const struct pw_node_methods pw_protocol_native_node_method_marshal = {
+ PW_VERSION_NODE_METHODS,
+ .add_listener = &node_method_marshal_add_listener,
+ .subscribe_params = &node_marshal_subscribe_params,
+ .enum_params = &node_marshal_enum_params,
+ .set_param = &node_marshal_set_param,
+ .send_command = &node_marshal_send_command,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_node_method_demarshal[PW_NODE_METHOD_NUM] =
+{
+ [PW_NODE_METHOD_ADD_LISTENER] = { NULL, 0, },
+ [PW_NODE_METHOD_SUBSCRIBE_PARAMS] = { &node_demarshal_subscribe_params, 0, },
+ [PW_NODE_METHOD_ENUM_PARAMS] = { &node_demarshal_enum_params, 0, },
+ [PW_NODE_METHOD_SET_PARAM] = { &node_demarshal_set_param, PW_PERM_W, },
+ [PW_NODE_METHOD_SEND_COMMAND] = { &node_demarshal_send_command, PW_PERM_W, },
+};
+
+static const struct pw_node_events pw_protocol_native_node_event_marshal = {
+ PW_VERSION_NODE_EVENTS,
+ .info = &node_marshal_info,
+ .param = &node_marshal_param,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_node_event_demarshal[PW_NODE_EVENT_NUM] = {
+ [PW_NODE_EVENT_INFO] = { &node_demarshal_info, 0, },
+ [PW_NODE_EVENT_PARAM] = { &node_demarshal_param, 0, }
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_node_marshal = {
+ PW_TYPE_INTERFACE_Node,
+ PW_VERSION_NODE,
+ 0,
+ PW_NODE_METHOD_NUM,
+ PW_NODE_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_node_method_marshal,
+ .server_demarshal = pw_protocol_native_node_method_demarshal,
+ .server_marshal = &pw_protocol_native_node_event_marshal,
+ .client_demarshal = pw_protocol_native_node_event_demarshal,
+};
+
+
+static const struct pw_port_methods pw_protocol_native_port_method_marshal = {
+ PW_VERSION_PORT_METHODS,
+ .add_listener = &port_method_marshal_add_listener,
+ .subscribe_params = &port_marshal_subscribe_params,
+ .enum_params = &port_marshal_enum_params,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_port_method_demarshal[PW_PORT_METHOD_NUM] =
+{
+ [PW_PORT_METHOD_ADD_LISTENER] = { NULL, 0, },
+ [PW_PORT_METHOD_SUBSCRIBE_PARAMS] = { &port_demarshal_subscribe_params, 0, },
+ [PW_PORT_METHOD_ENUM_PARAMS] = { &port_demarshal_enum_params, 0, },
+};
+
+static const struct pw_port_events pw_protocol_native_port_event_marshal = {
+ PW_VERSION_PORT_EVENTS,
+ .info = &port_marshal_info,
+ .param = &port_marshal_param,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_port_event_demarshal[PW_PORT_EVENT_NUM] =
+{
+ [PW_PORT_EVENT_INFO] = { &port_demarshal_info, 0, },
+ [PW_PORT_EVENT_PARAM] = { &port_demarshal_param, 0, }
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_port_marshal = {
+ PW_TYPE_INTERFACE_Port,
+ PW_VERSION_PORT,
+ 0,
+ PW_PORT_METHOD_NUM,
+ PW_PORT_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_port_method_marshal,
+ .server_demarshal = pw_protocol_native_port_method_demarshal,
+ .server_marshal = &pw_protocol_native_port_event_marshal,
+ .client_demarshal = pw_protocol_native_port_event_demarshal,
+};
+
+static const struct pw_client_methods pw_protocol_native_client_method_marshal = {
+ PW_VERSION_CLIENT_METHODS,
+ .add_listener = &client_method_marshal_add_listener,
+ .error = &client_marshal_error,
+ .update_properties = &client_marshal_update_properties,
+ .get_permissions = &client_marshal_get_permissions,
+ .update_permissions = &client_marshal_update_permissions,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_client_method_demarshal[PW_CLIENT_METHOD_NUM] =
+{
+ [PW_CLIENT_METHOD_ADD_LISTENER] = { NULL, 0, },
+ [PW_CLIENT_METHOD_ERROR] = { &client_demarshal_error, PW_PERM_W, },
+ [PW_CLIENT_METHOD_UPDATE_PROPERTIES] = { &client_demarshal_update_properties, PW_PERM_W, },
+ [PW_CLIENT_METHOD_GET_PERMISSIONS] = { &client_demarshal_get_permissions, 0, },
+ [PW_CLIENT_METHOD_UPDATE_PERMISSIONS] = { &client_demarshal_update_permissions, PW_PERM_W, },
+};
+
+static const struct pw_client_events pw_protocol_native_client_event_marshal = {
+ PW_VERSION_CLIENT_EVENTS,
+ .info = &client_marshal_info,
+ .permissions = &client_marshal_permissions,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_client_event_demarshal[PW_CLIENT_EVENT_NUM] =
+{
+ [PW_CLIENT_EVENT_INFO] = { &client_demarshal_info, 0, },
+ [PW_CLIENT_EVENT_PERMISSIONS] = { &client_demarshal_permissions, 0, }
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_client_marshal = {
+ PW_TYPE_INTERFACE_Client,
+ PW_VERSION_CLIENT,
+ 0,
+ PW_CLIENT_METHOD_NUM,
+ PW_CLIENT_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_client_method_marshal,
+ .server_demarshal = pw_protocol_native_client_method_demarshal,
+ .server_marshal = &pw_protocol_native_client_event_marshal,
+ .client_demarshal = pw_protocol_native_client_event_demarshal,
+};
+
+
+static const struct pw_link_methods pw_protocol_native_link_method_marshal = {
+ PW_VERSION_LINK_METHODS,
+ .add_listener = &link_method_marshal_add_listener,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_link_method_demarshal[PW_LINK_METHOD_NUM] =
+{
+ [PW_LINK_METHOD_ADD_LISTENER] = { NULL, 0, },
+};
+
+static const struct pw_link_events pw_protocol_native_link_event_marshal = {
+ PW_VERSION_LINK_EVENTS,
+ .info = &link_marshal_info,
+};
+
+static const struct pw_protocol_native_demarshal
+pw_protocol_native_link_event_demarshal[PW_LINK_EVENT_NUM] =
+{
+ [PW_LINK_EVENT_INFO] = { &link_demarshal_info, 0, }
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_link_marshal = {
+ PW_TYPE_INTERFACE_Link,
+ PW_VERSION_LINK,
+ 0,
+ PW_LINK_METHOD_NUM,
+ PW_LINK_EVENT_NUM,
+ .client_marshal = &pw_protocol_native_link_method_marshal,
+ .server_demarshal = pw_protocol_native_link_method_demarshal,
+ .server_marshal = &pw_protocol_native_link_event_marshal,
+ .client_demarshal = pw_protocol_native_link_event_demarshal,
+};
+
+void pw_protocol_native_init(struct pw_protocol *protocol)
+{
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_core_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_registry_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_module_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_device_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_node_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_port_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_factory_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_client_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_link_marshal);
+}
diff --git a/src/modules/module-protocol-native/test-connection.c b/src/modules/module-protocol-native/test-connection.c
new file mode 100644
index 0000000..c7d2f69
--- /dev/null
+++ b/src/modules/module-protocol-native/test-connection.c
@@ -0,0 +1,225 @@
+/* PipeWire
+ *
+ * Copyright © 2019 Wim Taymans
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <sys/socket.h>
+
+#include <spa/pod/builder.h>
+#include <spa/pod/parser.h>
+#include <spa/utils/result.h>
+
+#include <pipewire/pipewire.h>
+
+#include "connection.h"
+
+#define NAME "protocol-native"
+PW_LOG_TOPIC(mod_topic, "mod." NAME);
+PW_LOG_TOPIC(mod_topic_connection, "conn." NAME);
+
+static void test_create(struct pw_protocol_native_connection *conn)
+{
+ const struct pw_protocol_native_message *msg;
+ int res;
+
+ res = pw_protocol_native_connection_get_next(conn, &msg);
+ spa_assert_se(res != 1);
+
+ res = pw_protocol_native_connection_get_fd(conn, 0);
+ spa_assert_se(res == -ENOENT);
+
+ res = pw_protocol_native_connection_flush(conn);
+ spa_assert_se(res == 0);
+
+ res = pw_protocol_native_connection_clear(conn);
+ spa_assert_se(res == 0);
+}
+
+static void write_message(struct pw_protocol_native_connection *conn, int fd)
+{
+ struct pw_protocol_native_message *msg;
+ struct spa_pod_builder *b;
+ int seq = -1, res;
+
+ b = pw_protocol_native_connection_begin(conn, 1, 5, &msg);
+ spa_assert_se(b != NULL);
+ spa_assert_se(msg->seq != -1);
+
+ seq = SPA_RESULT_RETURN_ASYNC(msg->seq);
+
+ spa_pod_builder_add_struct(b,
+ SPA_POD_Int(42),
+ SPA_POD_Id(SPA_TYPE_Object),
+ SPA_POD_Int(pw_protocol_native_connection_add_fd(conn, fd)));
+
+ res = pw_protocol_native_connection_end(conn, b);
+ spa_assert_se(seq == res);
+}
+
+static int read_message(struct pw_protocol_native_connection *conn,
+ const struct pw_protocol_native_message **pmsg)
+{
+ struct spa_pod_parser prs;
+ const struct pw_protocol_native_message *msg;
+ int res, fd;
+ uint32_t v_int, v_id, fdidx;
+
+ res = pw_protocol_native_connection_get_next(conn, &msg);
+ if (res != 1) {
+ pw_log_error("got %d", res);
+ return -1;
+ }
+
+ if (pmsg)
+ *pmsg = msg;
+
+ spa_assert_se(msg->opcode == 5);
+ spa_assert_se(msg->id == 1);
+ spa_assert_se(msg->data != NULL);
+ spa_assert_se(msg->size > 0);
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ SPA_POD_Int(&v_int),
+ SPA_POD_Id(&v_id),
+ SPA_POD_Int(&fdidx)) < 0)
+ spa_assert_not_reached();
+
+ fd = pw_protocol_native_connection_get_fd(conn, fdidx);
+ spa_assert_se(fd != -ENOENT);
+ pw_log_debug("got fd %d %d", fdidx, fd);
+ return 0;
+}
+
+static void test_read_write(struct pw_protocol_native_connection *in,
+ struct pw_protocol_native_connection *out)
+{
+ write_message(out, 1);
+ pw_protocol_native_connection_flush(out);
+ write_message(out, 2);
+ pw_protocol_native_connection_flush(out);
+ spa_assert_se(read_message(in, NULL) == 0);
+ spa_assert_se(read_message(in, NULL) == 0);
+ spa_assert_se(read_message(in, NULL) == -1);
+
+ write_message(out, 1);
+ write_message(out, 2);
+ pw_protocol_native_connection_flush(out);
+ spa_assert_se(read_message(in, NULL) == 0);
+ spa_assert_se(read_message(in, NULL) == 0);
+ spa_assert_se(read_message(in, NULL) == -1);
+}
+
+static void test_reentering(struct pw_protocol_native_connection *in,
+ struct pw_protocol_native_connection *out)
+{
+ const struct pw_protocol_native_message *msg1, *msg2;
+ int i;
+
+#define READ_MSG(idx) \
+ spa_assert_se(read_message(in, &msg ## idx) == 0); \
+ spa_assert_se((msg ## idx)->n_fds == 1); \
+ spa_assert_se((msg ## idx)->size < sizeof(buf ## idx)); \
+ fd ## idx = (msg ## idx)->fds[0]; \
+ memcpy(buf ## idx, (msg ## idx)->data, (msg ## idx)->size); \
+ size ## idx = (msg ## idx)->size
+
+#define CHECK_MSG(idx) \
+ spa_assert_se((msg ## idx)->fds[0] == fd ## idx); \
+ spa_assert_se(memcmp((msg ## idx)->data, buf ## idx, size ## idx) == 0)
+
+ for (i = 0; i < 50; ++i) {
+ int fd1, fd2;
+ char buf1[1024], buf2[1024];
+ int size1, size2;
+
+ write_message(out, 1);
+ write_message(out, 2);
+ write_message(out, 1);
+ write_message(out, 2);
+ write_message(out, 1);
+ pw_protocol_native_connection_flush(out);
+
+ READ_MSG(1);
+ pw_protocol_native_connection_enter(in); /* 1 */
+ READ_MSG(2);
+ CHECK_MSG(1);
+ pw_protocol_native_connection_enter(in); /* 2 */
+ pw_protocol_native_connection_leave(in); /* 2 */
+ CHECK_MSG(1);
+ CHECK_MSG(2);
+ pw_protocol_native_connection_enter(in); /* 2 */
+ pw_protocol_native_connection_enter(in); /* 3 */
+ spa_assert_se(read_message(in, NULL) == 0);
+ CHECK_MSG(1);
+ CHECK_MSG(2);
+ pw_protocol_native_connection_leave(in); /* 3 */
+ spa_assert_se(read_message(in, NULL) == 0);
+ CHECK_MSG(1);
+ CHECK_MSG(2);
+ pw_protocol_native_connection_leave(in); /* 2 */
+ CHECK_MSG(2);
+ spa_assert_se(read_message(in, NULL) == 0);
+ CHECK_MSG(1);
+ pw_protocol_native_connection_leave(in); /* 1 */
+ CHECK_MSG(1);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ struct pw_main_loop *loop;
+ struct pw_context *context;
+ struct pw_protocol_native_connection *in, *out;
+ int fds[2];
+
+ pw_init(&argc, &argv);
+
+ PW_LOG_TOPIC_INIT(mod_topic);
+ PW_LOG_TOPIC_INIT(mod_topic_connection);
+
+ loop = pw_main_loop_new(NULL);
+ spa_assert_se(loop != NULL);
+ context = pw_context_new(pw_main_loop_get_loop(loop), NULL, 0);
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
+ spa_assert_not_reached();
+ return -1;
+ }
+
+ in = pw_protocol_native_connection_new(context, fds[0]);
+ spa_assert_se(in != NULL);
+ out = pw_protocol_native_connection_new(context, fds[1]);
+ spa_assert_se(out != NULL);
+
+ test_create(in);
+ test_create(out);
+ test_read_write(in, out);
+ test_reentering(in, out);
+
+ pw_protocol_native_connection_destroy(in);
+ pw_protocol_native_connection_destroy(out);
+ pw_context_destroy(context);
+ pw_main_loop_destroy(loop);
+
+ return 0;
+}
diff --git a/src/modules/module-protocol-native/v0/interfaces.h b/src/modules/module-protocol-native/v0/interfaces.h
new file mode 100644
index 0000000..dca9672
--- /dev/null
+++ b/src/modules/module-protocol-native/v0/interfaces.h
@@ -0,0 +1,534 @@
+/* PipeWire
+ *
+ * Copyright © 2016 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef PIPEWIRE_INTERFACES_V0_H
+#define PIPEWIRE_INTERFACES_V0_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <spa/utils/defs.h>
+#include <spa/param/param.h>
+#include <spa/node/node.h>
+
+#include <pipewire/pipewire.h>
+
+/** Core */
+
+#define PW_VERSION_CORE_V0 0
+
+#define PW_CORE_V0_METHOD_HELLO 0
+#define PW_CORE_V0_METHOD_UPDATE_TYPES 1
+#define PW_CORE_V0_METHOD_SYNC 2
+#define PW_CORE_V0_METHOD_GET_REGISTRY 3
+#define PW_CORE_V0_METHOD_CLIENT_UPDATE 4
+#define PW_CORE_V0_METHOD_PERMISSIONS 5
+#define PW_CORE_V0_METHOD_CREATE_OBJECT 6
+#define PW_CORE_V0_METHOD_DESTROY 7
+#define PW_CORE_V0_METHOD_NUM 8
+
+/**
+ * Key to update default permissions of globals without specific
+ * permissions. value is "[r][w][x]" */
+#define PW_CORE_PERMISSIONS_DEFAULT "permissions.default"
+
+/**
+ * Key to update specific permissions of a global. If the global
+ * did not have specific permissions, it will first be assigned
+ * the default permissions before it is updated.
+ * Value is "<global-id>:[r][w][x]"*/
+#define PW_CORE_PERMISSIONS_GLOBAL "permissions.global"
+
+/**
+ * Key to update specific permissions of all existing globals.
+ * This is equivalent to using \ref PW_CORE_PERMISSIONS_GLOBAL
+ * on each global id individually that did not have specific
+ * permissions.
+ * Value is "[r][w][x]" */
+#define PW_CORE_PERMISSIONS_EXISTING "permissions.existing"
+
+#define PW_LINK_OUTPUT_NODE_ID "link.output_node.id"
+#define PW_LINK_OUTPUT_PORT_ID "link.output_port.id"
+#define PW_LINK_INPUT_NODE_ID "link.input_node.id"
+#define PW_LINK_INPUT_PORT_ID "link.input_port.id"
+
+/**
+ * \struct pw_core_v0_methods
+ * \brief Core methods
+ *
+ * The core global object. This is a singleton object used for
+ * creating new objects in the remote PipeWire instance. It is
+ * also used for internal features.
+ */
+struct pw_core_v0_methods {
+#define PW_VERSION_CORE_V0_METHODS 0
+ uint32_t version;
+ /**
+ * Start a conversation with the server. This will send
+ * the core info and server types.
+ *
+ * All the existing resources for the client (except the core
+ * resource) will be destroyed.
+ */
+ void (*hello) (void *object);
+ /**
+ * Update the type map
+ *
+ * Send a type map update to the PipeWire server. The server uses this
+ * information to keep a mapping between client types and the server types.
+ * \param first_id the id of the first type
+ * \param types the types as a string
+ * \param n_types the number of types
+ */
+ void (*update_types) (void *object,
+ uint32_t first_id,
+ const char **types,
+ uint32_t n_types);
+ /**
+ * Do server roundtrip
+ *
+ * Ask the server to emit the 'done' event with \a id.
+ * Since methods are handled in-order and events are delivered
+ * in-order, this can be used as a barrier to ensure all previous
+ * methods and the resulting events have been handled.
+ * \param seq the sequence number passed to the done event
+ */
+ void (*sync) (void *object, uint32_t seq);
+ /**
+ * Get the registry object
+ *
+ * Create a registry object that allows the client to list and bind
+ * the global objects available from the PipeWire server
+ * \param version the client proxy id
+ * \param id the client proxy id
+ */
+ void (*get_registry) (void *object, uint32_t version, uint32_t new_id);
+ /**
+ * Update the client properties
+ * \param props the new client properties
+ */
+ void (*client_update) (void *object, const struct spa_dict *props);
+ /**
+ * Manage the permissions of the global objects
+ *
+ * Update the permissions of the global objects using the
+ * dictionary with properties.
+ *
+ * Globals can use the default permissions or can have specific
+ * permissions assigned to them.
+ *
+ * \param id the global id to change
+ * \param props dictionary with permission properties
+ */
+ void (*permissions) (void *object, const struct spa_dict *props);
+ /**
+ * Create a new object on the PipeWire server from a factory.
+ * Use a \a factory_name of "client-node" to create a
+ * \ref pw_client_node.
+ *
+ * \param factory_name the factory name to use
+ * \param type the interface to bind to
+ * \param version the version of the interface
+ * \param props extra properties
+ * \param new_id the client proxy id
+ */
+ void (*create_object) (void *object,
+ const char *factory_name,
+ uint32_t type,
+ uint32_t version,
+ const struct spa_dict *props,
+ uint32_t new_id);
+
+ /**
+ * Destroy an object id
+ *
+ * \param id the object id to destroy
+ */
+ void (*destroy) (void *object, uint32_t id);
+};
+
+#define PW_CORE_V0_EVENT_UPDATE_TYPES 0
+#define PW_CORE_V0_EVENT_DONE 1
+#define PW_CORE_V0_EVENT_ERROR 2
+#define PW_CORE_V0_EVENT_REMOVE_ID 3
+#define PW_CORE_V0_EVENT_INFO 4
+#define PW_CORE_V0_EVENT_NUM 5
+
+/** \struct pw_core_v0_events
+ * \brief Core events
+ * \ingroup pw_core_interface The pw_core interface
+ */
+struct pw_core_v0_events {
+#define PW_VERSION_CORE_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Update the type map
+ *
+ * Send a type map update to the client. The client uses this
+ * information to keep a mapping between server types and the client types.
+ * \param first_id the id of the first type
+ * \param types the types as a string
+ * \param n_types the number of \a types
+ */
+ void (*update_types) (void *data,
+ uint32_t first_id,
+ const char **types,
+ uint32_t n_types);
+ /**
+ * Emit a done event
+ *
+ * The done event is emitted as a result of a sync method with the
+ * same sequence number.
+ * \param seq the sequence number passed to the sync method call
+ */
+ void (*done) (void *data, uint32_t seq);
+ /**
+ * Fatal error event
+ *
+ * The error event is sent out when a fatal (non-recoverable)
+ * error has occurred. The id argument is the object where
+ * the error occurred, most often in response to a request to that
+ * object. The message is a brief description of the error,
+ * for (debugging) convenience.
+ * \param id object where the error occurred
+ * \param res error code
+ * \param error error description
+ */
+ void (*error) (void *data, uint32_t id, int res, const char *error, ...);
+ /**
+ * Remove an object ID
+ *
+ * This event is used internally by the object ID management
+ * logic. When a client deletes an object, the server will send
+ * this event to acknowledge that it has seen the delete request.
+ * When the client receives this event, it will know that it can
+ * safely reuse the object ID.
+ * \param id deleted object ID
+ */
+ void (*remove_id) (void *data, uint32_t id);
+ /**
+ * Notify new core info
+ *
+ * \param info new core info
+ */
+ void (*info) (void *data, struct pw_core_info *info);
+};
+
+#define pw_core_resource_v0_update_types(r,...) pw_resource_notify(r,struct pw_core_v0_events,update_types,__VA_ARGS__)
+#define pw_core_resource_v0_done(r,...) pw_resource_notify(r,struct pw_core_v0_events,done,__VA_ARGS__)
+#define pw_core_resource_v0_error(r,...) pw_resource_notify(r,struct pw_core_v0_events,error,__VA_ARGS__)
+#define pw_core_resource_v0_remove_id(r,...) pw_resource_notify(r,struct pw_core_v0_events,remove_id,__VA_ARGS__)
+#define pw_core_resource_v0_info(r,...) pw_resource_notify(r,struct pw_core_v0_events,info,__VA_ARGS__)
+
+
+#define PW_VERSION_REGISTRY_V0 0
+
+/** \page page_registry Registry
+ *
+ * \section page_registry_overview Overview
+ *
+ * The registry object is a singleton object that keeps track of
+ * global objects on the PipeWire instance. See also \ref page_global.
+ *
+ * Global objects typically represent an actual object in PipeWire
+ * (for example, a module or node) or they are singleton
+ * objects such as the core.
+ *
+ * When a client creates a registry object, the registry object
+ * will emit a global event for each global currently in the
+ * registry. Globals come and go as a result of device hotplugs or
+ * reconfiguration or other events, and the registry will send out
+ * global and global_remove events to keep the client up to date
+ * with the changes. To mark the end of the initial burst of
+ * events, the client can use the pw_core.sync methosd immediately
+ * after calling pw_core.get_registry.
+ *
+ * A client can bind to a global object by using the bind
+ * request. This creates a client-side proxy that lets the object
+ * emit events to the client and lets the client invoke methods on
+ * the object. See \ref page_proxy
+ *
+ * Clients can also change the permissions of the global objects that
+ * it can see. This is interesting when you want to configure a
+ * pipewire session before handing it to another application. You
+ * can, for example, hide certain existing or new objects or limit
+ * the access permissions on an object.
+ */
+#define PW_REGISTRY_V0_METHOD_BIND 0
+#define PW_REGISTRY_V0_METHOD_NUM 1
+
+/** Registry methods */
+struct pw_registry_v0_methods {
+#define PW_VERSION_REGISTRY_V0_METHODS 0
+ uint32_t version;
+ /**
+ * Bind to a global object
+ *
+ * Bind to the global object with \a id and use the client proxy
+ * with new_id as the proxy. After this call, methods can be
+ * send to the remote global object and events can be received
+ *
+ * \param id the global id to bind to
+ * \param type the interface type to bind to
+ * \param version the interface version to use
+ * \param new_id the client proxy to use
+ */
+ void (*bind) (void *object, uint32_t id, uint32_t type, uint32_t version, uint32_t new_id);
+};
+
+#define PW_REGISTRY_V0_EVENT_GLOBAL 0
+#define PW_REGISTRY_V0_EVENT_GLOBAL_REMOVE 1
+#define PW_REGISTRY_V0_EVENT_NUM 2
+
+/** Registry events */
+struct pw_registry_v0_events {
+#define PW_VERSION_REGISTRY_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify of a new global object
+ *
+ * The registry emits this event when a new global object is
+ * available.
+ *
+ * \param id the global object id
+ * \param parent_id the parent global id
+ * \param permissions the permissions of the object
+ * \param type the type of the interface
+ * \param version the version of the interface
+ * \param props extra properties of the global
+ */
+ void (*global) (void *data, uint32_t id, uint32_t parent_id,
+ uint32_t permissions, uint32_t type, uint32_t version,
+ const struct spa_dict *props);
+ /**
+ * Notify of a global object removal
+ *
+ * Emitted when a global object was removed from the registry.
+ * If the client has any bindings to the global, it should destroy
+ * those.
+ *
+ * \param id the id of the global that was removed
+ */
+ void (*global_remove) (void *data, uint32_t id);
+};
+
+#define pw_registry_resource_v0_global(r,...) pw_resource_notify(r,struct pw_registry_v0_events,global,__VA_ARGS__)
+#define pw_registry_resource_v0_global_remove(r,...) pw_resource_notify(r,struct pw_registry_v0_events,global_remove,__VA_ARGS__)
+
+
+#define PW_VERSION_MODULE_V0 0
+
+#define PW_MODULE_V0_EVENT_INFO 0
+#define PW_MODULE_V0_EVENT_NUM 1
+
+/** Module events */
+struct pw_module_v0_events {
+#define PW_VERSION_MODULE_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify module info
+ *
+ * \param info info about the module
+ */
+ void (*info) (void *data, struct pw_module_info *info);
+};
+
+#define pw_module_resource_v0_info(r,...) pw_resource_notify(r,struct pw_module_v0_events,info,__VA_ARGS__)
+
+#define PW_VERSION_NODE_V0 0
+
+#define PW_NODE_V0_EVENT_INFO 0
+#define PW_NODE_V0_EVENT_PARAM 1
+#define PW_NODE_V0_EVENT_NUM 2
+
+/** Node events */
+struct pw_node_v0_events {
+#define PW_VERSION_NODE_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify node info
+ *
+ * \param info info about the node
+ */
+ void (*info) (void *data, struct pw_node_info *info);
+ /**
+ * Notify a node param
+ *
+ * Event emitted as a result of the enum_params method.
+ *
+ * \param id the param id
+ * \param index the param index
+ * \param next the param index of the next param
+ * \param param the parameter
+ */
+ void (*param) (void *data,
+ uint32_t id, uint32_t index, uint32_t next,
+ const struct spa_pod *param);
+};
+
+#define pw_node_resource_v0_info(r,...) pw_resource_notify(r,struct pw_node_v0_events,info,__VA_ARGS__)
+#define pw_node_resource_v0_param(r,...) pw_resource_notify(r,struct pw_node_v0_events,param,__VA_ARGS__)
+
+#define PW_NODE_V0_METHOD_ENUM_PARAMS 0
+#define PW_NODE_V0_METHOD_NUM 1
+
+/** Node methods */
+struct pw_node_v0_methods {
+#define PW_VERSION_NODE_V0_METHODS 0
+ uint32_t version;
+ /**
+ * Enumerate node parameters
+ *
+ * Start enumeration of node parameters. For each param, a
+ * param event will be emitted.
+ *
+ * \param id the parameter id to enum or PW_ID_ANY for all
+ * \param start the start index or 0 for the first param
+ * \param num the maximum number of params to retrieve
+ * \param filter a param filter or NULL
+ */
+ void (*enum_params) (void *object, uint32_t id, uint32_t start, uint32_t num,
+ const struct spa_pod *filter);
+};
+
+#define PW_VERSION_PORT_V0 0
+
+#define PW_PORT_V0_EVENT_INFO 0
+#define PW_PORT_V0_EVENT_PARAM 1
+#define PW_PORT_V0_EVENT_NUM 2
+
+/** Port events */
+struct pw_port_v0_events {
+#define PW_VERSION_PORT_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify port info
+ *
+ * \param info info about the port
+ */
+ void (*info) (void *data, struct pw_port_info *info);
+ /**
+ * Notify a port param
+ *
+ * Event emitted as a result of the enum_params method.
+ *
+ * \param id the param id
+ * \param index the param index
+ * \param next the param index of the next param
+ * \param param the parameter
+ */
+ void (*param) (void *data,
+ uint32_t id, uint32_t index, uint32_t next,
+ const struct spa_pod *param);
+};
+
+#define pw_port_resource_v0_info(r,...) pw_resource_notify(r,struct pw_port_v0_events,info,__VA_ARGS__)
+#define pw_port_resource_v0_param(r,...) pw_resource_notify(r,struct pw_port_v0_events,param,__VA_ARGS__)
+
+#define PW_PORT_V0_METHOD_ENUM_PARAMS 0
+#define PW_PORT_V0_METHOD_NUM 1
+
+/** Port methods */
+struct pw_port_v0_methods {
+#define PW_VERSION_PORT_V0_METHODS 0
+ uint32_t version;
+ /**
+ * Enumerate port parameters
+ *
+ * Start enumeration of port parameters. For each param, a
+ * param event will be emitted.
+ *
+ * \param id the parameter id to enumerate
+ * \param start the start index or 0 for the first param
+ * \param num the maximum number of params to retrieve
+ * \param filter a param filter or NULL
+ */
+ void (*enum_params) (void *object, uint32_t id, uint32_t start, uint32_t num,
+ const struct spa_pod *filter);
+};
+
+#define PW_VERSION_FACTORY_V0 0
+
+#define PW_FACTORY_V0_EVENT_INFO 0
+#define PW_FACTORY_V0_EVENT_NUM 1
+
+/** Factory events */
+struct pw_factory_v0_events {
+#define PW_VERSION_FACTORY_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify factory info
+ *
+ * \param info info about the factory
+ */
+ void (*info) (void *data, struct pw_factory_info *info);
+};
+
+#define pw_factory_resource_v0_info(r,...) pw_resource_notify(r,struct pw_factory_v0_events,info,__VA_ARGS__)
+
+#define PW_VERSION_CLIENT_V0 0
+
+#define PW_CLIENT_V0_EVENT_INFO 0
+#define PW_CLIENT_V0_EVENT_NUM 1
+
+/** Client events */
+struct pw_client_v0_events {
+#define PW_VERSION_CLIENT_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify client info
+ *
+ * \param info info about the client
+ */
+ void (*info) (void *data, struct pw_client_info *info);
+};
+
+#define pw_client_resource_v0_info(r,...) pw_resource_notify(r,struct pw_client_v0_events,info,__VA_ARGS__)
+
+
+#define PW_VERSION_LINK_V0 0
+
+#define PW_LINK_V0_EVENT_INFO 0
+#define PW_LINK_V0_EVENT_NUM 1
+
+/** Link events */
+struct pw_link_v0_events {
+#define PW_VERSION_LINK_V0_EVENTS 0
+ uint32_t version;
+ /**
+ * Notify link info
+ *
+ * \param info info about the link
+ */
+ void (*info) (void *data, struct pw_link_info *info);
+};
+
+#define pw_link_resource_v0_info(r,...) pw_resource_notify(r,struct pw_link_v0_events,info,__VA_ARGS__)
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* PIPEWIRE_INTERFACES_V0_H */
diff --git a/src/modules/module-protocol-native/v0/protocol-native.c b/src/modules/module-protocol-native/v0/protocol-native.c
new file mode 100644
index 0000000..d6173ac
--- /dev/null
+++ b/src/modules/module-protocol-native/v0/protocol-native.c
@@ -0,0 +1,1371 @@
+/* PipeWire
+ *
+ * Copyright © 2017 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+
+#include "spa/pod/parser.h"
+#include "spa/pod/builder.h"
+#include "spa/debug/types.h"
+#include "spa/utils/string.h"
+
+#include "pipewire/pipewire.h"
+#include "pipewire/private.h"
+#include "pipewire/protocol.h"
+#include "pipewire/resource.h"
+#include "pipewire/extensions/protocol-native.h"
+#include "pipewire/extensions/metadata.h"
+#include "pipewire/extensions/session-manager.h"
+#include "pipewire/extensions/client-node.h"
+
+#include "interfaces.h"
+#include "typemap.h"
+
+#include "../connection.h"
+
+PW_LOG_TOPIC_EXTERN(mod_topic);
+#define PW_LOG_TOPIC_DEFAULT mod_topic
+
+#define PW_PROTOCOL_NATIVE_FLAG_REMAP (1<<0)
+
+SPA_EXPORT
+uint32_t pw_protocol_native0_find_type(struct pw_impl_client *client, const char *type)
+{
+ uint32_t i;
+ for (i = 0; i < SPA_N_ELEMENTS(type_map); i++) {
+ if (spa_streq(type_map[i].type, type))
+ return i;
+ }
+ return SPA_ID_INVALID;
+}
+
+static void
+update_types_server(struct pw_resource *resource)
+{
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_V0_EVENT_UPDATE_TYPES, NULL);
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", 0,
+ "i", SPA_N_ELEMENTS(type_map), NULL);
+
+ for (i = 0; i < SPA_N_ELEMENTS(type_map); i++) {
+ spa_pod_builder_add(b, "s", type_map[i].type, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+
+static void core_marshal_info(void *data, const struct pw_core_info *info)
+{
+ struct pw_resource *resource = data;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct protocol_compat_v2 *compat_v2 = client->compat_v2;
+ struct spa_pod_builder *b;
+ uint32_t i, n_items;
+ uint64_t change_mask = 0;
+ struct spa_pod_frame f;
+ struct pw_protocol_native_message *msg;
+
+#define PW_CORE_V0_CHANGE_MASK_USER_NAME (1 << 0)
+#define PW_CORE_V0_CHANGE_MASK_HOST_NAME (1 << 1)
+#define PW_CORE_V0_CHANGE_MASK_VERSION (1 << 2)
+#define PW_CORE_V0_CHANGE_MASK_NAME (1 << 3)
+#define PW_CORE_V0_CHANGE_MASK_COOKIE (1 << 4)
+#define PW_CORE_V0_CHANGE_MASK_PROPS (1 << 5)
+
+ if (compat_v2->send_types) {
+ update_types_server(resource);
+ change_mask |= PW_CORE_V0_CHANGE_MASK_USER_NAME |
+ PW_CORE_V0_CHANGE_MASK_HOST_NAME |
+ PW_CORE_V0_CHANGE_MASK_VERSION |
+ PW_CORE_V0_CHANGE_MASK_NAME |
+ PW_CORE_V0_CHANGE_MASK_COOKIE;
+ compat_v2->send_types = false;
+ }
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_V0_EVENT_INFO, &msg);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+ if (info->change_mask & PW_CORE_CHANGE_MASK_PROPS)
+ change_mask |= PW_CORE_V0_CHANGE_MASK_PROPS;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", change_mask,
+ "s", info->user_name,
+ "s", info->host_name,
+ "s", info->version,
+ "s", info->name,
+ "i", info->cookie,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_marshal_done(void *data, uint32_t id, int seq)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_V0_EVENT_DONE, NULL);
+
+ spa_pod_builder_add_struct(b, "i", seq);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_marshal_error(void *data, uint32_t id, int seq, int res, const char *error)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_V0_EVENT_ERROR, NULL);
+
+ spa_pod_builder_add_struct(b,
+ "i", id,
+ "i", res,
+ "s", error);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void core_marshal_remove_id(void *data, uint32_t id)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CORE_V0_EVENT_REMOVE_ID, NULL);
+
+ spa_pod_builder_add_struct(b, "i", id);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int core_demarshal_client_update(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_dict props;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f;
+ uint32_t i;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f) < 0 ||
+ spa_pod_parser_get(&prs,
+ "i", &props.n_items, NULL) < 0)
+ return -EINVAL;
+
+ props.items = alloca(props.n_items * sizeof(struct spa_dict_item));
+ for (i = 0; i < props.n_items; i++) {
+ if (spa_pod_parser_get(&prs,
+ "s", &props.items[i].key,
+ "s", &props.items[i].value,
+ NULL) < 0)
+ return -EINVAL;
+ }
+ pw_impl_client_update_properties(client, &props);
+ return 0;
+}
+
+static uint32_t parse_perms(const char *str)
+{
+ uint32_t perms = 0;
+
+ while (*str != '\0') {
+ switch (*str++) {
+ case 'r':
+ perms |= PW_PERM_R;
+ break;
+ case 'w':
+ perms |= PW_PERM_W;
+ break;
+ case 'x':
+ perms |= PW_PERM_X;
+ break;
+ }
+ }
+ return perms;
+}
+
+static int core_demarshal_permissions(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_dict props;
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f;
+ uint32_t i, n_permissions;
+ struct pw_permission *permissions, defperm = { 0, };
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f) < 0 ||
+ spa_pod_parser_get(&prs, "i", &props.n_items, NULL) < 0)
+ return -EINVAL;
+
+ props.items = alloca(props.n_items * sizeof(struct spa_dict_item));
+
+ n_permissions = 0;
+ permissions = alloca(props.n_items * sizeof(struct pw_permission));
+
+ for (i = 0; i < props.n_items; i++) {
+ uint32_t id, perms;
+ const char *str;
+
+ if (spa_pod_parser_get(&prs,
+ "s", &props.items[i].key,
+ "s", &props.items[i].value,
+ NULL) < 0)
+ return -EINVAL;
+
+ str = props.items[i].value;
+ /* first set global permissions */
+ if (spa_streq(props.items[i].key, PW_CORE_PERMISSIONS_GLOBAL)) {
+ size_t len;
+
+ /* <global-id>:[r][w][x] */
+ len = strcspn(str, ":");
+ if (len == 0)
+ continue;
+ id = atoi(str);
+ perms = parse_perms(str + len);
+ permissions[n_permissions++] = PW_PERMISSION_INIT(id, perms);
+ } else if (spa_streq(props.items[i].key, PW_CORE_PERMISSIONS_DEFAULT)) {
+ perms = parse_perms(str);
+ defperm = PW_PERMISSION_INIT(PW_ID_ANY, perms);
+ }
+ }
+ /* add default permission if set */
+ if (defperm.id == PW_ID_ANY)
+ permissions[n_permissions++] = defperm;
+
+ for (i = 0; i < n_permissions; i++) {
+ pw_log_debug("%d: %d: %08x", i, permissions[i].id, permissions[i].permissions);
+ }
+
+ return pw_impl_client_update_permissions(resource->client,
+ n_permissions, permissions);
+}
+
+static int core_demarshal_hello(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ void *ptr;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ "P", &ptr) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, hello, 0, 2);
+}
+
+static int core_demarshal_sync(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ uint32_t seq;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs, "i", &seq) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, sync, 0, 0, seq);
+}
+
+static int core_demarshal_get_registry(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct spa_pod_parser prs;
+ int32_t version, new_id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ "i", &version,
+ "i", &new_id) < 0)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, get_registry, 0, version, new_id);
+}
+
+SPA_EXPORT
+uint32_t pw_protocol_native0_type_from_v2(struct pw_impl_client *client, uint32_t type)
+{
+ void *t;
+ uint32_t index;
+ struct protocol_compat_v2 *compat_v2 = client->compat_v2;
+
+ if ((t = pw_map_lookup(&compat_v2->types, type)) == NULL)
+ return SPA_ID_INVALID;
+
+ index = PW_MAP_PTR_TO_ID(t);
+ if (index >= SPA_N_ELEMENTS(type_map))
+ return SPA_ID_INVALID;
+
+ return type_map[index].id;
+}
+
+SPA_EXPORT
+const char * pw_protocol_native0_name_from_v2(struct pw_impl_client *client, uint32_t type)
+{
+ void *t;
+ uint32_t index;
+ struct protocol_compat_v2 *compat_v2 = client->compat_v2;
+
+ if ((t = pw_map_lookup(&compat_v2->types, type)) == NULL)
+ return NULL;
+
+ index = PW_MAP_PTR_TO_ID(t);
+ if (index >= SPA_N_ELEMENTS(type_map))
+ return NULL;
+
+ return type_map[index].name;
+}
+
+SPA_EXPORT
+uint32_t pw_protocol_native0_name_to_v2(struct pw_impl_client *client, const char *name)
+{
+ uint32_t i;
+ /* match name to type table and return index */
+ for (i = 0; i < SPA_N_ELEMENTS(type_map); i++) {
+ if (type_map[i].name != NULL && spa_streq(type_map[i].name, name))
+ return i;
+ }
+ return SPA_ID_INVALID;
+}
+
+SPA_EXPORT
+uint32_t pw_protocol_native0_type_to_v2(struct pw_impl_client *client,
+ const struct spa_type_info *info, uint32_t type)
+{
+ const char *name;
+
+ /** find full name of type in type_info */
+ if ((name = spa_debug_type_find_name(info, type)) == NULL)
+ return SPA_ID_INVALID;
+
+ return pw_protocol_native0_name_to_v2(client, name);
+}
+
+struct spa_pod_prop_body0 {
+ uint32_t key;
+#define SPA_POD_PROP0_RANGE_NONE 0 /**< no range */
+#define SPA_POD_PROP0_RANGE_MIN_MAX 1 /**< property has range */
+#define SPA_POD_PROP0_RANGE_STEP 2 /**< property has range with step */
+#define SPA_POD_PROP0_RANGE_ENUM 3 /**< property has enumeration */
+#define SPA_POD_PROP0_RANGE_FLAGS 4 /**< property has flags */
+#define SPA_POD_PROP0_RANGE_MASK 0xf /**< mask to select range type */
+#define SPA_POD_PROP0_FLAG_UNSET (1 << 4) /**< property value is unset */
+#define SPA_POD_PROP0_FLAG_OPTIONAL (1 << 5) /**< property value is optional */
+#define SPA_POD_PROP0_FLAG_READONLY (1 << 6) /**< property is readonly */
+#define SPA_POD_PROP0_FLAG_DEPRECATED (1 << 7) /**< property is deprecated */
+#define SPA_POD_PROP0_FLAG_INFO (1 << 8) /**< property is informational and is not
+ * used when filtering */
+ uint32_t flags;
+ struct spa_pod value;
+ /* array with elements of value.size follows,
+ * first element is value/default, rest are alternatives */
+};
+
+/* v2 iterates object as containing spa_pod */
+#define SPA_POD_OBJECT_BODY_FOREACH0(body, size, iter) \
+ for ((iter) = SPA_PTROFF((body), sizeof(struct spa_pod_object_body), struct spa_pod); \
+ spa_pod_is_inside(body, size, iter); \
+ (iter) = spa_pod_next(iter))
+
+#define SPA_POD_PROP_ALTERNATIVE_FOREACH0(body, _size, iter) \
+ for ((iter) = SPA_PTROFF((body), (body)->value.size + \
+ sizeof(struct spa_pod_prop_body0), __typeof__(*iter)); \
+ (iter) <= SPA_PTROFF((body), (_size)-(body)->value.size, __typeof__(*iter)); \
+ (iter) = SPA_PTROFF((iter), (body)->value.size, __typeof__(*iter)))
+
+#define SPA0_POD_PROP_N_VALUES(b,size) (((size) - sizeof(struct spa_pod_prop_body0)) / (b)->value.size)
+
+static int remap_from_v2(uint32_t type, void *body, uint32_t size, struct pw_impl_client *client,
+ struct spa_pod_builder *builder)
+{
+ int res;
+
+ switch (type) {
+ case SPA_TYPE_Id:
+ spa_pod_builder_id(builder, pw_protocol_native0_type_from_v2(client, *(int32_t*) body));
+ break;
+
+ /** choice was props in v2 */
+ case SPA_TYPE_Choice:
+ {
+ struct spa_pod_prop_body0 *b = body;
+ struct spa_pod_frame f;
+ void *alt;
+ uint32_t key = pw_protocol_native0_type_from_v2(client, b->key);
+ enum spa_choice_type type;
+
+ spa_pod_builder_prop(builder, key, 0);
+
+ switch (b->flags & SPA_POD_PROP0_RANGE_MASK) {
+ default:
+ case SPA_POD_PROP0_RANGE_NONE:
+ type = SPA_CHOICE_None;
+ break;
+ case SPA_POD_PROP0_RANGE_MIN_MAX:
+ type = SPA_CHOICE_Range;
+ break;
+ case SPA_POD_PROP0_RANGE_STEP:
+ type = SPA_CHOICE_Step;
+ break;
+ case SPA_POD_PROP0_RANGE_ENUM:
+ type = SPA_CHOICE_Enum;
+ break;
+ case SPA_POD_PROP0_RANGE_FLAGS:
+ type = SPA_CHOICE_Flags;
+ break;
+ }
+ if (!SPA_FLAG_IS_SET(b->flags, SPA_POD_PROP0_FLAG_UNSET) &&
+ SPA0_POD_PROP_N_VALUES(b, size) == 1)
+ type = SPA_CHOICE_None;
+
+ spa_pod_builder_push_choice(builder, &f, type, 0);
+
+ if (b->value.type == SPA_TYPE_Id) {
+ uint32_t id;
+ if ((res = spa_pod_get_id(&b->value, &id)) < 0)
+ return res;
+ spa_pod_builder_id(builder, pw_protocol_native0_type_from_v2(client, id));
+ SPA_POD_PROP_ALTERNATIVE_FOREACH0(b, size, alt)
+ if ((res = remap_from_v2(b->value.type, alt, b->value.size, client, builder)) < 0)
+ return res;
+ } else {
+ spa_pod_builder_raw(builder, &b->value, size - sizeof(struct spa_pod));
+ }
+
+ spa_pod_builder_pop(builder, &f);
+
+ break;
+ }
+ case SPA_TYPE_Object:
+ {
+ struct spa_pod_object_body *b = body;
+ struct spa_pod *p;
+ struct spa_pod_frame f;
+ uint32_t type, count = 0;
+
+ /* type and id are switched */
+ type = pw_protocol_native0_type_from_v2(client, b->id),
+ spa_pod_builder_push_object(builder, &f, type,
+ pw_protocol_native0_type_from_v2(client, b->type));
+
+ /* object contained pods in v2 */
+ SPA_POD_OBJECT_BODY_FOREACH0(b, size, p) {
+ if (type == SPA_TYPE_OBJECT_Format && count < 2) {
+ uint32_t id;
+ if (spa_pod_get_id(p, &id) < 0)
+ continue;
+ id = pw_protocol_native0_type_from_v2(client, id);
+
+ if (count == 0) {
+ spa_pod_builder_prop(builder, SPA_FORMAT_mediaType, 0);
+ spa_pod_builder_id(builder, id);
+ }
+ if (count == 1) {
+ spa_pod_builder_prop(builder, SPA_FORMAT_mediaSubtype, 0);
+ spa_pod_builder_id(builder, id);
+ }
+ count++;
+ continue;
+ }
+ if ((res = remap_from_v2(p->type,
+ SPA_POD_BODY(p),
+ p->size,
+ client, builder)) < 0)
+ return res;
+ }
+ spa_pod_builder_pop(builder, &f);
+ break;
+ }
+ case SPA_TYPE_Struct:
+ {
+ struct spa_pod *b = body, *p;
+ struct spa_pod_frame f;
+
+ spa_pod_builder_push_struct(builder, &f);
+ SPA_POD_FOREACH(b, size, p)
+ if ((res = remap_from_v2(p->type, SPA_POD_BODY(p), p->size, client, builder)) < 0)
+ return res;
+ spa_pod_builder_pop(builder, &f);
+ break;
+ }
+ default:
+ break;
+ }
+ return 0;
+}
+
+static int remap_to_v2(struct pw_impl_client *client, const struct spa_type_info *info,
+ uint32_t type, void *body, uint32_t size,
+ struct spa_pod_builder *builder)
+{
+ int res;
+
+ switch (type) {
+ case SPA_TYPE_Id:
+ spa_pod_builder_id(builder, pw_protocol_native0_type_to_v2(client, info, *(int32_t*) body));
+ break;
+
+ case SPA_TYPE_Object:
+ {
+ struct spa_pod_object_body *b = body;
+ struct spa_pod_prop *p;
+ struct spa_pod_frame f[2];
+ uint32_t type;
+ const struct spa_type_info *ti, *ii;
+
+ ti = spa_debug_type_find(info, b->type);
+ ii = ti ? spa_debug_type_find(ti->values, 0) : NULL;
+
+ if (b->type == SPA_TYPE_COMMAND_Node ||
+ b->type == SPA_TYPE_EVENT_Node) {
+ spa_pod_builder_push_object(builder, &f[0], 0,
+ pw_protocol_native0_type_to_v2(client, ii ? ii->values : NULL, b->id));
+ } else {
+ ii = ii ? spa_debug_type_find(ii->values, b->id) : NULL;
+ /* type and id are switched */
+ type = pw_protocol_native0_type_to_v2(client, info, b->type),
+ spa_pod_builder_push_object(builder, &f[0],
+ pw_protocol_native0_type_to_v2(client, ii ? ii->values : NULL, b->id), type);
+ }
+
+
+ info = ti ? ti->values : info;
+
+ SPA_POD_OBJECT_BODY_FOREACH(b, size, p) {
+ uint32_t key, flags;
+ uint32_t n_vals, choice;
+ struct spa_pod *values;
+
+ ii = spa_debug_type_find(info, p->key);
+
+ values = spa_pod_get_values(&p->value, &n_vals, &choice);
+
+ if (b->type == SPA_TYPE_OBJECT_Format &&
+ (p->key == SPA_FORMAT_mediaType ||
+ p->key == SPA_FORMAT_mediaSubtype)) {
+ uint32_t val;
+
+ if (spa_pod_get_id(values, &val) < 0)
+ continue;
+ spa_pod_builder_id(builder,
+ pw_protocol_native0_type_to_v2(client, ii ? ii->values : NULL, val));
+ continue;
+ }
+
+ flags = 0;
+ switch(choice) {
+ case SPA_CHOICE_None:
+ flags |= SPA_POD_PROP0_RANGE_NONE;
+ break;
+ case SPA_CHOICE_Range:
+ flags |= SPA_POD_PROP0_RANGE_MIN_MAX | SPA_POD_PROP0_FLAG_UNSET;
+ break;
+ case SPA_CHOICE_Step:
+ flags |= SPA_POD_PROP0_RANGE_STEP | SPA_POD_PROP0_FLAG_UNSET;
+ break;
+ case SPA_CHOICE_Enum:
+ flags |= SPA_POD_PROP0_RANGE_ENUM | SPA_POD_PROP0_FLAG_UNSET;
+ break;
+ case SPA_CHOICE_Flags:
+ flags |= SPA_POD_PROP0_RANGE_FLAGS | SPA_POD_PROP0_FLAG_UNSET;
+ break;
+ }
+
+ key = pw_protocol_native0_type_to_v2(client, info, p->key);
+
+ spa_pod_builder_push_choice(builder, &f[1], key, flags);
+
+ if (values->type == SPA_TYPE_Id) {
+ uint32_t i, *id = SPA_POD_BODY(values);
+
+ for (i = 0; i < n_vals; i++) {
+ spa_pod_builder_id(builder,
+ pw_protocol_native0_type_to_v2(client, ii ? ii->values : NULL, id[i]));
+ }
+
+ } else {
+ spa_pod_builder_raw(builder, values, sizeof(struct spa_pod) + n_vals * values->size);
+ }
+ spa_pod_builder_pop(builder, &f[1]);
+ }
+ spa_pod_builder_pop(builder, &f[0]);
+ break;
+ }
+ case SPA_TYPE_Struct:
+ {
+ struct spa_pod *b = body, *p;
+ struct spa_pod_frame f;
+
+ spa_pod_builder_push_struct(builder, &f);
+ SPA_POD_FOREACH(b, size, p)
+ if ((res = remap_to_v2(client, info, p->type, SPA_POD_BODY(p), p->size, builder)) < 0)
+ return res;
+ spa_pod_builder_pop(builder, &f);
+ break;
+ }
+ default:
+ break;
+ }
+ return 0;
+}
+
+
+
+
+SPA_EXPORT
+struct spa_pod * pw_protocol_native0_pod_from_v2(struct pw_impl_client *client, const struct spa_pod *pod)
+{
+ uint8_t buffer[4096];
+ struct spa_pod *copy;
+ struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, 4096);
+ int res;
+
+ if (pod == NULL)
+ return NULL;
+
+ if ((res = remap_from_v2(SPA_POD_TYPE(pod),
+ SPA_POD_BODY(pod),
+ SPA_POD_BODY_SIZE(pod),
+ client, &b)) < 0) {
+ errno = -res;
+ return NULL;
+ }
+ copy = spa_pod_copy(b.data);
+ return copy;
+}
+
+SPA_EXPORT
+int pw_protocol_native0_pod_to_v2(struct pw_impl_client *client, const struct spa_pod *pod,
+ struct spa_pod_builder *b)
+{
+ int res;
+
+ if (pod == NULL) {
+ spa_pod_builder_none(b);
+ return 0;
+ }
+
+ if ((res = remap_to_v2(client, pw_type_info(),
+ SPA_POD_TYPE(pod),
+ SPA_POD_BODY(pod),
+ SPA_POD_BODY_SIZE(pod),
+ b)) < 0) {
+ return -res;
+ }
+ return 0;
+}
+
+static int core_demarshal_create_object(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_parser prs;
+ struct spa_pod_frame f;
+ uint32_t version, type, new_id, i;
+ const char *factory_name, *type_name;
+ struct spa_dict props;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f) < 0 ||
+ spa_pod_parser_get(&prs,
+ "s", &factory_name,
+ "I", &type,
+ "i", &version,
+ "i", &props.n_items, NULL) < 0)
+ return -EINVAL;
+
+ props.items = alloca(props.n_items * sizeof(struct spa_dict_item));
+ for (i = 0; i < props.n_items; i++) {
+ if (spa_pod_parser_get(&prs,
+ "s", &props.items[i].key,
+ "s", &props.items[i].value, NULL) < 0)
+ return -EINVAL;
+ }
+ if (spa_pod_parser_get(&prs, "i", &new_id, NULL) < 0)
+ return -EINVAL;
+
+ type_name = pw_protocol_native0_name_from_v2(client, type);
+ if (type_name == NULL)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_core_methods, create_object, 0, factory_name,
+ type_name, version,
+ &props, new_id);
+}
+
+static int core_demarshal_destroy(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object, *r;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_parser prs;
+ uint32_t id;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ "i", &id, NULL) < 0)
+ return -EINVAL;
+
+ pw_log_debug("client %p: destroy resource %u", client, id);
+
+ if ((r = pw_impl_client_find_resource(client, id)) == NULL)
+ goto no_resource;
+
+ return pw_resource_notify(resource, struct pw_core_methods, destroy, 0, r);
+
+no_resource:
+ pw_log_error("client %p: unknown resource %u op:%u", client, id, msg->opcode);
+ pw_resource_errorf(resource, -ENOENT, "unknown resource %d op:%u", id, msg->opcode);
+ return 0;
+}
+
+static int core_demarshal_update_types_server(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct protocol_compat_v2 *compat_v2 = client->compat_v2;
+ struct spa_pod_parser prs;
+ uint32_t first_id, n_types;
+ struct spa_pod_frame f;
+ const char **types;
+ uint32_t i;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_push_struct(&prs, &f) < 0 ||
+ spa_pod_parser_get(&prs,
+ "i", &first_id,
+ "i", &n_types,
+ NULL) < 0)
+ return -EINVAL;
+
+ if (first_id == 0)
+ compat_v2->send_types = true;
+
+ types = alloca(n_types * sizeof(char *));
+ for (i = 0; i < n_types; i++) {
+ if (spa_pod_parser_get(&prs, "s", &types[i], NULL) < 0)
+ return -EINVAL;
+ }
+
+ for (i = 0; i < n_types; i++, first_id++) {
+ uint32_t type_id = pw_protocol_native0_find_type(client, types[i]);
+ if (type_id == SPA_ID_INVALID)
+ continue;
+ if (pw_map_insert_at(&compat_v2->types, first_id, PW_MAP_ID_TO_PTR(type_id)) < 0)
+ pw_log_error("can't add type %d->%d for client", first_id, type_id);
+ }
+ return 0;
+}
+
+static void registry_marshal_global(void *data, uint32_t id, uint32_t permissions,
+ const char *type, uint32_t version, const struct spa_dict *props)
+{
+ struct pw_resource *resource = data;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items, parent_id;
+ uint32_t type_id;
+ const char *str;
+
+ type_id = pw_protocol_native0_find_type(client, type);
+ if (type_id == SPA_ID_INVALID)
+ return;
+
+ b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_V0_EVENT_GLOBAL, NULL);
+
+ n_items = props ? props->n_items : 0;
+
+ parent_id = 0;
+ if (props) {
+ if (spa_streq(type, PW_TYPE_INTERFACE_Port)) {
+ if ((str = spa_dict_lookup(props, "node.id")) != NULL)
+ parent_id = atoi(str);
+ } else if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
+ if ((str = spa_dict_lookup(props, "device.id")) != NULL)
+ parent_id = atoi(str);
+ } else if (spa_streq(type, PW_TYPE_INTERFACE_Client) ||
+ spa_streq(type, PW_TYPE_INTERFACE_Device) ||
+ spa_streq(type, PW_TYPE_INTERFACE_Factory)) {
+ if ((str = spa_dict_lookup(props, "module.id")) != NULL)
+ parent_id = atoi(str);
+ }
+ }
+
+ version = 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", id,
+ "i", parent_id,
+ "i", permissions,
+ "I", type_id,
+ "i", version,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", props->items[i].key,
+ "s", props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void registry_marshal_global_remove(void *data, uint32_t id)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+
+ b = pw_protocol_native_begin_resource(resource, PW_REGISTRY_V0_EVENT_GLOBAL_REMOVE, NULL);
+
+ spa_pod_builder_add_struct(b, "i", id);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int registry_demarshal_bind(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_parser prs;
+ uint32_t id, version, type, new_id;
+ const char *type_name;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ "i", &id,
+ "I", &type,
+ "i", &version,
+ "i", &new_id) < 0)
+ return -EINVAL;
+
+ type_name = pw_protocol_native0_name_from_v2(client, type);
+ if (type_name == NULL)
+ return -EINVAL;
+
+ return pw_resource_notify(resource, struct pw_registry_methods, bind, 0, id, type_name, version, new_id);
+}
+
+static void module_marshal_info(void *data, const struct pw_module_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items;
+
+ b = pw_protocol_native_begin_resource(resource, PW_MODULE_V0_EVENT_INFO, NULL);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", info->change_mask,
+ "s", info->name,
+ "s", info->filename,
+ "s", info->args,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void factory_marshal_info(void *data, const struct pw_factory_info *info)
+{
+ struct pw_resource *resource = data;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items, type, version;
+
+ type = pw_protocol_native0_find_type(client, info->type);
+ if (type == SPA_ID_INVALID)
+ return;
+
+ b = pw_protocol_native_begin_resource(resource, PW_FACTORY_V0_EVENT_INFO, NULL);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+ version = 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", info->change_mask,
+ "s", info->name,
+ "I", type,
+ "i", version,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void node_marshal_info(void *data, const struct pw_node_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items;
+
+ b = pw_protocol_native_begin_resource(resource, PW_NODE_V0_EVENT_INFO, NULL);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", info->change_mask,
+ "s", "node.name",
+ "i", info->max_input_ports,
+ "i", info->n_input_ports,
+ "i", info->max_output_ports,
+ "i", info->n_output_ports,
+ "i", info->state,
+ "s", info->error,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void node_marshal_param(void *data, int seq, uint32_t id, uint32_t index, uint32_t next,
+ const struct spa_pod *param)
+{
+ struct pw_resource *resource = data;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_NODE_V0_EVENT_PARAM, NULL);
+
+ id = pw_protocol_native0_type_to_v2(client, spa_type_param, id),
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "I", id,
+ "i", index,
+ "i", next,
+ NULL);
+ pw_protocol_native0_pod_to_v2(client, (struct spa_pod *)param, b);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int node_demarshal_enum_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_parser prs;
+ uint32_t id, index, num;
+ struct spa_pod *filter;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ "I", &id,
+ "i", &index,
+ "i", &num,
+ "P", &filter) < 0)
+ return -EINVAL;
+
+ id = pw_protocol_native0_type_from_v2(client, id);
+ filter = NULL;
+
+ return pw_resource_notify(resource, struct pw_node_methods, enum_params, 0,
+ 0, id, index, num, filter);
+}
+
+static void port_marshal_info(void *data, const struct pw_port_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items;
+ uint64_t change_mask = 0;
+ const char *port_name;
+
+ b = pw_protocol_native_begin_resource(resource, PW_PORT_V0_EVENT_INFO, NULL);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+#define PW_PORT_V0_CHANGE_MASK_NAME (1 << 0)
+#define PW_PORT_V0_CHANGE_MASK_PROPS (1 << 1)
+#define PW_PORT_V0_CHANGE_MASK_ENUM_PARAMS (1 << 2)
+
+ change_mask |= PW_PORT_V0_CHANGE_MASK_NAME;
+ if (info->change_mask & PW_PORT_CHANGE_MASK_PROPS)
+ change_mask |= PW_PORT_V0_CHANGE_MASK_PROPS;
+ if (info->change_mask & PW_PORT_CHANGE_MASK_PARAMS)
+ change_mask |= PW_PORT_V0_CHANGE_MASK_ENUM_PARAMS;
+
+ port_name = NULL;
+ if (info->props != NULL)
+ port_name = spa_dict_lookup(info->props, "port.name");
+ if (port_name == NULL)
+ port_name = "port.name";
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", change_mask,
+ "s", port_name,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void port_marshal_param(void *data, int seq, uint32_t id, uint32_t index, uint32_t next,
+ const struct spa_pod *param)
+{
+ struct pw_resource *resource = data;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+
+ b = pw_protocol_native_begin_resource(resource, PW_PORT_V0_EVENT_PARAM, NULL);
+
+ id = pw_protocol_native0_type_to_v2(client, spa_type_param, id),
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "I", id,
+ "i", index,
+ "i", next,
+ NULL);
+ pw_protocol_native0_pod_to_v2(client, (struct spa_pod *)param, b);
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static int port_demarshal_enum_params(void *object, const struct pw_protocol_native_message *msg)
+{
+ struct pw_resource *resource = object;
+ struct pw_impl_client *client = pw_resource_get_client(resource);
+ struct spa_pod_parser prs;
+ uint32_t id, index, num;
+ struct spa_pod *filter;
+
+ spa_pod_parser_init(&prs, msg->data, msg->size);
+ if (spa_pod_parser_get_struct(&prs,
+ "I", &id,
+ "i", &index,
+ "i", &num,
+ "P", &filter) < 0)
+ return -EINVAL;
+
+ id = pw_protocol_native0_type_from_v2(client, id);
+ filter = NULL;
+
+ return pw_resource_notify(resource, struct pw_port_methods, enum_params, 0,
+ 0, id, index, num, filter);
+}
+
+static void client_marshal_info(void *data, const struct pw_client_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items;
+
+ b = pw_protocol_native_begin_resource(resource, PW_CLIENT_V0_EVENT_INFO, NULL);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", info->change_mask,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static void client_marshal_permissions(void *data, uint32_t index, uint32_t n_permissions,
+ const struct pw_permission *permissions)
+{
+}
+
+
+static void link_marshal_info(void *data, const struct pw_link_info *info)
+{
+ struct pw_resource *resource = data;
+ struct spa_pod_builder *b;
+ struct spa_pod_frame f;
+ uint32_t i, n_items;
+
+ b = pw_protocol_native_begin_resource(resource, PW_LINK_V0_EVENT_INFO, NULL);
+
+ n_items = info->props ? info->props->n_items : 0;
+
+ spa_pod_builder_push_struct(b, &f);
+ spa_pod_builder_add(b,
+ "i", info->id,
+ "l", info->change_mask,
+ "i", info->output_node_id,
+ "i", info->output_port_id,
+ "i", info->input_node_id,
+ "i", info->input_port_id,
+ "P", info->format,
+ "i", n_items, NULL);
+
+ for (i = 0; i < n_items; i++) {
+ spa_pod_builder_add(b,
+ "s", info->props->items[i].key,
+ "s", info->props->items[i].value, NULL);
+ }
+ spa_pod_builder_pop(b, &f);
+
+ pw_protocol_native_end_resource(resource, b);
+}
+
+static const struct pw_protocol_native_demarshal pw_protocol_native_core_method_demarshal[PW_CORE_V0_METHOD_NUM] = {
+ [PW_CORE_V0_METHOD_HELLO] = { &core_demarshal_hello, 0, },
+ [PW_CORE_V0_METHOD_UPDATE_TYPES] = { &core_demarshal_update_types_server, 0, },
+ [PW_CORE_V0_METHOD_SYNC] = { &core_demarshal_sync, 0, },
+ [PW_CORE_V0_METHOD_GET_REGISTRY] = { &core_demarshal_get_registry, 0, },
+ [PW_CORE_V0_METHOD_CLIENT_UPDATE] = { &core_demarshal_client_update, 0, },
+ [PW_CORE_V0_METHOD_PERMISSIONS] = { &core_demarshal_permissions, 0, },
+ [PW_CORE_V0_METHOD_CREATE_OBJECT] = { &core_demarshal_create_object, 0, PW_PROTOCOL_NATIVE_FLAG_REMAP, },
+ [PW_CORE_V0_METHOD_DESTROY] = { &core_demarshal_destroy, 0, }
+};
+
+static const struct pw_core_events pw_protocol_native_core_event_marshal = {
+ PW_VERSION_CORE_EVENTS,
+ .info = &core_marshal_info,
+ .done = &core_marshal_done,
+ .error = &core_marshal_error,
+ .remove_id = &core_marshal_remove_id,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_core_marshal = {
+ PW_TYPE_INTERFACE_Core,
+ PW_VERSION_CORE_V0,
+ PW_CORE_V0_METHOD_NUM,
+ PW_CORE_EVENT_NUM,
+ 0,
+ NULL,
+ pw_protocol_native_core_method_demarshal,
+ &pw_protocol_native_core_event_marshal,
+ NULL
+};
+
+static const struct pw_protocol_native_demarshal pw_protocol_native_registry_method_demarshal[] = {
+ [PW_REGISTRY_V0_METHOD_BIND] = { &registry_demarshal_bind, 0, PW_PROTOCOL_NATIVE_FLAG_REMAP, },
+};
+
+static const struct pw_registry_events pw_protocol_native_registry_event_marshal = {
+ PW_VERSION_REGISTRY_EVENTS,
+ .global = &registry_marshal_global,
+ .global_remove = &registry_marshal_global_remove,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_registry_marshal = {
+ PW_TYPE_INTERFACE_Registry,
+ PW_VERSION_REGISTRY_V0,
+ PW_REGISTRY_V0_METHOD_NUM,
+ PW_REGISTRY_EVENT_NUM,
+ 0,
+ NULL,
+ pw_protocol_native_registry_method_demarshal,
+ &pw_protocol_native_registry_event_marshal,
+ NULL
+};
+
+static const struct pw_module_events pw_protocol_native_module_event_marshal = {
+ PW_VERSION_MODULE_EVENTS,
+ .info = &module_marshal_info,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_module_marshal = {
+ PW_TYPE_INTERFACE_Module,
+ PW_VERSION_MODULE_V0,
+ 0,
+ PW_MODULE_EVENT_NUM,
+ 0,
+ NULL, NULL,
+ &pw_protocol_native_module_event_marshal,
+ NULL
+};
+
+static const struct pw_factory_events pw_protocol_native_factory_event_marshal = {
+ PW_VERSION_FACTORY_EVENTS,
+ .info = &factory_marshal_info,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_factory_marshal = {
+ PW_TYPE_INTERFACE_Factory,
+ PW_VERSION_FACTORY_V0,
+ 0,
+ PW_FACTORY_EVENT_NUM,
+ 0,
+ NULL, NULL,
+ &pw_protocol_native_factory_event_marshal,
+ NULL,
+};
+
+static const struct pw_protocol_native_demarshal pw_protocol_native_node_method_demarshal[] = {
+ [PW_NODE_V0_METHOD_ENUM_PARAMS] = { &node_demarshal_enum_params, 0, PW_PROTOCOL_NATIVE_FLAG_REMAP, },
+};
+
+static const struct pw_node_events pw_protocol_native_node_event_marshal = {
+ PW_VERSION_NODE_EVENTS,
+ .info = &node_marshal_info,
+ .param = &node_marshal_param,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_node_marshal = {
+ PW_TYPE_INTERFACE_Node,
+ PW_VERSION_NODE_V0,
+ PW_NODE_V0_METHOD_NUM,
+ PW_NODE_EVENT_NUM,
+ 0,
+ NULL,
+ pw_protocol_native_node_method_demarshal,
+ &pw_protocol_native_node_event_marshal,
+ NULL
+};
+
+
+static const struct pw_protocol_native_demarshal pw_protocol_native_port_method_demarshal[] = {
+ [PW_PORT_V0_METHOD_ENUM_PARAMS] = { &port_demarshal_enum_params, 0, PW_PROTOCOL_NATIVE_FLAG_REMAP, },
+};
+
+static const struct pw_port_events pw_protocol_native_port_event_marshal = {
+ PW_VERSION_PORT_EVENTS,
+ .info = &port_marshal_info,
+ .param = &port_marshal_param,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_port_marshal = {
+ PW_TYPE_INTERFACE_Port,
+ PW_VERSION_PORT_V0,
+ PW_PORT_V0_METHOD_NUM,
+ PW_PORT_EVENT_NUM,
+ 0,
+ NULL,
+ pw_protocol_native_port_method_demarshal,
+ &pw_protocol_native_port_event_marshal,
+ NULL
+};
+
+static const struct pw_client_events pw_protocol_native_client_event_marshal = {
+ PW_VERSION_CLIENT_EVENTS,
+ .info = &client_marshal_info,
+ .permissions = &client_marshal_permissions,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_client_marshal = {
+ PW_TYPE_INTERFACE_Client,
+ PW_VERSION_CLIENT_V0,
+ 0,
+ PW_CLIENT_EVENT_NUM,
+ 0,
+ NULL, NULL,
+ &pw_protocol_native_client_event_marshal,
+ NULL,
+};
+
+static const struct pw_link_events pw_protocol_native_link_event_marshal = {
+ PW_VERSION_LINK_EVENTS,
+ .info = &link_marshal_info,
+};
+
+static const struct pw_protocol_marshal pw_protocol_native_link_marshal = {
+ PW_TYPE_INTERFACE_Link,
+ PW_VERSION_LINK_V0,
+ 0,
+ PW_LINK_EVENT_NUM,
+ 0,
+ NULL, NULL,
+ &pw_protocol_native_link_event_marshal,
+ NULL
+};
+
+void pw_protocol_native0_init(struct pw_protocol *protocol)
+{
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_core_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_registry_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_module_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_node_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_port_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_factory_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_client_marshal);
+ pw_protocol_add_marshal(protocol, &pw_protocol_native_link_marshal);
+}
diff --git a/src/modules/module-protocol-native/v0/typemap.h b/src/modules/module-protocol-native/v0/typemap.h
new file mode 100644
index 0000000..1d80ea2
--- /dev/null
+++ b/src/modules/module-protocol-native/v0/typemap.h
@@ -0,0 +1,282 @@
+static const struct type_info {
+ const char *type;
+ const char *name;
+ uint32_t id;
+} type_map[] = {
+ { "Spa:Interface:TypeMap", SPA_TYPE_INFO_INTERFACE_BASE, 0, },
+ { "Spa:Interface:Log", SPA_TYPE_INTERFACE_Log, 0, },
+ { "Spa:Interface:Loop", SPA_TYPE_INTERFACE_Loop, 0, },
+ { "Spa:Interface:LoopControl", SPA_TYPE_INTERFACE_LoopControl, 0, },
+ { "Spa:Interface:LoopUtils", SPA_TYPE_INTERFACE_LoopUtils, 0, },
+ { "PipeWire:Interface:Core", PW_TYPE_INTERFACE_Core, 0, },
+ { "PipeWire:Interface:Registry", PW_TYPE_INTERFACE_Registry, 0, },
+ { "PipeWire:Interface:Node", PW_TYPE_INTERFACE_Node, 0, },
+ { "PipeWire:Interface:Port", PW_TYPE_INTERFACE_Port,0, },
+ { "PipeWire:Interface:Factory", PW_TYPE_INTERFACE_Factory, 0, },
+ { "PipeWire:Interface:Link", PW_TYPE_INTERFACE_Link, 0, },
+ { "PipeWire:Interface:Client", PW_TYPE_INTERFACE_Client, 0, },
+ { "PipeWire:Interface:Module", PW_TYPE_INTERFACE_Module, 0, },
+ { "PipeWire:Interface:Device", PW_TYPE_INTERFACE_Device, 0, },
+
+ { "PipeWire:Interface:Metadata", PW_TYPE_INTERFACE_Metadata, 0, },
+ { "PipeWire:Interface:Session", PW_TYPE_INTERFACE_Session, 0, },
+ { "PipeWire:Interface:Endpoint", PW_TYPE_INTERFACE_Endpoint, 0, },
+ { "PipeWire:Interface:EndpointStream", PW_TYPE_INTERFACE_EndpointStream, 0, },
+ { "PipeWire:Interface:EndpointLink", PW_TYPE_INTERFACE_EndpointLink, 0, },
+
+ { "PipeWire:Interface:ClientNode", PW_TYPE_INTERFACE_ClientNode, 0, },
+ { "PipeWire:Interface:ClientSession", PW_TYPE_INTERFACE_ClientSession, 0, },
+ { "PipeWire:Interface:ClientEndpoint", PW_TYPE_INTERFACE_ClientEndpoint, 0, },
+
+ { "Spa:Interface:Node", SPA_TYPE_INTERFACE_Node, 0, },
+ { "Spa:Interface:Clock", },
+ { "Spa:Interface:Monitor", },
+ { "Spa:Interface:Device", SPA_TYPE_INTERFACE_Device, 0, },
+ { "Spa:POD:Object:Param:Format", SPA_TYPE_INFO_Format, SPA_TYPE_OBJECT_Format, },
+ { "Spa:POD:Object:Param:Props", SPA_TYPE_INFO_Props, SPA_TYPE_OBJECT_Props, },
+ { "Spa:Pointer:IO:Buffers", },
+ { "Spa:Pointer:IO:Control:Range", },
+ { "Spa:Pointer:IO:Prop", },
+ { "Spa:Enum:ParamId:List", },
+ { "Spa:POD:Object:Param:List", },
+ { "Spa:POD:Object:Param:List:id", },
+ { "Spa:Enum:ParamId:PropInfo", SPA_TYPE_INFO_PARAM_ID_BASE "PropInfo", SPA_PARAM_PropInfo, },
+ { "Spa:POD:Object:Param:PropInfo", SPA_TYPE_INFO_PROP_INFO_BASE, SPA_PROP_INFO_START, },
+ { "Spa:POD:Object:Param:PropInfo:id", SPA_TYPE_INFO_PROP_INFO_BASE "id", SPA_PROP_INFO_id, },
+ { "Spa:POD:Object:Param:PropInfo:name", SPA_TYPE_INFO_PROP_INFO_BASE "name", SPA_PROP_INFO_name, },
+ { "Spa:POD:Object:Param:PropInfo:type", SPA_TYPE_INFO_PROP_INFO_BASE "typ", SPA_PROP_INFO_type, },
+ { "Spa:POD:Object:Param:PropInfo:labels", SPA_TYPE_INFO_PROP_INFO_BASE "labels", SPA_PROP_INFO_labels, },
+ { "Spa:Enum:ParamId:Props", SPA_TYPE_INFO_PARAM_ID_BASE "Props", SPA_PARAM_Props, },
+ { "Spa:Enum:ParamId:EnumFormat", SPA_TYPE_INFO_PARAM_ID_BASE "EnumFormat", SPA_PARAM_EnumFormat,},
+ { "Spa:Enum:ParamId:Format", SPA_TYPE_INFO_PARAM_ID_BASE "Format", SPA_PARAM_Format, },
+ { "Spa:Enum:ParamId:Buffers", SPA_TYPE_INFO_PARAM_ID_BASE "Buffers", SPA_PARAM_Buffers },
+ { "Spa:Enum:ParamId:Meta", SPA_TYPE_INFO_PARAM_ID_BASE "Meta", SPA_PARAM_Meta, },
+ { "Spa:Pointer:Meta:Header", SPA_TYPE_INFO_META_BASE "Header", SPA_META_Header, },
+ { "Spa:Pointer:Meta:VideoCrop", SPA_TYPE_INFO_META_REGION_BASE "VideoCrop", SPA_META_VideoCrop, },
+ { "Spa:Pointer:Meta:VideoDamage", SPA_TYPE_INFO_META_ARRAY_REGION_BASE "VideoDamage", SPA_META_VideoDamage, },
+ { "Spa:Pointer:Meta:Bitmap", SPA_TYPE_INFO_META_BASE "Bitmap", SPA_META_Bitmap, },
+ { "Spa:Pointer:Meta:Cursor", SPA_TYPE_INFO_META_BASE "Cursor", SPA_META_Cursor, },
+ { "Spa:Enum:DataType:MemPtr", SPA_TYPE_INFO_DATA_BASE "MemPtr", SPA_DATA_MemPtr, },
+ { "Spa:Enum:DataType:Fd:MemFd", SPA_TYPE_INFO_DATA_FD_BASE "MemFd", SPA_DATA_MemFd, },
+ { "Spa:Enum:DataType:Fd:DmaBuf", SPA_TYPE_INFO_DATA_FD_BASE "DmaBuf", SPA_DATA_DmaBuf, },
+ { "Spa:POD:Object:Event:Node:Error", SPA_TYPE_INFO_NODE_EVENT_BASE "Error", SPA_NODE_EVENT_Error, },
+ { "Spa:POD:Object:Event:Node:Buffering", SPA_TYPE_INFO_NODE_EVENT_BASE "Buffering", SPA_NODE_EVENT_Buffering, },
+ { "Spa:POD:Object:Event:Node:RequestRefresh", SPA_TYPE_INFO_NODE_EVENT_BASE "RequestRefresh", SPA_NODE_EVENT_RequestRefresh, },
+ { "Spa:POD:Object:Event:Node:RequestClockUpdate", SPA_TYPE_INFO_NODE_EVENT_BASE "RequestClockUpdate", SPA_NODE0_EVENT_RequestClockUpdate, },
+ { "Spa:POD:Object:Command:Node", SPA_TYPE_INFO_COMMAND_BASE "Node", SPA_TYPE_COMMAND_Node,},
+ { "Spa:POD:Object:Command:Node:Suspend", SPA_TYPE_INFO_NODE_COMMAND_BASE "Suspend", SPA_NODE_COMMAND_Suspend,},
+ { "Spa:POD:Object:Command:Node:Pause", SPA_TYPE_INFO_NODE_COMMAND_BASE "Pause", SPA_NODE_COMMAND_Pause, },
+ { "Spa:POD:Object:Command:Node:Start", SPA_TYPE_INFO_NODE_COMMAND_BASE "Start", SPA_NODE_COMMAND_Start, },
+ { "Spa:POD:Object:Command:Node:Enable", SPA_TYPE_INFO_NODE_COMMAND_BASE "Enable", SPA_NODE_COMMAND_Enable, },
+ { "Spa:POD:Object:Command:Node:Disable", SPA_TYPE_INFO_NODE_COMMAND_BASE "Disable", SPA_NODE_COMMAND_Disable, },
+ { "Spa:POD:Object:Command:Node:Flush", SPA_TYPE_INFO_NODE_COMMAND_BASE "Flush", SPA_NODE_COMMAND_Flush, },
+ { "Spa:POD:Object:Command:Node:Drain", SPA_TYPE_INFO_NODE_COMMAND_BASE "Drain", SPA_NODE_COMMAND_Drain, },
+ { "Spa:POD:Object:Command:Node:Marker", SPA_TYPE_INFO_NODE_COMMAND_BASE "Marker", SPA_NODE_COMMAND_Marker, },
+ { "Spa:POD:Object:Command:Node:ClockUpdate", SPA_TYPE_INFO_NODE_COMMAND_BASE "ClockUpdate", SPA_NODE0_COMMAND_ClockUpdate, },
+ { "Spa:POD:Object:Event:Monitor:Added", },
+ { "Spa:POD:Object:Event:Monitor:Removed", },
+ { "Spa:POD:Object:Event:Monitor:Changed", },
+ { "Spa:POD:Object:MonitorItem", },
+ { "Spa:POD:Object:MonitorItem:id", },
+ { "Spa:POD:Object:MonitorItem:flags", },
+ { "Spa:POD:Object:MonitorItem:state", },
+ { "Spa:POD:Object:MonitorItem:name", },
+ { "Spa:POD:Object:MonitorItem:class", },
+ { "Spa:POD:Object:MonitorItem:info", },
+ { "Spa:POD:Object:MonitorItem:factory", },
+ { "Spa:POD:Object:Param:Buffers", SPA_TYPE_INFO_PARAM_Buffers, SPA_TYPE_OBJECT_ParamBuffers, },
+ { "Spa:POD:Object:Param:Buffers:size", SPA_TYPE_INFO_PARAM_BLOCK_INFO_BASE "size", SPA_PARAM_BUFFERS_size, },
+ { "Spa:POD:Object:Param:Buffers:stride", SPA_TYPE_INFO_PARAM_BLOCK_INFO_BASE "stride", SPA_PARAM_BUFFERS_stride, },
+ { "Spa:POD:Object:Param:Buffers:buffers", SPA_TYPE_INFO_PARAM_BUFFERS_BASE "buffers", SPA_PARAM_BUFFERS_buffers, },
+ { "Spa:POD:Object:Param:Buffers:align",SPA_TYPE_INFO_PARAM_BLOCK_INFO_BASE "align", SPA_PARAM_BUFFERS_align, },
+ { "Spa:POD:Object:Param:Meta", SPA_TYPE_INFO_PARAM_Meta, SPA_TYPE_OBJECT_ParamMeta, },
+ { "Spa:POD:Object:Param:Meta:type", SPA_TYPE_INFO_PARAM_META_BASE "type", SPA_PARAM_META_type, },
+ { "Spa:POD:Object:Param:Meta:size", SPA_TYPE_INFO_PARAM_META_BASE "size", SPA_PARAM_META_size, },
+ { "Spa:POD:Object:Param:IO:id", },
+ { "Spa:POD:Object:Param:IO:size", },
+ { "Spa:Enum:ParamId:IO:Buffers", },
+ { "Spa:POD:Object:Param:IO:Buffers", },
+ { "Spa:Enum:ParamId:IO:Control", },
+ { "Spa:POD:Object:Param:IO:Control", },
+ { "Spa:Enum:ParamId:IO:Props:In", },
+ { "Spa:Enum:ParamId:IO:Props:Out", },
+ { "Spa:POD:Object:Param:IO:Prop", },
+ { "Spa:Interface:DBus", SPA_TYPE_INFO_INTERFACE_BASE "DBus", 0, },
+ { "Spa:Enum:MediaType:audio", SPA_TYPE_INFO_MEDIA_TYPE_BASE "audio", SPA_MEDIA_TYPE_audio, },
+ { "Spa:Enum:MediaType:video", SPA_TYPE_INFO_MEDIA_TYPE_BASE "video", SPA_MEDIA_TYPE_video, },
+ { "Spa:Enum:MediaType:image", SPA_TYPE_INFO_MEDIA_TYPE_BASE "image", SPA_MEDIA_TYPE_image, },
+ { "Spa:Enum:MediaType:binary", SPA_TYPE_INFO_MEDIA_TYPE_BASE "binary", SPA_MEDIA_TYPE_binary, },
+ { "Spa:Enum:MediaType:stream", SPA_TYPE_INFO_MEDIA_TYPE_BASE "stream", SPA_MEDIA_TYPE_stream, },
+ { "Spa:Enum:MediaType:application", SPA_TYPE_INFO_MEDIA_TYPE_BASE "application", SPA_MEDIA_TYPE_application, },
+ { "Spa:Enum:MediaSubtype:raw", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "raw", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:dsp", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "dsp", SPA_MEDIA_SUBTYPE_dsp, },
+ { "Spa:Enum:MediaSubtype:control", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "control", SPA_MEDIA_SUBTYPE_control, },
+ { "Spa:Enum:MediaSubtype:h264", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "h264", SPA_MEDIA_SUBTYPE_h264, },
+ { "Spa:Enum:MediaSubtype:mjpg", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "mjpg", SPA_MEDIA_SUBTYPE_mjpg, },
+ { "Spa:Enum:MediaSubtype:dv", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "dv", SPA_MEDIA_SUBTYPE_dv, },
+ { "Spa:Enum:MediaSubtype:mpegts", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "mpegts", SPA_MEDIA_SUBTYPE_mpegts, },
+ { "Spa:Enum:MediaSubtype:h263", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "h263", SPA_MEDIA_SUBTYPE_h263, },
+ { "Spa:Enum:MediaSubtype:mpeg1", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "mpeg1", SPA_MEDIA_SUBTYPE_mpeg1, },
+ { "Spa:Enum:MediaSubtype:mpeg2", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "mpeg2", SPA_MEDIA_SUBTYPE_mpeg2, },
+ { "Spa:Enum:MediaSubtype:mpeg4", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "mpeg4", SPA_MEDIA_SUBTYPE_mpeg4, },
+ { "Spa:Enum:MediaSubtype:xvid", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "xvid", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:vc1", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "vc1", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:vp8", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "vp8", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:vp9", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "vp9", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:jpeg", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "jpeg", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:bayer", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "bayer", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:mp3", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "mp3", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:aac", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "aac", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:vorbis", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "vorbis", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:wma", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "wma", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:ra", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "ra", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:sbc", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "sbc", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:adpcm", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "adpcm", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:g723", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "g723", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:g726", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "g726", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:g729", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "g729", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:amr", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "amr", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:gsm", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "gsm", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:Enum:MediaSubtype:midi", SPA_TYPE_INFO_MEDIA_SUBTYPE_BASE "midi", SPA_MEDIA_SUBTYPE_raw, },
+ { "Spa:POD:Object:Param:Format:Video:format", SPA_TYPE_INFO_FORMAT_VIDEO_BASE "format", SPA_FORMAT_VIDEO_format,},
+ { "Spa:POD:Object:Param:Format:Video:size", SPA_TYPE_INFO_FORMAT_VIDEO_BASE "size", SPA_FORMAT_VIDEO_size,},
+ { "Spa:POD:Object:Param:Format:Video:framerate", SPA_TYPE_INFO_FORMAT_VIDEO_BASE "framerate", SPA_FORMAT_VIDEO_framerate},
+ { "Spa:POD:Object:Param:Format:Video:max-framerate", SPA_TYPE_INFO_FORMAT_VIDEO_BASE "maxFramerate", SPA_FORMAT_VIDEO_maxFramerate},
+ { "Spa:POD:Object:Param:Format:Video:views", SPA_TYPE_INFO_FORMAT_VIDEO_BASE "views", SPA_FORMAT_VIDEO_views},
+ { "Spa:POD:Object:Param:Format:Video:interlace-mode", },
+ { "Spa:POD:Object:Param:Format:Video:pixel-aspect-ratio", },
+ { "Spa:POD:Object:Param:Format:Video:multiview-mode", },
+ { "Spa:POD:Object:Param:Format:Video:multiview-flags", },
+ { "Spa:POD:Object:Param:Format:Video:chroma-site", },
+ { "Spa:POD:Object:Param:Format:Video:color-range", },
+ { "Spa:POD:Object:Param:Format:Video:color-matrix", },
+ { "Spa:POD:Object:Param:Format:Video:transfer-function", },
+ { "Spa:POD:Object:Param:Format:Video:color-primaries", },
+ { "Spa:POD:Object:Param:Format:Video:profile", },
+ { "Spa:POD:Object:Param:Format:Video:level", },
+ { "Spa:POD:Object:Param:Format:Video:stream-format", },
+ { "Spa:POD:Object:Param:Format:Video:alignment", },
+ { "Spa:POD:Object:Param:Format:Audio:format", SPA_TYPE_INFO_FORMAT_AUDIO_BASE "format", SPA_FORMAT_AUDIO_format,},
+ { "Spa:POD:Object:Param:Format:Audio:flags", },
+ { "Spa:POD:Object:Param:Format:Audio:layout", },
+ { "Spa:POD:Object:Param:Format:Audio:rate", },
+ { "Spa:POD:Object:Param:Format:Audio:channels", },
+ { "Spa:POD:Object:Param:Format:Audio:channel-mask", },
+ { "Spa:Enum:VideoFormat:encoded", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "encoded", SPA_VIDEO_FORMAT_ENCODED,},
+ { "Spa:Enum:VideoFormat:I420", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I420", SPA_VIDEO_FORMAT_I420,},
+ { "Spa:Enum:VideoFormat:YV12", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "YV12", SPA_VIDEO_FORMAT_YV12,},
+ { "Spa:Enum:VideoFormat:YUY2", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "YUY2", SPA_VIDEO_FORMAT_YUY2,},
+ { "Spa:Enum:VideoFormat:UYVY", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "UYVY", SPA_VIDEO_FORMAT_UYVY,},
+ { "Spa:Enum:VideoFormat:AYUV", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "AYUV", SPA_VIDEO_FORMAT_AYUV,},
+ { "Spa:Enum:VideoFormat:RGBx", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGBx", SPA_VIDEO_FORMAT_RGBx,},
+ { "Spa:Enum:VideoFormat:BGRx", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGRx", SPA_VIDEO_FORMAT_BGRx,},
+ { "Spa:Enum:VideoFormat:xRGB", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "xRGB", SPA_VIDEO_FORMAT_xRGB,},
+ { "Spa:Enum:VideoFormat:xBGR", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "xBGR", SPA_VIDEO_FORMAT_xBGR,},
+ { "Spa:Enum:VideoFormat:RGBA", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGBA", SPA_VIDEO_FORMAT_RGBA,},
+ { "Spa:Enum:VideoFormat:BGRA", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGRA", SPA_VIDEO_FORMAT_BGRA,},
+ { "Spa:Enum:VideoFormat:ARGB", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "ARGB", SPA_VIDEO_FORMAT_ARGB,},
+ { "Spa:Enum:VideoFormat:ABGR", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "ABGR", SPA_VIDEO_FORMAT_ABGR,},
+ { "Spa:Enum:VideoFormat:RGB", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGB", SPA_VIDEO_FORMAT_RGB,},
+ { "Spa:Enum:VideoFormat:BGR", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGR", SPA_VIDEO_FORMAT_BGR,},
+ { "Spa:Enum:VideoFormat:Y41B", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y41B", SPA_VIDEO_FORMAT_Y41B,},
+ { "Spa:Enum:VideoFormat:Y42B", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y42B", SPA_VIDEO_FORMAT_Y42B,},
+ { "Spa:Enum:VideoFormat:YVYU", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "YVYU", SPA_VIDEO_FORMAT_YVYU,},
+ { "Spa:Enum:VideoFormat:Y444", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y444", SPA_VIDEO_FORMAT_Y444,},
+ { "Spa:Enum:VideoFormat:v210", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "v210", SPA_VIDEO_FORMAT_v210,},
+ { "Spa:Enum:VideoFormat:v216", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "v216", SPA_VIDEO_FORMAT_v216,},
+ { "Spa:Enum:VideoFormat:NV12", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "NV12", SPA_VIDEO_FORMAT_NV12,},
+ { "Spa:Enum:VideoFormat:NV21", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "NV21", SPA_VIDEO_FORMAT_NV21,},
+ { "Spa:Enum:VideoFormat:GRAY8", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GRAY8", SPA_VIDEO_FORMAT_GRAY8,},
+ { "Spa:Enum:VideoFormat:GRAY16_BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GRAY16_BE", SPA_VIDEO_FORMAT_GRAY16_BE,},
+ { "Spa:Enum:VideoFormat:GRAY16_LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GRAY16_LE", SPA_VIDEO_FORMAT_GRAY16_LE,},
+ { "Spa:Enum:VideoFormat:v308", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "v308", SPA_VIDEO_FORMAT_v308,},
+ { "Spa:Enum:VideoFormat:RGB16", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGB16", SPA_VIDEO_FORMAT_RGB16,},
+ { "Spa:Enum:VideoFormat:BGR16", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGR16", SPA_VIDEO_FORMAT_BGR16,},
+ { "Spa:Enum:VideoFormat:RGB15", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGB15", SPA_VIDEO_FORMAT_RGB15,},
+ { "Spa:Enum:VideoFormat:BGR15", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGR15", SPA_VIDEO_FORMAT_BGR15,},
+ { "Spa:Enum:VideoFormat:UYVP", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "UYVP", SPA_VIDEO_FORMAT_UYVP,},
+ { "Spa:Enum:VideoFormat:A420", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A420", SPA_VIDEO_FORMAT_A420,},
+ { "Spa:Enum:VideoFormat:RGB8P", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGB8P", SPA_VIDEO_FORMAT_RGB8P,},
+ { "Spa:Enum:VideoFormat:YUV9", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "YUV9", SPA_VIDEO_FORMAT_YUV9,},
+ { "Spa:Enum:VideoFormat:YVU9", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "YVU9", SPA_VIDEO_FORMAT_YVU9,},
+ { "Spa:Enum:VideoFormat:IYU1", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "IYU1", SPA_VIDEO_FORMAT_IYU1,},
+ { "Spa:Enum:VideoFormat:ARGB64", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "ARGB64", SPA_VIDEO_FORMAT_ARGB64,},
+ { "Spa:Enum:VideoFormat:AYUV64", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "AYUV64", SPA_VIDEO_FORMAT_AYUV64,},
+ { "Spa:Enum:VideoFormat:r210", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "r210", SPA_VIDEO_FORMAT_r210,},
+ { "Spa:Enum:VideoFormat:I420_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I420_10BE", SPA_VIDEO_FORMAT_I420_10BE,},
+ { "Spa:Enum:VideoFormat:I420_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I420_10LE", SPA_VIDEO_FORMAT_I420_10LE,},
+ { "Spa:Enum:VideoFormat:I422_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I422_10BE", SPA_VIDEO_FORMAT_I422_10BE,},
+ { "Spa:Enum:VideoFormat:I422_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I422_10LE", SPA_VIDEO_FORMAT_I422_10LE,},
+ { "Spa:Enum:VideoFormat:Y444_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y444_10BE", SPA_VIDEO_FORMAT_Y444_10BE,},
+ { "Spa:Enum:VideoFormat:Y444_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y444_10LE", SPA_VIDEO_FORMAT_Y444_10LE,},
+ { "Spa:Enum:VideoFormat:GBR", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBR", SPA_VIDEO_FORMAT_GBR,},
+ { "Spa:Enum:VideoFormat:GBR_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBR_10BE", SPA_VIDEO_FORMAT_GBR_10BE,},
+ { "Spa:Enum:VideoFormat:GBR_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBR_10LE", SPA_VIDEO_FORMAT_GBR_10LE,},
+ { "Spa:Enum:VideoFormat:NV16", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "NV16", SPA_VIDEO_FORMAT_NV16,},
+ { "Spa:Enum:VideoFormat:NV24", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "NV24", SPA_VIDEO_FORMAT_NV24,},
+ { "Spa:Enum:VideoFormat:NV12_64Z32", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "NV12_64Z32", SPA_VIDEO_FORMAT_NV12_64Z32,},
+ { "Spa:Enum:VideoFormat:A420_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A420_10BE", SPA_VIDEO_FORMAT_A420_10BE,},
+ { "Spa:Enum:VideoFormat:A420_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A420_10LE", SPA_VIDEO_FORMAT_A420_10LE,},
+ { "Spa:Enum:VideoFormat:A422_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A422_10BE", SPA_VIDEO_FORMAT_A422_10BE,},
+ { "Spa:Enum:VideoFormat:A422_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A422_10LE", SPA_VIDEO_FORMAT_A422_10LE,},
+ { "Spa:Enum:VideoFormat:A444_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A444_10BE", SPA_VIDEO_FORMAT_A444_10BE,},
+ { "Spa:Enum:VideoFormat:A444_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "A444_10LE", SPA_VIDEO_FORMAT_A444_10LE,},
+ { "Spa:Enum:VideoFormat:NV61", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "NV61", SPA_VIDEO_FORMAT_NV61,},
+ { "Spa:Enum:VideoFormat:P010_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "P010_10BE", SPA_VIDEO_FORMAT_P010_10BE,},
+ { "Spa:Enum:VideoFormat:P010_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "P010_10LE", SPA_VIDEO_FORMAT_P010_10LE,},
+ { "Spa:Enum:VideoFormat:IYU2", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "IYU2", SPA_VIDEO_FORMAT_IYU2,},
+ { "Spa:Enum:VideoFormat:VYUY", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "VYUY", SPA_VIDEO_FORMAT_VYUY,},
+ { "Spa:Enum:VideoFormat:GBRA", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBRA", SPA_VIDEO_FORMAT_GBRA,},
+ { "Spa:Enum:VideoFormat:GBRA_10BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBRA_10BE", SPA_VIDEO_FORMAT_GBRA_10BE,},
+ { "Spa:Enum:VideoFormat:GBRA_10LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBRA_10LE", SPA_VIDEO_FORMAT_GBRA_10LE,},
+ { "Spa:Enum:VideoFormat:GBR_12BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBR_12BE", SPA_VIDEO_FORMAT_GBR_12BE,},
+ { "Spa:Enum:VideoFormat:GBR_12LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBR_12LE", SPA_VIDEO_FORMAT_GBR_12LE,},
+ { "Spa:Enum:VideoFormat:GBRA_12BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBRA_12BE", SPA_VIDEO_FORMAT_GBRA_12BE,},
+ { "Spa:Enum:VideoFormat:GBRA_12LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "GBRA_12LE", SPA_VIDEO_FORMAT_GBRA_12LE,},
+ { "Spa:Enum:VideoFormat:I420_12BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I420_12BE", SPA_VIDEO_FORMAT_I420_12BE,},
+ { "Spa:Enum:VideoFormat:I420_12LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I420_12LE", SPA_VIDEO_FORMAT_I420_12LE,},
+ { "Spa:Enum:VideoFormat:I422_12BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I422_12BE", SPA_VIDEO_FORMAT_I422_12BE,},
+ { "Spa:Enum:VideoFormat:I422_12LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "I422_12LE", SPA_VIDEO_FORMAT_I422_12LE,},
+ { "Spa:Enum:VideoFormat:Y444_12BE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y444_12BE", SPA_VIDEO_FORMAT_Y444_12BE,},
+ { "Spa:Enum:VideoFormat:Y444_12LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "Y444_12LE", SPA_VIDEO_FORMAT_Y444_12LE,},
+ { "Spa:Enum:VideoFormat:xRGB_210LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "xRGB_210LE", SPA_VIDEO_FORMAT_xRGB_210LE,},
+ { "Spa:Enum:VideoFormat:xBGR_210LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "xBGR_210LE", SPA_VIDEO_FORMAT_xBGR_210LE,},
+ { "Spa:Enum:VideoFormat:RGBx_102LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGBx_102LE", SPA_VIDEO_FORMAT_RGBx_102LE,},
+ { "Spa:Enum:VideoFormat:BGRx_102LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGRx_102LE", SPA_VIDEO_FORMAT_BGRx_102LE,},
+ { "Spa:Enum:VideoFormat:ARGB_210LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "ARGB_210LE", SPA_VIDEO_FORMAT_ARGB_210LE,},
+ { "Spa:Enum:VideoFormat:ABGR_210LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "ABGR_210LE", SPA_VIDEO_FORMAT_ABGR_210LE,},
+ { "Spa:Enum:VideoFormat:RGBA_102LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "RGBA_102LE", SPA_VIDEO_FORMAT_RGBA_102LE,},
+ { "Spa:Enum:VideoFormat:BGRA_102LE", SPA_TYPE_INFO_VIDEO_FORMAT_BASE "BGRA_102LE", SPA_VIDEO_FORMAT_BGRA_102LE,},
+ { "Spa:Enum:AudioFormat:ENCODED", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "ENCODED", SPA_AUDIO_FORMAT_ENCODED,},
+ { "Spa:Enum:AudioFormat:S8", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S8", SPA_AUDIO_FORMAT_S8, },
+ { "Spa:Enum:AudioFormat:U8", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U8", SPA_AUDIO_FORMAT_U8, },
+ { "Spa:Enum:AudioFormat:S16LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S16_LE", SPA_AUDIO_FORMAT_S16_LE, },
+ { "Spa:Enum:AudioFormat:U16LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U16_LE", SPA_AUDIO_FORMAT_U16_LE, },
+ { "Spa:Enum:AudioFormat:S24_32LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S24_32_LE", SPA_AUDIO_FORMAT_S24_32_LE, },
+ { "Spa:Enum:AudioFormat:U24_32LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U24_32_LE", SPA_AUDIO_FORMAT_U24_32_LE, },
+ { "Spa:Enum:AudioFormat:S32LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S32_LE", SPA_AUDIO_FORMAT_S32_LE, },
+ { "Spa:Enum:AudioFormat:U32LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U32_LE", SPA_AUDIO_FORMAT_U32_LE, },
+ { "Spa:Enum:AudioFormat:S24LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S24_LE", SPA_AUDIO_FORMAT_S24_LE, },
+ { "Spa:Enum:AudioFormat:U24LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U24_LE", SPA_AUDIO_FORMAT_U24_LE, },
+ { "Spa:Enum:AudioFormat:S20LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S20_LE", SPA_AUDIO_FORMAT_S20_LE, },
+ { "Spa:Enum:AudioFormat:U20LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U20_LE", SPA_AUDIO_FORMAT_U20_LE, },
+ { "Spa:Enum:AudioFormat:S18LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S18_LE", SPA_AUDIO_FORMAT_S18_LE, },
+ { "Spa:Enum:AudioFormat:U18LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U18_LE", SPA_AUDIO_FORMAT_U18_LE, },
+ { "Spa:Enum:AudioFormat:F32LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "F32_LE", SPA_AUDIO_FORMAT_F32_LE, },
+ { "Spa:Enum:AudioFormat:F64LE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "F64_LE", SPA_AUDIO_FORMAT_F64_LE, },
+ { "Spa:Enum:AudioFormat:S16BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S16_BE", SPA_AUDIO_FORMAT_S16_BE, },
+ { "Spa:Enum:AudioFormat:U16BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U16_BE", SPA_AUDIO_FORMAT_U16_BE, },
+ { "Spa:Enum:AudioFormat:S24_32BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S24_32_BE", SPA_AUDIO_FORMAT_S24_32_BE, },
+ { "Spa:Enum:AudioFormat:U24_32BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U24_32_BE", SPA_AUDIO_FORMAT_U24_32_BE, },
+ { "Spa:Enum:AudioFormat:S32BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S32_BE", SPA_AUDIO_FORMAT_S32_BE, },
+ { "Spa:Enum:AudioFormat:U32BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U32_BE", SPA_AUDIO_FORMAT_U32_BE, },
+ { "Spa:Enum:AudioFormat:S24BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S24_BE", SPA_AUDIO_FORMAT_S24_BE, },
+ { "Spa:Enum:AudioFormat:U24BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U24_BE", SPA_AUDIO_FORMAT_U24_BE, },
+ { "Spa:Enum:AudioFormat:S20BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S20_BE", SPA_AUDIO_FORMAT_S20_BE, },
+ { "Spa:Enum:AudioFormat:U20BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U20_BE", SPA_AUDIO_FORMAT_U20_BE, },
+ { "Spa:Enum:AudioFormat:S18BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "S18_BE", SPA_AUDIO_FORMAT_S18_BE, },
+ { "Spa:Enum:AudioFormat:U18BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "U18_BE", SPA_AUDIO_FORMAT_U18_BE, },
+ { "Spa:Enum:AudioFormat:F32BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "F32_BE", SPA_AUDIO_FORMAT_F32_BE, },
+ { "Spa:Enum:AudioFormat:F64BE", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "F64_BE", SPA_AUDIO_FORMAT_F64_BE, },
+ { "Spa:Enum:AudioFormat:F32P", SPA_TYPE_INFO_AUDIO_FORMAT_BASE "F32P", SPA_AUDIO_FORMAT_F32P, },
+};