From patchwork Sat May 2 13:53:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3666 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C0045603FD for ; Sat, 2 May 2020 15:54:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hBE/v70p"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5344572C for ; Sat, 2 May 2020 15:54:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588427642; bh=OKFX7xSr0bMo3PigJy5KE87+0TYmKQR173fRRvRb1vI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hBE/v70pDuHtajtbN2+3Hc98A1d2ttHWzHL9aaTKOHFKrzz56geDvttxSgE4FoO7f 2eTYpvB2punFXEMcW/Si6jODClJsRyRLPGzBrUZFd85L/5jn/Rfny55+uD+6vSefTQ gnuMlHR/YZzS2xbk4TC7w+wF1MKKhkl3WwEEvSSY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 2 May 2020 16:53:53 +0300 Message-Id: <20200502135355.22757-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200502135355.22757-1-laurent.pinchart@ideasonboard.com> References: <20200502135355.22757-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: camera_sensor: Access entity directly 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: Sat, 02 May 2020 13:54:03 -0000 The CameraSensor::logPrefix() function accesses the entity from the subdev. Remove the level of indirection as we stored a pointer to the entity internally. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/camera_sensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index d7e11cdae7f0..ab2bed561cc6 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -539,7 +539,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const std::string CameraSensor::logPrefix() const { - return "'" + subdev_->entity()->name() + "'"; + return "'" + entity_->name() + "'"; } } /* namespace libcamera */ From patchwork Sat May 2 13:53:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3667 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 79D6A61632 for ; Sat, 2 May 2020 15:54:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RCqPYELr"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A54CD521 for ; Sat, 2 May 2020 15:54:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588427642; bh=FmAEuxMTptQY2dFF+o4azp4/AAyMQKLRr1GghYzWMS8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RCqPYELrATOufehlpqEHt9tlN8r6hag64QiwDWT9PdFFQIJdekzN+QjHpPwwpE05K +pfjZENHXJZ+CLe1tWChF2EWbcR+E4nh/lFdlFzof75qaSSKIEq/VIb+2RMIMf0fTL 8nX7OlN8orDYr3/3Fx1+0AvA6GYAvp1LEfNKAoq4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 2 May 2020 16:53:54 +0300 Message-Id: <20200502135355.22757-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200502135355.22757-1-laurent.pinchart@ideasonboard.com> References: <20200502135355.22757-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] libcamera: camera_sensor: Store subdevice in std::unique_ptr 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: Sat, 02 May 2020 13:54:03 -0000 Avoid the need for a manual delete in the destructor by using a unique pointer. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/camera_sensor.cpp | 5 ++--- src/libcamera/include/camera_sensor.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index ab2bed561cc6..9cfb3847dda6 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -133,7 +133,6 @@ LOG_DEFINE_CATEGORY(CameraSensor); CameraSensor::CameraSensor(const MediaEntity *entity) : entity_(entity), properties_(properties::properties) { - subdev_ = new V4L2Subdevice(entity); } /** @@ -141,7 +140,6 @@ CameraSensor::CameraSensor(const MediaEntity *entity) */ CameraSensor::~CameraSensor() { - delete subdev_; } /** @@ -197,7 +195,8 @@ int CameraSensor::init() else model_ = entityName; - /* Open the subdev. */ + /* Create and open the subdev. */ + subdev_ = std::make_unique(entity_); ret = subdev_->open(); if (ret < 0) return ret; diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index f39ea96dc77a..92cd90353e72 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_CAMERA_SENSOR_H__ #define __LIBCAMERA_CAMERA_SENSOR_H__ +#include #include #include @@ -68,7 +69,7 @@ protected: private: const MediaEntity *entity_; - V4L2Subdevice *subdev_; + std::unique_ptr subdev_; std::string model_; std::vector mbusCodes_; From patchwork Sat May 2 13:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3668 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C652261632 for ; Sat, 2 May 2020 15:54:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VQgffJzA"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6747372C for ; Sat, 2 May 2020 15:54:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1588427643; bh=56/vvXRpAYox/lAeKW3OCV3zjREAEV6rs+3uVkFWG0U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VQgffJzA8tDpf3N/GsSRpwptFCSmmrNGVrEHQyxZSCMja4xTA+T9G3Gu2QsvikDZv WVsWm/wepF4aM3A5sENkPhsYSeXTvKQ7u8l0QEjRxVbqqmRYd6bRgrqXzeBAm4KLWK Xl37T/OU5iPxAOQ0QlxS1NpqQmghZrlHX8xq/oaU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 2 May 2020 16:53:55 +0300 Message-Id: <20200502135355.22757-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.25.3 In-Reply-To: <20200502135355.22757-1-laurent.pinchart@ideasonboard.com> References: <20200502135355.22757-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] libcamera: camera_sensor: Prepare for multi-subdev camera sensors 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: Sat, 02 May 2020 13:54:04 -0000 While most camera sensors are exposed to userspace as a single subdev, this is not always the case. A notable exception is the smiapp driver, which exposes two or three subdevs. The subdev at the output of the camera sensor will thus have more than one pad. Prepare for this by removing the single-pad restriction, and locating the source pad dynamically. Signed-off-by: Laurent Pinchart --- src/libcamera/camera_sensor.cpp | 23 ++++++++++++++--------- src/libcamera/include/camera_sensor.h | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9cfb3847dda6..673d24ea8be6 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -131,7 +131,7 @@ LOG_DEFINE_CATEGORY(CameraSensor); * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), properties_(properties::properties) + : entity_(entity), pad_(UINT_MAX), properties_(properties::properties) { } @@ -152,9 +152,14 @@ CameraSensor::~CameraSensor() */ int CameraSensor::init() { - int ret; + for (const MediaPad *pad : entity_->pads()) { + if (pad->flags()) { + pad_ = pad->index(); + break; + } + } - if (entity_->pads().size() != 1) { + if (pad_ == UINT_MAX) { LOG(CameraSensor, Error) << "Sensors with more than one pad are not supported"; return -EINVAL; @@ -197,7 +202,7 @@ int CameraSensor::init() /* Create and open the subdev. */ subdev_ = std::make_unique(entity_); - ret = subdev_->open(); + int ret = subdev_->open(); if (ret < 0) return ret; @@ -241,7 +246,7 @@ int CameraSensor::init() properties_.set(properties::Rotation, propertyValue); /* Enumerate and cache media bus codes and sizes. */ - const ImageFormats formats = subdev_->formats(0); + const ImageFormats formats = subdev_->formats(pad_); if (formats.isEmpty()) { LOG(CameraSensor, Error) << "No image format found"; return -EINVAL; @@ -405,7 +410,7 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector &mbu */ int CameraSensor::setFormat(V4L2SubdeviceFormat *format) { - return subdev_->setFormat(0, format); + return subdev_->setFormat(pad_, format); } /** @@ -489,7 +494,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const /* Get the active area size. */ Rectangle rect = {}; - int ret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP_DEFAULT, &rect); + int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &rect); if (ret) { LOG(CameraSensor, Error) << "Failed to construct camera sensor info: " @@ -500,7 +505,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const 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); + ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &info->analogCrop); if (ret) { LOG(CameraSensor, Error) << "Failed to construct camera sensor info: " @@ -510,7 +515,7 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const /* The bit depth and image size depend on the currently applied format. */ V4L2SubdeviceFormat format{}; - ret = subdev_->getFormat(0, &format); + ret = subdev_->getFormat(pad_, &format); if (ret) return ret; info->bitsPerPixel = format.bitsPerPixel(); diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index 92cd90353e72..24993b74148f 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -70,6 +70,8 @@ protected: private: const MediaEntity *entity_; std::unique_ptr subdev_; + unsigned int pad_; + std::string model_; std::vector mbusCodes_;