From patchwork Mon Jun 29 16:39:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8511 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D4590BFFE2 for ; Mon, 29 Jun 2020 16:39:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED055609C9; Mon, 29 Jun 2020 18:39:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pvdy/ZbB"; dkim-atps=neutral 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 D99F2609C9 for ; Mon, 29 Jun 2020 18:39:20 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 604B0734; Mon, 29 Jun 2020 18:39:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593448760; bh=OIP4WTruUp1o6JlxmW87MKbgWJZeLFdeDZmsN0fkOQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pvdy/ZbBArZwGt2fpFMn9p1sVuQ6125/mgpciPntVI4fttloQkAloabpZiQNUvzNY 1NciEVydNasYPsG5zNgmFUKtfmhnDEOCrQRml8S1JzKcjc1Gi0nJ89FHRmjhKMLD7V eD/Oh6/z1MBwRZ+VNhC21r0W7L18R/6YcKt7ZtUo= From: Kieran Bingham To: libcamera devel Date: Mon, 29 Jun 2020 17:39:13 +0100 Message-Id: <20200629163916.1815321-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> References: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] libcamera: camera: Allow unspecified roles for generateConfiguration 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Providing an empty set of roles is permitted to generate an empty configuration from the pipeline handlers. Overload the generateConfiguration() function such that not specifying a roles parameter will use an empty set, and return an empty configuration. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/camera.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 9c0e58f7864b..4d1a4a9f52ec 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -89,7 +89,7 @@ public: const ControlList &properties(); const std::set &streams() const; - std::unique_ptr generateConfiguration(const StreamRoles &roles); + std::unique_ptr generateConfiguration(const StreamRoles &roles = {}); int configure(CameraConfiguration *config); Request *createRequest(uint64_t cookie = 0); From patchwork Mon Jun 29 16:39:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8512 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E3FB3BFFE2 for ; Mon, 29 Jun 2020 16:39:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B172160AF2; Mon, 29 Jun 2020 18:39:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XoTlh50A"; dkim-atps=neutral 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 20B16609DB for ; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B41AEAF3; Mon, 29 Jun 2020 18:39:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593448760; bh=VvYQCSZDSdlBx3pYRD0FSJ2qtclPcmtvodBctcl9sDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XoTlh50A3KWlfH7oqXCHmOx+WBweFPFSlIkRG4cqxl8+QWhkN+jV3rLn1Ie80V1yE GkLLxvDo81BVa6qZv/AYVuRiOeqz7bBn8Z5XIqAKCrW2MqMhZ+vCq//n9wGwvh3KF+ g1wS+c6ipG81Pab7a2JNx0lsXIwdg/sdLnVOmOKY= From: Kieran Bingham To: libcamera devel Date: Mon, 29 Jun 2020 17:39:14 +0100 Message-Id: <20200629163916.1815321-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> References: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] libcamera: camera: Return a reference to the new configuration when adding 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Facilitate easily referencing of the newly added StreamConfiguration as the source structure is copied, and not used after it has been added. This simplifies the caller, and allows the caller to compare the structure it passed to add, and the newly added configuration after validate() has been called. Signed-off-by: Kieran Bingham --- include/libcamera/camera.h | 3 ++- src/libcamera/camera.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 4d1a4a9f52ec..aee3a69881fc 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -38,7 +38,8 @@ public: virtual ~CameraConfiguration(); - void addConfiguration(const StreamConfiguration &cfg); + StreamConfiguration &addConfiguration(const StreamConfiguration &cfg); + virtual Status validate() = 0; StreamConfiguration &at(unsigned int index); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 69a1b4428e3f..a3b91cecc86d 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -104,10 +104,18 @@ CameraConfiguration::~CameraConfiguration() /** * \brief Add a stream configuration to the camera configuration * \param[in] cfg The stream configuration + * + * This method adds a new stream configuration to the CameraConfiguration using + * the values given in cfg, which are copied. A reference to the destination + * new StreamConfiguration is returned. + * + * \return A reference to the newly added stream configuration */ -void CameraConfiguration::addConfiguration(const StreamConfiguration &cfg) +StreamConfiguration &CameraConfiguration::addConfiguration(const StreamConfiguration &cfg) { config_.push_back(cfg); + + return config_.back(); } /** From patchwork Mon Jun 29 16:39:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8513 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4E671C2E69 for ; Mon, 29 Jun 2020 16:39:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1771A60AFB; Mon, 29 Jun 2020 18:39:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="b0QJky2h"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7DFA7609DB for ; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1597C299; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593448761; bh=LCQ+bda7b5ut7nTHw6bSZBz2T05n5oUAGbVR1vch/yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b0QJky2hrsbdKgBcQEnPj2DPMpOrTvAkHmGbmbgCD+lnoEf1C2WRuudl2R4YR+oi4 0cvS6SQbkSY/GqJ0RcsqHgvLyiAcGoNLee7ojRoPKqealH60kLOnrRdENajd7vw3Mi YMMbqeY7EPFQDzERXrRTg1AnVOkJj9E+j5f/vmz8= From: Kieran Bingham To: libcamera devel Date: Mon, 29 Jun 2020 17:39:15 +0100 Message-Id: <20200629163916.1815321-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> References: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] android: camera_device: Provide a toPixelFormat helper 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rather than converting pixelformats through the map, and then dereferencing the iterator later, create a helper to explicitly return a PixelFormat type. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 29 +++++++++++++++++++++-------- src/android/camera_device.h | 1 + 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f788c11e7254..a6410f42fee8 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -923,6 +923,20 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) return requestTemplate->get(); } +PixelFormat CameraDevice::toPixelFormat(int format) +{ + /* Translate Android format code to libcamera pixel format. */ + auto it = formatsMap_.find(format); + if (it == formatsMap_.end()) { + LOG(HAL, Error) << "Requested format " + << utils::hex(format) + << " not supported"; + return PixelFormat(); + } + + return it->second; +} + /* * Inspect the stream_list to produce a list of StreamConfiguration to * be use to configure the Camera. @@ -932,11 +946,14 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; + PixelFormat format = toPixelFormat(stream->format); + LOG(HAL, Info) << "Stream #" << i << ", direction: " << stream->stream_type << ", width: " << stream->width << ", height: " << stream->height - << ", format: " << utils::hex(stream->format); + << ", format: " << utils::hex(stream->format) + << " (" << format.toString() << ")"; } /* Only one stream is supported. */ @@ -947,13 +964,9 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) camera3_stream_t *camera3Stream = stream_list->streams[0]; /* Translate Android format code to libcamera pixel format. */ - auto it = formatsMap_.find(camera3Stream->format); - if (it == formatsMap_.end()) { - LOG(HAL, Error) << "Requested format " - << utils::hex(camera3Stream->format) - << " not supported"; + PixelFormat format = toPixelFormat(camera3Stream->format); + if (!format.isValid()) return -EINVAL; - } /* * Hardcode viewfinder role, replacing the generated configuration @@ -969,7 +982,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) StreamConfiguration *streamConfiguration = &config_->at(0); streamConfiguration->size.width = camera3Stream->width; streamConfiguration->size.height = camera3Stream->height; - streamConfiguration->pixelFormat = it->second; + streamConfiguration->pixelFormat = format; switch (config_->validate()) { case CameraConfiguration::Valid: diff --git a/src/android/camera_device.h b/src/android/camera_device.h index ed11410a5577..5bd6cf416156 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -72,6 +72,7 @@ private: std::tuple calculateStaticMetadataSize(); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); + libcamera::PixelFormat toPixelFormat(int format); std::unique_ptr getResultMetadata(int frame_number, int64_t timestamp); From patchwork Mon Jun 29 16:39:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8514 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C423EBFFE2 for ; Mon, 29 Jun 2020 16:39:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B9E360AFF; Mon, 29 Jun 2020 18:39:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="M3qo4M/b"; dkim-atps=neutral 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 CF9C6609DB for ; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 69AC3734; Mon, 29 Jun 2020 18:39:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593448761; bh=2diS92rUVzZmaoS2xhsb+2exXlUEV3EBcAhvWMDMEEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3qo4M/b8uKaENRl3irwHmKgizEd3qyWxn6s56Vb9+kxQzqM5BPSvnNgCCqYwBSOa sB9uBPaALonlnE7OXHjVR0Peqp0ttXZd+b0mhTuvgH9yZEgKwKK2Jmv0e5wL3ipk1i rrXWoBUpdyCHQrBChhau+2uieLGmrqJfdOa+45p8= From: Kieran Bingham To: libcamera devel Date: Mon, 29 Jun 2020 17:39:16 +0100 Message-Id: <20200629163916.1815321-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> References: <20200629163916.1815321-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] android: camera_device: support multiple stream configurations 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create an initial Camera Configuration using an empty role set, and populate the StreamConfigurations manually from each of the streams given by the Android camera3_stream_configuration_t stream_list. Signed-off-by: Kieran Bingham --- src/android/camera_device.cpp | 72 ++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a6410f42fee8..568ba28067d0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -956,48 +956,52 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) << " (" << format.toString() << ")"; } - /* Only one stream is supported. */ - if (stream_list->num_streams != 1) { - LOG(HAL, Error) << "Only one stream supported"; - return -EINVAL; - } - camera3_stream_t *camera3Stream = stream_list->streams[0]; - - /* Translate Android format code to libcamera pixel format. */ - PixelFormat format = toPixelFormat(camera3Stream->format); - if (!format.isValid()) - return -EINVAL; - /* - * Hardcode viewfinder role, replacing the generated configuration - * parameters with the ones requested by the Android framework. + * Generate an empty configuration, and construct a StreamConfiguration + * for each camera3_stream to add to it. */ - StreamRoles roles = { StreamRole::Viewfinder }; - config_ = camera_->generateConfiguration(roles); - if (!config_ || config_->empty()) { + config_ = camera_->generateConfiguration(); + if (!config_) { LOG(HAL, Error) << "Failed to generate camera configuration"; return -EINVAL; } - StreamConfiguration *streamConfiguration = &config_->at(0); - streamConfiguration->size.width = camera3Stream->width; - streamConfiguration->size.height = camera3Stream->height; - streamConfiguration->pixelFormat = format; + for (unsigned int i = 0; i < stream_list->num_streams; ++i) { + camera3_stream_t *stream = stream_list->streams[i]; - switch (config_->validate()) { - case CameraConfiguration::Valid: - break; - case CameraConfiguration::Adjusted: - LOG(HAL, Info) << "Camera configuration adjusted"; - config_.reset(); - return -EINVAL; - case CameraConfiguration::Invalid: - LOG(HAL, Info) << "Camera configuration invalid"; - config_.reset(); - return -EINVAL; - } + PixelFormat format = toPixelFormat(stream->format); + if (!format.isValid()) + return -EINVAL; + + StreamConfiguration streamConfiguration; + + streamConfiguration.size.width = stream->width; + streamConfiguration.size.height = stream->height; + streamConfiguration.pixelFormat = format; + + StreamConfiguration &cfg = config_->addConfiguration(streamConfiguration); + + /* 'cfg' can be modifed during the validation process */ + CameraConfiguration::Status status = config_->validate(); + + LOG(HAL, Info) << "Stream #" << i << " (validated): " << cfg.toString(); - camera3Stream->max_buffers = streamConfiguration->bufferCount; + switch (status) { + case CameraConfiguration::Valid: + break; + case CameraConfiguration::Adjusted: + LOG(HAL, Info) << "Camera configuration adjusted"; + config_.reset(); + return -EINVAL; + case CameraConfiguration::Invalid: + LOG(HAL, Info) << "Camera configuration invalid"; + config_.reset(); + return -EINVAL; + } + + /* Use the bufferCount confirmed by the validation process. */ + stream->max_buffers = cfg.bufferCount; + } /* * Once the CameraConfiguration has been adjusted/validated