[{"id":36102,"web_url":"https://patchwork.libcamera.org/comment/36102/","msgid":"<175948738407.935713.17112237415408302347@ping.linuxembedded.co.uk>","date":"2025-10-03T10:29:44","subject":"Re: [PATCH v1 08/33] 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-09-30 13:26:29)\n> Add support for V4L2 reuests.\n\nrequests.\n\nPerhaps we could be a bit more expansive on the commit message too.\n\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>  .../internal/converter/converter_v4l2_m2m.h   |  9 ++++-\n>  .../converter/converter_v4l2_m2m.cpp          | 34 ++++++++++++++++++-\n>  2 files changed, 41 insertions(+), 2 deletions(-)\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..3b8fc5392b7d 100644\n> --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> @@ -73,7 +73,12 @@ public:\n>         std::pair<Rectangle, Rectangle> inputCropBounds() override { return inputCropBounds_; }\n>         std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream) override;\n>  \n> -private:\n> +       int allocateRequests(unsigned int count,\n> +                            std::vector<std::unique_ptr<V4L2Request>> *requests);\n> +\n> +       bool supportsRequests();\n> +\n> +protected:\n>         class V4L2M2MStream : protected Loggable\n>         {\n>         public:\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> +       bool ret = media_->supportsRequests();\n\nI think it shouldn't matter in practice - as if we're not able to\nacquire the camera we won't stream - but I expect even if a camera is\nstreaming - another process might try to enumerate it or detect the\ncapabilities (without acquiring) - so I think determining if the device\n'supports' requests should be possible without locking/acquireing the\nmedia device...\n\nBut it probably doesn't make much material difference?\n\n\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.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 0990FBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Oct 2025 10:29:50 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D02106B5AA;\n\tFri,  3 Oct 2025 12:29:49 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 87FDA69318\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Oct 2025 12:29:47 +0200 (CEST)","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 81D76192C;\n\tFri,  3 Oct 2025 12:28:16 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"DaMxhTRg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1759487296;\n\tbh=wu42TTvZqQi3WTiZ7ti/T8mYUZjAYH7HswJQ24iqFOg=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=DaMxhTRgC2JNE8h/r94NgY0IEjuLD2Mx3EFl57vWPUeSi9WMkPExpnPVOCzEp7cRu\n\t3CK3Emen9Al+Sc/X8sYCpChO0XU41KjaR0KogkvMJeP3FDlGNcw1h9PqnULVanJUYH\n\t7YU41nyitUGOMfXOLH+mdAJywKPAw69VG/CR1sEk=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250930122726.1837524-9-stefan.klug@ideasonboard.com>","References":"<20250930122726.1837524-1-stefan.klug@ideasonboard.com>\n\t<20250930122726.1837524-9-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v1 08/33] 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":"Fri, 03 Oct 2025 11:29:44 +0100","Message-ID":"<175948738407.935713.17112237415408302347@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>"}},{"id":36392,"web_url":"https://patchwork.libcamera.org/comment/36392/","msgid":"<176113974755.6155.7976855835907858194@localhost>","date":"2025-10-22T13:29:07","subject":"Re: [PATCH v1 08/33] libcamera: converter_v4l2_m2m: Add suport for\n\tV4L2 requests","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the review.\n\nQuoting Kieran Bingham (2025-10-03 12:29:44)\n> Quoting Stefan Klug (2025-09-30 13:26:29)\n> > Add support for V4L2 reuests.\n> \n> requests.\n> \n> Perhaps we could be a bit more expansive on the commit message too.\n> \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> >  .../internal/converter/converter_v4l2_m2m.h   |  9 ++++-\n> >  .../converter/converter_v4l2_m2m.cpp          | 34 ++++++++++++++++++-\n> >  2 files changed, 41 insertions(+), 2 deletions(-)\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..3b8fc5392b7d 100644\n> > --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> > +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> > @@ -73,7 +73,12 @@ public:\n> >         std::pair<Rectangle, Rectangle> inputCropBounds() override { return inputCropBounds_; }\n> >         std::pair<Rectangle, Rectangle> inputCropBounds(const Stream *stream) override;\n> >  \n> > -private:\n> > +       int allocateRequests(unsigned int count,\n> > +                            std::vector<std::unique_ptr<V4L2Request>> *requests);\n> > +\n> > +       bool supportsRequests();\n> > +\n> > +protected:\n> >         class V4L2M2MStream : protected Loggable\n> >         {\n> >         public:\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> > +       bool ret = media_->supportsRequests();\n> \n> I think it shouldn't matter in practice - as if we're not able to\n> acquire the camera we won't stream - but I expect even if a camera is\n> streaming - another process might try to enumerate it or detect the\n> capabilities (without acquiring) - so I think determining if the device\n> 'supports' requests should be possible without locking/acquireing the\n> media device...\n> \n> But it probably doesn't make much material difference?\n\nI was unsure about the contracts here. MediaDevice::open() is private,\nso the only way to ensure it is opened is by acquiring it. Do you have a\nsuggestion for a better solution?\n\nBest regards,\nStefan\n\n> \n> \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.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 1BB59C3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 22 Oct 2025 13:29:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CD670607AE;\n\tWed, 22 Oct 2025 15:29:12 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EB6C60763\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 22 Oct 2025 15:29:10 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:743e:771f:a1ba:58db])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 2E7E583D;\n\tWed, 22 Oct 2025 15:27:26 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IuC3h35e\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761139646;\n\tbh=pCBQO8LLkJFS/ePA/8AChfJQFqwZ/b+FmdqnsnMepVs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=IuC3h35ekPXrJILWc1Jfs96o9Q73sbeHA0MaddlG0RILtoKwN8QPDCN5SQkaD6qpB\n\tdfyJILs6DGMj9/kXHhxvHfWZA0wHUJrcYPW0OwOeKcT6fCB/hzqwIHsDFDEX4NwYex\n\tQPoYmxTSt0Q+rKyK5ABO7dxLsoKV+Ed7+UsrxR6g=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<175948738407.935713.17112237415408302347@ping.linuxembedded.co.uk>","References":"<20250930122726.1837524-1-stefan.klug@ideasonboard.com>\n\t<20250930122726.1837524-9-stefan.klug@ideasonboard.com>\n\t<175948738407.935713.17112237415408302347@ping.linuxembedded.co.uk>","Subject":"Re: [PATCH v1 08/33] libcamera: converter_v4l2_m2m: Add suport for\n\tV4L2 requests","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 22 Oct 2025 15:29:07 +0200","Message-ID":"<176113974755.6155.7976855835907858194@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>"}}]