From ad1dbf15411602b6864bd3c268dbe3e922ee3724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 25 Jul 2025 19:14:45 +0200 Subject: [PATCH] spa: libcamera: source: store the request pointer in ring buffer The request will be needed later, so store that directly in the completion ring buffer for easy access. This is fine even though `impl::requestComplete()` calls `Request::reuse()` because only the request cookie is used in `libcamera_on_fd_events()` and that remains constant during the lifetime of a request object. (cherry picked from commit 099292d63d2851682740b38d5e958abff56dde6b) --- spa/plugins/libcamera/libcamera-source.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index a5de3af87..b3c0fd912 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -80,7 +80,7 @@ struct port { uint32_t n_buffers = 0; struct spa_list queue; struct spa_ringbuffer ring = SPA_RINGBUFFER_INIT(); - uint32_t ring_ids[MAX_BUFFERS]; + 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; @@ -1042,9 +1042,11 @@ void libcamera_on_fd_events(struct spa_source *source) spa_log_error(impl->log, "nothing is queued"); return; } - buffer_id = port->ring_ids[index & MASK_BUFFERS]; + + auto *request = port->ring_ids[index & MASK_BUFFERS]; spa_ringbuffer_read_update(&port->ring, index + 1); + buffer_id = request->cookie(); b = &port->buffers[buffer_id]; spa_list_append(&port->queue, &b->link); @@ -1286,7 +1288,7 @@ 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] = buffer_id; + port->ring_ids[index & MASK_BUFFERS] = request; spa_ringbuffer_write_update(&port->ring, index + 1); if (spa_system_eventfd_write(impl->system, impl->source.fd, 1) < 0)