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

@ -80,22 +80,22 @@ static void handle_events(struct data *data)
}
}
static int impl_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
static int impl_set_io(void *object, uint32_t id, void *data, size_t size)
{
return 0;
}
static int impl_send_command(struct spa_node *node, const struct spa_command *command)
static int impl_send_command(void *object, const struct spa_command *command)
{
return 0;
}
static int impl_add_listener(struct spa_node *node,
static int impl_add_listener(void *object,
struct spa_hook *listener,
const struct spa_node_events *events,
void *data)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct data *d = object;
struct spa_port_info info;
struct spa_hook_list save;
@ -112,16 +112,16 @@ static int impl_add_listener(struct spa_node *node,
return 0;
}
static int impl_set_callbacks(struct spa_node *node,
static int impl_set_callbacks(void *object,
const struct spa_node_callbacks *callbacks, void *data)
{
return 0;
}
static int impl_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id,
static int impl_port_set_io(void *object, enum spa_direction direction, uint32_t port_id,
uint32_t id, void *data, size_t size)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct data *d = object;
if (id == SPA_IO_Buffers)
d->io = data;
@ -131,12 +131,12 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction,
return 0;
}
static int impl_port_enum_params(struct spa_node *node, int seq,
static int impl_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 data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct data *d = object;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
uint8_t buffer[1024];
@ -200,10 +200,10 @@ static int impl_port_enum_params(struct spa_node *node, int seq,
return 0;
}
static int port_set_format(struct spa_node *node, enum spa_direction direction, uint32_t port_id,
static int port_set_format(void *object, enum spa_direction direction, uint32_t port_id,
uint32_t flags, const struct spa_pod *format)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct data *d = object;
Uint32 sdl_format;
void *dest;
@ -229,22 +229,22 @@ static int port_set_format(struct spa_node *node, enum spa_direction direction,
return 0;
}
static int impl_port_set_param(struct spa_node *node,
static int impl_port_set_param(void *object,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
if (id == SPA_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
return port_set_format(object, direction, port_id, flags, param);
}
else
return -ENOENT;
}
static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direction, uint32_t port_id,
static int impl_port_use_buffers(void *object, enum spa_direction direction, uint32_t port_id,
struct spa_buffer **buffers, uint32_t n_buffers)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct data *d = object;
uint32_t i;
for (i = 0; i < n_buffers; i++)
@ -303,9 +303,9 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq,
return 0;
}
static int impl_node_process(struct spa_node *node)
static int impl_node_process(void *object)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct data *d = object;
int res;
if ((res = pw_loop_invoke(pw_main_loop_get_loop(d->loop), do_render,
@ -319,9 +319,8 @@ static int impl_node_process(struct spa_node *node)
return SPA_STATUS_NEED_BUFFER;
}
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_add_listener,
.set_callbacks = impl_set_callbacks,
.set_io = impl_set_io,
@ -339,7 +338,10 @@ static void make_nodes(struct data *data)
struct pw_properties *props;
data->node = pw_node_new(data->core, "SDL-sink", NULL, 0);
data->impl_node = impl_node;
data->impl_node.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
&impl_node, data);
pw_node_set_implementation(data->node, &data->impl_node);
pw_node_register(data->node, NULL, NULL, NULL);
@ -350,7 +352,7 @@ static void make_nodes(struct data *data)
data->v4l2 = pw_factory_create_object(factory,
NULL,
PW_TYPE_INTERFACE_Node,
PW_VERSION_NODE,
PW_VERSION_NODE_PROXY,
props,
SPA_ID_INVALID);
data->link = pw_link_new(data->core,