From patchwork Sat Aug 17 10:59:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1816 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A788061917 for ; Sat, 17 Aug 2019 12:58:18 +0200 (CEST) X-Originating-IP: 87.5.130.64 Received: from uno.homenet.telecomitalia.it (host64-130-dynamic.5-87-r.retail.telecomitalia.it [87.5.130.64]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 1E4CE1C0002; Sat, 17 Aug 2019 10:58:17 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 12:59:36 +0200 Message-Id: <20190817105937.29353-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190817105937.29353-1-jacopo@jmondi.org> References: <20190817105937.29353-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] libcamera: v4l2_subdevice: Add G_SELECTION ioctl support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Aug 2019 10:58:18 -0000 Add a private operation to perform G_SELECTION ioctl on the v4l2 subdevice and create two public methods to retrieve the crop bound rectangle and the subdevice native area size. Signed-off-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/include/v4l2_subdevice.h | 4 +++ src/libcamera/v4l2_subdevice.cpp | 48 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h index 9c077674f997..5316617c6873 100644 --- a/src/libcamera/include/v4l2_subdevice.h +++ b/src/libcamera/include/v4l2_subdevice.h @@ -43,6 +43,8 @@ public: int setCrop(unsigned int pad, Rectangle *rect); int setCompose(unsigned int pad, Rectangle *rect); + int getCropBounds(unsigned int pad, Rectangle *rect); + int getNativeSize(unsigned int pad, Rectangle *rect); ImageFormats formats(unsigned int pad); @@ -62,6 +64,8 @@ private: int setSelection(unsigned int pad, unsigned int target, Rectangle *rect); + int getSelection(unsigned int pad, unsigned int target, + Rectangle *rect); const MediaEntity *entity_; }; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index a188298de34c..5e661e2ef1fc 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -148,6 +148,28 @@ int V4L2Subdevice::setCompose(unsigned int pad, Rectangle *rect) return setSelection(pad, V4L2_SEL_TGT_COMPOSE, rect); } +/** + * \brief Get the crop bounds rectangle on one of the V4L2 subdevice pads + * \param[in] pad The 0-indexed pad number the rectangle is retrived from + * \param[out] rect The rectangle describing the crop bounds area + * \return 0 on success or a negative error code otherwise + */ +int V4L2Subdevice::getCropBounds(unsigned int pad, Rectangle *rect) +{ + return getSelection(pad, V4L2_SEL_TGT_CROP_BOUNDS, rect); +} + +/** + * \brief Get the native area size on one of the V4L2 subdevice pads + * \param[in] pad The 0-indexed pad number the native area is retrieved from + * \param[out] rect The rectangle describing the native size area + * \return 0 on success or a negative error code otherwise + */ +int V4L2Subdevice::getNativeSize(unsigned int pad, Rectangle *rect) +{ + return getSelection(pad, V4L2_SEL_TGT_NATIVE_SIZE, rect); +} + /** * \brief Enumerate all media bus codes and frame sizes on a \a pad * \param[in] pad The 0-indexed pad number to enumerate formats on @@ -360,4 +382,30 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target, return 0; } +int V4L2Subdevice::getSelection(unsigned int pad, unsigned int target, + Rectangle *rect) +{ + struct v4l2_subdev_selection sel = {}; + + sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; + sel.pad = pad; + sel.target = target; + sel.flags = 0; + + int ret = ioctl(VIDIOC_SUBDEV_G_SELECTION, &sel); + if (ret < 0) { + LOG(V4L2, Error) + << "Unable to get rectangle " << target << " on pad " + << pad << ": " << strerror(-ret); + return ret; + } + + rect->x = sel.r.left; + rect->y = sel.r.top; + rect->w = sel.r.width; + rect->h = sel.r.height; + + return 0; +} + } /* namespace libcamera */