From patchwork Tue Aug 27 09:50:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1861 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0534461580 for ; Tue, 27 Aug 2019 11:48:48 +0200 (CEST) Received: from uno.homenet.telecomitalia.it (unknown [87.18.63.98]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 796BF100008; Tue, 27 Aug 2019 09:48:47 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 27 Aug 2019 11:50:05 +0200 Message-Id: <20190827095008.11405-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827095008.11405-1-jacopo@jmondi.org> References: <20190827095008.11405-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/7] libcamera: camera_sensor: Collect camera properties 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: Tue, 27 Aug 2019 09:48:48 -0000 Store the camera sensor location and rotation by parsing the associated V4L2 controls. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 39 +++++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 4 +++ 2 files changed, 43 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index a7670b449b31..fc7fdcdcaf5b 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -89,6 +89,45 @@ int CameraSensor::init() if (ret < 0) return ret; + /* Retrieve and store the camera sensor properties. */ + V4L2ControlList controls({ + V4L2_CID_CAMERA_SENSOR_LOCATION, + V4L2_CID_CAMERA_SENSOR_ROTATION, + }); + ret = subdev_->getControls(&controls); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to get camera sensor controls: " << ret; + return ret; + } + + V4L2Control *control = controls[V4L2_CID_CAMERA_SENSOR_LOCATION]; + int64_t value = control->value(); + switch (value) { + 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: " << value; + return -EINVAL; + } + + control = controls[V4L2_CID_CAMERA_SENSOR_ROTATION]; + value = control->value(); + if (value < 0 || value > 360) { + LOG(CameraSensor, Error) + << "Unsupported camera rotation: " << value; + return -EINVAL; + } + rotation_ = value; + /* 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..32d39127b275 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,9 @@ private: std::vector mbusCodes_; std::vector sizes_; + + CameraLocation location_; + unsigned int rotation_; }; } /* namespace libcamera */