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.

(cherry picked from commit b9b7c0ab05)
This commit is contained in:
Barnabás Pőcze 2025-08-08 10:06:59 +02:00 committed by Robert Mader
parent a5cb888578
commit b28eb20c1f

View file

@ -353,7 +353,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();
@ -1818,6 +1817,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);