hook: separate spa_callbacks from the hook

Make a spa_callbacks with just the functions and data and use this
in the hook and objects.
This commit is contained in:
Wim Taymans 2019-05-15 12:17:52 +02:00
parent 6ee192dff5
commit 448c1937ad
28 changed files with 97 additions and 84 deletions

View file

@ -245,7 +245,7 @@ static void node_port_init(void *data, struct pw_port *port)
if (direction == PW_DIRECTION_INPUT) {
pw_log_debug("mix node %p", p->spa_node);
pw_port_set_mix(port, p->spa_node, PW_PORT_MIX_FLAG_MULTI);
port->impl = SPA_HOOK_INIT(&port_implementation, p);
port->impl = SPA_CALLBACKS_INIT(&port_implementation, p);
}
spa_list_append(&n->ports, &p->link);
}

View file

@ -128,7 +128,7 @@ struct node {
struct spa_loop *data_loop;
struct spa_hook_list hooks;
struct spa_hook callbacks;
struct spa_callbacks callbacks;
struct io ios[MAX_IO];
struct pw_resource *resource;
@ -520,7 +520,7 @@ impl_node_set_callbacks(struct spa_node *node,
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
this->callbacks = SPA_HOOK_INIT(callbacks, data);
this->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
return 0;
}
@ -1529,7 +1529,7 @@ static void node_port_added(void *data, struct pw_port *port)
PW_PORT_MIX_FLAG_MULTI |
PW_PORT_MIX_FLAG_MIX_ONLY);
port->impl = SPA_HOOK_INIT(&port_impl, p);
port->impl = SPA_CALLBACKS_INIT(&port_impl, p);
port->owner_data = impl;
}

View file

@ -72,7 +72,7 @@ struct node {
struct spa_param_info params[5];
struct spa_hook_list hooks;
struct spa_hook callbacks;
struct spa_callbacks callbacks;
};
struct impl {
@ -377,7 +377,7 @@ impl_node_set_callbacks(struct spa_node *node,
this = SPA_CONTAINER_OF(node, struct node, node);
this->callbacks = SPA_HOOK_INIT(callbacks, data);
this->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
return 0;
}

View file

@ -201,7 +201,7 @@ void pw_factory_set_implementation(struct pw_factory *factory,
const struct pw_factory_implementation *implementation,
void *data)
{
factory->impl = SPA_HOOK_INIT(implementation, data);
factory->impl = SPA_CALLBACKS_INIT(implementation, data);
}
SPA_EXPORT
@ -213,7 +213,7 @@ void *pw_factory_create_object(struct pw_factory *factory,
uint32_t new_id)
{
void *res = NULL;
spa_hook_call_res(&factory->impl,
spa_callbacks_call_res(&factory->impl,
struct pw_factory_implementation,
res, create_object, 0,
resource, type, version, properties, new_id);

View file

@ -175,8 +175,7 @@ int pw_port_init_mix(struct pw_port *port, struct pw_port_mix *mix)
if (port->mix->add_port)
port->mix->add_port(port->mix, port->direction, port_id, NULL);
spa_hook_call_res(&port->impl, struct pw_port_implementation,
res, init_mix, 0, mix);
res = pw_port_call_init_mix(port, mix);
/* set the same format on the mixer as on the port if any */
if (port->mix->enum_params && port->mix->set_param) {
@ -211,8 +210,7 @@ int pw_port_release_mix(struct pw_port *port, struct pw_port_mix *mix)
spa_list_remove(&mix->link);
port->n_mix--;
spa_hook_call_res(&port->impl, struct pw_port_implementation,
res, release_mix, 0, mix);
res = pw_port_call_release_mix(port, mix);
if (port->mix->remove_port) {
port->mix->remove_port(port->mix, port->direction, port_id);
@ -1033,8 +1031,7 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
port->allocated = false;
free_allocation(&port->allocation);
spa_hook_call_res(&port->impl, struct pw_port_implementation,
res, use_buffers, 0, buffers, n_buffers);
res = pw_port_call_use_buffers(port, buffers, n_buffers);
}
if (n_buffers > 0 && !SPA_RESULT_IS_ASYNC(res)) {
@ -1062,9 +1059,7 @@ int pw_port_alloc_buffers(struct pw_port *port,
}
if (res >= 0) {
spa_hook_call_res(&port->impl, struct pw_port_implementation,
res, alloc_buffers, 0,
params, n_params, buffers, n_buffers);
res = pw_port_call_alloc_buffers(port, params, n_params, buffers, n_buffers);
if (res < 0) {
pw_log_error("port %p: %d implementation alloc failed: %d (%s)",
port, port->port_id, res, spa_strerror(res));

View file

@ -453,6 +453,20 @@ struct pw_port_implementation {
struct spa_buffer **buffers, uint32_t *n_buffers);
};
#define pw_port_call(p,m,v,...) \
({ \
int _res = 0; \
spa_callbacks_call_res(&(p)->impl, \
struct pw_port_implementation, \
_res, m, v, ## __VA_ARGS__); \
_res; \
})
#define pw_port_call_init_mix(p,m) pw_port_call(p,init_mix,0,m)
#define pw_port_call_release_mix(p,m) pw_port_call(p,release_mix,0,m)
#define pw_port_call_use_buffers(p,b,n) pw_port_call(p,use_buffers,0,b,n)
#define pw_port_call_alloc_buffers(p,pp,np,b,n) pw_port_call(p,alloc_buffers,0,pp,np,b,n)
#define pw_port_emit(o,m,v,...) spa_hook_list_call(&o->listener_list, struct pw_port_events, m, v, ##__VA_ARGS__)
#define pw_port_emit_destroy(p) pw_port_emit(p, destroy, 0)
#define pw_port_emit_free(p) pw_port_emit(p, free, 0)
@ -497,7 +511,7 @@ struct pw_port {
struct spa_hook_list listener_list;
struct spa_hook impl;
struct spa_callbacks impl;
struct spa_node *mix; /**< port buffer mix/split */
#define PW_PORT_MIX_FLAG_MULTI (1<<0) /**< multi input or output */
@ -700,7 +714,7 @@ struct pw_factory {
struct spa_hook_list listener_list; /**< event listeners */
struct spa_hook impl;
struct spa_callbacks impl;
void *user_data;

View file

@ -142,8 +142,7 @@ void pw_resource_set_implementation(struct pw_resource *resource,
{
struct pw_client *client = resource->client;
resource->implementation.funcs = implementation;
resource->implementation.data = data;
resource->implementation.cb = SPA_CALLBACKS_INIT(implementation, data);
pw_client_emit_resource_impl(client, resource);
}

View file

@ -118,7 +118,7 @@ struct stream {
struct spa_node impl_node;
struct spa_hook_list hooks;
struct spa_hook callbacks;
struct spa_callbacks callbacks;
struct spa_io_buffers *io;
struct spa_io_position *position;
uint32_t io_control_size;
@ -405,7 +405,7 @@ static int impl_set_callbacks(struct spa_node *node,
{
struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node);
d->callbacks = SPA_HOOK_INIT(callbacks, data);
d->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
return 0;
}