[{"id":36708,"web_url":"https://patchwork.libcamera.org/comment/36708/","msgid":"<176236118056.2116251.13129594156909163964@neptunite.rasen.tech>","date":"2025-11-05T16:46:20","subject":"Re: [PATCH v2 07/35] libcamera: converter_v4l2_m2m: Add suport for\n\tV4L2 requests","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-10-23 23:48:08)\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\nIsn't checking the return value of acquire() sufficient?\n\n> +               LOG(Converter, Error)\n> +                       << \"MediaDevice must be valid.\";\n> +       int ret = media_->allocateRequests(count, requests);\n> +       media_->release();\n\nDoesn't closing the media device release the requests?\n\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\nSame here.\n\n> +               LOG(Converter, Error)\n> +                       << \"MediaDevice must be valid.\";\n> +       bool ret = media_->supportsRequests();\n> +       media_->release();\n\nI guess it's ok here since we's only checking for support. Although we should\nprobably cache the supports flag here too.\n\n\nThanks,\n\nPaul\n\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.48.1\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 DA371BDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 Nov 2025 16:46:28 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8FF7560AA3;\n\tWed,  5 Nov 2025 17:46:28 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 24986609D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 Nov 2025 17:46:27 +0100 (CET)","from neptunite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:d4d0:27ea:7a74:8a9e])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 2181A13D9; \n\tWed,  5 Nov 2025 17:44:31 +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=\"V3X0TlMX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1762361072;\n\tbh=sqjJG+Q5326k44bi3a+t3Wz3RPpEWip+jLDPrUqiXtA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=V3X0TlMX0T2yE8E2TTHFMjPq1992ph1CJzowAlY3hxyQPhayOj2+YvT4atPJjpUNk\n\tON4Z3KIifZofkupc0TgDkagCihgmpEARZN2Xdb+EENKl2sJlP5+jazR6f0pQdCifMv\n\tZ1wUYlK7yjSOwpZko++K45pNyjBkg2tPW1IcS1GE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251023144841.403689-8-stefan.klug@ideasonboard.com>","References":"<20251023144841.403689-1-stefan.klug@ideasonboard.com>\n\t<20251023144841.403689-8-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 07/35] libcamera: converter_v4l2_m2m: Add suport for\n\tV4L2 requests","From":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 06 Nov 2025 01:46:20 +0900","Message-ID":"<176236118056.2116251.13129594156909163964@neptunite.rasen.tech>","User-Agent":"alot/0.0.0","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>"}}]