[libcamera-devel] [PATCH v1 5/5] cam: Move request processing to main thread

Marvin Schmidt marvin.schmidt1987 at gmail.com
Fri Nov 13 13:35:40 CET 2020


Hey Laurent,

Thanks for your work

Am Fr., 13. Nov. 2020 um 07:38 Uhr schrieb Laurent Pinchart
<laurent.pinchart at ideasonboard.com>:
>
> The request completion handler is invoked in the camera manager thread,
> which shouldn't be blocked for large amounts of time. As writing the
> frames to disk can be a time-consuming process, move request processing
> to the main thread by queueing an event to the event loop.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
>  src/cam/capture.cpp | 9 +++++++++
>  src/cam/capture.h   | 1 +
>  2 files changed, 10 insertions(+)
>
> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp
> index 7580f798288c..43b109d099f6 100644
> --- a/src/cam/capture.cpp
> +++ b/src/cam/capture.cpp
> @@ -157,6 +157,15 @@ void Capture::requestComplete(Request *request)
>         if (request->status() == Request::RequestCancelled)
>                 return;
>
> +       /*
> +        * Defer processing of the completed request to the event loop, to avoid
> +        * blocking the camera manager thread.
> +        */
> +       loop_->callLater(std::bind(&Capture::processRequest, this, request));

You could use a lambda here instead of std::bind:

    [=] { processRequest(request); }

std::bind would otherwise require including `<functional>`

> +}
> +
> +void Capture::processRequest(Request *request)
> +{
>         const Request::BufferMap &buffers = request->buffers();
>
>         /*
> diff --git a/src/cam/capture.h b/src/cam/capture.h
> index 45e5e8a9ba27..d21c95a26ce7 100644
> --- a/src/cam/capture.h
> +++ b/src/cam/capture.h
> @@ -33,6 +33,7 @@ private:
>         int capture(libcamera::FrameBufferAllocator *allocator);
>
>         void requestComplete(libcamera::Request *request);
> +       void processRequest(libcamera::Request *request);
>
>         std::shared_ptr<libcamera::Camera> camera_;
>         libcamera::CameraConfiguration *config_;


More information about the libcamera-devel mailing list