hook: handle port and factory implementation with hook

This way we can also handle the version number.
This commit is contained in:
Wim Taymans 2019-05-14 18:08:02 +02:00
parent 23d4ed62dd
commit 903cbeb7c1
5 changed files with 23 additions and 26 deletions

View file

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

View file

@ -1532,9 +1532,7 @@ static void node_port_added(void *data, struct pw_port *port)
PW_PORT_MIX_FLAG_MULTI | PW_PORT_MIX_FLAG_MULTI |
PW_PORT_MIX_FLAG_MIX_ONLY); PW_PORT_MIX_FLAG_MIX_ONLY);
port->implementation = &port_impl; port->impl = SPA_HOOK_INIT(&port_impl, p);
port->implementation_data = p;
port->owner_data = impl; port->owner_data = impl;
} }

View file

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

View file

@ -162,7 +162,6 @@ int pw_port_init_mix(struct pw_port *port, struct pw_port_mix *mix)
{ {
uint32_t port_id; uint32_t port_id;
int res = 0; int res = 0;
const struct pw_port_implementation *pi = port->implementation;
port_id = pw_map_insert_new(&port->mix_port_map, mix); port_id = pw_map_insert_new(&port->mix_port_map, mix);
@ -176,8 +175,8 @@ int pw_port_init_mix(struct pw_port *port, struct pw_port_mix *mix)
if (port->mix->add_port) if (port->mix->add_port)
port->mix->add_port(port->mix, port->direction, port_id, NULL); port->mix->add_port(port->mix, port->direction, port_id, NULL);
if (pi && pi->init_mix) spa_hook_call_res(&port->impl, struct pw_port_implementation,
res = pi->init_mix(port->implementation_data, mix); res, init_mix, 0, mix);
/* set the same format on the mixer as on the port if any */ /* set the same format on the mixer as on the port if any */
if (port->mix->enum_params && port->mix->set_param) { if (port->mix->enum_params && port->mix->set_param) {
@ -207,14 +206,13 @@ int pw_port_release_mix(struct pw_port *port, struct pw_port_mix *mix)
{ {
int res = 0; int res = 0;
uint32_t port_id = mix->port.port_id; uint32_t port_id = mix->port.port_id;
const struct pw_port_implementation *pi = port->implementation;
pw_map_remove(&port->mix_port_map, port_id); pw_map_remove(&port->mix_port_map, port_id);
spa_list_remove(&mix->link); spa_list_remove(&mix->link);
port->n_mix--; port->n_mix--;
if (pi && pi->release_mix) spa_hook_call_res(&port->impl, struct pw_port_implementation,
res = pi->release_mix(port->implementation_data, mix); res, release_mix, 0, mix);
if (port->mix->remove_port) { if (port->mix->remove_port) {
port->mix->remove_port(port->mix, port->direction, port_id); port->mix->remove_port(port->mix, port->direction, port_id);
@ -1000,7 +998,6 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
int res = 0; int res = 0;
struct pw_node *node = port->node; struct pw_node *node = port->node;
struct pw_port_mix *mix = NULL; struct pw_port_mix *mix = NULL;
const struct pw_port_implementation *pi = port->implementation;
pw_log_debug("port %p: %d:%d.%d: %d buffers %d", port, pw_log_debug("port %p: %d:%d.%d: %d buffers %d", port,
port->direction, port->port_id, mix_id, n_buffers, port->state); port->direction, port->port_id, mix_id, n_buffers, port->state);
@ -1035,8 +1032,9 @@ int pw_port_use_buffers(struct pw_port *port, uint32_t mix_id,
} }
port->allocated = false; port->allocated = false;
free_allocation(&port->allocation); free_allocation(&port->allocation);
if (pi && pi->use_buffers)
res = pi->use_buffers(port->implementation_data, buffers, n_buffers); spa_hook_call_res(&port->impl, struct pw_port_implementation,
res, use_buffers, 0, buffers, n_buffers);
} }
if (n_buffers > 0 && !SPA_RESULT_IS_ASYNC(res)) { if (n_buffers > 0 && !SPA_RESULT_IS_ASYNC(res)) {
@ -1052,7 +1050,6 @@ int pw_port_alloc_buffers(struct pw_port *port,
{ {
int res; int res;
struct pw_node *node = port->node; struct pw_node *node = port->node;
const struct pw_port_implementation *pi = port->implementation;
if (port->state < PW_PORT_STATE_READY) if (port->state < PW_PORT_STATE_READY)
return -EIO; return -EIO;
@ -1064,9 +1061,11 @@ int pw_port_alloc_buffers(struct pw_port *port,
res, spa_strerror(res)); res, spa_strerror(res));
} }
if (res >= 0 && pi && pi->alloc_buffers) { if (res >= 0) {
if ((res = pi->alloc_buffers(port->implementation_data, spa_hook_call_res(&port->impl, struct pw_port_implementation,
params, n_params, buffers, n_buffers)) < 0) { res, alloc_buffers, 0,
params, n_params, buffers, n_buffers);
if (res < 0) {
pw_log_error("port %p: %d implementation alloc failed: %d (%s)", pw_log_error("port %p: %d implementation alloc failed: %d (%s)",
port, port->port_id, res, spa_strerror(res)); port, port->port_id, res, spa_strerror(res));
} }

View file

@ -497,8 +497,7 @@ struct pw_port {
struct spa_hook_list listener_list; struct spa_hook_list listener_list;
const struct pw_port_implementation *implementation; struct spa_hook impl;
void *implementation_data;
struct spa_node *mix; /**< port buffer mix/split */ struct spa_node *mix; /**< port buffer mix/split */
#define PW_PORT_MIX_FLAG_MULTI (1<<0) /**< multi input or output */ #define PW_PORT_MIX_FLAG_MULTI (1<<0) /**< multi input or output */
@ -701,8 +700,7 @@ struct pw_factory {
struct spa_hook_list listener_list; /**< event listeners */ struct spa_hook_list listener_list; /**< event listeners */
const struct pw_factory_implementation *implementation; struct spa_hook impl;
void *implementation_data;
void *user_data; void *user_data;