mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
link: work on activate/deactivate
Recursively activate links when activating nodes
This commit is contained in:
parent
d2f877912a
commit
9fa1df6f2c
13 changed files with 215 additions and 133 deletions
|
|
@ -28,6 +28,7 @@ extern "C" {
|
|||
|
||||
struct spa_graph_scheduler {
|
||||
struct spa_graph *graph;
|
||||
struct spa_list ready;
|
||||
struct spa_list pending;
|
||||
struct spa_graph_node *node;
|
||||
};
|
||||
|
|
@ -36,6 +37,7 @@ static inline void spa_graph_scheduler_init(struct spa_graph_scheduler *sched,
|
|||
struct spa_graph *graph)
|
||||
{
|
||||
sched->graph = graph;
|
||||
spa_list_init(&sched->ready);
|
||||
spa_list_init(&sched->pending);
|
||||
sched->node = NULL;
|
||||
}
|
||||
|
|
@ -55,16 +57,34 @@ static inline int spa_graph_scheduler_default(struct spa_graph_node *node)
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline void spa_scheduler_port_check(struct spa_graph_scheduler *sched, struct spa_graph_port *port)
|
||||
{
|
||||
struct spa_graph_node *node = port->node;
|
||||
|
||||
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);
|
||||
|
||||
if (node->required_in > 0 && node->ready_in == node->required_in) {
|
||||
node->action = SPA_GRAPH_ACTION_IN;
|
||||
if (node->ready_link.next == NULL)
|
||||
spa_list_insert(sched->ready.prev, &node->ready_link);
|
||||
} else if (node->ready_link.next) {
|
||||
spa_list_remove(&node->ready_link);
|
||||
node->ready_link.next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool spa_graph_scheduler_iterate(struct spa_graph_scheduler *sched)
|
||||
{
|
||||
bool res;
|
||||
struct spa_graph *graph = sched->graph;
|
||||
struct spa_graph_port *p;
|
||||
struct spa_graph_node *n;
|
||||
|
||||
res = !spa_list_is_empty(&graph->ready);
|
||||
res = !spa_list_is_empty(&sched->ready);
|
||||
if (res) {
|
||||
n = spa_list_first(&graph->ready, struct spa_graph_node, ready_link);
|
||||
n = spa_list_first(&sched->ready, struct spa_graph_node, ready_link);
|
||||
|
||||
spa_list_remove(&n->ready_link);
|
||||
n->ready_link.next = NULL;
|
||||
|
|
@ -79,7 +99,7 @@ static inline bool spa_graph_scheduler_iterate(struct spa_graph_scheduler *sched
|
|||
if (n->action == SPA_GRAPH_ACTION_IN && n == sched->node)
|
||||
break;
|
||||
n->action = SPA_GRAPH_ACTION_CHECK;
|
||||
spa_list_insert(graph->ready.prev, &n->ready_link);
|
||||
spa_list_insert(sched->ready.prev, &n->ready_link);
|
||||
break;
|
||||
|
||||
case SPA_GRAPH_ACTION_CHECK:
|
||||
|
|
@ -91,7 +111,7 @@ static inline bool spa_graph_scheduler_iterate(struct spa_graph_scheduler *sched
|
|||
if (pn != sched->node
|
||||
|| pn->flags & SPA_GRAPH_NODE_FLAG_ASYNC) {
|
||||
pn->action = SPA_GRAPH_ACTION_OUT;
|
||||
spa_list_insert(graph->ready.prev,
|
||||
spa_list_insert(sched->ready.prev,
|
||||
&pn->ready_link);
|
||||
}
|
||||
} else if (p->io->status == SPA_RESULT_OK)
|
||||
|
|
@ -99,14 +119,14 @@ static inline bool spa_graph_scheduler_iterate(struct spa_graph_scheduler *sched
|
|||
}
|
||||
} else if (n->state == SPA_RESULT_HAVE_BUFFER) {
|
||||
spa_list_for_each(p, &n->ports[SPA_DIRECTION_OUTPUT], link)
|
||||
spa_graph_port_check(graph, p->peer);
|
||||
spa_scheduler_port_check(sched, p->peer);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
res = !spa_list_is_empty(&graph->ready);
|
||||
res = !spa_list_is_empty(&sched->ready);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -118,7 +138,7 @@ static inline void spa_graph_scheduler_pull(struct spa_graph_scheduler *sched, s
|
|||
node->state = SPA_RESULT_NEED_BUFFER;
|
||||
sched->node = node;
|
||||
if (node->ready_link.next == NULL)
|
||||
spa_list_insert(sched->graph->ready.prev, &node->ready_link);
|
||||
spa_list_insert(sched->ready.prev, &node->ready_link);
|
||||
}
|
||||
|
||||
static inline void spa_graph_scheduler_push(struct spa_graph_scheduler *sched, struct spa_graph_node *node)
|
||||
|
|
@ -127,7 +147,7 @@ static inline void spa_graph_scheduler_push(struct spa_graph_scheduler *sched, s
|
|||
node->action = SPA_GRAPH_ACTION_OUT;
|
||||
sched->node = node;
|
||||
if (node->ready_link.next == NULL)
|
||||
spa_list_insert(sched->graph->ready.prev, &node->ready_link);
|
||||
spa_list_insert(sched->ready.prev, &node->ready_link);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -41,6 +41,36 @@ static inline int spa_graph_scheduler_default(struct spa_graph_node *node)
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline void spa_graph_port_check(struct spa_graph *graph, struct spa_graph_port *port)
|
||||
{
|
||||
struct spa_graph_node *node = port->node;
|
||||
|
||||
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);
|
||||
|
||||
if (node->required_in > 0 && node->ready_in == node->required_in) {
|
||||
node->action = SPA_GRAPH_ACTION_IN;
|
||||
if (node->ready_link.next == NULL)
|
||||
spa_list_insert(graph->ready.prev, &node->ready_link);
|
||||
} else if (node->ready_link.next) {
|
||||
spa_list_remove(&node->ready_link);
|
||||
node->ready_link.next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void spa_graph_node_update(struct spa_graph *graph, struct spa_graph_node *node) {
|
||||
struct spa_graph_port *p;
|
||||
|
||||
node->ready_in = 0;
|
||||
spa_list_for_each(p, &node->ports[SPA_DIRECTION_INPUT], link) {
|
||||
if (p->io->status == SPA_RESULT_OK && !(node->flags & SPA_GRAPH_NODE_FLAG_ASYNC))
|
||||
node->ready_in++;
|
||||
}
|
||||
debug("node %p update %d ready\n", node, node->ready_in);
|
||||
}
|
||||
|
||||
static inline bool spa_graph_scheduler_iterate(struct spa_graph *graph)
|
||||
{
|
||||
bool empty;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ extern "C" {
|
|||
|
||||
struct spa_graph_scheduler {
|
||||
struct spa_graph *graph;
|
||||
struct spa_list pending;
|
||||
struct spa_graph_node *node;
|
||||
};
|
||||
|
||||
|
|
@ -36,7 +35,6 @@ static inline void spa_graph_scheduler_init(struct spa_graph_scheduler *sched,
|
|||
struct spa_graph *graph)
|
||||
{
|
||||
sched->graph = graph;
|
||||
spa_list_init(&sched->pending);
|
||||
sched->node = NULL;
|
||||
}
|
||||
|
||||
|
|
@ -67,8 +65,11 @@ static inline void spa_graph_scheduler_pull(struct spa_graph_scheduler *sched, s
|
|||
|
||||
node->ready_in = 0;
|
||||
spa_list_for_each(p, &node->ports[SPA_DIRECTION_INPUT], link) {
|
||||
struct spa_graph_port *pport = p->peer;
|
||||
struct spa_graph_node *pnode = pport->node;
|
||||
struct spa_graph_port *pport;
|
||||
struct spa_graph_node *pnode;
|
||||
if ((pport = p->peer) == NULL)
|
||||
continue;
|
||||
pnode = pport->node;
|
||||
debug("node %p peer %p io %d\n", node, pnode, pport->io->status);
|
||||
if (pport->io->status == SPA_RESULT_NEED_BUFFER) {
|
||||
spa_list_insert(ready.prev, &pnode->ready_link);
|
||||
|
|
@ -102,7 +103,8 @@ static inline void spa_graph_scheduler_pull(struct spa_graph_scheduler *sched, s
|
|||
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)
|
||||
p->peer->node->ready_in++;
|
||||
if (p->peer)
|
||||
p->peer->node->ready_in++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -125,8 +127,11 @@ static inline void spa_graph_scheduler_push(struct spa_graph_scheduler *sched, s
|
|||
spa_list_init(&ready);
|
||||
|
||||
spa_list_for_each(p, &node->ports[SPA_DIRECTION_OUTPUT], link) {
|
||||
struct spa_graph_port *pport = p->peer;
|
||||
struct spa_graph_node *pnode = pport->node;
|
||||
struct spa_graph_port *pport;
|
||||
struct spa_graph_node *pnode;
|
||||
if ((pport = p->peer) == NULL)
|
||||
continue;
|
||||
pnode = pport->node;
|
||||
if (pport->io->status == SPA_RESULT_HAVE_BUFFER)
|
||||
pnode->ready_in++;
|
||||
|
||||
|
|
@ -161,7 +166,8 @@ static inline void spa_graph_scheduler_push(struct spa_graph_scheduler *sched, s
|
|||
node->ready_in = 0;
|
||||
spa_list_for_each(p, &node->ports[SPA_DIRECTION_INPUT], link) {
|
||||
if (p->io->status == SPA_RESULT_OK && !(n->flags & SPA_GRAPH_NODE_FLAG_ASYNC))
|
||||
p->peer->node->ready_in++;
|
||||
if (p->peer)
|
||||
p->peer->node->ready_in++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ struct spa_graph_port;
|
|||
|
||||
struct spa_graph {
|
||||
struct spa_list nodes;
|
||||
struct spa_list ready;
|
||||
};
|
||||
|
||||
typedef int (*spa_graph_node_func_t) (struct spa_graph_node * node);
|
||||
|
|
@ -76,7 +75,6 @@ struct spa_graph_port {
|
|||
static inline void spa_graph_init(struct spa_graph *graph)
|
||||
{
|
||||
spa_list_init(&graph->nodes);
|
||||
spa_list_init(&graph->ready);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
@ -96,36 +94,6 @@ spa_graph_node_add(struct spa_graph *graph, struct spa_graph_node *node,
|
|||
debug("node %p add\n", node);
|
||||
}
|
||||
|
||||
static inline void spa_graph_port_check(struct spa_graph *graph, struct spa_graph_port *port)
|
||||
{
|
||||
struct spa_graph_node *node = port->node;
|
||||
|
||||
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);
|
||||
|
||||
if (node->required_in > 0 && node->ready_in == node->required_in) {
|
||||
node->action = SPA_GRAPH_ACTION_IN;
|
||||
if (node->ready_link.next == NULL)
|
||||
spa_list_insert(graph->ready.prev, &node->ready_link);
|
||||
} else if (node->ready_link.next) {
|
||||
spa_list_remove(&node->ready_link);
|
||||
node->ready_link.next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void spa_graph_node_update(struct spa_graph *graph, struct spa_graph_node *node) {
|
||||
struct spa_graph_port *p;
|
||||
|
||||
node->ready_in = 0;
|
||||
spa_list_for_each(p, &node->ports[SPA_DIRECTION_INPUT], link) {
|
||||
if (p->io->status == SPA_RESULT_OK && !(node->flags & SPA_GRAPH_NODE_FLAG_ASYNC))
|
||||
node->ready_in++;
|
||||
}
|
||||
debug("node %p update %d ready\n", node, node->ready_in);
|
||||
}
|
||||
|
||||
static inline void
|
||||
spa_graph_port_add(struct spa_graph *graph,
|
||||
struct spa_graph_node *node,
|
||||
|
|
@ -135,7 +103,7 @@ spa_graph_port_add(struct spa_graph *graph,
|
|||
uint32_t flags,
|
||||
struct spa_port_io *io)
|
||||
{
|
||||
debug("port %p add %d to node %p \n", port, direction, node);
|
||||
debug("port %p add type %d id %d to node %p \n", port, direction, port_id, node);
|
||||
port->node = node;
|
||||
port->direction = direction;
|
||||
port->port_id = port_id;
|
||||
|
|
@ -145,7 +113,6 @@ spa_graph_port_add(struct spa_graph *graph,
|
|||
node->max_in++;
|
||||
if (!(port->flags & SPA_PORT_INFO_FLAG_OPTIONAL) && direction == SPA_DIRECTION_INPUT)
|
||||
node->required_in++;
|
||||
spa_graph_port_check(graph, port);
|
||||
}
|
||||
|
||||
static inline void spa_graph_node_remove(struct spa_graph *graph, struct spa_graph_node *node)
|
||||
|
|
|
|||
|
|
@ -256,6 +256,8 @@ static int impl_node_add_port(struct spa_node *node, enum spa_direction directio
|
|||
if (this->last_port <= port_id)
|
||||
this->last_port = port_id + 1;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: add port %d", this, port_id);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -289,6 +291,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3
|
|||
|
||||
this->last_port = i + 1;
|
||||
}
|
||||
spa_log_info(this->log, NAME " %p: remove port %d", this, port_id);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -414,11 +417,11 @@ impl_node_port_set_format(struct spa_node *node,
|
|||
this->copy = this->ops.copy[CONV_F32_F32];
|
||||
this->add = this->ops.add[CONV_F32_F32];
|
||||
}
|
||||
|
||||
}
|
||||
if (!port->have_format) {
|
||||
this->n_formats++;
|
||||
port->have_format = true;
|
||||
spa_log_info(this->log, NAME " %p: set format on port %d", this, port_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue