[{"id":31369,"web_url":"https://patchwork.libcamera.org/comment/31369/","msgid":"<76c47da8-4d0f-4968-8077-12f384d1e8d8@ideasonboard.com>","date":"2024-09-26T04:28:21","subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 25/09/24 11:37 pm, Laurent Pinchart wrote:\n> The V4L2VideoDevice class implements setSelection() but not\n> getSelection(). The latter is useful for instance to query crop bounds.\n> Implement the function.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI was already in favour of this a while ago ;-)\n\nhttps://patchwork.libcamera.org/patch/20432/\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>   include/libcamera/internal/v4l2_videodevice.h |  1 +\n>   src/libcamera/v4l2_videodevice.cpp            | 32 +++++++++++++++++++\n>   2 files changed, 33 insertions(+)\n>\n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 9057be08f18a..f021c2a0177b 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -208,6 +208,7 @@ public:\n>   \tint setFormat(V4L2DeviceFormat *format);\n>   \tFormats formats(uint32_t code = 0);\n>   \n> +\tint getSelection(unsigned int target, Rectangle *rect);\n>   \tint setSelection(unsigned int target, Rectangle *rect);\n>   \n>   \tint allocateBuffers(unsigned int count,\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 93cb1697935e..14eba0561d6a 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1214,6 +1214,38 @@ std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat)\n>   \treturn sizes;\n>   }\n>   \n> +/**\n> + * \\brief Get the selection rectangle for \\a target\n> + * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> + * \\param[out] rect The selection rectangle to retrieve\n> + *\n> + * \\todo Define a V4L2SelectionTarget enum for the selection target\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::getSelection(unsigned int target, Rectangle *rect)\n> +{\n> +\tstruct v4l2_selection sel = {};\n> +\n> +\tsel.type = bufferType_;\n> +\tsel.target = target;\n> +\tsel.flags = 0;\n> +\n> +\tint ret = ioctl(VIDIOC_G_SELECTION, &sel);\n> +\tif (ret < 0) {\n> +\t\tLOG(V4L2, Error) << \"Unable to get rectangle \" << target\n> +\t\t\t\t << \": \" << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\trect->x = sel.r.left;\n> +\trect->y = sel.r.top;\n> +\trect->width = sel.r.width;\n> +\trect->height = sel.r.height;\n> +\n> +\treturn 0;\n> +}\n> +\n>   /**\n>    * \\brief Set a selection rectangle \\a rect for \\a target\n>    * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n>\n> base-commit: 8bcec687344e5cc2ccef1361c03b87f0fd2cc59b","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 AAFC7C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 04:28:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9C3656350E;\n\tThu, 26 Sep 2024 06:28:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63782618D7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 06:28:25 +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 09AB6169;\n\tThu, 26 Sep 2024 06:26:56 +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=\"R2HfLp61\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727324817;\n\tbh=iwXDTwODdGjeOIOXteF6vuMNhYbFaujgT5ID0XVuSdg=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=R2HfLp61E8FB6BMOTc0dFAWvkH5ahUW5p+ChBQUD5byFVg/yUi1+NVnsKLLxlVHId\n\tXeQgVckZXDi05vBeVWk/cDMDkRtWSUDmWSWvM7kavGDfsEteY+Ooa5ixktTupvewpa\n\tBqFjJgMWgUySgMdDzp/bLCEVhmuIil1f3rfufE3g=","Message-ID":"<76c47da8-4d0f-4968-8077-12f384d1e8d8@ideasonboard.com>","Date":"Thu, 26 Sep 2024 09:58:21 +0530","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20240925180713.27476-1-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<20240925180713.27476-1-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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":31375,"web_url":"https://patchwork.libcamera.org/comment/31375/","msgid":"<uszhpfa4d6ejxw64t6nlh654bofi7rdedssemtvjap6ekmxhri@nqducaawqy36>","date":"2024-09-26T08:06:14","subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Laurent\n\nOn Wed, Sep 25, 2024 at 09:07:13PM GMT, Laurent Pinchart wrote:\n> The V4L2VideoDevice class implements setSelection() but not\n> getSelection(). The latter is useful for instance to query crop bounds.\n> Implement the function.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  include/libcamera/internal/v4l2_videodevice.h |  1 +\n>  src/libcamera/v4l2_videodevice.cpp            | 32 +++++++++++++++++++\n>  2 files changed, 33 insertions(+)\n>\n> diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> index 9057be08f18a..f021c2a0177b 100644\n> --- a/include/libcamera/internal/v4l2_videodevice.h\n> +++ b/include/libcamera/internal/v4l2_videodevice.h\n> @@ -208,6 +208,7 @@ public:\n>  \tint setFormat(V4L2DeviceFormat *format);\n>  \tFormats formats(uint32_t code = 0);\n>\n> +\tint getSelection(unsigned int target, Rectangle *rect);\n>  \tint setSelection(unsigned int target, Rectangle *rect);\n>\n>  \tint allocateBuffers(unsigned int count,\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 93cb1697935e..14eba0561d6a 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1214,6 +1214,38 @@ std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat)\n>  \treturn sizes;\n>  }\n>\n> +/**\n> + * \\brief Get the selection rectangle for \\a target\n> + * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> + * \\param[out] rect The selection rectangle to retrieve\n> + *\n> + * \\todo Define a V4L2SelectionTarget enum for the selection target\n> + *\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::getSelection(unsigned int target, Rectangle *rect)\n> +{\n> +\tstruct v4l2_selection sel = {};\n> +\n> +\tsel.type = bufferType_;\n> +\tsel.target = target;\n> +\tsel.flags = 0;\n> +\n> +\tint ret = ioctl(VIDIOC_G_SELECTION, &sel);\n> +\tif (ret < 0) {\n> +\t\tLOG(V4L2, Error) << \"Unable to get rectangle \" << target\n> +\t\t\t\t << \": \" << strerror(-ret);\n> +\t\treturn ret;\n\nJust noticed in this class we don't\n\n\t\tret = -errno;\n\t\tLOG(V4L2, Error) <<\n\t\t\t\t << strerror(-ret);\n\t\treturn ret;\n\nNot related to this patch though\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n> +\t}\n> +\n> +\trect->x = sel.r.left;\n> +\trect->y = sel.r.top;\n> +\trect->width = sel.r.width;\n> +\trect->height = sel.r.height;\n> +\n> +\treturn 0;\n> +}\n> +\n>  /**\n>   * \\brief Set a selection rectangle \\a rect for \\a target\n>   * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n>\n> base-commit: 8bcec687344e5cc2ccef1361c03b87f0fd2cc59b\n> --\n> Regards,\n>\n> Laurent Pinchart\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 DB0C1C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 08:06:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8ACAF6350E;\n\tThu, 26 Sep 2024 10:06:19 +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 E47CB634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 10:06:17 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C4C35169;\n\tThu, 26 Sep 2024 10:04:49 +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=\"idAG4Aib\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727337889;\n\tbh=s5ImiMgc7iDiflgXEGuWdXI9GeA0DeqUa3ensReUjeE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=idAG4Aib2sBHep7BF7f7xIoufLLH30OE+jZfgSOnlcdgIbYLhL5uvkKHhmY41xeVB\n\t0rV+UqMl2qvFRYFIkt1HNfXhZRhuQNbz97dpx26pw9gL5yNQdeIWzxa+ESJKGGJ1Au\n\tyYUAx1uiGCj/gTsGyf7RwPzjWOu/IKEDDPLO9kN8=","Date":"Thu, 26 Sep 2024 10:06:14 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","Message-ID":"<uszhpfa4d6ejxw64t6nlh654bofi7rdedssemtvjap6ekmxhri@nqducaawqy36>","References":"<20240925180713.27476-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240925180713.27476-1-laurent.pinchart@ideasonboard.com>","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":31386,"web_url":"https://patchwork.libcamera.org/comment/31386/","msgid":"<20240926093327.GC27736@pendragon.ideasonboard.com>","date":"2024-09-26T09:33:27","subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Sep 26, 2024 at 10:06:14AM +0200, Jacopo Mondi wrote:\n> Hi Laurent\n> \n> On Wed, Sep 25, 2024 at 09:07:13PM GMT, Laurent Pinchart wrote:\n> > The V4L2VideoDevice class implements setSelection() but not\n> > getSelection(). The latter is useful for instance to query crop bounds.\n> > Implement the function.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  include/libcamera/internal/v4l2_videodevice.h |  1 +\n> >  src/libcamera/v4l2_videodevice.cpp            | 32 +++++++++++++++++++\n> >  2 files changed, 33 insertions(+)\n> >\n> > diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> > index 9057be08f18a..f021c2a0177b 100644\n> > --- a/include/libcamera/internal/v4l2_videodevice.h\n> > +++ b/include/libcamera/internal/v4l2_videodevice.h\n> > @@ -208,6 +208,7 @@ public:\n> >  \tint setFormat(V4L2DeviceFormat *format);\n> >  \tFormats formats(uint32_t code = 0);\n> >\n> > +\tint getSelection(unsigned int target, Rectangle *rect);\n> >  \tint setSelection(unsigned int target, Rectangle *rect);\n> >\n> >  \tint allocateBuffers(unsigned int count,\n> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > index 93cb1697935e..14eba0561d6a 100644\n> > --- a/src/libcamera/v4l2_videodevice.cpp\n> > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > @@ -1214,6 +1214,38 @@ std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat)\n> >  \treturn sizes;\n> >  }\n> >\n> > +/**\n> > + * \\brief Get the selection rectangle for \\a target\n> > + * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> > + * \\param[out] rect The selection rectangle to retrieve\n> > + *\n> > + * \\todo Define a V4L2SelectionTarget enum for the selection target\n> > + *\n> > + * \\return 0 on success or a negative error code otherwise\n> > + */\n> > +int V4L2VideoDevice::getSelection(unsigned int target, Rectangle *rect)\n> > +{\n> > +\tstruct v4l2_selection sel = {};\n> > +\n> > +\tsel.type = bufferType_;\n> > +\tsel.target = target;\n> > +\tsel.flags = 0;\n> > +\n> > +\tint ret = ioctl(VIDIOC_G_SELECTION, &sel);\n> > +\tif (ret < 0) {\n> > +\t\tLOG(V4L2, Error) << \"Unable to get rectangle \" << target\n> > +\t\t\t\t << \": \" << strerror(-ret);\n> > +\t\treturn ret;\n> \n> Just noticed in this class we don't\n> \n> \t\tret = -errno;\n> \t\tLOG(V4L2, Error) <<\n> \t\t\t\t << strerror(-ret);\n> \t\treturn ret;\n\nThat's because we're calling V4L2Device::ioctl(), which returns -errno.\n\n> Not related to this patch though\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> \n> > +\t}\n> > +\n> > +\trect->x = sel.r.left;\n> > +\trect->y = sel.r.top;\n> > +\trect->width = sel.r.width;\n> > +\trect->height = sel.r.height;\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> >  /**\n> >   * \\brief Set a selection rectangle \\a rect for \\a target\n> >   * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> >\n> > base-commit: 8bcec687344e5cc2ccef1361c03b87f0fd2cc59b","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 14705C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 09:33:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3FE3D6350E;\n\tThu, 26 Sep 2024 11:33:32 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 78CC6634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 11:33:30 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A9631237;\n\tThu, 26 Sep 2024 11:32:01 +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=\"Yfv54i4D\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727343122;\n\tbh=1NlGDhWf9JYgV7NMg2tJuwlABi08FJzAz4U8nUdXQPE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Yfv54i4DGk9hAublopaZsBjhYx1Yd5N3IH2GZsdcUn99HyFI2O7/+2m9lnh8intk2\n\tadAZDEPab+8fs7e5sTaM2nrKCnooptGxZWe50bUW/b+3jh6OIMvb1ua/dHeC44/kFq\n\t98aS4KZnt5arVtQyhLmQzpdw5icHKWdjHJCzI7OM=","Date":"Thu, 26 Sep 2024 12:33:27 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","Message-ID":"<20240926093327.GC27736@pendragon.ideasonboard.com>","References":"<20240925180713.27476-1-laurent.pinchart@ideasonboard.com>\n\t<uszhpfa4d6ejxw64t6nlh654bofi7rdedssemtvjap6ekmxhri@nqducaawqy36>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<uszhpfa4d6ejxw64t6nlh654bofi7rdedssemtvjap6ekmxhri@nqducaawqy36>","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":31389,"web_url":"https://patchwork.libcamera.org/comment/31389/","msgid":"<k3t5gjbl3hub2edjla5qgpxx4gefc22uey7u6dvcriruzxmdo5@eqt5yn2wtdw4>","date":"2024-09-26T09:39:52","subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"On Thu, Sep 26, 2024 at 12:33:27PM GMT, Laurent Pinchart wrote:\n> On Thu, Sep 26, 2024 at 10:06:14AM +0200, Jacopo Mondi wrote:\n> > Hi Laurent\n> >\n> > On Wed, Sep 25, 2024 at 09:07:13PM GMT, Laurent Pinchart wrote:\n> > > The V4L2VideoDevice class implements setSelection() but not\n> > > getSelection(). The latter is useful for instance to query crop bounds.\n> > > Implement the function.\n> > >\n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  include/libcamera/internal/v4l2_videodevice.h |  1 +\n> > >  src/libcamera/v4l2_videodevice.cpp            | 32 +++++++++++++++++++\n> > >  2 files changed, 33 insertions(+)\n> > >\n> > > diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\n> > > index 9057be08f18a..f021c2a0177b 100644\n> > > --- a/include/libcamera/internal/v4l2_videodevice.h\n> > > +++ b/include/libcamera/internal/v4l2_videodevice.h\n> > > @@ -208,6 +208,7 @@ public:\n> > >  \tint setFormat(V4L2DeviceFormat *format);\n> > >  \tFormats formats(uint32_t code = 0);\n> > >\n> > > +\tint getSelection(unsigned int target, Rectangle *rect);\n> > >  \tint setSelection(unsigned int target, Rectangle *rect);\n> > >\n> > >  \tint allocateBuffers(unsigned int count,\n> > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> > > index 93cb1697935e..14eba0561d6a 100644\n> > > --- a/src/libcamera/v4l2_videodevice.cpp\n> > > +++ b/src/libcamera/v4l2_videodevice.cpp\n> > > @@ -1214,6 +1214,38 @@ std::vector<SizeRange> V4L2VideoDevice::enumSizes(V4L2PixelFormat pixelFormat)\n> > >  \treturn sizes;\n> > >  }\n> > >\n> > > +/**\n> > > + * \\brief Get the selection rectangle for \\a target\n> > > + * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> > > + * \\param[out] rect The selection rectangle to retrieve\n> > > + *\n> > > + * \\todo Define a V4L2SelectionTarget enum for the selection target\n> > > + *\n> > > + * \\return 0 on success or a negative error code otherwise\n> > > + */\n> > > +int V4L2VideoDevice::getSelection(unsigned int target, Rectangle *rect)\n> > > +{\n> > > +\tstruct v4l2_selection sel = {};\n> > > +\n> > > +\tsel.type = bufferType_;\n> > > +\tsel.target = target;\n> > > +\tsel.flags = 0;\n> > > +\n> > > +\tint ret = ioctl(VIDIOC_G_SELECTION, &sel);\n> > > +\tif (ret < 0) {\n> > > +\t\tLOG(V4L2, Error) << \"Unable to get rectangle \" << target\n> > > +\t\t\t\t << \": \" << strerror(-ret);\n> > > +\t\treturn ret;\n> >\n> > Just noticed in this class we don't\n> >\n> > \t\tret = -errno;\n> > \t\tLOG(V4L2, Error) <<\n> > \t\t\t\t << strerror(-ret);\n> > \t\treturn ret;\n>\n> That's because we're calling V4L2Device::ioctl(), which returns -errno.\n\nI thought the whole point of the above churn was because writing to an\niostream like LOG() << does overwrites errno, but indeed in this case\nerrno is already returned by the ioctl() function. Sorry for the noise!\n\n>\n> > Not related to this patch though\n> > Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> >\n> > > +\t}\n> > > +\n> > > +\trect->x = sel.r.left;\n> > > +\trect->y = sel.r.top;\n> > > +\trect->width = sel.r.width;\n> > > +\trect->height = sel.r.height;\n> > > +\n> > > +\treturn 0;\n> > > +}\n> > > +\n> > >  /**\n> > >   * \\brief Set a selection rectangle \\a rect for \\a target\n> > >   * \\param[in] target The selection target defined by the V4L2_SEL_TGT_* flags\n> > >\n> > > base-commit: 8bcec687344e5cc2ccef1361c03b87f0fd2cc59b\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 14279C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Sep 2024 09:39:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 35C9A6350F;\n\tThu, 26 Sep 2024 11:39:58 +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 C9943634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Sep 2024 11:39:56 +0200 (CEST)","from ideasonboard.com (mob-5-90-51-229.net.vodafone.it\n\t[5.90.51.229])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3B8CC8D4;\n\tThu, 26 Sep 2024 11:38:28 +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=\"ihC6LN3h\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727343508;\n\tbh=d/FYB4EDSom375idP2SMJahHAAmmW8yiefAUbK6axWA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ihC6LN3hGPKbwT4/ImngvzoQjqnasaxIq7So6ADIqrG2XT5chA4SbTfFb6Kl5Fa4O\n\t0Yn6tcLwC2PfVmmngQvZuwKFPilimEDs3nDc97kCVhjGiVWoQcqlsTvVxjTXQQum9u\n\tRvGwjfk3aqnELT+BND0MjJwDUZJxRC/hGMN0tiSQ=","Date":"Thu, 26 Sep 2024 11:39:52 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] libcamera: v4l2_videodevice: Add getSelection() function","Message-ID":"<k3t5gjbl3hub2edjla5qgpxx4gefc22uey7u6dvcriruzxmdo5@eqt5yn2wtdw4>","References":"<20240925180713.27476-1-laurent.pinchart@ideasonboard.com>\n\t<uszhpfa4d6ejxw64t6nlh654bofi7rdedssemtvjap6ekmxhri@nqducaawqy36>\n\t<20240926093327.GC27736@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240926093327.GC27736@pendragon.ideasonboard.com>","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>"}}]