impl-node: update the io position from the data-loop

So that the update is synchronized with the data processing and
we don't accidentally process an old driver activation.
This commit is contained in:
Wim Taymans 2021-03-10 13:03:34 +01:00
parent 4f816c1fb0
commit cc26ef9614

View file

@ -707,15 +707,26 @@ static int
do_move_nodes(struct spa_loop *loop, do_move_nodes(struct spa_loop *loop,
bool async, uint32_t seq, const void *data, size_t size, void *user_data) bool async, uint32_t seq, const void *data, size_t size, void *user_data)
{ {
struct impl *src = user_data; struct impl *impl = user_data;
struct pw_impl_node *driver = *(struct pw_impl_node **)data; struct pw_impl_node *driver = *(struct pw_impl_node **)data;
struct pw_impl_node *this = &src->this; struct pw_impl_node *node = &impl->this;
int res;
pw_log_trace(NAME" %p: driver:%p->%p", this, this->driver_node, driver); pw_log_trace(NAME" %p: driver:%p->%p", node, node->driver_node, driver);
if (this->source.loop != NULL) { if ((res = spa_node_set_io(node->node,
remove_node(this); SPA_IO_Position,
add_node(this, driver); &driver->rt.activation->position,
sizeof(struct spa_io_position))) < 0) {
pw_log_debug(NAME" %p: set position: %s", node, spa_strerror(res));
}
pw_log_trace(NAME" %p: set position %p", node, &driver->rt.activation->position);
node->rt.position = &driver->rt.activation->position;
if (node->source.loop != NULL) {
remove_node(node);
add_node(node, driver);
} }
return 0; return 0;
} }
@ -732,7 +743,6 @@ int pw_impl_node_set_driver(struct pw_impl_node *node, struct pw_impl_node *driv
{ {
struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this); struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this);
struct pw_impl_node *old = node->driver_node; struct pw_impl_node *old = node->driver_node;
int res;
if (driver == NULL) if (driver == NULL)
driver = node; driver = node;
@ -754,21 +764,12 @@ int pw_impl_node_set_driver(struct pw_impl_node *node, struct pw_impl_node *driv
node->driver_node = driver; node->driver_node = driver;
pw_impl_node_emit_driver_changed(node, old, driver);
if ((res = spa_node_set_io(node->node,
SPA_IO_Position,
&driver->rt.activation->position,
sizeof(struct spa_io_position))) < 0) {
pw_log_debug(NAME" %p: set position: %s", node, spa_strerror(res));
}
pw_log_trace(NAME" %p: set position %p", node, &driver->rt.activation->position);
node->rt.position = &driver->rt.activation->position;
pw_loop_invoke(node->data_loop, pw_loop_invoke(node->data_loop,
do_move_nodes, SPA_ID_INVALID, &driver, sizeof(struct pw_impl_node *), do_move_nodes, SPA_ID_INVALID, &driver, sizeof(struct pw_impl_node *),
true, impl); true, impl);
pw_impl_node_emit_driver_changed(node, old, driver);
return 0; return 0;
} }