From patchwork Fri Jun 5 14:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 3950 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 CF3C160410 for ; Fri, 5 Jun 2020 16:07:12 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from localhost.localdomain (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 9102A20002; Fri, 5 Jun 2020 14:07:11 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Jun 2020 16:10:00 +0200 Message-Id: <20200605141002.49119-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200605141002.49119-1-jacopo@jmondi.org> References: <20200605141002.49119-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 6/8] libcamera: camera_sensor: Break out properties initialization 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: Fri, 05 Jun 2020 14:07:13 -0000 Refactor the CameraSensor properties initialization to a dedicated function as it is expected to grow as we augment the number of properties. While at it, move documentation of the properties() method to match the declaration order in the class definition. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- include/libcamera/internal/camera_sensor.h | 2 + src/libcamera/camera_sensor.cpp | 83 ++++++++++++---------- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d79bd9ce9d58..44dd4b099913 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -69,6 +69,8 @@ protected: std::string logPrefix() const; private: + int initProperties(); + const MediaEntity *entity_; std::unique_ptr subdev_; unsigned int pad_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index b14b4051dca6..b9428175c55e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -205,7 +205,47 @@ int CameraSensor::init() if (ret < 0) return ret; - /* Retrieve and store the camera sensor properties. */ + /* Enumerate, sort and cache media bus codes and sizes. */ + formats_ = subdev_->formats(pad_); + if (formats_.isEmpty()) { + LOG(CameraSensor, Error) << "No image format found"; + return -EINVAL; + } + + mbusCodes_ = formats_.formats(); + std::sort(mbusCodes_.begin(), mbusCodes_.end()); + + for (const auto &format : formats_.data()) { + const std::vector &ranges = format.second; + std::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes_), + [](const SizeRange &range) { return range.max; }); + } + + std::sort(sizes_.begin(), sizes_.end()); + + /* Remove duplicates. */ + auto last = std::unique(sizes_.begin(), sizes_.end()); + sizes_.erase(last, sizes_.end()); + + /* + * The sizes_ vector is sorted in ascending order, the resolution is + * thus the last element of the vector. + */ + resolution_ = sizes_.back(); + + return initProperties(); +} + +/** + * \brief Initialize the camera sensor standard properties + * + * This method initializes the camera sensor standard properties, by inspecting + * the control information reported by the sensor subdevice. + * + * \return 0 on success, a negative error code otherwise + */ +int CameraSensor::initProperties() +{ const ControlInfoMap &controls = subdev_->controls(); int32_t propertyValue; @@ -243,35 +283,6 @@ int CameraSensor::init() propertyValue = 0; properties_.set(properties::Rotation, propertyValue); - /* Enumerate, sort and cache media bus codes and sizes. */ - formats_ = subdev_->formats(pad_); - if (formats_.isEmpty()) { - LOG(CameraSensor, Error) << "No image format found"; - return -EINVAL; - } - - mbusCodes_ = formats_.formats(); - std::sort(mbusCodes_.begin(), mbusCodes_.end()); - - for (const auto &format : formats_.data()) { - const std::vector &ranges = format.second; - std::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes_), - [](const SizeRange &range) { return range.max; }); - } - - std::sort(sizes_.begin(), sizes_.end()); - - /* Remove duplicates. */ - auto last = std::unique(sizes_.begin(), sizes_.end()); - sizes_.erase(last, sizes_.end()); - - /* - * The sizes_ vector is sorted in ascending order, the resolution is - * thus the last element of the vector. - */ - resolution_ = sizes_.back(); - - return 0; } /** @@ -438,12 +449,6 @@ ControlList CameraSensor::getControls(const std::vector &ids) return subdev_->getControls(ids); } -/** - * \fn CameraSensor::properties() - * \brief Retrieve the camera sensor properties - * \return The list of camera sensor properties - */ - /** * \brief Write controls to the sensor * \param[in] ctrls The list of controls to write @@ -535,6 +540,12 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const return 0; } +/** + * \fn CameraSensor::properties() + * \brief Retrieve the camera sensor properties + * \return The list of camera sensor properties + */ + std::string CameraSensor::logPrefix() const { return "'" + entity_->name() + "'";