[{"id":37067,"web_url":"https://patchwork.libcamera.org/comment/37067/","msgid":"<176409505143.567526.6769418875150879316@ping.linuxembedded.co.uk>","date":"2025-11-25T18:24:11","subject":"Re: [PATCH v3 05/29] libcamera: converter_v4l2_m2m: Add suport for\n\tV4L2 requests","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-11-25 16:28:17)\n> To actually use requests with the m2m device, requests need to be\n> allocated on the underlying media device. This can only be done if the\n> media device is opened which means acquiring it. Add a function to check\n> if the m2m device supports requests by acquiring the media device,\n> asking it and then releasing it again. Also add a function to allocate\n> requests that acquires the internal media device and releases it after\n> allocating the requests.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n> ---\n> \n> ToDo:\n> - Fix the place where the MediaObject is acquired/released\n> \n> Changes in v2:\n> - Improved commit message\n> - Dropped the change from private to protected as that belongs to a\n>   different patch\n> ---\n>  .../internal/converter/converter_v4l2_m2m.h   |  7 ++++\n>  .../converter/converter_v4l2_m2m.cpp          | 34 ++++++++++++++++++-\n>  2 files changed, 40 insertions(+), 1 deletion(-)\n> \n> diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> index 1b2a88c4a608..bc85bff7a07b 100644\n> --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> @@ -73,6 +73,11 @@ public:\n>         std::pair<Rectangle, Rectangle> inputCropBounds() override { return inputCropBounds_; }\n>         std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream) override;\n>  \n> +       int allocateRequests(unsigned int count,\n> +                            std::vector<std::unique_ptr<V4L2Request>> *requests);\n> +\n> +       bool supportsRequests();\n> +\n>  private:\n>         class V4L2M2MStream : protected Loggable\n>         {\n> @@ -122,6 +127,8 @@ private:\n>         std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;\n>         std::map<FrameBuffer *, unsigned int> queue_;\n>         std::pair<Rectangle, Rectangle> inputCropBounds_;\n> +\n> +       std::shared_ptr<MediaDevice> media_;\n>  };\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp\n> index ff11a9735db7..c6153d728c9a 100644\n> --- a/src/libcamera/converter/converter_v4l2_m2m.cpp\n> +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp\n> @@ -9,6 +9,7 @@\n>  #include \"libcamera/internal/converter/converter_v4l2_m2m.h\"\n>  \n>  #include <algorithm>\n> +#include <errno.h>\n>  #include <limits.h>\n>  #include <memory>\n>  #include <set>\n> @@ -266,7 +267,7 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer)\n>   * \\param[in] media The media device implementing the converter\n>   */\n>  V4L2M2MConverter::V4L2M2MConverter(std::shared_ptr<MediaDevice> media)\n> -       : Converter(media)\n> +       : Converter(media), media_(media)\n>  {\n>         if (deviceNode().empty())\n>                 return;\n> @@ -742,6 +743,37 @@ int V4L2M2MConverter::queueBuffers(FrameBuffer *input,\n>         return 0;\n>  }\n>  \n> +/**\n> + * \\copydoc libcamera::MediaDevice::allocateRequests\n> + */\n> +int V4L2M2MConverter::allocateRequests(unsigned int count,\n> +                                      std::vector<std::unique_ptr<V4L2Request>> *requests)\n> +{\n> +       /* \\todo The acquire() must be moved to the right place. */\n> +       media_->acquire();\n> +       if (!media_->busy())\n> +               LOG(Converter, Error)\n> +                       << \"MediaDevice must be valid.\";\n> +       int ret = media_->allocateRequests(count, requests);\n> +       media_->release();\n> +       return ret;\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::MediaDevice::supportsRequests\n> + */\n> +bool V4L2M2MConverter::supportsRequests()\n> +{\n> +       /* \\todo The acquire() must be moved to the right place. */\n> +       media_->acquire();\n> +       if (!media_->busy())\n> +               LOG(Converter, Error)\n> +                       << \"MediaDevice must be valid.\";\n\nI expect this will report an error while trying to enumerate cameras\nwhen one is already in use ?\n\nWhat's the impact there? will this return a failure so the camera won't\nshow up ?\n\nI expect it will just not support requests - and will mean the camera\nwill show up - but if you try to open a camera separately to use - even\nif you stop the camera in process A, process B might have seen the\ncamera but won't be able to use say the dewarper.\n\nI think we're into corner cases that don't need to be handled 'right\nnow' but it's probably something we need to resolve somehow.\n\nBut you've already got a todo so :\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +       bool ret = media_->supportsRequests();\n> +       media_->release();\n> +       return ret;\n> +}\n> +\n>  /*\n>   * \\todo This should be extended to include Feature::Flag to denote\n>   * what each converter supports feature-wise.\n> -- \n> 2.51.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A2172C333D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Nov 2025 18:24:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8C43860A85;\n\tTue, 25 Nov 2025 19:24:16 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 100FF609D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Nov 2025 19:24:15 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB56F524;\n\tTue, 25 Nov 2025 19:22:05 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"UolFY5q0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764094925;\n\tbh=WJT1mubA8j+66KAz0LtFg/c7u+y5DKX7gTapft0zdO8=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=UolFY5q0l42+o2XLnRJk2OMhE8ZUJD5d0cJ4xDl1ksWbCSyE2YnzMhnQTioSv+aDG\n\tbJt3zu321IiXAkNmZmQWoKACM91DrqKijtxW6g6gsIdAiY7sGwYxah//oFByNM9hZM\n\twsQMBzyETox8eLUDJCkmXBa35jy59UGE1BgElWmk=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251125162851.2301793-6-stefan.klug@ideasonboard.com>","References":"<20251125162851.2301793-1-stefan.klug@ideasonboard.com>\n\t<20251125162851.2301793-6-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 05/29] libcamera: converter_v4l2_m2m: Add suport for\n\tV4L2 requests","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 25 Nov 2025 18:24:11 +0000","Message-ID":"<176409505143.567526.6769418875150879316@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]