From patchwork Tue Apr 28 09:19:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3592 Return-Path: Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DBC4961AD4 for ; Tue, 28 Apr 2020 11:16:39 +0200 (CEST) X-Originating-IP: 212.216.150.148 Received: from uno.homenet.telecomitalia.it (a-ur1-85.tin.it [212.216.150.148]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id E143140004; Tue, 28 Apr 2020 09:16:38 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Apr 2020 11:19:33 +0200 Message-Id: <20200428091934.341550-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200428091934.341550-1-jacopo@jmondi.org> References: <20200428091934.341550-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 6/7] libcamera: camera_sensor: Add method to get sensor info X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Apr 2020 09:16:40 -0000 Add a method to retrieve the CameraSensorInfo to the CameraSensor class. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 62 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 1 + 2 files changed, 63 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 2c016791e32f..5d2db28152be 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -461,6 +461,68 @@ int CameraSensor::setControls(ControlList *ctrls) return subdev_->setControls(ctrls); } +/** + * \brief Assemble and return the camera sensor info + * \param[out] info The camera sensor info + * + * The CameraSensorInfo content is assembled by inspecting the currently + * applied sensor configuration and the sensor static properties. + * + * \return 0 on success, a negative error code otherwise + */ +int CameraSensor::sensorInfo(CameraSensorInfo *info) const +{ + info->model = model(); + + /* Get the active area size. */ + Rectangle rect = {}; + int ret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP_DEFAULT, &rect); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to construct camera sensor info: " + << "the camera sensor does not report the active area"; + + return ret; + } + info->activeAreaSize = { rect.width, rect.height }; + + /* It's mandatory for the subdevice to report its crop rectangle. */ + ret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP, &info->analogCrop); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to construct camera sensor info: " + << "the camera sensor does not report the crop rectangle"; + return ret; + } + + /* The bit depth and image size depend on the currently applied format. */ + V4L2SubdeviceFormat format{}; + ret = subdev_->getFormat(0, &format); + if (ret) + return ret; + info->bitsPerPixel = format.bitsPerPixel(); + info->outputSize = format.size; + + /* + * Retrieve the pixel rate and the line length through V4L2 controls. + * Support for the V4L2_CID_PIXEL_RATE and V4L2_CID_HBLANK controls is + * mandatory. + */ + ControlList ctrls = subdev_->getControls({ V4L2_CID_PIXEL_RATE, + V4L2_CID_HBLANK }); + if (ctrls.empty()) { + LOG(CameraSensor, Error) + << "Failed to retrieve camera info controls"; + return -EINVAL; + } + + int32_t hblank = ctrls.get(V4L2_CID_HBLANK).get(); + info->lineLength = info->outputSize.width + hblank; + info->pixelRate = ctrls.get(V4L2_CID_PIXEL_RATE).get(); + + return 0; +} + std::string CameraSensor::logPrefix() const { return "'" + subdev_->entity()->name() + "'"; diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 33997f2ed7f2..9e029139b9b7 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -61,6 +61,7 @@ public: int setControls(ControlList *ctrls); const ControlList &properties() const { return properties_; } + int sensorInfo(CameraSensorInfo *info) const; protected: std::string logPrefix() const;