mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
hook: handle port and factory implementation with hook
This way we can also handle the version number.
This commit is contained in:
parent
23d4ed62dd
commit
903cbeb7c1
5 changed files with 23 additions and 26 deletions
|
|
@ -245,8 +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->implementation = &port_implementation;
|
||||
port->implementation_data = p;
|
||||
port->impl = SPA_HOOK_INIT(&port_implementation, p);
|
||||
}
|
||||
spa_list_append(&n->ports, &p->link);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1532,9 +1532,7 @@ static void node_port_added(void *data, struct pw_port *port)
|
|||
PW_PORT_MIX_FLAG_MULTI |
|
||||
PW_PORT_MIX_FLAG_MIX_ONLY);
|
||||
|
||||
port->implementation = &port_impl;
|
||||
port->implementation_data = p;
|
||||
|
||||
port->impl = SPA_HOOK_INIT(&port_impl, p);
|
||||
port->owner_data = impl;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,8 +201,7 @@ void pw_factory_set_implementation(struct pw_factory *factory,
|
|||
const struct pw_factory_implementation *implementation,
|
||||
void *data)
|
||||
{
|
||||
factory->implementation = implementation;
|
||||
factory->implementation_data = data;
|
||||
factory->impl = SPA_HOOK_INIT(implementation, data);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
@ -213,6 +212,10 @@ void *pw_factory_create_object(struct pw_factory *factory,
|
|||
struct pw_properties *properties,
|
||||
uint32_t new_id)
|
||||
{
|
||||
return factory->implementation->create_object(factory->implementation_data,
|
||||
void *res = NULL;
|
||||
spa_hook_call_res(&factory->impl,
|
||||
struct pw_factory_implementation,
|
||||
res, create_object, 0,
|
||||
resource, type, version, properties, new_id);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,7 +162,6 @@ int pw_port_init_mix(struct pw_port *port, struct pw_port_mix *mix)
|
|||
{
|
||||
uint32_t port_id;
|
||||
int res = 0;
|
||||
const struct pw_port_implementation *pi = port->implementation;
|
||||
|
||||
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)
|
||||
port->mix->add_port(port->mix, port->direction, port_id, NULL);
|
||||
|
||||
if (pi && pi->init_mix)
|
||||
res = pi->init_mix(port->implementation_data, mix);
|
||||
spa_hook_call_res(&port->impl, struct pw_port_implementation,
|
||||
res, init_mix, 0, mix);
|
||||
|
||||
/* set the same format on the mixer as on the port if any */
|
||||
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;
|
||||
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);
|
||||
spa_list_remove(&mix->link);
|
||||
port->n_mix--;
|
||||
|
||||
if (pi && pi->release_mix)
|
||||
res = pi->release_mix(port->implementation_data, mix);
|
||||
spa_hook_call_res(&port->impl, struct pw_port_implementation,
|
||||
res, release_mix, 0, mix);
|
||||
|
||||
if (port->mix->remove_port) {
|
||||
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;
|
||||
struct pw_node *node = port->node;
|
||||
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,
|
||||
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;
|
||||
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)) {
|
||||
|
|
@ -1052,7 +1050,6 @@ int pw_port_alloc_buffers(struct pw_port *port,
|
|||
{
|
||||
int res;
|
||||
struct pw_node *node = port->node;
|
||||
const struct pw_port_implementation *pi = port->implementation;
|
||||
|
||||
if (port->state < PW_PORT_STATE_READY)
|
||||
return -EIO;
|
||||
|
|
@ -1064,9 +1061,11 @@ int pw_port_alloc_buffers(struct pw_port *port,
|
|||
res, spa_strerror(res));
|
||||
}
|
||||
|
||||
if (res >= 0 && pi && pi->alloc_buffers) {
|
||||
if ((res = pi->alloc_buffers(port->implementation_data,
|
||||
params, n_params, buffers, n_buffers)) < 0) {
|
||||
if (res >= 0) {
|
||||
spa_hook_call_res(&port->impl, struct pw_port_implementation,
|
||||
res, alloc_buffers, 0,
|
||||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -497,8 +497,7 @@ struct pw_port {
|
|||
|
||||
struct spa_hook_list listener_list;
|
||||
|
||||
const struct pw_port_implementation *implementation;
|
||||
void *implementation_data;
|
||||
struct spa_hook impl;
|
||||
|
||||
struct spa_node *mix; /**< port buffer mix/split */
|
||||
#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 */
|
||||
|
||||
const struct pw_factory_implementation *implementation;
|
||||
void *implementation_data;
|
||||
struct spa_hook impl;
|
||||
|
||||
void *user_data;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue