interface: add an interface struct

The interface struct has the type,version and methods of the
interface.
Make spa interfaces extend from spa_interface and make a
separate structure for the methods.
Pass a generic void* as the first argument of methods, like
we don in PipeWire.
Bundle the methods + implementation in a versioned inteface
and use that to invoke methods. This way we can do version
checks on the methods.
Make resource and proxy interfaces that we can can call. We
can then make the core interfaces independent on proxy/resource and
hide them in the lower layers.
Add add_listener method to methods of core interfaces, just
like SPA.
This commit is contained in:
Wim Taymans 2019-05-20 16:11:23 +02:00
parent eb6481efb3
commit ff946e3d4b
85 changed files with 3051 additions and 3000 deletions

View file

@ -173,6 +173,33 @@ struct impl {
int other_fds[2];
};
#define pw_client_node_resource(r,m,v,...) \
pw_resource_notify_res(r,struct pw_client_node_proxy_events,m,v,__VA_ARGS__)
#define pw_client_node_resource_add_mem(r,...) \
pw_client_node_resource(r,add_mem,0,__VA_ARGS__)
#define pw_client_node_resource_transport(r,...) \
pw_client_node_resource(r,transport,0,__VA_ARGS__)
#define pw_client_node_resource_set_param(r,...) \
pw_client_node_resource(r,set_param,0,__VA_ARGS__)
#define pw_client_node_resource_set_io(r,...) \
pw_client_node_resource(r,set_io,0,__VA_ARGS__)
#define pw_client_node_resource_event(r,...) \
pw_client_node_resource(r,event,0,__VA_ARGS__)
#define pw_client_node_resource_command(r,...) \
pw_client_node_resource(r,command,0,__VA_ARGS__)
#define pw_client_node_resource_add_port(r,...) \
pw_client_node_resource(r,add_port,0,__VA_ARGS__)
#define pw_client_node_resource_remove_port(r,...) \
pw_client_node_resource(r,remove_port,0,__VA_ARGS__)
#define pw_client_node_resource_port_set_param(r,...) \
pw_client_node_resource(r,port_set_param,0,__VA_ARGS__)
#define pw_client_node_resource_port_use_buffers(r,...) \
pw_client_node_resource(r,port_use_buffers,0,__VA_ARGS__)
#define pw_client_node_resource_port_set_io(r,...) \
pw_client_node_resource(r,port_set_io,0,__VA_ARGS__)
#define pw_client_node_resource_set_activation(r,...) \
pw_client_node_resource(r,set_activation,0,__VA_ARGS__)
static int
do_port_use_buffers(struct impl *impl,
enum spa_direction direction,
@ -356,21 +383,19 @@ static void mix_clear(struct node *this, struct mix *mix)
mix->valid = false;
}
static int impl_node_enum_params(struct spa_node *node, int seq,
static int impl_node_enum_params(void *object, int seq,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter)
{
struct node *this;
struct node *this = object;
uint8_t buffer[1024];
struct spa_pod_builder b = { 0 };
struct spa_result_node_params result;
uint32_t count = 0;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
result.id = id;
result.next = start;
@ -399,14 +424,12 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
return 0;
}
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct node *this;
struct node *this = object;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
spa_return_val_if_fail(this != NULL, -EINVAL);
if (this->resource == NULL)
return -EIO;
@ -414,17 +437,16 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
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)
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
{
struct node *this;
struct node *this = object;
struct impl *impl;
struct pw_memblock *mem;
struct mem *m;
uint32_t memid, mem_offset, mem_size;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (impl->this.flags & 1)
@ -461,19 +483,17 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size
return 0;
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
static int impl_node_send_command(void *object, const struct spa_command *command)
{
struct node *this;
struct node *this = object;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(command != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
if (this->resource == NULL)
return -EIO;
pw_log_debug("client-node %p: send command %d", node, SPA_COMMAND_TYPE(command));
pw_log_debug("client-node %p: send command %d", this, SPA_COMMAND_TYPE(command));
return pw_client_node_resource_command(this->resource, command);
}
@ -484,18 +504,17 @@ static void emit_port_info(struct node *this, struct port *port)
port->direction, port->id, &port->info);
}
static int impl_node_add_listener(struct spa_node *node,
static int impl_node_add_listener(void *object,
struct spa_hook *listener,
const struct spa_node_events *events,
void *data)
{
struct node *this;
struct node *this = object;
struct spa_hook_list save;
uint32_t i;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
for (i = 0; i < MAX_INPUTS; i++) {
@ -512,29 +531,30 @@ static int impl_node_add_listener(struct spa_node *node,
}
static int
impl_node_set_callbacks(struct spa_node *node,
impl_node_set_callbacks(void *object,
const struct spa_node_callbacks *callbacks,
void *data)
{
struct node *this;
struct node *this = object;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
this->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
return 0;
}
static int
impl_node_sync(struct spa_node *node, int seq)
impl_node_sync(void *object, int 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", node);
struct node *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
pw_log_debug("client-node %p: sync", this);
if (this->resource == NULL)
return -EIO;
return pw_resource_ping(this->resource, seq);
}
@ -622,50 +642,43 @@ clear_port(struct node *this, struct port *port)
}
static int
impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id,
impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id,
const struct spa_dict *props)
{
struct node *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
struct node *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(CHECK_FREE_PORT(this, direction, port_id), -EINVAL);
return pw_client_node_resource_add_port(this->resource, direction, port_id, props);
}
static int
impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id)
{
struct node *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
struct node *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
return pw_client_node_resource_remove_port(this->resource, direction, port_id);
}
static int
impl_node_port_enum_params(struct spa_node *node, int seq,
impl_node_port_enum_params(void *object, int seq,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter)
{
struct node *this;
struct node *this = object;
struct port *port;
uint8_t buffer[1024];
struct spa_pod_builder b = { 0 };
struct spa_result_node_params result;
uint32_t count = 0;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
@ -702,17 +715,14 @@ impl_node_port_enum_params(struct spa_node *node, int seq,
}
static int
impl_node_port_set_param(struct spa_node *node,
impl_node_port_set_param(void *object,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct node *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
struct node *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (this->resource == NULL)
@ -783,7 +793,7 @@ static int do_port_set_io(struct impl *impl,
}
static int
impl_node_port_set_io(struct spa_node *node,
impl_node_port_set_io(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t id,
@ -907,18 +917,17 @@ do_port_use_buffers(struct impl *impl,
}
static int
impl_node_port_use_buffers(struct spa_node *node,
impl_node_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
struct node *this;
struct node *this = object;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
return do_port_use_buffers(impl, direction, port_id,
@ -926,7 +935,7 @@ impl_node_port_use_buffers(struct spa_node *node,
}
static int
impl_node_port_alloc_buffers(struct spa_node *node,
impl_node_port_alloc_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
struct spa_pod **params,
@ -934,14 +943,11 @@ impl_node_port_alloc_buffers(struct spa_node *node,
struct spa_buffer **buffers,
uint32_t *n_buffers)
{
struct node *this;
struct node *this = object;
struct port *port;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(buffers != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
@ -954,13 +960,11 @@ impl_node_port_alloc_buffers(struct spa_node *node,
}
static int
impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
{
struct node *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
struct node *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(CHECK_OUT_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL);
spa_log_trace_fp(this->log, "reuse buffer %d", buffer_id);
@ -968,9 +972,9 @@ impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t bu
return -ENOTSUP;
}
static int impl_node_process(struct spa_node *node)
static int impl_node_process(void *object)
{
struct node *this = SPA_CONTAINER_OF(node, struct node, node);
struct node *this = object;
struct impl *impl = this->impl;
struct pw_node *n = impl->this.node;
struct timespec ts;
@ -988,18 +992,22 @@ static int impl_node_process(struct spa_node *node)
return SPA_STATUS_OK;
}
static int
static struct pw_node_proxy *
client_node_get_node(void *data,
uint32_t version,
uint32_t new_id)
size_t user_data_size)
{
struct impl *impl = data;
struct node *this = &impl->node;
uint32_t new_id = user_data_size;
pw_log_debug("node %p: bind %u/%u", this, new_id, version);
impl->bind_node_version = version;
impl->bind_node_id = new_id;
pw_map_insert_at(&this->resource->client->objects, new_id, NULL);
return 0;
return NULL;
}
static int
@ -1118,9 +1126,8 @@ static void node_on_data_fd_events(struct spa_source *source)
}
}
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
NULL,
static const struct spa_node_methods impl_node = {
SPA_VERSION_NODE_METHODS,
.add_listener = impl_node_add_listener,
.set_callbacks = impl_node_set_callbacks,
.sync = impl_node_sync,
@ -1164,7 +1171,10 @@ node_init(struct node *this,
return -EINVAL;
}
this->node = impl_node;
this->node.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
&impl_node, this);
spa_hook_list_init(&this->hooks);
spa_list_init(&this->pending_list);
@ -1380,59 +1390,59 @@ static const struct pw_port_implementation port_impl = {
};
static int
impl_mix_port_enum_params(struct spa_node *node, int seq,
impl_mix_port_enum_params(void *object, int seq,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter)
{
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
struct port *port = object;
return impl_node_port_enum_params(&port->node->node, seq, direction, port->id,
id, start, num, filter);
}
static int
impl_mix_port_set_param(struct spa_node *node,
impl_mix_port_set_param(void *object,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
struct port *port = object;
return impl_node_port_set_param(&port->node->node, direction, port->id,
id, flags, param);
}
static int
impl_mix_add_port(struct spa_node *node, enum spa_direction direction, uint32_t mix_id,
impl_mix_add_port(void *object, enum spa_direction direction, uint32_t mix_id,
const struct spa_dict *props)
{
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
pw_log_debug("client-node %p: add port %d:%d.%d", node, direction, port->id, mix_id);
struct port *port = object;
pw_log_debug("client-node %p: add port %d:%d.%d", object, direction, port->id, mix_id);
return 0;
}
static int
impl_mix_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t mix_id)
impl_mix_remove_port(void *object, enum spa_direction direction, uint32_t mix_id)
{
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
pw_log_debug("client-node %p: remove port %d:%d.%d", node, direction, port->id, mix_id);
struct port *port = object;
pw_log_debug("client-node %p: remove port %d:%d.%d", object, direction, port->id, mix_id);
return 0;
}
static int
impl_mix_port_use_buffers(struct spa_node *node,
impl_mix_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t mix_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
struct port *port = object;
struct impl *impl = port->impl;
return do_port_use_buffers(impl, direction, port->id, mix_id, buffers, n_buffers);
}
static int
impl_mix_port_alloc_buffers(struct spa_node *node,
impl_mix_port_alloc_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
struct spa_pod **params,
@ -1443,11 +1453,11 @@ impl_mix_port_alloc_buffers(struct spa_node *node,
return -ENOTSUP;
}
static int impl_mix_port_set_io(struct spa_node *node,
static int impl_mix_port_set_io(void *object,
enum spa_direction direction, uint32_t mix_id,
uint32_t id, void *data, size_t size)
{
struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node);
struct port *p = object;
struct pw_port *port = p->port;
struct impl *impl = port->owner_data;
struct pw_port_mix *mix;
@ -1469,20 +1479,19 @@ static int impl_mix_port_set_io(struct spa_node *node,
}
static int
impl_mix_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_mix_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
{
struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node);
struct port *p = object;
return impl_node_port_reuse_buffer(&p->node->node, p->id, buffer_id);
}
static int impl_mix_process(struct spa_node *data)
static int impl_mix_process(void *object)
{
return SPA_STATUS_HAVE_BUFFER;
}
static const struct spa_node impl_port_mix = {
SPA_VERSION_NODE,
NULL,
static const struct spa_node_methods impl_port_mix = {
SPA_VERSION_NODE_METHODS,
.port_enum_params = impl_mix_port_enum_params,
.port_set_param = impl_mix_port_set_param,
.add_port = impl_mix_add_port,
@ -1508,7 +1517,10 @@ static void node_port_init(void *data, struct pw_port *port)
p->direction = port->direction;
p->id = port->port_id;
p->impl = impl;
p->mix_node = impl_port_mix;
p->mix_node.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
&impl_port_mix, p);
mix_init(&p->mix[MAX_MIX], p, SPA_ID_INVALID);
if (p->direction == SPA_DIRECTION_INPUT) {
@ -1526,7 +1538,7 @@ static void node_port_added(void *data, struct pw_port *port)
struct impl *impl = data;
struct port *p = pw_port_get_user_data(port);
pw_port_set_mix(port, &p->mix_node,
pw_port_set_mix(port, (struct spa_node *)&p->mix_node,
PW_PORT_MIX_FLAG_MULTI |
PW_PORT_MIX_FLAG_MIX_ONLY);
@ -1613,7 +1625,7 @@ static int process_node(void *data)
{
struct impl *impl = data;
pw_log_trace_fp("client-node %p: process", impl);
return spa_node_process(&impl->node.node);
return spa_node_process((struct spa_node*)&impl->node.node);
}
/** Create a new client node
@ -1670,7 +1682,7 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
name,
PW_SPA_NODE_FLAG_ASYNC |
(do_register ? 0 : PW_SPA_NODE_FLAG_NO_REGISTER),
&impl->node.node,
(struct spa_node *)&impl->node.node,
NULL,
properties, 0);
if (this->node == NULL)

View file

@ -116,11 +116,11 @@ struct impl {
/** \endcond */
static int impl_node_enum_params(struct spa_node *node, int seq,
static int impl_node_enum_params(void *object, int seq,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter)
{
struct node *this;
struct node *this = object;
struct impl *impl;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
@ -129,10 +129,9 @@ static int impl_node_enum_params(struct spa_node *node, int seq,
uint32_t count = 0;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
result.id = id;
@ -224,14 +223,13 @@ static void emit_node_info(struct node *this, bool full)
}
}
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
int res = 0;
struct node *this;
struct node *this = object;
struct impl *impl;
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
switch (id) {
@ -263,15 +261,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag
return res;
}
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
{
struct node *this;
struct node *this = object;
struct impl *impl;
int res = 0;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (impl->adapter)
@ -283,15 +280,14 @@ static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size
return res;
}
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
static int impl_node_send_command(void *object, const struct spa_command *command)
{
struct node *this;
struct node *this = object;
struct impl *impl;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
switch (SPA_NODE_COMMAND_ID(command)) {
@ -343,19 +339,18 @@ static const struct spa_node_events adapter_node_events = {
.result = adapter_result,
};
static int impl_node_add_listener(struct spa_node *node,
static int impl_node_add_listener(void *object,
struct spa_hook *listener,
const struct spa_node_events *events,
void *data)
{
struct node *this;
struct node *this = object;
struct impl *impl;
struct spa_hook l;
struct spa_hook_list save;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
pw_log_debug("%p: add listener %p", this, listener);
@ -375,15 +370,14 @@ static int impl_node_add_listener(struct spa_node *node,
}
static int
impl_node_set_callbacks(struct spa_node *node,
impl_node_set_callbacks(void *object,
const struct spa_node_callbacks *callbacks,
void *data)
{
struct node *this;
struct node *this = object;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
this->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
@ -391,30 +385,28 @@ impl_node_set_callbacks(struct spa_node *node,
}
static int
impl_node_sync(struct spa_node *node, int seq)
impl_node_sync(void *object, int seq)
{
struct node *this;
struct node *this = object;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != 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,
impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id,
const struct spa_dict *props)
{
struct node *this;
struct node *this = object;
struct impl *impl;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (direction != impl->direction)
@ -427,14 +419,13 @@ impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t
}
static int
impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id)
{
struct node *this;
struct node *this = object;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (direction != this->impl->direction)
@ -444,18 +435,17 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
}
static int
impl_node_port_enum_params(struct spa_node *node, int seq,
impl_node_port_enum_params(void *object, int seq,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t num,
const struct spa_pod *filter)
{
struct node *this;
struct node *this = object;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
spa_return_val_if_fail(num != 0, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (direction != impl->direction)
@ -698,18 +688,17 @@ static int negotiate_buffers(struct impl *impl)
}
static int
impl_node_port_set_param(struct spa_node *node,
impl_node_port_set_param(void *object,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct node *this;
struct node *this = object;
struct impl *impl;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (direction != impl->direction)
@ -737,19 +726,18 @@ impl_node_port_set_param(struct spa_node *node,
}
static int
impl_node_port_set_io(struct spa_node *node,
impl_node_port_set_io(void *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t id,
void *data, size_t size)
{
struct node *this;
struct node *this = object;
struct impl *impl;
int res = 0;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
spa_log_debug(this->log, "set io %d %d %d %d", port_id, id, direction, impl->direction);
@ -769,19 +757,18 @@ impl_node_port_set_io(struct spa_node *node,
}
static int
impl_node_port_use_buffers(struct spa_node *node,
impl_node_port_use_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
struct node *this;
struct node *this = object;
struct impl *impl;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (direction != impl->direction)
@ -802,7 +789,7 @@ impl_node_port_use_buffers(struct spa_node *node,
}
static int
impl_node_port_alloc_buffers(struct spa_node *node,
impl_node_port_alloc_buffers(void *object,
enum spa_direction direction,
uint32_t port_id,
struct spa_pod **params,
@ -810,12 +797,11 @@ impl_node_port_alloc_buffers(struct spa_node *node,
struct spa_buffer **buffers,
uint32_t *n_buffers)
{
struct node *this;
struct node *this = object;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
if (direction != impl->direction)
@ -826,22 +812,21 @@ impl_node_port_alloc_buffers(struct spa_node *node,
}
static int
impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
{
struct node *this;
struct node *this = object;
struct impl *impl;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(this != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
return spa_node_port_reuse_buffer(impl->adapter, port_id, buffer_id);
}
static int impl_node_process(struct spa_node *node)
static int impl_node_process(void *object)
{
struct node *this = SPA_CONTAINER_OF(node, struct node, node);
struct node *this = object;
struct impl *impl = this->impl;
struct spa_io_position *q = impl->this.node->driver_node->rt.position;
int status, trigger;
@ -890,8 +875,8 @@ static int impl_node_process(struct spa_node *node)
return status;
}
static const struct spa_node impl_node = {
SPA_VERSION_NODE,
static const struct spa_node_methods impl_node = {
SPA_VERSION_NODE_METHODS,
.add_listener = impl_node_add_listener,
.set_callbacks = impl_node_set_callbacks,
.sync = impl_node_sync,
@ -922,7 +907,10 @@ node_init(struct node *this,
if (support[i].type == SPA_TYPE_INTERFACE_Log)
this->log = support[i].data;
}
this->node = impl_node;
this->node.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
&impl_node, this);
spa_hook_list_init(&this->hooks);
this->info_all = SPA_NODE_CHANGE_MASK_PARAMS;
@ -1301,7 +1289,7 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
name,
PW_SPA_NODE_FLAG_ASYNC |
PW_SPA_NODE_FLAG_ACTIVATE,
&impl->node.node,
(struct spa_node *)&impl->node.node,
NULL,
properties, 0);
if (this->node == NULL)

View file

@ -47,11 +47,29 @@ static void push_dict(struct spa_pod_builder *b, const struct spa_dict *dict)
spa_pod_builder_pop(b, &f);
}
static int
client_node_marshal_get_node(void *object, uint32_t version, uint32_t new_id)
static int client_node_marshal_add_listener(void *object,
struct spa_hook *listener,
const struct pw_client_node_proxy_events *events,
void *data)
{
struct pw_proxy *proxy = object;
pw_proxy_add_proxy_listener(proxy, listener, events, data);
return 0;
}
static struct pw_node_proxy *
client_node_marshal_get_node(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_Node, user_data_size);
if (res == NULL)
return NULL;
new_id = pw_proxy_get_id(res);
b = pw_protocol_native_begin_proxy(proxy, PW_CLIENT_NODE_PROXY_METHOD_GET_NODE, NULL);
@ -59,7 +77,9 @@ client_node_marshal_get_node(void *object, uint32_t version, uint32_t new_id)
SPA_POD_Int(version),
SPA_POD_Int(new_id));
return pw_protocol_native_end_proxy(proxy, b);
pw_protocol_native_end_proxy(proxy, b);
return (struct pw_node_proxy *) res;
}
static int
@ -1000,50 +1020,56 @@ static int client_node_demarshal_event_method(void *object, const struct pw_prot
static const struct pw_client_node_proxy_methods pw_protocol_native_client_node_method_marshal = {
PW_VERSION_CLIENT_NODE_PROXY_METHODS,
&client_node_marshal_get_node,
&client_node_marshal_update,
&client_node_marshal_port_update,
&client_node_marshal_set_active,
&client_node_marshal_event_method
.add_listener = &client_node_marshal_add_listener,
.get_node = &client_node_marshal_get_node,
.update = &client_node_marshal_update,
.port_update = &client_node_marshal_port_update,
.set_active = &client_node_marshal_set_active,
.event = &client_node_marshal_event_method
};
static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_method_demarshal[] = {
{ &client_node_demarshal_get_node, 0 },
{ &client_node_demarshal_update, 0 },
{ &client_node_demarshal_port_update, 0 },
{ &client_node_demarshal_set_active, 0 },
{ &client_node_demarshal_event_method, 0 }
static const struct pw_protocol_native_demarshal
pw_protocol_native_client_node_method_demarshal[PW_CLIENT_NODE_PROXY_METHOD_NUM] =
{
[PW_CLIENT_NODE_PROXY_METHOD_ADD_LISTENER] = { NULL, 0 },
[PW_CLIENT_NODE_PROXY_METHOD_GET_NODE] = { &client_node_demarshal_get_node, 0 },
[PW_CLIENT_NODE_PROXY_METHOD_UPDATE] = { &client_node_demarshal_update, 0 },
[PW_CLIENT_NODE_PROXY_METHOD_PORT_UPDATE] = { &client_node_demarshal_port_update, 0 },
[PW_CLIENT_NODE_PROXY_METHOD_SET_ACTIVE] = { &client_node_demarshal_set_active, 0 },
[PW_CLIENT_NODE_PROXY_METHOD_EVENT] = { &client_node_demarshal_event_method, 0 }
};
static const struct pw_client_node_proxy_events pw_protocol_native_client_node_event_marshal = {
PW_VERSION_CLIENT_NODE_PROXY_EVENTS,
&client_node_marshal_add_mem,
&client_node_marshal_transport,
&client_node_marshal_set_param,
&client_node_marshal_set_io,
&client_node_marshal_event_event,
&client_node_marshal_command,
&client_node_marshal_add_port,
&client_node_marshal_remove_port,
&client_node_marshal_port_set_param,
&client_node_marshal_port_use_buffers,
&client_node_marshal_port_set_io,
&client_node_marshal_set_activation,
.add_mem = &client_node_marshal_add_mem,
.transport = &client_node_marshal_transport,
.set_param = &client_node_marshal_set_param,
.set_io = &client_node_marshal_set_io,
.event = &client_node_marshal_event_event,
.command = &client_node_marshal_command,
.add_port = &client_node_marshal_add_port,
.remove_port = &client_node_marshal_remove_port,
.port_set_param = &client_node_marshal_port_set_param,
.port_use_buffers = &client_node_marshal_port_use_buffers,
.port_set_io = &client_node_marshal_port_set_io,
.set_activation = &client_node_marshal_set_activation,
};
static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_event_demarshal[] = {
{ &client_node_demarshal_add_mem, 0 },
{ &client_node_demarshal_transport, 0 },
{ &client_node_demarshal_set_param, 0 },
{ &client_node_demarshal_set_io, 0 },
{ &client_node_demarshal_event_event, 0 },
{ &client_node_demarshal_command, 0 },
{ &client_node_demarshal_add_port, 0 },
{ &client_node_demarshal_remove_port, 0 },
{ &client_node_demarshal_port_set_param, 0 },
{ &client_node_demarshal_port_use_buffers, 0 },
{ &client_node_demarshal_port_set_io, 0 },
{ &client_node_demarshal_set_activation, 0 }
static const struct pw_protocol_native_demarshal
pw_protocol_native_client_node_event_demarshal[PW_CLIENT_NODE_PROXY_EVENT_NUM] =
{
[PW_CLIENT_NODE_PROXY_EVENT_ADD_MEM] = { &client_node_demarshal_add_mem, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_TRANSPORT] = { &client_node_demarshal_transport, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_SET_PARAM] = { &client_node_demarshal_set_param, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_SET_IO] = { &client_node_demarshal_set_io, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_EVENT] = { &client_node_demarshal_event_event, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_COMMAND] = { &client_node_demarshal_command, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_ADD_PORT] = { &client_node_demarshal_add_port, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_REMOVE_PORT] = { &client_node_demarshal_remove_port, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_PARAM] = { &client_node_demarshal_port_set_param, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_PORT_USE_BUFFERS] = { &client_node_demarshal_port_use_buffers, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_PORT_SET_IO] = { &client_node_demarshal_port_set_io, 0 },
[PW_CLIENT_NODE_PROXY_EVENT_SET_ACTIVATION] = { &client_node_demarshal_set_activation, 0 }
};
static const struct pw_protocol_marshal pw_protocol_native_client_node_marshal = {

View file

@ -1218,7 +1218,7 @@ static struct pw_proxy *node_export(struct pw_remote *remote, void *object, bool
do_node_init(proxy);
data->proxy = (struct pw_proxy*) pw_client_node_proxy_get_node(data->node_proxy,
PW_VERSION_NODE, 0);
PW_VERSION_NODE_PROXY, 0);
return data->proxy;
}