Rework node and ports

Rework the node and port API so that other implementations can be used
than the spa_node. The plan is to morph this into the stream and
context API.
Rework the graph API a little so that init + add is separated.
This commit is contained in:
Wim Taymans 2017-07-07 17:55:26 +02:00
parent b0f5d34cf7
commit 0738f7fcf5
28 changed files with 1585 additions and 857 deletions

View file

@ -38,21 +38,34 @@ static inline void spa_graph_scheduler_init(struct spa_graph_scheduler *sched,
sched->node = NULL;
}
static inline int spa_graph_scheduler_default(struct spa_graph_node *node)
static inline int spa_graph_scheduler_input(struct spa_graph_node *node, void *user_data)
{
int res;
struct spa_node *n = node->user_data;
if (node->action == SPA_GRAPH_ACTION_IN)
res = spa_node_process_input(n);
else if (node->action == SPA_GRAPH_ACTION_OUT)
res = spa_node_process_output(n);
else
res = SPA_RESULT_ERROR;
return res;
return spa_node_process_input(n);
}
static inline int spa_graph_scheduler_output(struct spa_graph_node *node, void *user_data)
{
struct spa_node *n = node->user_data;
return spa_node_process_output(n);
}
static inline int spa_graph_scheduler_reuse_buffer(struct spa_graph_port *port,
uint32_t buffer_id, void *user_data)
{
printf("port %p reuse buffer %d\n", port, buffer_id);
struct spa_graph_node *node = port->node;
struct spa_node *n = node->user_data;
return spa_node_port_reuse_buffer(n, port->port_id, buffer_id);
}
static const struct spa_graph_node_methods spa_graph_scheduler_default = {
SPA_VERSION_GRAPH_NODE_METHODS,
spa_graph_scheduler_input,
spa_graph_scheduler_output,
spa_graph_scheduler_reuse_buffer,
};
static inline void spa_graph_scheduler_pull(struct spa_graph_scheduler *sched, struct spa_graph_node *node)
{
struct spa_graph_port *p;
@ -79,9 +92,8 @@ static inline void spa_graph_scheduler_pull(struct spa_graph_scheduler *sched, s
}
spa_list_for_each_safe(n, t, &ready, ready_link) {
n->action = SPA_GRAPH_ACTION_OUT;
n->state = n->schedule(n);
debug("peer %p scheduled %d %d\n", n, n->action, n->state);
n->state = n->methods->schedule_output(n, n->user_data);
debug("peer %p scheduled out %d\n", n, n->state);
if (n->state == SPA_RESULT_NEED_BUFFER)
spa_graph_scheduler_pull(sched, n);
else {
@ -97,9 +109,8 @@ static inline void spa_graph_scheduler_pull(struct spa_graph_scheduler *sched, s
debug("node %p %d %d\n", node, node->ready_in, node->required_in);
if (node->required_in > 0 && node->ready_in == node->required_in) {
node->action = SPA_GRAPH_ACTION_IN;
node->state = node->schedule(node);
debug("node %p scheduled %d %d\n", node, node->action, node->state);
node->state = node->methods->schedule_input(node, node->user_data);
debug("node %p scheduled in %d\n", node, node->state);
if (node->state == SPA_RESULT_HAVE_BUFFER) {
spa_list_for_each(p, &node->ports[SPA_DIRECTION_OUTPUT], link) {
if (p->io->status == SPA_RESULT_HAVE_BUFFER)
@ -143,9 +154,8 @@ static inline void spa_graph_scheduler_push(struct spa_graph_scheduler *sched, s
}
spa_list_for_each_safe(n, t, &ready, ready_link) {
n->action = SPA_GRAPH_ACTION_IN;
n->state = n->schedule(n);
debug("peer %p scheduled %d %d\n", n, n->action, n->state);
n->state = n->methods->schedule_input(n, n->user_data);
debug("peer %p scheduled in %d\n", n, n->state);
if (n->state == SPA_RESULT_HAVE_BUFFER)
spa_graph_scheduler_push(sched, n);
else {
@ -159,9 +169,8 @@ static inline void spa_graph_scheduler_push(struct spa_graph_scheduler *sched, s
n->ready_link.next = NULL;
}
node->action = SPA_GRAPH_ACTION_OUT;
node->state = node->schedule(node);
debug("node %p scheduled %d %d\n", node, node->action, node->state);
node->state = node->methods->schedule_output(node, node->user_data);
debug("node %p scheduled out %d\n", node, node->state);
if (node->state == SPA_RESULT_NEED_BUFFER) {
node->ready_in = 0;
spa_list_for_each(p, &node->ports[SPA_DIRECTION_INPUT], link) {