mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
simplify things with just 1 process function
Make just one process function in spa node. With the io area states we can do more complicated io patterns.
This commit is contained in:
parent
e8d0281982
commit
9b0a880afb
21 changed files with 202 additions and 359 deletions
|
|
@ -136,21 +136,35 @@ static inline int spa_graph_impl_have_output(void *data, struct spa_graph_node *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline void spa_graph_impl_add_graph(struct spa_graph *g, struct spa_list *pending)
|
||||
{
|
||||
struct spa_graph_node *n;
|
||||
struct spa_graph *sg;
|
||||
|
||||
spa_list_for_each(n, &g->nodes, link) {
|
||||
n->state->pending = n->state->required + 1;
|
||||
spa_debug("graph %p node %p: add %d %d status %d", g, n,
|
||||
n->state->pending, n->state->required, n->state->status);
|
||||
spa_list_append(pending, &n->sched_link);
|
||||
}
|
||||
spa_list_for_each(sg, &g->subgraphs, link)
|
||||
spa_graph_impl_add_graph(sg, pending);
|
||||
}
|
||||
|
||||
static inline int spa_graph_impl_run(void *data)
|
||||
{
|
||||
struct spa_graph_data *d = (struct spa_graph_data *) data;
|
||||
struct spa_graph *g = d->graph;
|
||||
struct spa_graph_node *n;
|
||||
struct spa_graph_node *n, *tmp;
|
||||
struct spa_list pending;
|
||||
|
||||
spa_debug("graph %p run", d->graph);
|
||||
|
||||
spa_list_for_each(n, &g->nodes, link) {
|
||||
n->state->pending = n->state->required + 1;
|
||||
spa_debug("node %p: add %d %d status %d", n,
|
||||
n->state->pending, n->state->required,
|
||||
n->state->status);
|
||||
}
|
||||
spa_list_for_each(n, &g->nodes, link)
|
||||
spa_list_init(&pending);
|
||||
|
||||
spa_graph_impl_add_graph(g, &pending);
|
||||
|
||||
spa_list_for_each_safe(n, tmp, &pending, sched_link)
|
||||
spa_graph_trigger(d->graph, n);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ struct spa_graph_callbacks {
|
|||
|
||||
struct spa_graph {
|
||||
struct spa_list link; /* link for subgraph */
|
||||
#define SPA_GRAPH_FLAG_DRIVER (1 << 0)
|
||||
uint32_t flags; /* flags */
|
||||
struct spa_graph *parent; /* parent graph or NULL when driver */
|
||||
struct spa_list nodes; /* list of nodes of this graph */
|
||||
struct spa_list subgraphs; /* list of subgraphs */
|
||||
|
|
@ -55,25 +57,6 @@ struct spa_graph {
|
|||
void *callbacks_data;
|
||||
};
|
||||
|
||||
static inline struct spa_graph * spa_graph_find_root(struct spa_graph *graph)
|
||||
{
|
||||
while (graph->parent)
|
||||
graph = graph->parent;
|
||||
return graph;
|
||||
}
|
||||
|
||||
static inline void spa_graph_add_subgraph(struct spa_graph *graph, struct spa_graph *subgraph)
|
||||
{
|
||||
subgraph->parent = graph;
|
||||
spa_list_append(&graph->subgraphs, &subgraph->link);
|
||||
}
|
||||
|
||||
static inline void spa_graph_remove_subgraph(struct spa_graph *subgraph)
|
||||
{
|
||||
subgraph->parent = NULL;
|
||||
spa_list_remove(&subgraph->link);
|
||||
}
|
||||
|
||||
#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)))
|
||||
#define spa_graph_run(g) ((g)->callbacks->run((g)->callbacks_data))
|
||||
|
|
@ -124,6 +107,8 @@ static inline void spa_graph_init(struct spa_graph *graph)
|
|||
{
|
||||
spa_list_init(&graph->nodes);
|
||||
spa_list_init(&graph->subgraphs);
|
||||
graph->flags = 0;
|
||||
spa_debug("graph %p init", graph);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -135,6 +120,27 @@ spa_graph_set_callbacks(struct spa_graph *graph,
|
|||
graph->callbacks_data = data;
|
||||
}
|
||||
|
||||
static inline struct spa_graph *spa_graph_find_root(struct spa_graph *graph)
|
||||
{
|
||||
while (graph->parent)
|
||||
graph = graph->parent;
|
||||
return graph;
|
||||
}
|
||||
|
||||
static inline void spa_graph_add_subgraph(struct spa_graph *graph, struct spa_graph *subgraph)
|
||||
{
|
||||
subgraph->parent = graph;
|
||||
spa_list_append(&graph->subgraphs, &subgraph->link);
|
||||
spa_debug("graph %p add subgraph %p", graph, subgraph);
|
||||
}
|
||||
|
||||
static inline void spa_graph_remove_subgraph(struct spa_graph *subgraph)
|
||||
{
|
||||
subgraph->parent = NULL;
|
||||
spa_list_remove(&subgraph->link);
|
||||
spa_debug("graph %p remove subgraph", subgraph);
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_graph_node_init(struct spa_graph_node *node, struct spa_graph_state *state)
|
||||
{
|
||||
|
|
@ -163,7 +169,7 @@ spa_graph_node_add(struct spa_graph *graph,
|
|||
node->graph = graph;
|
||||
node->sched_link.next = NULL;
|
||||
spa_list_append(&graph->nodes, &node->link);
|
||||
spa_debug("node %p add", node);
|
||||
spa_debug("node %p add to graph %p", node, graph);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -241,15 +247,9 @@ static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node
|
|||
{
|
||||
struct spa_graph *g = node->graph;
|
||||
struct spa_node *n = data;
|
||||
//int old = node->state->status, res = 0;
|
||||
int res = 0;
|
||||
|
||||
// if (old == SPA_STATUS_NEED_BUFFER && n->process_input &&
|
||||
if (n->process_input &&
|
||||
!spa_list_is_empty(&node->ports[SPA_DIRECTION_INPUT]))
|
||||
res = spa_node_process_input(n);
|
||||
else
|
||||
res = spa_node_process_output(n);
|
||||
res = spa_node_process(n);
|
||||
|
||||
spa_debug("node %p: process %d", node, res);
|
||||
|
||||
|
|
@ -258,8 +258,6 @@ static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node
|
|||
if (res == SPA_STATUS_HAVE_BUFFER)
|
||||
spa_graph_have_output(g, node);
|
||||
|
||||
spa_debug("node %p: end %d", node, res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -479,81 +479,21 @@ struct spa_node {
|
|||
uint32_t port_id,
|
||||
const struct spa_command *command);
|
||||
/**
|
||||
* Process the input area of the node.
|
||||
* Process the node
|
||||
*
|
||||
* For synchronous nodes, this function is called to start processing data
|
||||
* or when process_output returned SPA_STATUS_NEED_BUFFER
|
||||
* Output io areas with SPA_STATUS_NEED_BUFFER will recycle the
|
||||
* buffers if any.
|
||||
*
|
||||
* For Asynchronous nodes, this function is called when a need_input event
|
||||
* is received from the node.
|
||||
* Input areas with SPA_STATUS_HAVE_BUFFER are consumed if possible
|
||||
* and the status is set to SPA_STATUS_NEED_BUFFER or SPA_STATUS_OK.
|
||||
*
|
||||
* Before calling this function, you must configure spa_port_io structures
|
||||
* on the input ports you want to process data on.
|
||||
* When the node has new output buffers, SPA_STATUS_HAVE_BUFFER
|
||||
* is returned.
|
||||
*
|
||||
* The node will loop through all spa_port_io structures and will
|
||||
* process the buffers. For each port, the port io will be used as:
|
||||
*
|
||||
* - if status is set to SPA_STATUS_HAVE_BUFFER, buffer_id is read and processed.
|
||||
*
|
||||
* The spa_port_io of the port is then updated as follows.
|
||||
*
|
||||
* - buffer_id is set to a buffer id that should be reused. SPA_ID_INVALID
|
||||
* is set when there is no buffer to reuse
|
||||
*
|
||||
* - status is set to SPA_STATUS_OK when no new buffer is needed on the port
|
||||
*
|
||||
* - status is set to SPA_STATUS_NEED_BUFFER when a new buffer is needed
|
||||
* on the port.
|
||||
*
|
||||
* - status is set to a negative errno style error code when the buffer_id
|
||||
* was invalid or any processing error happened on the port.
|
||||
*
|
||||
* This function must be called from the data thread.
|
||||
*
|
||||
* \param node a spa_node
|
||||
* \return SPA_STATUS_OK on success or when the node is asynchronous
|
||||
* SPA_STATUS_HAVE_BUFFER for synchronous nodes when output
|
||||
* can be consumed.
|
||||
* < 0 for errno style errors. One or more of the spa_port_io
|
||||
* areas has an error.
|
||||
* When no new output could be produced, SPA_STATUS_NEED_BUFFER is
|
||||
* returned.
|
||||
*/
|
||||
int (*process_input) (struct spa_node *node);
|
||||
|
||||
/**
|
||||
* Tell the node that output is consumed.
|
||||
*
|
||||
* For synchronous nodes, this function can be called when process_input
|
||||
* returned SPA_STATUS_HAVE_BUFFER and the output on the spa_port_io
|
||||
* areas has been consumed.
|
||||
*
|
||||
* For Asynchronous node, this function is called when a have_output event
|
||||
* is received from the node.
|
||||
*
|
||||
* Before calling this function you must process the buffers
|
||||
* in each of the output ports spa_port_io structure as follows:
|
||||
*
|
||||
* - use the buffer_id from the io for all the ports where the status is
|
||||
* SPA_STATUS_HAVE_BUFFER
|
||||
*
|
||||
* - set buffer_id to a buffer_id you would like to reuse or SPA_ID_INVALID
|
||||
* when no buffer is to be reused.
|
||||
*
|
||||
* - set the status to SPA_STATUS_NEED_BUFFER for all port you want more
|
||||
* output from
|
||||
*
|
||||
* - set the status to SPA_STATUS_OK for the port you don't want more
|
||||
* buffers from.
|
||||
*
|
||||
* This function must be called from the data thread.
|
||||
*
|
||||
* \param node a spa_node
|
||||
* \return SPA_STATUS_OK on success or when the node is asynchronous
|
||||
* SPA_STATUS_NEED_BUFFER for synchronous nodes when input
|
||||
* is needed.
|
||||
* < 0 for errno style errors. One or more of the spa_port_io
|
||||
* areas has an error.
|
||||
*/
|
||||
int (*process_output) (struct spa_node *node);
|
||||
int (*process) (struct spa_node *node);
|
||||
};
|
||||
|
||||
#define spa_node_enum_params(n,...) (n)->enum_params((n),__VA_ARGS__)
|
||||
|
|
@ -572,8 +512,7 @@ struct spa_node {
|
|||
#define spa_node_port_set_io(n,...) (n)->port_set_io((n),__VA_ARGS__)
|
||||
#define spa_node_port_reuse_buffer(n,...) (n)->port_reuse_buffer((n),__VA_ARGS__)
|
||||
#define spa_node_port_send_command(n,...) (n)->port_send_command((n),__VA_ARGS__)
|
||||
#define spa_node_process_input(n) (n)->process_input((n))
|
||||
#define spa_node_process_output(n) (n)->process_output((n))
|
||||
#define spa_node_process(n) (n)->process((n))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue