interfaces: improve remote API

Add return values to events and method callbacks. This makes it
possible to pass any error or async return value.
Add sync/done/error in both directions so that both proxy and resource
and perform/reply sync and produce errors.
Return a SPA_ASYNC from remote method calls (and events), keep the
sequence number in the connection.
With the core sync/done we can remove the client-node done method and
it's internal sequence number along with the seq number in method calls.
We can also use the method/event async return value to perform a sync
with as the unique sequence number for this method.
Add sync method and done/error event to proxy and resource.
This commit is contained in:
Wim Taymans 2019-02-18 12:31:36 +01:00
parent 0d8821096a
commit eea062ee53
41 changed files with 1180 additions and 817 deletions

View file

@ -146,8 +146,6 @@ struct node {
uint32_t n_params;
struct spa_pod **params;
uint32_t seq;
};
struct impl {
@ -396,9 +394,7 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
if (this->resource == NULL)
return 0;
pw_client_node_resource_set_param(this->resource, this->seq, id, flags, param);
return SPA_RESULT_RETURN_ASYNC(this->seq++);
return pw_client_node_resource_set_param(this->resource, id, flags, param);
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
@ -448,7 +444,6 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
{
struct node *this;
int res = 0;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(command != NULL, -EINVAL);
@ -458,10 +453,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
if (this->resource == NULL)
return 0;
pw_client_node_resource_command(this->resource, this->seq, command);
res = SPA_RESULT_RETURN_ASYNC(this->seq++);
return res;
pw_log_debug("client-node %p: send command %d", node, SPA_COMMAND_TYPE(command));
return pw_client_node_resource_command(this->resource, command);
}
@ -497,6 +490,16 @@ impl_node_set_callbacks(struct spa_node *node,
return 0;
}
static int
impl_node_sync(struct spa_node *node, uint32_t seq)
{
struct node *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
pw_log_debug("client-node %p: sync %u", node, seq);
return pw_resource_sync(this->resource, seq);
}
static void
do_update_port(struct node *this,
struct port *port,
@ -585,11 +588,7 @@ impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t
spa_return_val_if_fail(CHECK_FREE_PORT(this, direction, port_id), -EINVAL);
pw_client_node_resource_add_port(this->resource,
this->seq,
direction, port_id);
return SPA_RESULT_RETURN_ASYNC(this->seq++);
return pw_client_node_resource_add_port(this->resource, direction, port_id);
}
static int
@ -602,11 +601,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
pw_client_node_resource_remove_port(this->resource,
this->seq,
direction, port_id);
return SPA_RESULT_RETURN_ASYNC(this->seq++);
return pw_client_node_resource_remove_port(this->resource, direction, port_id);
}
static int
@ -667,13 +662,14 @@ impl_node_port_set_param(struct spa_node *node,
if (this->resource == NULL)
return 0;
pw_client_node_resource_port_set_param(this->resource,
this->seq,
pw_log_debug("node %p: port %d.%d add param %s %d", this,
direction, port_id,
spa_debug_type_find_name(spa_type_param, id), id);
return pw_client_node_resource_port_set_param(this->resource,
direction, port_id,
id, flags,
param);
return SPA_RESULT_RETURN_ASYNC(this->seq++);
}
static int do_port_set_io(struct impl *impl,
@ -722,15 +718,12 @@ static int do_port_set_io(struct impl *impl,
update_io(this, mix->ios, id, memid);
pw_client_node_resource_port_set_io(this->resource,
this->seq,
return pw_client_node_resource_port_set_io(this->resource,
direction, port_id,
mix_id,
id,
memid,
mem_offset, mem_size);
return SPA_RESULT_RETURN_ASYNC(this->seq++);
}
static int
@ -855,12 +848,9 @@ do_port_use_buffers(struct impl *impl,
}
}
pw_client_node_resource_port_use_buffers(this->resource,
this->seq,
return pw_client_node_resource_port_use_buffers(this->resource,
direction, port_id, mix_id,
n_buffers, mb);
return SPA_RESULT_RETURN_ASYNC(this->seq++);
}
static int
@ -946,16 +936,7 @@ static int impl_node_process(struct spa_node *node)
return SPA_STATUS_OK;
}
static void
client_node_done(void *data, int seq, int res)
{
struct impl *impl = data;
struct node *this = &impl->node;
if (this->callbacks && this->callbacks->done)
this->callbacks->done(this->callbacks_data, seq, res);
}
static void
static int
client_node_update(void *data,
uint32_t change_mask,
uint32_t max_input_ports,
@ -988,9 +969,10 @@ client_node_update(void *data,
}
spa_log_debug(this->log, "node %p: got node update max_in %u, max_out %u", this,
this->max_inputs, this->max_outputs);
return 0;
}
static void
static int
client_node_port_update(void *data,
enum spa_direction direction,
uint32_t port_id,
@ -1006,7 +988,7 @@ client_node_port_update(void *data,
spa_log_debug(this->log, "node %p: got port update", this);
if (!CHECK_PORT_ID(this, direction, port_id))
return;
return -EINVAL;
remove = (change_mask == 0);
@ -1033,25 +1015,26 @@ client_node_port_update(void *data,
info && (change_mask & PW_CLIENT_NODE_PORT_UPDATE_INFO))
this->callbacks->port_info(this->callbacks_data, direction, port_id, info);
}
return 0;
}
static void client_node_set_active(void *data, bool active)
static int client_node_set_active(void *data, bool active)
{
struct impl *impl = data;
pw_node_set_active(impl->this.node, active);
return pw_node_set_active(impl->this.node, active);
}
static void client_node_event(void *data, struct spa_event *event)
static int client_node_event(void *data, struct spa_event *event)
{
struct impl *impl = data;
struct node *this = &impl->node;
if (this->callbacks && this->callbacks->event)
this->callbacks->event(this->callbacks_data, event);
return 0;
}
static struct pw_client_node_proxy_methods client_node_methods = {
PW_VERSION_CLIENT_NODE_PROXY_METHODS,
.done = client_node_done,
.update = client_node_update,
.port_update = client_node_port_update,
.set_active = client_node_set_active,
@ -1082,11 +1065,12 @@ static void node_on_data_fd_events(struct spa_source *source)
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
NULL,
.set_callbacks = impl_node_set_callbacks,
.sync = impl_node_sync,
.enum_params = impl_node_enum_params,
.set_param = impl_node_set_param,
.set_io = impl_node_set_io,
.send_command = impl_node_send_command,
.set_callbacks = impl_node_set_callbacks,
.add_port = impl_node_add_port,
.remove_port = impl_node_remove_port,
.port_enum_params = impl_node_port_enum_params,
@ -1133,9 +1117,7 @@ node_init(struct node *this,
this->data_source.mask = SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP;
this->data_source.rmask = 0;
this->seq = 1;
return SPA_RESULT_RETURN_ASYNC(this->seq++);
return 0;
}
static int node_clear(struct node *this)
@ -1186,6 +1168,25 @@ static void client_node_resource_destroy(void *data)
pw_node_destroy(this->node);
}
static void client_node_resource_error(void *data, int res, const char *message)
{
struct impl *impl = data;
struct node *this = &impl->node;
pw_log_error("client-node %p: error %d: %s", this, res, message);
if (this->callbacks && this->callbacks->error)
this->callbacks->error(this->callbacks_data, res, message);
}
static void client_node_resource_done(void *data, uint32_t seq)
{
struct impl *impl = data;
struct node *this = &impl->node;
pw_log_debug("client-node %p: done %d", this, seq);
if (this->callbacks && this->callbacks->done)
this->callbacks->done(this->callbacks_data, SPA_RESULT_ASYNC_SEQ(seq));
}
void pw_client_node_registered(struct pw_client_node *this, uint32_t node_id)
{
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
@ -1541,6 +1542,8 @@ static const struct pw_node_events node_events = {
static const struct pw_resource_events resource_events = {
PW_VERSION_RESOURCE_EVENTS,
.destroy = client_node_resource_destroy,
.error = client_node_resource_error,
.done = client_node_resource_done,
};
static int root_impl_process(void *data, struct spa_graph_node *node)
@ -1630,6 +1633,8 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
pw_node_add_listener(this->node, &impl->node_listener, &node_events, impl);
pw_resource_sync(this->resource, 0);
return this;
error_no_node:

View file

@ -281,11 +281,10 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
if ((res = spa_node_send_command(impl->cnode, command)) < 0)
return res;
}
return 0;
return res;
}
static void adapter_port_info(void *data,
static int adapter_port_info(void *data,
enum spa_direction direction, uint32_t port_id,
const struct spa_port_info *info)
{
@ -297,6 +296,7 @@ static void adapter_port_info(void *data,
this->callbacks->port_info(this->callbacks_data, direction, port_id, info);
}
}
return 0;
}
static const struct spa_node_callbacks adapter_node_callbacks = {
@ -326,6 +326,20 @@ impl_node_set_callbacks(struct spa_node *node,
return 0;
}
static int
impl_node_sync(struct spa_node *node, uint32_t seq)
{
struct node *this;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
return spa_node_sync(impl->cnode, seq);
}
static int
impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
{
@ -816,11 +830,12 @@ static int impl_node_process(struct spa_node *node)
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
.set_callbacks = impl_node_set_callbacks,
.sync = impl_node_sync,
.enum_params = impl_node_enum_params,
.set_param = impl_node_set_param,
.set_io = impl_node_set_io,
.send_command = impl_node_send_command,
.set_callbacks = impl_node_set_callbacks,
.add_port = impl_node_add_port,
.remove_port = impl_node_remove_port,
.port_enum_params = impl_node_port_enum_params,
@ -1077,7 +1092,7 @@ static void client_node_async_complete(void *data, uint32_t seq, int res)
struct node *node = &impl->node;
pw_log_debug("client-stream %p: async complete %d %d", &impl->this, seq, res);
node->callbacks->done(node->callbacks_data, seq, res);
node->callbacks->done(node->callbacks_data, seq);
}
static void client_node_active_changed(void *data, bool active)

View file

@ -31,23 +31,7 @@
#include <extensions/protocol-native.h>
#include <extensions/client-node.h>
static void
client_node_marshal_done(void *object, int seq, int res)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_DONE);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Int(res));
pw_protocol_native_end_proxy(proxy, b);
}
static void
static int
client_node_marshal_update(void *object,
uint32_t change_mask,
uint32_t max_input_ports,
@ -83,10 +67,10 @@ client_node_marshal_update(void *object,
}
spa_pod_builder_pop(b, &f);
pw_protocol_native_end_proxy(proxy, b);
return pw_protocol_native_end_proxy(proxy, b);
}
static void
static int
client_node_marshal_port_update(void *object,
enum spa_direction direction,
uint32_t port_id,
@ -133,10 +117,10 @@ client_node_marshal_port_update(void *object,
}
spa_pod_builder_pop(b, &f[0]);
pw_protocol_native_end_proxy(proxy, b);
return pw_protocol_native_end_proxy(proxy, b);
}
static void client_node_marshal_set_active(void *object, bool active)
static int client_node_marshal_set_active(void *object, bool active)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
@ -146,10 +130,10 @@ static void client_node_marshal_set_active(void *object, bool active)
spa_pod_builder_add_struct(b,
SPA_POD_Bool(active));
pw_protocol_native_end_proxy(proxy, b);
return pw_protocol_native_end_proxy(proxy, b);
}
static void client_node_marshal_event_method(void *object, struct spa_event *event)
static int client_node_marshal_event_method(void *object, struct spa_event *event)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
@ -159,7 +143,7 @@ static void client_node_marshal_event_method(void *object, struct spa_event *eve
spa_pod_builder_add_struct(b,
SPA_POD_Pod(event));
pw_protocol_native_end_proxy(proxy, b);
return pw_protocol_native_end_proxy(proxy, b);
}
static int client_node_demarshal_add_mem(void *object, void *data, size_t size)
@ -215,18 +199,17 @@ static int client_node_demarshal_set_param(void *object, void *data, size_t size
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t seq, id, flags;
uint32_t id, flags;
const struct spa_pod *param = NULL;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_Id(&id),
SPA_POD_Int(&flags),
SPA_POD_PodObject(&param)) < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, set_param, 0, seq, id, flags, param);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, set_param, 0, id, flags, param);
return 0;
}
@ -250,15 +233,13 @@ static int client_node_demarshal_command(void *object, void *data, size_t size)
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
const struct spa_command *command;
uint32_t seq;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_PodObject(&command)) < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, command, 0, seq, command);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, command, 0, command);
return 0;
}
@ -266,16 +247,15 @@ static int client_node_demarshal_add_port(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
int32_t seq, direction, port_id;
int32_t direction, port_id;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_Int(&direction),
SPA_POD_Int(&port_id)) < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, add_port, 0, seq, direction, port_id);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, add_port, 0, direction, port_id);
return 0;
}
@ -283,16 +263,15 @@ static int client_node_demarshal_remove_port(void *object, void *data, size_t si
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
int32_t seq, direction, port_id;
int32_t direction, port_id;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_Int(&direction),
SPA_POD_Int(&port_id)) < 0)
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, remove_port, 0, seq, direction, port_id);
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, remove_port, 0, direction, port_id);
return 0;
}
@ -300,12 +279,11 @@ static int client_node_demarshal_port_set_param(void *object, void *data, size_t
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t seq, direction, port_id, id, flags;
uint32_t direction, port_id, id, flags;
const struct spa_pod *param = NULL;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_Int(&direction),
SPA_POD_Int(&port_id),
SPA_POD_Id(&id),
@ -314,7 +292,7 @@ static int client_node_demarshal_port_set_param(void *object, void *data, size_t
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, port_set_param, 0,
seq, direction, port_id, id, flags, param);
direction, port_id, id, flags, param);
return 0;
}
@ -323,14 +301,13 @@ static int client_node_demarshal_port_use_buffers(void *object, void *data, size
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
struct spa_pod_frame f;
uint32_t seq, direction, port_id, mix_id, n_buffers, data_id;
uint32_t direction, port_id, mix_id, n_buffers, data_id;
struct pw_client_node_buffer *buffers;
uint32_t i, j;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_push_struct(&prs, &f) < 0 ||
spa_pod_parser_get(&prs,
SPA_POD_Int(&seq),
SPA_POD_Int(&direction),
SPA_POD_Int(&port_id),
SPA_POD_Int(&mix_id),
@ -376,7 +353,7 @@ static int client_node_demarshal_port_use_buffers(void *object, void *data, size
d->data = SPA_UINT32_TO_PTR(data_id);
}
}
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, port_use_buffers, 0, seq,
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, port_use_buffers, 0,
direction,
port_id,
mix_id,
@ -388,11 +365,10 @@ static int client_node_demarshal_port_set_io(void *object, void *data, size_t si
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t seq, direction, port_id, mix_id, id, memid, off, sz;
uint32_t direction, port_id, mix_id, id, memid, off, sz;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_Int(&direction),
SPA_POD_Int(&port_id),
SPA_POD_Int(&mix_id),
@ -403,7 +379,6 @@ static int client_node_demarshal_port_set_io(void *object, void *data, size_t si
return -EINVAL;
pw_proxy_notify(proxy, struct pw_client_node_proxy_events, port_set_io, 0,
seq,
direction, port_id, mix_id,
id, memid,
off, sz);
@ -457,7 +432,7 @@ static int client_node_demarshal_set_io(void *object, void *data, size_t size)
return 0;
}
static void
static int
client_node_marshal_add_mem(void *object,
uint32_t mem_id,
uint32_t type,
@ -474,10 +449,10 @@ client_node_marshal_add_mem(void *object,
SPA_POD_Int(pw_protocol_native_add_resource_fd(resource, memfd)),
SPA_POD_Int(flags));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd)
static int client_node_marshal_transport(void *object, uint32_t node_id, int readfd, int writefd)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -489,11 +464,11 @@ static void client_node_marshal_transport(void *object, uint32_t node_id, int re
SPA_POD_Int(pw_protocol_native_add_resource_fd(resource, readfd)),
SPA_POD_Int(pw_protocol_native_add_resource_fd(resource, writefd)));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
client_node_marshal_set_param(void *object, uint32_t seq, uint32_t id, uint32_t flags,
static int
client_node_marshal_set_param(void *object, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct pw_resource *resource = object;
@ -502,15 +477,14 @@ client_node_marshal_set_param(void *object, uint32_t seq, uint32_t id, uint32_t
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_SET_PARAM);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Id(id),
SPA_POD_Int(flags),
SPA_POD_Pod(param));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void client_node_marshal_event_event(void *object, const struct spa_event *event)
static int client_node_marshal_event_event(void *object, const struct spa_event *event)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -520,11 +494,11 @@ static void client_node_marshal_event_event(void *object, const struct spa_event
spa_pod_builder_add_struct(b,
SPA_POD_Pod(event));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
client_node_marshal_command(void *object, uint32_t seq, const struct spa_command *command)
static int
client_node_marshal_command(void *object, const struct spa_command *command)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -532,15 +506,14 @@ client_node_marshal_command(void *object, uint32_t seq, const struct spa_command
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_COMMAND);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Pod(command));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_add_port(void *object,
uint32_t seq, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction, uint32_t port_id)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -548,16 +521,15 @@ client_node_marshal_add_port(void *object,
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_ADD_PORT);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Int(direction),
SPA_POD_Int(port_id));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_remove_port(void *object,
uint32_t seq, enum spa_direction direction, uint32_t port_id)
enum spa_direction direction, uint32_t port_id)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
@ -565,16 +537,14 @@ client_node_marshal_remove_port(void *object,
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_REMOVE_PORT);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Int(direction),
SPA_POD_Int(port_id));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_port_set_param(void *object,
uint32_t seq,
enum spa_direction direction,
uint32_t port_id,
uint32_t id,
@ -587,19 +557,17 @@ client_node_marshal_port_set_param(void *object,
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_PARAM);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Int(direction),
SPA_POD_Int(port_id),
SPA_POD_Id(id),
SPA_POD_Int(flags),
SPA_POD_Pod(param));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_port_use_buffers(void *object,
uint32_t seq,
enum spa_direction direction,
uint32_t port_id,
uint32_t mix_id,
@ -614,7 +582,6 @@ client_node_marshal_port_use_buffers(void *object,
spa_pod_builder_push_struct(b, &f);
spa_pod_builder_add(b,
SPA_POD_Int(seq),
SPA_POD_Int(direction),
SPA_POD_Int(port_id),
SPA_POD_Int(mix_id),
@ -649,12 +616,11 @@ client_node_marshal_port_use_buffers(void *object,
}
spa_pod_builder_pop(b, &f);
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_port_set_io(void *object,
uint32_t seq,
uint32_t direction,
uint32_t port_id,
uint32_t mix_id,
@ -669,7 +635,6 @@ client_node_marshal_port_set_io(void *object,
b = pw_protocol_native_begin_resource(resource, PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_IO);
spa_pod_builder_add_struct(b,
SPA_POD_Int(seq),
SPA_POD_Int(direction),
SPA_POD_Int(port_id),
SPA_POD_Int(mix_id),
@ -678,10 +643,10 @@ client_node_marshal_port_set_io(void *object,
SPA_POD_Int(offset),
SPA_POD_Int(size));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_set_activation(void *object,
uint32_t node_id,
int signalfd,
@ -701,10 +666,10 @@ client_node_marshal_set_activation(void *object,
SPA_POD_Int(offset),
SPA_POD_Int(size));
pw_protocol_native_end_resource(resource, b);
return pw_protocol_native_end_resource(resource, b);
}
static void
static int
client_node_marshal_set_io(void *object,
uint32_t id,
uint32_t memid,
@ -720,23 +685,7 @@ client_node_marshal_set_io(void *object,
SPA_POD_Int(memid),
SPA_POD_Int(offset),
SPA_POD_Int(size));
pw_protocol_native_end_resource(resource, b);
}
static int client_node_demarshal_done(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
struct spa_pod_parser prs;
uint32_t seq, res;
spa_pod_parser_init(&prs, data, size);
if (spa_pod_parser_get_struct(&prs,
SPA_POD_Int(&seq),
SPA_POD_Int(&res)) < 0)
return -EINVAL;
pw_resource_do(resource, struct pw_client_node_proxy_methods, done, 0, seq, res);
return 0;
return pw_protocol_native_end_resource(resource, b);
}
static int client_node_demarshal_update(void *object, void *data, size_t size)
@ -882,7 +831,6 @@ static int client_node_demarshal_event_method(void *object, void *data, size_t s
static const struct pw_client_node_proxy_methods pw_protocol_native_client_node_method_marshal = {
PW_VERSION_CLIENT_NODE_PROXY_METHODS,
&client_node_marshal_done,
&client_node_marshal_update,
&client_node_marshal_port_update,
&client_node_marshal_set_active,
@ -890,7 +838,6 @@ static const struct pw_client_node_proxy_methods pw_protocol_native_client_node_
};
static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_method_demarshal[] = {
{ &client_node_demarshal_done, 0 },
{ &client_node_demarshal_update, 0 },
{ &client_node_demarshal_port_update, 0 },
{ &client_node_demarshal_set_active, 0 },

View file

@ -343,9 +343,9 @@ static struct mix *ensure_mix(struct node_data *data,
return mix;
}
static void client_node_add_mem(void *object,
uint32_t mem_id,
uint32_t type, int memfd, uint32_t flags)
static int client_node_add_mem(void *object,
uint32_t mem_id,
uint32_t type, int memfd, uint32_t flags)
{
struct pw_proxy *proxy = object;
struct node_data *data = proxy->user_data;
@ -355,7 +355,7 @@ static void client_node_add_mem(void *object,
if (m) {
pw_log_warn("duplicate mem %u, fd %d, flags %d",
mem_id, memfd, flags);
return;
return -EINVAL;
}
m = pw_array_add(&data->mems, sizeof(struct mem));
@ -367,10 +367,11 @@ static void client_node_add_mem(void *object,
m->ref = 0;
m->map.map = PW_MAP_RANGE_INIT;
m->map.ptr = NULL;
return 0;
}
static void client_node_transport(void *object, uint32_t node_id,
int readfd, int writefd)
static int client_node_transport(void *object, uint32_t node_id,
int readfd, int writefd)
{
struct pw_proxy *proxy = object;
struct node_data *data = proxy->user_data;
@ -392,14 +393,16 @@ static void client_node_transport(void *object, uint32_t node_id,
pw_client_node_proxy_set_active(data->node_proxy, true);
pw_remote_events_exported(remote, proxy->id, node_id);
return 0;
}
static void add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32_t change_mask)
static int add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32_t change_mask)
{
struct node_data *data = proxy->user_data;
struct spa_port_info pi = SPA_PORT_INFO_INIT();
uint32_t n_params = 0;
struct spa_pod **params = NULL;
int res;
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
uint32_t idx1, idx2, id;
@ -446,7 +449,7 @@ static void add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32
pi.flags &= ~SPA_PORT_FLAG_CAN_ALLOC_BUFFERS;
}
pw_client_node_proxy_port_update(data->node_proxy,
res = pw_client_node_proxy_port_update(data->node_proxy,
port->direction,
port->port_id,
change_mask,
@ -458,17 +461,19 @@ static void add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32
free(params[--n_params]);
free(params);
}
return res;
}
static void
client_node_set_param(void *object, uint32_t seq, uint32_t id, uint32_t flags,
static int
client_node_set_param(void *object, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
pw_log_warn("set param not implemented");
return -ENOTSUP;
}
static void
static int
client_node_set_io(void *object,
uint32_t id,
uint32_t memid,
@ -488,12 +493,12 @@ client_node_set_io(void *object,
m = find_mem(data, memid);
if (m == NULL) {
pw_log_warn("unknown memory id %u", memid);
return;
return -EINVAL;
}
ptr = mem_map(data, &m->map, m->fd,
PROT_READ|PROT_WRITE, offset, size);
if (ptr == NULL)
return;
return -errno;
m->ref++;
}
@ -508,12 +513,13 @@ client_node_set_io(void *object,
}
data->position = ptr;
}
spa_node_set_io(data->node->node, id, ptr, size);
return spa_node_set_io(data->node->node, id, ptr, size);
}
static void client_node_event(void *object, const struct spa_event *event)
static int client_node_event(void *object, const struct spa_event *event)
{
pw_log_warn("unhandled node event %d", SPA_EVENT_TYPE(event));
return -ENOTSUP;
}
static int
@ -527,7 +533,7 @@ do_pause_source(struct spa_loop *loop,
return 0;
}
static void client_node_command(void *object, uint32_t seq, const struct spa_command *command)
static int client_node_command(void *object, const struct spa_command *command)
{
struct pw_proxy *proxy = object;
struct node_data *data = proxy->user_data;
@ -536,50 +542,58 @@ static void client_node_command(void *object, uint32_t seq, const struct spa_com
switch (SPA_NODE_COMMAND_ID(command)) {
case SPA_NODE_COMMAND_Pause:
pw_log_debug("node %p: pause %d", proxy, seq);
pw_log_debug("node %p: pause", proxy);
if (data->rtsocket_source) {
pw_loop_invoke(data->core->data_loop,
do_pause_source, 1, NULL, 0, true, data);
}
if ((res = pw_node_set_state(data->node, PW_NODE_STATE_IDLE)) < 0)
if ((res = pw_node_set_state(data->node, PW_NODE_STATE_IDLE)) < 0) {
pw_log_warn("node %p: pause failed", proxy);
pw_proxy_error(proxy, res, "pause failed");
}
pw_client_node_proxy_done(data->node_proxy, seq, res);
break;
case SPA_NODE_COMMAND_Start:
pw_log_debug("node %p: start %d", proxy, seq);
pw_log_debug("node %p: start", proxy);
if ((res = pw_node_set_state(data->node, PW_NODE_STATE_RUNNING)) < 0) {
pw_log_warn("node %p: start failed", proxy);
pw_proxy_error(proxy, res, "start failed");
}
else if (data->rtsocket_source) {
pw_loop_update_io(remote->core->data_loop,
data->rtsocket_source,
SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP);
}
pw_client_node_proxy_done(data->node_proxy, seq, res);
break;
default:
pw_log_warn("unhandled node command %d", SPA_NODE_COMMAND_ID(command));
pw_client_node_proxy_done(data->node_proxy, seq, -ENOTSUP);
res = -ENOTSUP;
pw_proxy_error(proxy, res, "command %d not supported", SPA_NODE_COMMAND_ID(command));
}
return res;
}
static void
client_node_add_port(void *object, uint32_t seq, enum spa_direction direction, uint32_t port_id)
static int
client_node_add_port(void *object, enum spa_direction direction, uint32_t port_id)
{
struct pw_proxy *proxy = object;
pw_log_warn("add port not supported");
pw_proxy_error(proxy, -ENOTSUP, "add port not supported");
return -ENOTSUP;
}
static void
client_node_remove_port(void *object, uint32_t seq, enum spa_direction direction, uint32_t port_id)
static int
client_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id)
{
struct pw_proxy *proxy = object;
pw_log_warn("remove port not supported");
pw_proxy_error(proxy, -ENOTSUP, "remove port not supported");
return -ENOTSUP;
}
static void clear_buffers(struct node_data *data, struct mix *mix)
static int clear_buffers(struct node_data *data, struct mix *mix)
{
struct pw_port *port = mix->port;
struct buffer *b;
@ -589,7 +603,7 @@ static void clear_buffers(struct node_data *data, struct mix *mix)
pw_log_debug("port %p: clear buffers %d", port, mix->mix_id);
if ((res = pw_port_use_buffers(port, mix->mix_id, NULL, 0)) < 0) {
pw_log_error("port %p: error clear buffers %s", port, spa_strerror(res));
return;
return res;
}
pw_array_for_each(b, &mix->buffers) {
@ -608,11 +622,11 @@ static void clear_buffers(struct node_data *data, struct mix *mix)
free(b->buf);
}
mix->buffers.size = 0;
return 0;
}
static void
static int
client_node_port_set_param(void *object,
uint32_t seq,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
@ -625,6 +639,7 @@ client_node_port_set_param(void *object,
port = pw_node_find_port(data->node, direction, port_id);
if (port == NULL) {
res = -EINVAL;
pw_proxy_error(proxy, res, "unknown port");
goto done;
}
@ -639,20 +654,22 @@ client_node_port_set_param(void *object,
}
res = pw_port_set_param(port, SPA_ID_INVALID, id, flags, param);
if (res < 0)
if (res < 0) {
pw_proxy_error(proxy, res, "can't set port param: %s", spa_strerror(res));
goto done;
}
add_port_update(proxy, port,
if ((res = add_port_update(proxy, port,
PW_CLIENT_NODE_PORT_UPDATE_PARAMS |
PW_CLIENT_NODE_PORT_UPDATE_INFO);
PW_CLIENT_NODE_PORT_UPDATE_INFO)) < 0)
pw_proxy_error(proxy, res, "can't add port update");
done:
pw_client_node_proxy_done(data->node_proxy, seq, res);
return res;
}
static void
static int
client_node_port_use_buffers(void *object,
uint32_t seq,
enum spa_direction direction, uint32_t port_id, uint32_t mix_id,
uint32_t n_buffers, struct pw_client_node_buffer *buffers)
{
@ -667,6 +684,7 @@ client_node_port_use_buffers(void *object,
mix = ensure_mix(data, direction, port_id, mix_id);
if (mix == NULL) {
res = -EINVAL;
pw_proxy_error(proxy, res, "can add mix");
goto done;
}
@ -687,6 +705,7 @@ client_node_port_use_buffers(void *object,
if (m == NULL) {
pw_log_error("unknown memory id %u", buffers[i].mem_id);
res = -EINVAL;
pw_proxy_error(proxy, res, "unknown memory %u", buffers[i].mem_id);
goto cleanup;
}
@ -698,6 +717,7 @@ client_node_port_use_buffers(void *object,
buffers[i].offset, buffers[i].size);
if (bmem.map.ptr == NULL) {
res = -errno;
pw_proxy_error(proxy, res, "can't mmap memory: %s", spa_strerror(res));
goto cleanup;
}
if (mlock(bmem.map.ptr, bmem.map.map.size) < 0)
@ -716,6 +736,7 @@ client_node_port_use_buffers(void *object,
b = bid->buf = malloc(size);
if (b == NULL) {
res = -ENOMEM;
pw_proxy_error(proxy, res, "can't alloc memory: %s", spa_strerror(res));
goto cleanup;
}
memcpy(b, buffers[i].buffer, sizeof(struct spa_buffer));
@ -757,6 +778,7 @@ client_node_port_use_buffers(void *object,
if (bm == NULL) {
pw_log_error("unknown buffer mem %u", mem_id);
res = -EINVAL;
pw_proxy_error(proxy, res, "unknown buffer mem %u", mem_id);
goto cleanup;
}
@ -783,11 +805,11 @@ client_node_port_use_buffers(void *object,
bufs[i] = b;
}
res = pw_port_use_buffers(mix->port, mix->mix_id, bufs, n_buffers);
if ((res = pw_port_use_buffers(mix->port, mix->mix_id, bufs, n_buffers)) < 0)
pw_proxy_error(proxy, res, "can't use buffers: %s", spa_strerror(res));
done:
pw_client_node_proxy_done(data->node_proxy, seq, res);
return;
return res;
cleanup:
clear_buffers(data, mix);
@ -795,9 +817,8 @@ client_node_port_use_buffers(void *object,
}
static void
static int
client_node_port_set_io(void *object,
uint32_t seq,
uint32_t direction,
uint32_t port_id,
uint32_t mix_id,
@ -811,10 +832,14 @@ client_node_port_set_io(void *object,
struct mix *mix;
struct mem *m;
void *ptr;
int res = 0;
mix = ensure_mix(data, direction, port_id, mix_id);
if (mix == NULL)
return;
if (mix == NULL) {
res = -EINVAL;
pw_proxy_error(proxy, res, "can't get mixer: %s", spa_strerror(res));
return res;
}
if (memid == SPA_ID_INVALID) {
ptr = NULL;
@ -824,12 +849,17 @@ client_node_port_set_io(void *object,
m = find_mem(data, memid);
if (m == NULL) {
pw_log_warn("unknown memory id %u", memid);
return;
res = -EINVAL;
pw_proxy_error(proxy, res, "unknown memory id %u", memid);
return res;
}
ptr = mem_map(data, &m->map, m->fd,
PROT_READ|PROT_WRITE, offset, size);
if (ptr == NULL)
return;
if (ptr == NULL) {
res = -errno;
pw_proxy_error(proxy, res, "mmap failed: %s", spa_strerror(res));
return res;
}
m->ref++;
}
@ -848,12 +878,14 @@ client_node_port_set_io(void *object,
if (ptr)
activate_mix(data, mix);
} else {
spa_node_port_set_io(mix->port->node->node,
if ((res = spa_node_port_set_io(mix->port->node->node,
direction, port_id,
id,
ptr,
size);
size)) < 0)
pw_proxy_error(proxy, res, "set_io failed: %s", spa_strerror(res));
}
return res;
}
#if 0
@ -868,7 +900,7 @@ static int link_signal_func(void *user_data)
}
#endif
static void
static int
client_node_set_activation(void *object,
uint32_t node_id,
int signalfd,
@ -881,6 +913,7 @@ client_node_set_activation(void *object,
struct pw_node *node = data->node;
struct mem *m;
struct pw_node_activation *ptr;
int res = 0;
if (memid == SPA_ID_INVALID) {
ptr = NULL;
@ -890,12 +923,17 @@ client_node_set_activation(void *object,
m = find_mem(data, memid);
if (m == NULL) {
pw_log_warn("unknown memory id %u", memid);
return;
res = -EINVAL;
pw_proxy_error(proxy, res, "unknown memory id %u", memid);
return res;
}
ptr = mem_map(data, &m->map, m->fd,
PROT_READ|PROT_WRITE, offset, size);
if (ptr == NULL)
return;
if (ptr == NULL) {
res = -errno;
pw_proxy_error(proxy, res, "mmap failed: %s", spa_strerror(res));
return res;
}
m->ref++;
}
pw_log_debug("node %p: set activation %d", node, node_id);
@ -914,6 +952,7 @@ client_node_set_activation(void *object,
link->link.state->pending);
}
#endif
return res;
}
static const struct pw_client_node_proxy_events client_node_events = {
@ -956,7 +995,6 @@ static void do_node_init(struct pw_proxy *proxy)
PW_CLIENT_NODE_PORT_UPDATE_PARAMS |
PW_CLIENT_NODE_PORT_UPDATE_INFO);
}
pw_client_node_proxy_done(data->node_proxy, 0, 0);
}
static void clear_mix(struct node_data *data, struct mix *mix)