mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
graph: use spa_node as implementation
Always use a spa_node as the graph implementation, implementing the methods is just as easy. Plug some mem leaks in remote
This commit is contained in:
parent
6953642ed5
commit
577f86be0d
16 changed files with 167 additions and 206 deletions
|
|
@ -45,24 +45,6 @@ static inline void spa_graph_data_init(struct spa_graph_data *data,
|
|||
data->node = NULL;
|
||||
}
|
||||
|
||||
static inline int spa_graph_node_impl_input(void *data)
|
||||
{
|
||||
struct spa_node *n = data;
|
||||
return spa_node_process_input(n);
|
||||
}
|
||||
|
||||
static inline int spa_graph_node_impl_output(void *data)
|
||||
{
|
||||
struct spa_node *n = data;
|
||||
return spa_node_process_output(n);
|
||||
}
|
||||
|
||||
static const struct spa_graph_node_callbacks spa_graph_node_impl_default = {
|
||||
SPA_VERSION_GRAPH_NODE_CALLBACKS,
|
||||
spa_graph_node_impl_input,
|
||||
spa_graph_node_impl_output,
|
||||
};
|
||||
|
||||
static inline void spa_graph_data_port_check(struct spa_graph_data *data, struct spa_graph_port *port)
|
||||
{
|
||||
struct spa_graph_node *node = port->node;
|
||||
|
|
@ -70,7 +52,8 @@ static inline void spa_graph_data_port_check(struct spa_graph_data *data, struct
|
|||
if (port->io->status == SPA_RESULT_HAVE_BUFFER)
|
||||
node->ready_in++;
|
||||
|
||||
debug("port %p node %p check %d %d %d\n", port, node, port->io->status, node->ready_in, node->required_in);
|
||||
debug("port %p node %p check %d %d %d\n", port, node,
|
||||
port->io->status, node->ready_in, node->required_in);
|
||||
|
||||
if (node->required_in > 0 && node->ready_in == node->required_in) {
|
||||
node->state = SPA_GRAPH_STATE_IN;
|
||||
|
|
@ -100,7 +83,7 @@ static inline bool spa_graph_data_iterate(struct spa_graph_data *data)
|
|||
|
||||
switch (n->state) {
|
||||
case SPA_GRAPH_STATE_IN:
|
||||
state = n->callbacks->process_input(n->callbacks_data);
|
||||
state = spa_node_process_input(n->implementation);
|
||||
if (state == SPA_RESULT_NEED_BUFFER)
|
||||
n->state = SPA_GRAPH_STATE_CHECK_IN;
|
||||
else if (state == SPA_RESULT_HAVE_BUFFER)
|
||||
|
|
@ -112,7 +95,7 @@ static inline bool spa_graph_data_iterate(struct spa_graph_data *data)
|
|||
break;
|
||||
|
||||
case SPA_GRAPH_STATE_OUT:
|
||||
state = n->callbacks->process_output(n->callbacks_data);
|
||||
state = spa_node_process_output(n->implementation);
|
||||
if (state == SPA_RESULT_NEED_BUFFER)
|
||||
n->state = SPA_GRAPH_STATE_CHECK_IN;
|
||||
else if (state == SPA_RESULT_HAVE_BUFFER)
|
||||
|
|
|
|||
|
|
@ -26,38 +26,6 @@ extern "C" {
|
|||
|
||||
#include <spa/graph.h>
|
||||
|
||||
static inline int spa_graph_node_impl_input(void *data)
|
||||
{
|
||||
struct spa_node *n = data;
|
||||
return spa_node_process_input(n);
|
||||
}
|
||||
|
||||
static inline int spa_graph_node_impl_output(void *data)
|
||||
{
|
||||
struct spa_node *n = data;
|
||||
return spa_node_process_output(n);
|
||||
}
|
||||
|
||||
static const struct spa_graph_node_callbacks spa_graph_node_impl_default = {
|
||||
SPA_VERSION_GRAPH_NODE_CALLBACKS,
|
||||
spa_graph_node_impl_input,
|
||||
spa_graph_node_impl_output,
|
||||
};
|
||||
|
||||
static inline int spa_graph_port_impl_reuse_buffer(void *data,
|
||||
uint32_t buffer_id)
|
||||
{
|
||||
struct spa_graph_port *port = data;
|
||||
struct spa_node *node = port->node->callbacks_data;
|
||||
debug("port %p reuse buffer %d\n", port, buffer_id);
|
||||
return spa_node_port_reuse_buffer(node, port->port_id, buffer_id);
|
||||
}
|
||||
|
||||
static const struct spa_graph_port_callbacks spa_graph_port_impl_default = {
|
||||
SPA_VERSION_GRAPH_PORT_CALLBACKS,
|
||||
spa_graph_port_impl_reuse_buffer,
|
||||
};
|
||||
|
||||
static inline int spa_graph_impl_need_input(void *data, struct spa_graph_node *node)
|
||||
{
|
||||
struct spa_graph_port *p;
|
||||
|
|
@ -85,7 +53,7 @@ static inline int spa_graph_impl_need_input(void *data, struct spa_graph_node *n
|
|||
}
|
||||
|
||||
spa_list_for_each_safe(n, t, &ready, ready_link) {
|
||||
n->state = n->callbacks->process_output(n->callbacks_data);
|
||||
n->state = spa_node_process_output(n->implementation);
|
||||
debug("peer %p processed out %d\n", n, n->state);
|
||||
if (n->state == SPA_RESULT_NEED_BUFFER)
|
||||
spa_graph_need_input(n->graph, n);
|
||||
|
|
@ -102,7 +70,7 @@ static inline int spa_graph_impl_need_input(void *data, struct spa_graph_node *n
|
|||
debug("node %p ready_in:%d required_in:%d\n", node, node->ready_in, node->required_in);
|
||||
|
||||
if (node->required_in > 0 && node->ready_in == node->required_in) {
|
||||
node->state = node->callbacks->process_input(node->callbacks_data);
|
||||
node->state = spa_node_process_input(node->implementation);
|
||||
debug("node %p processed in %d\n", node, node->state);
|
||||
if (node->state == SPA_RESULT_HAVE_BUFFER) {
|
||||
spa_list_for_each(p, &node->ports[SPA_DIRECTION_OUTPUT], link) {
|
||||
|
|
@ -143,7 +111,7 @@ static inline int spa_graph_impl_have_output(void *data, struct spa_graph_node *
|
|||
}
|
||||
|
||||
spa_list_for_each_safe(n, t, &ready, ready_link) {
|
||||
n->state = n->callbacks->process_input(n->callbacks_data);
|
||||
n->state = spa_node_process_input(n->implementation);
|
||||
debug("node %p chain processed in %d\n", n, n->state);
|
||||
if (n->state == SPA_RESULT_HAVE_BUFFER)
|
||||
spa_graph_have_output(n->graph, n);
|
||||
|
|
@ -159,7 +127,7 @@ static inline int spa_graph_impl_have_output(void *data, struct spa_graph_node *
|
|||
n->ready_link.next = NULL;
|
||||
}
|
||||
|
||||
node->state = node->callbacks->process_output(node->callbacks_data);
|
||||
node->state = spa_node_process_output(node->implementation);
|
||||
debug("node %p processed out %d\n", node, node->state);
|
||||
if (node->state == SPA_RESULT_NEED_BUFFER) {
|
||||
node->ready_in = 0;
|
||||
|
|
|
|||
|
|
@ -56,21 +56,7 @@ struct spa_graph {
|
|||
|
||||
#define spa_graph_need_input(g,n) ((g)->callbacks->need_input((g)->callbacks_data, (n)))
|
||||
#define spa_graph_have_output(g,n) ((g)->callbacks->have_output((g)->callbacks_data, (n)))
|
||||
|
||||
struct spa_graph_node_callbacks {
|
||||
#define SPA_VERSION_GRAPH_NODE_CALLBACKS 0
|
||||
uint32_t version;
|
||||
|
||||
int (*process_input) (void *data);
|
||||
int (*process_output) (void *data);
|
||||
};
|
||||
|
||||
struct spa_graph_port_callbacks {
|
||||
#define SPA_VERSION_GRAPH_PORT_CALLBACKS 0
|
||||
uint32_t version;
|
||||
|
||||
int (*reuse_buffer) (void *data, uint32_t buffer_id);
|
||||
};
|
||||
#define spa_graph_reuse_buffer(g,n,p,i) ((g)->callbacks->reuse_buffer((g)->callbacks_data, (n),(p),(i)))
|
||||
|
||||
struct spa_graph_node {
|
||||
struct spa_list link; /**< link in graph nodes list */
|
||||
|
|
@ -82,9 +68,7 @@ struct spa_graph_node {
|
|||
uint32_t required_in; /**< required number of ports */
|
||||
uint32_t ready_in; /**< number of ports with data */
|
||||
int state; /**< state of the node */
|
||||
/** callbacks and data */
|
||||
const struct spa_graph_node_callbacks *callbacks;
|
||||
void *callbacks_data;
|
||||
struct spa_node *implementation;/**< node implementation */
|
||||
void *scheduler_data; /**< scheduler private data */
|
||||
};
|
||||
|
||||
|
|
@ -96,9 +80,6 @@ struct spa_graph_port {
|
|||
uint32_t flags; /**< port flags */
|
||||
struct spa_port_io *io; /**< io area of the port */
|
||||
struct spa_graph_port *peer; /**< peer */
|
||||
/** callbacks and data */
|
||||
const struct spa_graph_port_callbacks *callbacks;
|
||||
void *callbacks_data;
|
||||
void *scheduler_data; /**< scheduler private data */
|
||||
};
|
||||
|
||||
|
|
@ -127,12 +108,10 @@ spa_graph_node_init(struct spa_graph_node *node)
|
|||
}
|
||||
|
||||
static inline void
|
||||
spa_graph_node_set_callbacks(struct spa_graph_node *node,
|
||||
const struct spa_graph_node_callbacks *callbacks,
|
||||
void *data)
|
||||
spa_graph_node_set_implementation(struct spa_graph_node *node,
|
||||
struct spa_node *implementation)
|
||||
{
|
||||
node->callbacks = callbacks;
|
||||
node->callbacks_data = data;
|
||||
node->implementation = implementation;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -160,15 +139,6 @@ spa_graph_port_init(struct spa_graph_port *port,
|
|||
port->io = io;
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_graph_port_set_callbacks(struct spa_graph_port *port,
|
||||
const struct spa_graph_port_callbacks *callbacks,
|
||||
void *data)
|
||||
{
|
||||
port->callbacks = callbacks;
|
||||
port->callbacks_data = data;
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_graph_port_add(struct spa_graph_node *node,
|
||||
struct spa_graph_port *port)
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ static int loop_iterate(struct spa_loop_control *ctrl, int timeout)
|
|||
}
|
||||
}
|
||||
spa_list_for_each_safe(source, tmp, &impl->destroy_list, link)
|
||||
free(source);
|
||||
free(source);
|
||||
|
||||
spa_list_init(&impl->destroy_list);
|
||||
|
||||
|
|
|
|||
|
|
@ -337,13 +337,13 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, &data->volume_sink_io[0]);
|
||||
|
||||
spa_graph_node_init(&data->source_node);
|
||||
spa_graph_node_set_callbacks(&data->source_node, &spa_graph_node_impl_default, data->source);
|
||||
spa_graph_node_set_implementation(&data->source_node, data->source);
|
||||
spa_graph_node_add(&data->graph, &data->source_node);
|
||||
spa_graph_port_init(&data->source_out, SPA_DIRECTION_OUTPUT, 0, 0, &data->source_volume_io[0]);
|
||||
spa_graph_port_add(&data->source_node, &data->source_out);
|
||||
|
||||
spa_graph_node_init(&data->volume_node);
|
||||
spa_graph_node_set_callbacks(&data->volume_node, &spa_graph_node_impl_default, data->volume);
|
||||
spa_graph_node_set_implementation(&data->volume_node, data->volume);
|
||||
spa_graph_node_add(&data->graph, &data->volume_node);
|
||||
spa_graph_port_init(&data->volume_in, SPA_DIRECTION_INPUT, 0, 0, &data->source_volume_io[0]);
|
||||
spa_graph_port_add(&data->volume_node, &data->volume_in);
|
||||
|
|
@ -354,7 +354,7 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_graph_port_add(&data->volume_node, &data->volume_out);
|
||||
|
||||
spa_graph_node_init(&data->sink_node);
|
||||
spa_graph_node_set_callbacks(&data->sink_node, &spa_graph_node_impl_default, data->sink);
|
||||
spa_graph_node_set_implementation(&data->sink_node, data->sink);
|
||||
spa_graph_node_add(&data->graph, &data->sink_node);
|
||||
spa_graph_port_init(&data->sink_in, SPA_DIRECTION_INPUT, 0, 0, &data->volume_sink_io[0]);
|
||||
spa_graph_port_add(&data->sink_node, &data->sink_in);
|
||||
|
|
|
|||
|
|
@ -414,19 +414,19 @@ static int make_nodes(struct data *data, const char *device)
|
|||
|
||||
#ifdef USE_GRAPH
|
||||
spa_graph_node_init(&data->source1_node);
|
||||
spa_graph_node_set_callbacks(&data->source1_node, &spa_graph_node_impl_default, data->source1);
|
||||
spa_graph_node_set_implementation(&data->source1_node, data->source1);
|
||||
spa_graph_port_init(&data->source1_out, SPA_DIRECTION_OUTPUT, 0, 0, &data->source1_mix_io[0]);
|
||||
spa_graph_port_add(&data->source1_node, &data->source1_out);
|
||||
spa_graph_node_add(&data->graph, &data->source1_node);
|
||||
|
||||
spa_graph_node_init(&data->source2_node);
|
||||
spa_graph_node_set_callbacks(&data->source2_node, &spa_graph_node_impl_default, data->source2);
|
||||
spa_graph_node_set_implementation(&data->source2_node, data->source2);
|
||||
spa_graph_port_init(&data->source2_out, SPA_DIRECTION_OUTPUT, 0, 0, &data->source2_mix_io[0]);
|
||||
spa_graph_port_add(&data->source2_node, &data->source2_out);
|
||||
spa_graph_node_add(&data->graph, &data->source2_node);
|
||||
|
||||
spa_graph_node_init(&data->mix_node);
|
||||
spa_graph_node_set_callbacks(&data->mix_node, &spa_graph_node_impl_default, data->mix);
|
||||
spa_graph_node_set_implementation(&data->mix_node, data->mix);
|
||||
spa_graph_port_init(&data->mix_in[0], SPA_DIRECTION_INPUT,
|
||||
data->mix_ports[0], 0, &data->source1_mix_io[0]);
|
||||
spa_graph_port_add(&data->mix_node, &data->mix_in[0]);
|
||||
|
|
@ -442,7 +442,7 @@ static int make_nodes(struct data *data, const char *device)
|
|||
spa_graph_port_add(&data->mix_node, &data->mix_out);
|
||||
|
||||
spa_graph_node_init(&data->sink_node);
|
||||
spa_graph_node_set_callbacks(&data->sink_node, &spa_graph_node_impl_default, data->sink);
|
||||
spa_graph_node_set_implementation(&data->sink_node, data->sink);
|
||||
spa_graph_port_init(&data->sink_in, SPA_DIRECTION_INPUT, 0, 0, &data->mix_sink_io[0]);
|
||||
spa_graph_port_add(&data->sink_node, &data->sink_in);
|
||||
spa_graph_node_add(&data->graph, &data->sink_node);
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ static int make_nodes(struct data *data)
|
|||
spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, &data->source_sink_io[0]);
|
||||
|
||||
spa_graph_node_init(&data->source_node);
|
||||
spa_graph_node_set_callbacks(&data->source_node, &spa_graph_node_impl_default, data->source);
|
||||
spa_graph_node_set_implementation(&data->source_node, data->source);
|
||||
spa_graph_node_add(&data->graph, &data->source_node);
|
||||
|
||||
data->source_node.flags = (data->mode & MODE_ASYNC_PUSH) ? SPA_GRAPH_NODE_FLAG_ASYNC : 0;
|
||||
|
|
@ -370,7 +370,7 @@ static int make_nodes(struct data *data)
|
|||
spa_graph_port_add(&data->source_node, &data->source_out);
|
||||
|
||||
spa_graph_node_init(&data->sink_node);
|
||||
spa_graph_node_set_callbacks(&data->sink_node, &spa_graph_node_impl_default, data->sink);
|
||||
spa_graph_node_set_implementation(&data->sink_node, data->sink);
|
||||
spa_graph_node_add(&data->graph, &data->sink_node);
|
||||
|
||||
data->sink_node.flags = (data->mode & MODE_ASYNC_PULL) ? SPA_GRAPH_NODE_FLAG_ASYNC : 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue