From patchwork Tue Nov 19 16:44:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2330 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1ED85617A0 for ; Tue, 19 Nov 2019 17:42:29 +0100 (CET) X-Originating-IP: 93.34.114.233 Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id B657020005; Tue, 19 Nov 2019 16:42:28 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Nov 2019 17:44:21 +0100 Message-Id: <20191119164421.68983-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191119164421.68983-1-jacopo@jmondi.org> References: <20191119164421.68983-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 6/6] libcamera: camera_sensor: Collect camera properties 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, 19 Nov 2019 16:42:29 -0000 Store the camera sensor location and rotation by parsing the associated V4L2 controls. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 32 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 86f0c772861b..857853f4fcf9 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -13,6 +13,8 @@ #include #include +#include + #include "formats.h" #include "utils.h" #include "v4l2_subdevice.h" @@ -89,6 +91,36 @@ int CameraSensor::init() if (ret < 0) return ret; + /* Retrieve and store the camera sensor properties. */ + const ControlInfoMap &controls = subdev_->controls(); + int32_t controlValue = V4L2_LOCATION_EXTERNAL; + + const auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION); + if (locationControl != controls.end()) + controlValue = locationControl->second.defaultValue().get(); + + switch (controlValue) { + case V4L2_LOCATION_EXTERNAL: + location_ = CAMERA_LOCATION_EXTERNAL; + break; + 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: " << controlValue; + return -EINVAL; + } + + controlValue = 0; + const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); + if (rotationControl != controls.end()) + controlValue = rotationControl->second.defaultValue().get(); + rotation_ = controlValue; + /* 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 1fb36a4f4951..ee26ca20ac20 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -56,6 +56,9 @@ private: std::vector mbusCodes_; std::vector sizes_; + + unsigned int location_; + unsigned int rotation_; }; } /* namespace libcamera */