From patchwork Sat Aug 17 10:59:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1813 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 7B0FF600F9 for ; Sat, 17 Aug 2019 12:58:16 +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 F0EBE1C0002; Sat, 17 Aug 2019 10:58:15 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 12:59:33 +0200 Message-Id: <20190817105937.29353-2-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 1/5] [TEMP] include: linux: Update v4l2-controls.h 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:16 -0000 Import a temporary version of the v4l2-controls.h with the newly added definition of V4L2_CID_CAMERA_SENSOR_LOCATION control. This patch should be temporary applied waiting for the newly added control to land in the mainline kernel version. Signed-off-by: Jacopo Mondi --- include/linux/v4l2-controls.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/v4l2-controls.h b/include/linux/v4l2-controls.h index 06479f2fb3ae..1d39129cb7d3 100644 --- a/include/linux/v4l2-controls.h +++ b/include/linux/v4l2-controls.h @@ -881,6 +881,11 @@ enum v4l2_auto_focus_range { #define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) #define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) +#define V4L2_CID_CAMERA_SENSOR_LOCATION (V4L2_CID_CAMERA_CLASS_BASE+34) +#define V4L2_LOCATION_FRONT 0 +#define V4L2_LOCATION_BACK 1 +#define V4L2_LOCATION_EXTERNAL 2 + /* FM Modulator class control IDs */ #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) From patchwork Sat Aug 17 10:59:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1814 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 36F1561919 for ; Sat, 17 Aug 2019 12:58:17 +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 ACC711C0002; Sat, 17 Aug 2019 10:58:16 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 12:59:34 +0200 Message-Id: <20190817105937.29353-3-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 2/5] libcamera: controls: Add camera location control 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:17 -0000 Define a new libcamera control used to specify the camera location. Provide an enumeration of possible values to describe the "front", "back" and "external" camera locations. Signed-off-by: Jacopo Mondi --- include/libcamera/control_ids.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/libcamera/control_ids.h b/include/libcamera/control_ids.h index 75b6a2d5cafe..97ba11ec5f7b 100644 --- a/include/libcamera/control_ids.h +++ b/include/libcamera/control_ids.h @@ -12,6 +12,12 @@ namespace libcamera { +enum CameraLocation { + CAMERA_LOCATION_FRONT, + CAMERA_LOCATION_BACK, + CAMERA_LOCATION_EXTERNAL, +}; + enum ControlId { AwbEnable, Brightness, @@ -19,6 +25,7 @@ enum ControlId { Saturation, ManualExposure, ManualGain, + Location, }; } /* namespace libcamera */ From patchwork Sat Aug 17 10:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1815 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 DFACD61919 for ; Sat, 17 Aug 2019 12:58:17 +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 648CD1C0002; 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:35 +0200 Message-Id: <20190817105937.29353-4-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 3/5] libcamera: camera_sensor: Store the camera location 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 Store the camera sensor location by parsing the V4L2_CID_CAMERA_SENSOR_LOCATION V4L2 control. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 25 +++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index a7670b449b31..2703d10c719e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -89,6 +89,31 @@ int CameraSensor::init() if (ret < 0) return ret; + /* Retrieve and store the camera sensor location. */ + V4L2ControlList controls; + controls.add(V4L2_CID_CAMERA_SENSOR_LOCATION); + + ret = subdev_->getControls(&controls); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to get camera sensor controls: " << ret; + return ret; + } + + V4L2Control *locationControl = controls[V4L2_CID_CAMERA_SENSOR_LOCATION]; + int64_t v4l2Location = locationControl->value(); + switch (v4l2Location) { + case V4L2_LOCATION_FRONT: + location_ = CAMERA_LOCATION_FRONT; + break; + case V4L2_LOCATION_BACK: + location_ = CAMERA_LOCATION_BACK; + break; + default: + LOG(CameraSensor, Error) << "Unsupported camera location"; + return -EINVAL; + } + /* Enumerate and cache media bus codes and sizes. */ const ImageFormats formats = subdev_->formats(0); if (formats.isEmpty()) { diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index fe033fb374c1..a237a1684605 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -10,6 +10,7 @@ #include #include +#include #include #include "log.h" @@ -55,6 +56,8 @@ private: std::vector mbusCodes_; std::vector sizes_; + + CameraLocation location_; }; } /* namespace libcamera */ 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 */ From patchwork Sat Aug 17 10:59:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1817 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 66C4661917 for ; Sat, 17 Aug 2019 12:58:19 +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 D9D311C0002; Sat, 17 Aug 2019 10:58:18 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 12:59:37 +0200 Message-Id: <20190817105937.29353-6-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 5/5] libcamera: camera_sensor: Retrieve sensor sizes 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:19 -0000 Retrieve the camera sensor pixel array sizes and the active pixel sizes using the V4L2 selection APIs. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 13 +++++++++++++ src/libcamera/include/camera_sensor.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 2703d10c719e..e6b01c242328 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -114,6 +114,19 @@ int CameraSensor::init() return -EINVAL; } + /* Retrieve and store the sensor pixel array and active area sizes. */ + ret = subdev_->getCropBounds(0, &activeAreaSize_); + if (ret) + return ret; + + Rectangle rect = {}; + ret = subdev_->getNativeSize(0, &rect); + if (ret) + return ret; + + pixelArraySize_.width = rect.w; + pixelArraySize_.height = rect.h; + /* Enumerate and cache media bus codes and sizes. */ const ImageFormats formats = subdev_->formats(0); if (formats.isEmpty()) { diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index a237a1684605..f6b184bf2838 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -58,6 +58,8 @@ private: std::vector sizes_; CameraLocation location_; + Size pixelArraySize_; + Rectangle activeAreaSize_; }; } /* namespace libcamera */