diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index fba3d8b0b..a0b4b5cec 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -1571,6 +1571,8 @@ int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) int impl_node_send_command(void *object, const struct spa_command *command) { struct impl *impl = (struct impl*)object; + struct port *port; + struct spa_io_buffers *io; int res; spa_return_val_if_fail(impl != nullptr, -EINVAL); @@ -1592,8 +1594,13 @@ int impl_node_send_command(void *object, const struct spa_command *command) } case SPA_NODE_COMMAND_Pause: case SPA_NODE_COMMAND_Suspend: - if ((res = spa_libcamera_stream_off(impl)) < 0) - return res; + spa_libcamera_stream_off(impl); + port = GET_OUT_PORT(impl, 0); + io = port->io; + if (io && (io->buffer_id < port->n_buffers)) { + spa_libcamera_buffer_recycle(impl, port, io->buffer_id); + io->buffer_id = SPA_ID_INVALID; + } break; default: return -ENOTSUP; diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index db5c90113..355dcb328 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -334,10 +334,25 @@ static void on_output(void* data, uint64_t expirations) spa_node_call_ready(&this->callbacks, res); } +static inline void reuse_buffer(struct impl *this, struct port *port, uint32_t id) +{ + struct buffer *b = &port->buffers[id]; + spa_return_if_fail(b->outstanding); + + spa_log_trace(this->log, "%p: reuse buffer %d", this, id); + + b->outstanding = false; + spa_list_append(&port->empty, &b->link); + + if (!this->props.live) + set_timer(this, true); +} + static int impl_node_send_command(void *object, const struct spa_command *command) { struct impl *this = object; struct port *port; + struct spa_io_buffers *io; spa_return_val_if_fail(this != NULL, -EINVAL); spa_return_val_if_fail(command != NULL, -EINVAL); @@ -375,6 +390,11 @@ static int impl_node_send_command(void *object, const struct spa_command *comman return 0; this->started = false; set_timer(this, false); + io = port->io; + if (io && (io->buffer_id < port->n_buffers)) { + reuse_buffer(this, port, io->buffer_id); + io->buffer_id = SPA_ID_INVALID; + } break; default: return -ENOTSUP; @@ -513,7 +533,7 @@ impl_node_port_enum_params(void *object, int seq, result.id = id; result.next = start; - next: +next: result.index = result.next++; spa_pod_builder_init(&b, buffer, sizeof(buffer)); @@ -746,20 +766,6 @@ impl_node_port_set_io(void *object, return 0; } -static inline void reuse_buffer(struct impl *this, struct port *port, uint32_t id) -{ - struct buffer *b = &port->buffers[id]; - spa_return_if_fail(b->outstanding); - - spa_log_trace(this->log, "%p: reuse buffer %d", this, id); - - b->outstanding = false; - spa_list_append(&port->empty, &b->link); - - if (!this->props.live) - set_timer(this, true); -} - static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) { struct impl *this = object;