[{"id":29563,"web_url":"https://patchwork.libcamera.org/comment/29563/","msgid":"<171620232021.2248009.9132217154973139915@ping.linuxembedded.co.uk>","date":"2024-05-20T10:52:00","subject":"Re: [PATCH v2 2/4] libcamera: converter_v4l2_m2m: Support crop\n\tselection","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Umang Jain (2024-05-19 12:56:20)\n> Add a helper to set selection rectangle on the video node\n> to support cropping and scaling capabilites.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  .../internal/converter/converter_v4l2_m2m.h   |  5 ++++\n>  .../converter/converter_v4l2_m2m.cpp          | 26 +++++++++++++++++++\n>  2 files changed, 31 insertions(+)\n> \n> diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> index 1126050c..acc6424c 100644\n> --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n> @@ -29,6 +29,7 @@ class MediaDevice;\n>  class Size;\n>  class SizeRange;\n>  struct StreamConfiguration;\n> +class Rectangle;\n>  class V4L2M2MDevice;\n>  \n>  class V4L2M2MConverter : public Converter\n> @@ -56,6 +57,8 @@ public:\n>         int queueBuffers(FrameBuffer *input,\n>                          const std::map<unsigned int, FrameBuffer *> &outputs);\n>  \n> +       int setSelection(unsigned int output, unsigned int target, Rectangle *rect);\n> +\n\nWould there be any value in also adding the corresponding 'getSelection'\ncall here too? Or would it not be used? (Not using it /yet/ is also a\nvalid reason I suspect).\n\n\n\n>  private:\n>         class Stream : protected Loggable\n>         {\n> @@ -74,6 +77,8 @@ private:\n>  \n>                 int queueBuffers(FrameBuffer *input, FrameBuffer *output);\n>  \n> +               int setSelection(unsigned int target, Rectangle *rect);\n> +\n>         protected:\n>                 std::string logPrefix() const override;\n>  \n> diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp\n> index d8929fc5..2d3ee257 100644\n> --- a/src/libcamera/converter/converter_v4l2_m2m.cpp\n> +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp\n> @@ -155,6 +155,15 @@ int V4L2M2MConverter::Stream::queueBuffers(FrameBuffer *input, FrameBuffer *outp\n>         return 0;\n>  }\n>  \n> +int V4L2M2MConverter::Stream::setSelection(unsigned int target, Rectangle *rect)\n> +{\n> +       int ret = m2m_->output()->setSelection(target, rect);\n\n\nAha, ok - so we really only apply on outputs..\n\n\n> +       if (ret < 0)\n> +               return ret;\n> +\n> +       return 0;\n> +}\n> +\n>  std::string V4L2M2MConverter::Stream::logPrefix() const\n>  {\n>         return \"stream\" + std::to_string(index_);\n> @@ -370,6 +379,23 @@ int V4L2M2MConverter::exportBuffers(unsigned int output, unsigned int count,\n>         return streams_[output].exportBuffers(count, buffers);\n>  }\n>  \n> +/**\n> + * \\brief Set a selection rectangle \\a rect for \\a target\n> + * \\param[in] output Index of the output stream\n\nEek, this bit looks a bit awkward, as we're utilising the internal\nstream index, while I suspect the APIs here would instead reference a\nStream object?\n\nMaybe that will be clearer on the next patches/users. But I'd also\nprobably call this 'stream', rather than 'output' I think.\n\nCan selection rectangles only meaningfully be set on the outputs? or\nwill we find a reason to apply (or get) a rectangle from the Input?\n\nI suspect as this is an M2M device there's a bit more nuance here than I\nimagine, or simply restrictions depending on the type of device used...\n\n\n\n> + * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> + * \\param[inout] rect The selection rectangle to be applied\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2M2MConverter::setSelection(unsigned int output, unsigned int target,\n> +                                  Rectangle *rect)\n> +{\n> +       if (output >= streams_.size())\n> +               return -EINVAL;\n> +\n> +       return streams_[output].setSelection(target, rect);\n> +}\n> +\n>  /**\n>   * \\copydoc libcamera::Converter::start\n>   */\n> -- \n> 2.44.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 808A4BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 May 2024 10:52:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 578DC6347C;\n\tMon, 20 May 2024 12:52:06 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3034261A58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 May 2024 12:52:03 +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 B8408581;\n\tMon, 20 May 2024 12:51:51 +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=\"UK7NprA9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1716202311;\n\tbh=WydYDycJVoBcO3aSRzqw1bCDannTCRBYFKULr+QX81I=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=UK7NprA97dIpW/ZRPPIH+zE0H5po9OGutuLMVpvHu/mGyMdzfyscgZy1lRZQ2b4ch\n\t6xi3kYk+F3vsXnZOxWn+3p/JY97ZceEwAaGiR5vuHHxZFanIUDLLf+/8mX2eOxd1Wb\n\tUS6s+fTOQpffDRyKThtJBumzMzmt2DoYm85rdlr8=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240519115622.32170-3-umang.jain@ideasonboard.com>","References":"<20240519115622.32170-1-umang.jain@ideasonboard.com>\n\t<20240519115622.32170-3-umang.jain@ideasonboard.com>","Subject":"Re: [PATCH v2 2/4] libcamera: converter_v4l2_m2m: Support crop\n\tselection","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Umang Jain <umang.jain@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 20 May 2024 11:52:00 +0100","Message-ID":"<171620232021.2248009.9132217154973139915@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":29571,"web_url":"https://patchwork.libcamera.org/comment/29571/","msgid":"<b53b9d1f-ef80-4f1e-adaa-4effe2d1f6b0@ideasonboard.com>","date":"2024-05-20T12:43:20","subject":"Re: [PATCH v2 2/4] libcamera: converter_v4l2_m2m: Support crop\n\tselection","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Kirean\n\nOn 20/05/24 4:22 pm, Kieran Bingham wrote:\n> Quoting Umang Jain (2024-05-19 12:56:20)\n>> Add a helper to set selection rectangle on the video node\n>> to support cropping and scaling capabilites.\n>>\n>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n>> ---\n>>   .../internal/converter/converter_v4l2_m2m.h   |  5 ++++\n>>   .../converter/converter_v4l2_m2m.cpp          | 26 +++++++++++++++++++\n>>   2 files changed, 31 insertions(+)\n>>\n>> diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n>> index 1126050c..acc6424c 100644\n>> --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h\n>> +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h\n>> @@ -29,6 +29,7 @@ class MediaDevice;\n>>   class Size;\n>>   class SizeRange;\n>>   struct StreamConfiguration;\n>> +class Rectangle;\n>>   class V4L2M2MDevice;\n>>   \n>>   class V4L2M2MConverter : public Converter\n>> @@ -56,6 +57,8 @@ public:\n>>          int queueBuffers(FrameBuffer *input,\n>>                           const std::map<unsigned int, FrameBuffer *> &outputs);\n>>   \n>> +       int setSelection(unsigned int output, unsigned int target, Rectangle *rect);\n>> +\n> Would there be any value in also adding the corresponding 'getSelection'\n> call here too? Or would it not be used? (Not using it /yet/ is also a\n> valid reason I suspect).\n\nI haven't found a use yet so...\n>\n>\n>>   private:\n>>          class Stream : protected Loggable\n>>          {\n>> @@ -74,6 +77,8 @@ private:\n>>   \n>>                  int queueBuffers(FrameBuffer *input, FrameBuffer *output);\n>>   \n>> +               int setSelection(unsigned int target, Rectangle *rect);\n>> +\n>>          protected:\n>>                  std::string logPrefix() const override;\n>>   \n>> diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp\n>> index d8929fc5..2d3ee257 100644\n>> --- a/src/libcamera/converter/converter_v4l2_m2m.cpp\n>> +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp\n>> @@ -155,6 +155,15 @@ int V4L2M2MConverter::Stream::queueBuffers(FrameBuffer *input, FrameBuffer *outp\n>>          return 0;\n>>   }\n>>   \n>> +int V4L2M2MConverter::Stream::setSelection(unsigned int target, Rectangle *rect)\n>> +{\n>> +       int ret = m2m_->output()->setSelection(target, rect);\n>\n> Aha, ok - so we really only apply on outputs..\n>\n>\n>> +       if (ret < 0)\n>> +               return ret;\n>> +\n>> +       return 0;\n>> +}\n>> +\n>>   std::string V4L2M2MConverter::Stream::logPrefix() const\n>>   {\n>>          return \"stream\" + std::to_string(index_);\n>> @@ -370,6 +379,23 @@ int V4L2M2MConverter::exportBuffers(unsigned int output, unsigned int count,\n>>          return streams_[output].exportBuffers(count, buffers);\n>>   }\n>>   \n>> +/**\n>> + * \\brief Set a selection rectangle \\a rect for \\a target\n>> + * \\param[in] output Index of the output stream\n> Eek, this bit looks a bit awkward, as we're utilising the internal\n> stream index, while I suspect the APIs here would instead reference a\n> Stream object?\n\nIt should reference a Stream object ideally. The converter interface \nshould be fixed for doing that actually,\n\nFor .e.g even queuing frame buffers to the converter, works on indexes \nof the stream\n\n```\n  * \\fn Converter::queueBuffers()\n  * \\brief Queue buffers to converter device\n  * \\param[in] input The frame buffer to apply the conversion\n  * \\param[out] outputs The container holding the output stream indexes and\n  * their respective frame buffer outputs.\n...\n```\n\nProbably a separate but orthogonal task to this.\n>\n> Maybe that will be clearer on the next patches/users. But I'd also\n> probably call this 'stream', rather than 'output' I think.\n\nI can rename to streamIdx for now\n> Can selection rectangles only meaningfully be set on the outputs? or\n> will we find a reason to apply (or get) a rectangle from the Input?\n\nIt errors out if you try to set on the capture\n\n>\n> I suspect as this is an M2M device there's a bit more nuance here than I\n> imagine, or simply restrictions depending on the type of device used...\n\nIt was naunce, and I didn't actually realise for a day that \nV4L2M2MConverter actually has m2m instance per-stream + a separate \ninstance just at constructor-level or to check isValid() calls.\n\nI was setting crop rectangle at the latter, and wasn't getting expected \nresults until I noticed, the m2m instance is per-stream and I have set \nrectangles on that m2m instance which corresponds to the stream.\n\n>\n>\n>> + * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n>> + * \\param[inout] rect The selection rectangle to be applied\n>> + *\n>> + * \\return 0 on success or a negative error code otherwise\n>> + */\n>> +int V4L2M2MConverter::setSelection(unsigned int output, unsigned int target,\n>> +                                  Rectangle *rect)\n>> +{\n>> +       if (output >= streams_.size())\n>> +               return -EINVAL;\n>> +\n>> +       return streams_[output].setSelection(target, rect);\n>> +}\n>> +\n>>   /**\n>>    * \\copydoc libcamera::Converter::start\n>>    */\n>> -- \n>> 2.44.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 C1DD7BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 May 2024 12:43:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CF7EE63471;\n\tMon, 20 May 2024 14:43:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C445F61A58\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 May 2024 14:43:24 +0200 (CEST)","from [IPV6:2405:201:2015:f873:c173:4b:4a04:3a21] (unknown\n\t[IPv6:2405:201:2015:f873:c173:4b:4a04:3a21])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E9F95593;\n\tMon, 20 May 2024 14:43:12 +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=\"LPLG3s0w\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1716208993;\n\tbh=qJO5PtX/LUQn+2xS8COH1sOKmsbXHr3e/iVXcM565eA=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=LPLG3s0wNSM6YnVFILy77e+t5PRP/uD7aH7ZzQ++uI3q+QNmGllwUBcv5FTQX1XZY\n\tHIpcTod2SwxoWjzoTiiYzIlReffOly101b/2T+oJM0KFQ4uoGuzhD5KqMf+gst1Q6p\n\tTKtfjW4oKtnykQ6csPPaRA2wqVI+OMqgiOlaqvSY=","Message-ID":"<b53b9d1f-ef80-4f1e-adaa-4effe2d1f6b0@ideasonboard.com>","Date":"Mon, 20 May 2024 18:13:20 +0530","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 2/4] libcamera: converter_v4l2_m2m: Support crop\n\tselection","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20240519115622.32170-1-umang.jain@ideasonboard.com>\n\t<20240519115622.32170-3-umang.jain@ideasonboard.com>\n\t<171620232021.2248009.9132217154973139915@ping.linuxembedded.co.uk>","Content-Language":"en-US","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<171620232021.2248009.9132217154973139915@ping.linuxembedded.co.uk>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>"}}]