From patchwork Wed Dec 18 14:49:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2438 X-Patchwork-Delegate: jacopo@jmondi.org Return-Path: Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DEB01605D7 for ; Wed, 18 Dec 2019 15:47:53 +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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 6EF4160003; Wed, 18 Dec 2019 14:47:53 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 18 Dec 2019 15:49:57 +0100 Message-Id: <20191218145001.22283-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191218145001.22283-1-jacopo@jmondi.org> References: <20191218145001.22283-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 3/7] libcamera: camera_sensor: Factorize out 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: Wed, 18 Dec 2019 14:47:54 -0000 Factorize CameraSensor properties initialization to a dedicated virtual function that dervied classes could subclass to register sensor-specific properties. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 94 ++++++++++++++++----------- src/libcamera/include/camera_sensor.h | 5 +- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index d1c9c9bcd58f..9692895d9b7b 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -77,7 +77,7 @@ CameraSensor *CameraSensorFactory::create(const MediaEntity *entity) * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), properties_(properties::properties) + : properties_(properties::properties), entity_(entity) { subdev_ = new V4L2Subdevice(entity); } @@ -119,42 +119,6 @@ int CameraSensor::init() if (ret < 0) return ret; - /* Retrieve and store the camera sensor properties. */ - const ControlInfoMap &controls = subdev_->controls(); - int32_t propertyValue; - - /* Camera Location: default is front location. */ - const auto &locationControl = controls.find(V4L2_CID_CAMERA_SENSOR_LOCATION); - if (locationControl != controls.end()) { - int32_t v4l2Location = - locationControl->second.def().get(); - switch (v4l2Location) { - case V4L2_LOCATION_EXTERNAL: - propertyValue = properties::CameraLocationExternal; - break; - case V4L2_LOCATION_FRONT: - propertyValue = properties::CameraLocationFront; - break; - case V4L2_LOCATION_BACK: - propertyValue = properties::CameraLocationBack; - break; - default: - LOG(CameraSensor, Error) - << "Unsupported camera location: " << v4l2Location; - return -EINVAL; - } - } else { - propertyValue = properties::CameraLocationFront; - } - properties_.set(properties::Location, propertyValue); - - /* Camera Rotation: default is 0 degrees. */ - propertyValue = 0; - const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); - if (rotationControl != controls.end()) - propertyValue = rotationControl->second.def().get(); - properties_.set(properties::Rotation, propertyValue); - /* Enumerate and cache media bus codes and sizes. */ const ImageFormats formats = subdev_->formats(0); if (formats.isEmpty()) { @@ -185,6 +149,62 @@ int CameraSensor::init() std::sort(mbusCodes_.begin(), mbusCodes_.end()); std::sort(sizes_.begin(), sizes_.end()); + return initProperties(subdev_->controls()); +} + +/** + * \brief Initialize the camera sensor properties + * \param[in] controlMap The map of control information provided by the sensor + * + * This method initializes the camera sensor properties, by inspecting the + * control information reported by the sensor media entity in \a controlMap. + * For each supported standard V4L2 control reported by the sensor, a libcamera + * property is created and registered in the list of properties supported by the + * sensor. + * + * Derived classes are free to override this method to register sensor specific + * properties as they like, by inspecting custom controls or by adding + * properties with pre-defined values, and eventually call this base class + * implementation to register standard ones. + * + * \return 0 on success, a negative error code otherwise + */ +int CameraSensor::initProperties(const ControlInfoMap &controlMap) +{ + int32_t propertyValue; + + /* Camera Location: default is front location. */ + const auto &locationControl = controlMap.find(V4L2_CID_CAMERA_SENSOR_LOCATION); + if (locationControl != controlMap.end()) { + int32_t v4l2Location = + locationControl->second.def().get(); + switch (v4l2Location) { + case V4L2_LOCATION_EXTERNAL: + propertyValue = properties::CameraLocationExternal; + break; + case V4L2_LOCATION_FRONT: + propertyValue = properties::CameraLocationFront; + break; + case V4L2_LOCATION_BACK: + propertyValue = properties::CameraLocationBack; + break; + default: + LOG(CameraSensor, Error) + << "Unsupported camera location: " << v4l2Location; + return -EINVAL; + } + } else { + propertyValue = properties::CameraLocationFront; + } + properties_.set(properties::Location, propertyValue); + + /* Camera Rotation: default is 0 degrees. */ + propertyValue = 0; + const auto &rotationControl = controlMap.find(V4L2_CID_CAMERA_SENSOR_ROTATION); + if (rotationControl != controlMap.end()) + propertyValue = rotationControl->second.def().get(); + properties_.set(properties::Rotation, propertyValue); + return 0; } diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 2c09b1bdb61b..43748a6c8535 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -38,6 +38,7 @@ public: CameraSensor &operator=(const CameraSensor &) = delete; int init(); + virtual int initProperties(const ControlInfoMap &controlMap); const MediaEntity *entity() const { return entity_; } const std::vector &mbusCodes() const { return mbusCodes_; } @@ -55,6 +56,8 @@ public: const ControlList &properties() const { return properties_; } protected: + ControlList properties_; + friend class CameraSensorFactory; explicit CameraSensor(const MediaEntity *entity); std::string logPrefix() const; @@ -65,8 +68,6 @@ private: std::vector mbusCodes_; std::vector sizes_; - - ControlList properties_; }; } /* namespace libcamera */