From 72fd462090971f222383e4a8d13dd6530b3f5b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 25 Jul 2025 19:20:27 +0200 Subject: [PATCH] spa: libcamera: source: move request completion data to `impl` A `libcamera::Request` is directly tied to the camera, not any ports ("streams") of it. So move the request completion ring buffer into the `impl` struct. This is a prerequisite for supporting multiple libcamera streams (~ exposing multiple ports on the node) in the future. --- spa/plugins/libcamera/libcamera-source.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index f07411370..de4e425ef 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -79,8 +79,6 @@ struct port { struct buffer buffers[MAX_BUFFERS]; uint32_t n_buffers = 0; struct spa_list queue; - struct spa_ringbuffer ring = SPA_RINGBUFFER_INIT(); - libcamera::Request *ring_ids[MAX_BUFFERS]; static constexpr uint64_t info_all = SPA_PORT_CHANGE_MASK_FLAGS | SPA_PORT_CHANGE_MASK_PROPS | SPA_PORT_CHANGE_MASK_PARAMS; @@ -156,6 +154,8 @@ struct impl { FrameBufferAllocator *allocator = nullptr; std::vector> requestPool; + spa_ringbuffer completed_requests_rb = SPA_RINGBUFFER_INIT(); + std::array completed_requests; void requestComplete(libcamera::Request *request); @@ -363,7 +363,7 @@ int spa_libcamera_clear_buffers(struct impl *impl, struct port *port) } port->n_buffers = 0; - port->ring = SPA_RINGBUFFER_INIT(); + impl->completed_requests_rb = SPA_RINGBUFFER_INIT(); return 0; } @@ -1040,13 +1040,13 @@ void libcamera_on_fd_events(struct spa_source *source) return; } - if (spa_ringbuffer_get_read_index(&port->ring, &index) < 1) { + if (spa_ringbuffer_get_read_index(&impl->completed_requests_rb, &index) < 1) { spa_log_error(impl->log, "nothing is queued"); return; } - auto *request = port->ring_ids[index & MASK_BUFFERS]; - spa_ringbuffer_read_update(&port->ring, index + 1); + auto *request = impl->completed_requests[index & MASK_BUFFERS]; + spa_ringbuffer_read_update(&impl->completed_requests_rb, index + 1); buffer_id = request->cookie(); b = &port->buffers[buffer_id]; @@ -1289,9 +1289,9 @@ void impl::requestComplete(libcamera::Request *request) } request->reuse(libcamera::Request::ReuseFlag::ReuseBuffers); - spa_ringbuffer_get_write_index(&port->ring, &index); - port->ring_ids[index & MASK_BUFFERS] = request; - spa_ringbuffer_write_update(&port->ring, index + 1); + spa_ringbuffer_get_write_index(&impl->completed_requests_rb, &index); + impl->completed_requests[index & MASK_BUFFERS] = request; + spa_ringbuffer_write_update(&impl->completed_requests_rb, index + 1); if (spa_system_eventfd_write(impl->system, impl->source.fd, 1) < 0) spa_log_error(impl->log, "Failed to write on event fd");