graph: don't let required number of ports become negative

Add a check against letting the required number of ports become
negative for a node. With certain timing between the main and data
thread, this can otherwise happen.

For nodes where links are unlinked and relinked, a negative number may
mean that the scheduler skips the node and doesn't call
process_output().
This commit is contained in:
David Svensson Fors 2017-12-01 16:31:37 +01:00 committed by Wim Taymans
parent c1aa3b4625
commit 6503351a0d

View file

@ -160,9 +160,11 @@ static inline void spa_graph_port_remove(struct spa_graph_port *port)
{ {
spa_debug("port %p remove", port); spa_debug("port %p remove", port);
spa_list_remove(&port->link); spa_list_remove(&port->link);
if (!(port->flags & SPA_PORT_INFO_FLAG_OPTIONAL)) if (!(port->flags & SPA_PORT_INFO_FLAG_OPTIONAL) &&
port->node->required[port->direction] > 0) {
port->node->required[port->direction]--; port->node->required[port->direction]--;
} }
}
static inline void static inline void
spa_graph_port_link(struct spa_graph_port *out, struct spa_graph_port *in) spa_graph_port_link(struct spa_graph_port *out, struct spa_graph_port *in)