From b9b7c0ab05a8ec94b4166fa85a4f33cb39d4cd88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 8 Aug 2025 10:06:59 +0200 Subject: [PATCH] spa: libcamera: source: freeBuffers(): call when format is unset At the moment the libcamera buffer allocation is completely tied to format negotiation. `freeBuffers()` undoes `allocBuffers()`. And `allocBuffers()` is called as part of `spa_libcamera_set_format()`. Therefore `freeBuffers()` should be called independent of the state of the buffers on any port. Otherwise unsetting the format while there are no buffers on the port will cause the libcamera requests and buffers not to be released correctly. Similarly, removing the buffers from a port would clear the libcamera requests and buffers, making the node unusable without setting a new format. --- spa/plugins/libcamera/libcamera-source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index 87fa2761c..3e5715b2a 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -354,7 +354,6 @@ int spa_libcamera_clear_buffers(struct impl *impl, struct port *port) } impl->pendingRequests.clear(); - freeBuffers(impl, port); port->n_buffers = 0; port->ring = SPA_RINGBUFFER_INIT(); @@ -1831,6 +1830,7 @@ int port_set_format(struct impl *impl, struct port *port, spa_libcamera_stream_off(impl); spa_libcamera_clear_buffers(impl, port); + freeBuffers(impl, port); port->current_format.reset(); spa_libcamera_close(impl);