[{"id":4621,"web_url":"https://patchwork.libcamera.org/comment/4621/","msgid":"<20200428165321.GG5859@pendragon.ideasonboard.com>","date":"2020-04-28T16:53:21","subject":"Re: [libcamera-devel] [PATCH v5 1/7] libcamera: v4l2_subdevice:\n\tExpose setSelection()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Tue, Apr 28, 2020 at 11:19:28AM +0200, Jacopo Mondi wrote:\n> Expose V4L2Subdevice::setSelection() method and drop\n> V4L2Subdevice::setCrop() and V4L2Subdevice::setComopse() as wrapping\n\ns/setComopse/setCompose/\n\n> each target with a single function does not provide any benefit.\n> \n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/include/v4l2_subdevice.h |  7 +--\n>  src/libcamera/pipeline/ipu3/ipu3.cpp   |  4 +-\n>  src/libcamera/v4l2_subdevice.cpp       | 76 ++++++++++----------------\n>  3 files changed, 34 insertions(+), 53 deletions(-)\n> \n> diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\n> index 4a04eadfb1f9..9a5c812db9b6 100644\n> --- a/src/libcamera/include/v4l2_subdevice.h\n> +++ b/src/libcamera/include/v4l2_subdevice.h\n> @@ -46,8 +46,8 @@ public:\n>  \n>  \tconst MediaEntity *entity() const { return entity_; }\n>  \n> -\tint setCrop(unsigned int pad, Rectangle *rect);\n> -\tint setCompose(unsigned int pad, Rectangle *rect);\n> +\tint setSelection(unsigned int pad, unsigned int target,\n> +\t\t\t Rectangle *rect);\n>  \n>  \tImageFormats formats(unsigned int pad);\n>  \n> @@ -67,9 +67,6 @@ private:\n>  \tstd::vector<SizeRange> enumPadSizes(unsigned int pad,\n>  \t\t\t\t\t    unsigned int code);\n>  \n> -\tint setSelection(unsigned int pad, unsigned int target,\n> -\t\t\t Rectangle *rect);\n> -\n>  \tconst MediaEntity *entity_;\n>  };\n>  \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index b45900159d06..ff33f15f9eac 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -1135,11 +1135,11 @@ int ImgUDevice::configureInput(const Size &size,\n>  \t\t.width = inputFormat->size.width,\n>  \t\t.height = inputFormat->size.height,\n>  \t};\n> -\tret = imgu_->setCrop(PAD_INPUT, &rect);\n> +\tret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_CROP, &rect);\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> -\tret = imgu_->setCompose(PAD_INPUT, &rect);\n> +\tret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_COMPOSE, &rect);\n>  \tif (ret)\n>  \t\treturn ret;\n>  \n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index 5a479a96b795..432e89eacbd3 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -134,27 +134,42 @@ int V4L2Subdevice::open()\n>   */\n>  \n>  /**\n> - * \\brief Set a crop rectangle on one of the V4L2 subdevice pads\n> + * \\brief Set selection rectangle \\a rect for \\a target\n>   * \\param[in] pad The 0-indexed pad number the rectangle is to be applied to\n> - * \\param[inout] rect The rectangle describing crop target area\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>   * \\return 0 on success or a negative error code otherwise\n>   */\n> -int V4L2Subdevice::setCrop(unsigned int pad, Rectangle *rect)\n> +int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n> +\t\t\t\tRectangle *rect)\n>  {\n> -\treturn setSelection(pad, V4L2_SEL_TGT_CROP, rect);\n> -}\n> +\tstruct v4l2_subdev_selection sel = {};\n>  \n> -/**\n> - * \\brief Set a compose rectangle on one of the V4L2 subdevice pads\n> - * \\param[in] pad The 0-indexed pad number the rectangle is to be applied to\n> - * \\param[inout] rect The rectangle describing the compose target area\n> - * \\return 0 on success or a negative error code otherwise\n> - */\n> -int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect)\n> -{\n> -\treturn setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect);\n> -}\n> +\tsel.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> +\tsel.pad = pad;\n> +\tsel.target = target;\n> +\tsel.flags = 0;\n>  \n> +\tsel.r.left = rect->x;\n> +\tsel.r.top = rect->y;\n> +\tsel.r.width = rect->width;\n> +\tsel.r.height = rect->height;\n> +\n> +\tint ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);\n> +\tif (ret < 0) {\n> +\t\tLOG(V4L2, Error)\n> +\t\t\t<< \"Unable to set rectangle \" << target << \" on pad \"\n> +\t\t\t<< pad << \": \" << 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>   * \\brief Enumerate all media bus codes and frame sizes on a \\a pad\n>   * \\param[in] pad The 0-indexed pad number to enumerate formats on\n> @@ -343,35 +358,4 @@ std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n>  \treturn sizes;\n>  }\n>  \n> -int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n> -\t\t\t\tRectangle *rect)\n> -{\n> -\tstruct v4l2_subdev_selection sel = {};\n> -\n> -\tsel.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n> -\tsel.pad = pad;\n> -\tsel.target = target;\n> -\tsel.flags = 0;\n> -\n> -\tsel.r.left = rect->x;\n> -\tsel.r.top = rect->y;\n> -\tsel.r.width = rect->width;\n> -\tsel.r.height = rect->height;\n> -\n> -\tint ret = ioctl(VIDIOC_SUBDEV_S_SELECTION, &sel);\n> -\tif (ret < 0) {\n> -\t\tLOG(V4L2, Error)\n> -\t\t\t<< \"Unable to set rectangle \" << target << \" on pad \"\n> -\t\t\t<< pad << \": \" << 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>  } /* namespace libcamera */","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 91C5C60AF5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Apr 2020 18:53:37 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EC69172C;\n\tTue, 28 Apr 2020 18:53:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Geztqp+I\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1588092817;\n\tbh=EXxaYsFQZRQhcxqWJ9Rjp9VprfjHh1rjAVAsYtrMXoA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Geztqp+IiAa7egh9mzUAr6jyA8IebLLzcu8WE36OgVa5n318A8N0jbUv8oJh293oV\n\tSQhF0Kpg3yCUp1KIoSNtpz0SDQoliGz0OJVb1tXbrcs/sd5iN4oAji0Jluwbpvu5JE\n\t28XQuM0X5oes1xQpFNUrWIk8XBYm/6WGomGmHv04=","Date":"Tue, 28 Apr 2020 19:53:21 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org, Niklas =?utf-8?q?S=C3=B6derlund?=\n\t<niklas.soderlund@ragnatech.se>","Message-ID":"<20200428165321.GG5859@pendragon.ideasonboard.com>","References":"<20200428091934.341550-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200428091934.341550-1-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v5 1/7] libcamera: v4l2_subdevice:\n\tExpose setSelection()","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>","X-List-Received-Date":"Tue, 28 Apr 2020 16:53:37 -0000"}}]