From 06905cd53b789dfbab1ca28f90fc90c439a575f1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 10 Apr 2024 17:22:34 +0200 Subject: [PATCH] impl-node: improve set_io some more Make sure we first set up our own state before calling into the implementation. That way, the implementation can look at the new state. --- src/pipewire/impl-node.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/pipewire/impl-node.c b/src/pipewire/impl-node.c index a86630dcd..808cb8fef 100644 --- a/src/pipewire/impl-node.c +++ b/src/pipewire/impl-node.c @@ -715,8 +715,10 @@ do_update_position(struct spa_loop *loop, void *position = *(void**)data; pw_log_trace("%p: set position %p", node, position); node->rt.position = position; - node->target_rate = node->rt.position->clock.target_rate; - node->target_quantum = node->rt.position->clock.target_duration; + if (position) { + node->target_rate = node->rt.position->clock.target_rate; + node->target_quantum = node->rt.position->clock.target_duration; + } return 0; } @@ -726,19 +728,23 @@ int pw_impl_node_set_io(struct pw_impl_node *this, uint32_t id, void *data, size int res; struct pw_impl_port *port; - res = spa_node_set_io(this->node, id, data, size); - switch (id) { case SPA_IO_Position: - pw_log_debug("%p: set position %p: %s", this, data, spa_strerror(res)); + if (data != NULL && size < sizeof(struct spa_io_position)) + return -EINVAL; + pw_log_debug("%p: set position %p", this, data); pw_loop_invoke(this->data_loop, do_update_position, SPA_ID_INVALID, &data, sizeof(void*), true, this); break; case SPA_IO_Clock: - pw_log_debug("%p: set clock %p: %s", this, data, spa_strerror(res)); + if (data != NULL && size < sizeof(struct spa_io_clock)) + return -EINVAL; + pw_log_debug("%p: set clock %p", this, data); this->rt.clock = data; - this->info.id = this->rt.clock->id; - this->rt.target.id = this->info.id; + if (this->rt.clock) { + this->info.id = this->rt.clock->id; + this->rt.target.id = this->info.id; + } break; } this->driving = this->driver && this->rt.clock && this->rt.position && @@ -753,6 +759,10 @@ int pw_impl_node_set_io(struct pw_impl_node *this, uint32_t id, void *data, size spa_list_for_each(port, &this->output_ports, link) spa_node_set_io(port->mix, id, data, size); + res = spa_node_set_io(this->node, id, data, size); + + pw_log_debug("%p: set io: %s", this, spa_strerror(res)); + return res; }