mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-05 13:30:02 -05:00
node: always use a spa_node as the implementation
Avoid duplicating API, remove implementations from port and node and always use an spa_node as the implementation, it's just as easy to implement a spa node. With the implementation always being a spa_node we will be able to better implement the negotiation of the mixers.
This commit is contained in:
parent
b7b80683bc
commit
28ae844de9
14 changed files with 548 additions and 761 deletions
|
|
@ -48,121 +48,16 @@ struct impl {
|
|||
struct spa_hook node_listener;
|
||||
};
|
||||
|
||||
struct port {
|
||||
struct pw_port *port;
|
||||
enum pw_direction direction;
|
||||
uint32_t port_id;
|
||||
struct spa_node *node;
|
||||
};
|
||||
|
||||
static int port_impl_set_io(void *data, struct spa_port_io *io)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_set_io(p->node, p->direction, p->port_id, io);
|
||||
}
|
||||
|
||||
static int port_impl_enum_formats(void *data,
|
||||
struct spa_format **format,
|
||||
const struct spa_format *filter,
|
||||
int32_t index)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_enum_formats(p->node, p->direction, p->port_id, format, filter, index);
|
||||
}
|
||||
|
||||
static int port_impl_set_format(void *data, uint32_t flags, const struct spa_format *format)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_set_format(p->node, p->direction, p->port_id, flags, format);
|
||||
}
|
||||
|
||||
static int port_impl_get_format(void *data, const struct spa_format **format)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_get_format(p->node, p->direction, p->port_id, format);
|
||||
}
|
||||
|
||||
static int port_impl_get_info(void *data, const struct spa_port_info **info)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_get_info(p->node, p->direction, p->port_id, info);
|
||||
}
|
||||
|
||||
static int port_impl_enum_params(void *data, uint32_t index, struct spa_param **param)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_enum_params(p->node, p->direction, p->port_id, index, param);
|
||||
}
|
||||
|
||||
static int port_impl_set_param(void *data, struct spa_param *param)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_set_param(p->node, p->direction, p->port_id, param);
|
||||
}
|
||||
|
||||
static int port_impl_use_buffers(void *data, struct spa_buffer **buffers, uint32_t n_buffers)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_use_buffers(p->node, p->direction, p->port_id, buffers, n_buffers);
|
||||
}
|
||||
|
||||
static int port_impl_alloc_buffers(void *data,
|
||||
struct spa_param **params, uint32_t n_params,
|
||||
struct spa_buffer **buffers, uint32_t *n_buffers)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_alloc_buffers(p->node, p->direction, p->port_id,
|
||||
params, n_params, buffers, n_buffers);
|
||||
}
|
||||
|
||||
static int port_impl_reuse_buffer(void *data, uint32_t buffer_id)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_reuse_buffer(p->node, p->port_id, buffer_id);
|
||||
}
|
||||
|
||||
static int port_impl_send_command(void *data, struct spa_command *command)
|
||||
{
|
||||
struct port *p = data;
|
||||
return spa_node_port_send_command(p->node,
|
||||
p->direction,
|
||||
p->port_id,
|
||||
command);
|
||||
}
|
||||
|
||||
const struct pw_port_implementation port_impl = {
|
||||
PW_VERSION_PORT_IMPLEMENTATION,
|
||||
.set_io = port_impl_set_io,
|
||||
.enum_formats = port_impl_enum_formats,
|
||||
.set_format = port_impl_set_format,
|
||||
.get_format = port_impl_get_format,
|
||||
.get_info = port_impl_get_info,
|
||||
.enum_params = port_impl_enum_params,
|
||||
.set_param = port_impl_set_param,
|
||||
.use_buffers = port_impl_use_buffers,
|
||||
.alloc_buffers = port_impl_alloc_buffers,
|
||||
.reuse_buffer = port_impl_reuse_buffer,
|
||||
.send_command = port_impl_send_command,
|
||||
};
|
||||
|
||||
static struct pw_port *
|
||||
make_port(struct impl *impl, enum pw_direction direction, uint32_t port_id)
|
||||
{
|
||||
struct pw_node *node = impl->this;
|
||||
struct pw_port *port;
|
||||
struct port *p;
|
||||
|
||||
port = pw_port_new(direction, port_id, NULL, sizeof(struct port));
|
||||
port = pw_port_new(direction, port_id, NULL, 0);
|
||||
if (port == NULL)
|
||||
return NULL;
|
||||
|
||||
p = pw_port_get_user_data(port);
|
||||
p->port = port;
|
||||
p->direction = direction;
|
||||
p->port_id = port_id;
|
||||
p->node = impl->node;
|
||||
|
||||
pw_port_set_implementation(port, &port_impl, p);
|
||||
pw_port_add(port, node);
|
||||
|
||||
return port;
|
||||
|
|
@ -200,62 +95,6 @@ static void update_port_ids(struct impl *impl)
|
|||
}
|
||||
|
||||
|
||||
static int node_impl_get_props(void *data, struct spa_props **props)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
return spa_node_get_props(impl->node, props);
|
||||
}
|
||||
|
||||
static int node_impl_set_props(void *data, const struct spa_props *props)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
return spa_node_set_props(impl->node, props);
|
||||
}
|
||||
|
||||
static int node_impl_send_command(void *data, const struct spa_command *command)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
return spa_node_send_command(impl->node, command);
|
||||
}
|
||||
|
||||
static struct pw_port*
|
||||
node_impl_add_port(void *data,
|
||||
enum pw_direction direction,
|
||||
uint32_t port_id)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
int res;
|
||||
|
||||
if ((res = spa_node_add_port(impl->node, direction, port_id)) < 0) {
|
||||
pw_log_error("node %p: could not add port %d %d", impl->this, port_id, res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return make_port(impl, direction, port_id);
|
||||
}
|
||||
|
||||
static int node_impl_process_input(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
return spa_node_process_input(impl->node);
|
||||
}
|
||||
|
||||
static int node_impl_process_output(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
return spa_node_process_output(impl->node);
|
||||
}
|
||||
|
||||
static const struct pw_node_implementation node_impl = {
|
||||
PW_VERSION_NODE_IMPLEMENTATION,
|
||||
.get_props = node_impl_get_props,
|
||||
.set_props = node_impl_set_props,
|
||||
.send_command = node_impl_send_command,
|
||||
.add_port = node_impl_add_port,
|
||||
.process_input = node_impl_process_input,
|
||||
.process_output = node_impl_process_output,
|
||||
};
|
||||
|
||||
static void pw_spa_node_destroy(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
|
|
@ -280,7 +119,7 @@ static void complete_init(struct impl *impl)
|
|||
pw_node_register(this);
|
||||
}
|
||||
|
||||
static void on_node_done(void *data, int seq, int res)
|
||||
static void on_node_done(void *data, uint32_t seq, int res)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_node *this = impl->this;
|
||||
|
|
@ -289,54 +128,13 @@ static void on_node_done(void *data, int seq, int res)
|
|||
complete_init(impl);
|
||||
impl->async_init = false;
|
||||
}
|
||||
|
||||
pw_log_debug("spa-node %p: async complete event %d %d", this, seq, res);
|
||||
spa_hook_list_call(pw_node_get_listeners(this), struct pw_node_events, async_complete, seq, res);
|
||||
}
|
||||
|
||||
static void on_node_event(void *data, struct spa_event *event)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_node *this = impl->this;
|
||||
|
||||
spa_hook_list_call(pw_node_get_listeners(this), struct pw_node_events, event, event);
|
||||
}
|
||||
|
||||
static void on_node_need_input(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_node *this = impl->this;
|
||||
spa_hook_list_call(pw_node_get_listeners(this), struct pw_node_events, need_input);
|
||||
}
|
||||
|
||||
static void on_node_have_output(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_node *this = impl->this;
|
||||
spa_hook_list_call(pw_node_get_listeners(this), struct pw_node_events, have_output);
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_reuse_buffer(void *data, uint32_t port_id, uint32_t buffer_id)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct pw_node *this = impl->this;
|
||||
spa_hook_list_call(pw_node_get_listeners(this), struct pw_node_events,
|
||||
reuse_buffer, port_id, buffer_id);
|
||||
}
|
||||
|
||||
static const struct spa_node_callbacks spa_node_callbacks = {
|
||||
SPA_VERSION_NODE_CALLBACKS,
|
||||
.done = on_node_done,
|
||||
.event = on_node_event,
|
||||
.need_input = on_node_need_input,
|
||||
.have_output = on_node_have_output,
|
||||
.reuse_buffer = on_node_reuse_buffer,
|
||||
};
|
||||
|
||||
static const struct pw_node_events node_events = {
|
||||
PW_VERSION_NODE_EVENTS,
|
||||
.destroy = pw_spa_node_destroy,
|
||||
.async_complete = on_node_done,
|
||||
};
|
||||
|
||||
struct pw_node *
|
||||
|
|
@ -379,11 +177,7 @@ pw_spa_node_new(struct pw_core *core,
|
|||
impl->async_init = async;
|
||||
|
||||
pw_node_add_listener(this, &impl->node_listener, &node_events, impl);
|
||||
|
||||
pw_node_set_implementation(this, &node_impl, impl);
|
||||
|
||||
if (spa_node_set_callbacks(impl->node, &spa_node_callbacks, impl) < 0)
|
||||
pw_log_warn("spa-node %p: error setting callback", this);
|
||||
pw_node_set_implementation(this, node);
|
||||
|
||||
if (!async)
|
||||
complete_init(impl);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue