[libcamera-devel] Problems opening/closing camera in different processes

Naushir Patuck naush at raspberrypi.com
Tue Nov 8 09:42:18 CET 2022


Hi all,

On Mon, 7 Nov 2022 at 12:26, David Plowman via libcamera-devel <
libcamera-devel at lists.libcamera.org> wrote:

> Hi everyone
>
> Recently I've been working with multiple cameras and trying to make it
> possible to close them in one process and open them in another
> (without terminating the first process altogether). I'm still left
> with one problem and would like to get some suggestions as to how we
> should solve it.
>
> To illustrate the problem:
>
> Case 1 (works):
>
> In process 1, acquire the camera and then release it (but do not
> terminate the process).
>
> Process 2 can now acquire the camera and start it successfully. Hurray!
>
> Case 2 (broken):
>
> In process 1, acquire the camera, start it, then stop it and release
> it (again, do not terminate the process).
>
> Process 2 can acquire the camera but when you try to start it, it fails.
> :(
>
> The reason is that process 1 still holds file descriptors for all the
> devices in question (which is fair enough) but crucially it still has
> DMABUFs allocated, and this stops anyone else from doing so.
>
> Currently the CameraData (RPiCameraData in our case) gets no
> notification that the camera has been released - perhaps it should?
> The PipelineHandler could simply tell the CameraData that it's being
> released, and that would give us a place to free those buffers.
>

> Thoughts?
>

Freeing buffer allocations on stopDevice() would resolve this issue, but we
don't
want to do that.  It is entirely reasonbale for an application to do a
stop()
and start() without a configure(), so buffers do want to persist in this
case.

Adding an acquire() and release() call into the individual pipeline handlers
seems like a reasonable approach to me.  This would also provide a path to
fix
the uvc pipeline handler bug [1] which looks to be related to leaving the
device
open even if the camera has not yet been acquired.

Regards,
Naush

[1] https://bugs.libcamera.org/show_bug.cgi?id=168


> Thanks!
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20221108/e82b0c62/attachment.htm>


More information about the libcamera-devel mailing list