From patchwork Mon Jul 6 15:38:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8652 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 5E253BD790 for ; Mon, 6 Jul 2020 15:38:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8CB6360E05; Mon, 6 Jul 2020 17:38:14 +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="eLE2zV5H"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F2D28603AA for ; Mon, 6 Jul 2020 17:38:12 +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 600DEAC6; Mon, 6 Jul 2020 17:38:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049892; bh=Ryw+qOixyBuEMieEDC/DJyE24i6nMiEbmEfegzYOkVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLE2zV5HTN70rdMyGFFs3DsvjuGeO/zyy02PKmP5SWxXlS8Judh6M2jbe9WE1jvjj FtJYmjdGwFngqrUANqC3tzll6OBF39Krx54wv5E54v1veqw2Jyl6z+4OOqbMQ7Y+bN +HFRvSTOUFlDcNUAfJPrCF84notXT4W2vFIfEPGQ= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:01 +0100 Message-Id: <20200706153808.2340919-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/8] 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 Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- 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 Jul 6 15:38:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8653 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 120F1BD790 for ; Mon, 6 Jul 2020 15:38:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CFF2A60E14; Mon, 6 Jul 2020 17:38:15 +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="c2c3W4zF"; 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 53DB9603AA for ; Mon, 6 Jul 2020 17:38:13 +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 CD115B1A; Mon, 6 Jul 2020 17:38:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049893; bh=sMhLp06T6QO0sZZzIFLbIjnWFqMx2rxp+l/GxwKKhHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c2c3W4zFkqSHWEY/LqnYoszFHqrpXM+zlJg7n/R4MgvSgFRNzM6QHqdzXOTN5pbaq dumgwAviCp1G1DzsRo7DrINQCBERs5k5E7CMKQDEQF54ZsuBia33qVKAuuQbK9BwiS VEFICtWnqt2bBGB/PBlwGrMAzyhGAwhrfbQxblDY= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:02 +0100 Message-Id: <20200706153808.2340919-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/8] 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 Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 28 ++++++++++++++++++++-------- src/android/camera_device.h | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f788c11e7254..b9031ff0c2a4 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -923,6 +923,19 @@ 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 +945,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 +963,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 +981,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 Jul 6 15:38:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8654 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 7A786BD790 for ; Mon, 6 Jul 2020 15:38:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2982D60E3F; Mon, 6 Jul 2020 17:38:16 +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="ubBvyeb/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BF021603AA for ; Mon, 6 Jul 2020 17:38:13 +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 452CDD6E; Mon, 6 Jul 2020 17:38:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049893; bh=Ptc5zwAay6Z3ejmiQwbWhpduyqCOONZtcScINP8ZE9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ubBvyeb/PU44K3GXqYQkzLXzL4Chj3nfSVLCHywLLLjtG2Ko0EPOfrCtd8OfxE8zm /78myKHYDoXzEkbdvgNr3ZYXl7KjcKqO8ZTt8HSJaYsK9byBRi7qapYbVi/oDX6QXJ 2JkH5gRbpMBAnObPsYfpluMfFtCnFFvKf7F3AKIU= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:03 +0100 Message-Id: <20200706153808.2340919-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/8] 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 Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 51 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index b9031ff0c2a4..03dcdd520794 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -942,6 +942,16 @@ PixelFormat CameraDevice::toPixelFormat(int format) */ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) { + /* + * Generate an empty configuration, and construct a StreamConfiguration + * for each camera3_stream to add to it. + */ + config_ = camera_->generateConfiguration(); + if (!config_) { + LOG(HAL, Error) << "Failed to generate camera configuration"; + return -EINVAL; + } + for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; @@ -953,35 +963,18 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) << ", height: " << stream->height << ", format: " << utils::hex(stream->format) << " (" << 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]; + if (!format.isValid()) + return -EINVAL; - /* Translate Android format code to libcamera pixel format. */ - PixelFormat format = toPixelFormat(camera3Stream->format); - if (!format.isValid()) - return -EINVAL; + StreamConfiguration streamConfiguration; - /* - * Hardcode viewfinder role, replacing the generated configuration - * parameters with the ones requested by the Android framework. - */ - StreamRoles roles = { StreamRole::Viewfinder }; - config_ = camera_->generateConfiguration(roles); - if (!config_ || config_->empty()) { - LOG(HAL, Error) << "Failed to generate camera configuration"; - return -EINVAL; - } + streamConfiguration.size.width = stream->width; + streamConfiguration.size.height = stream->height; + streamConfiguration.pixelFormat = format; - StreamConfiguration *streamConfiguration = &config_->at(0); - streamConfiguration->size.width = camera3Stream->width; - streamConfiguration->size.height = camera3Stream->height; - streamConfiguration->pixelFormat = format; + config_->addConfiguration(streamConfiguration); + } switch (config_->validate()) { case CameraConfiguration::Valid: @@ -996,7 +989,13 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return -EINVAL; } - camera3Stream->max_buffers = streamConfiguration->bufferCount; + for (unsigned int i = 0; i < stream_list->num_streams; ++i) { + camera3_stream_t *stream = stream_list->streams[i]; + StreamConfiguration &streamConfiguration = config_->at(i); + + /* Use the bufferCount confirmed by the validation process. */ + stream->max_buffers = streamConfiguration.bufferCount; + } /* * Once the CameraConfiguration has been adjusted/validated From patchwork Mon Jul 6 15:38:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8655 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 EEDCDBD790 for ; Mon, 6 Jul 2020 15:38:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BB17F60E18; Mon, 6 Jul 2020 17:38:18 +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="jGO+GV2e"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 378D860E14 for ; Mon, 6 Jul 2020 17:38:14 +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 B318ED98; Mon, 6 Jul 2020 17:38:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049893; bh=FIgZ7tdHmAgZPdqa+5fkin4TBMksUd11jEpciokXp24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jGO+GV2eNsyn/dOrdygreI6Kf6i6ZoQE7R4D+IKbyrlt9sBMWDhpdJD3LdHm+WOrh dDqDG6pMDBMw/Vhsa/JaeCwt6NmXY1IuIv3lCh8uiVFyrk8DQf8dlLKZ8cEI7O6zAz eOOHlCzAO9uLefKvEg81qVWJBM5VZ0nwiAhysCX8= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:04 +0100 Message-Id: <20200706153808.2340919-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 4/8] android: camera_device: Simplify FrameBuffer construction from a buffer_handle_t 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" Move the code which constructs a FrameBuffer from the Android buffer handle to it's own function to simplify the code flow and readability. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 35 +++++++++++++++++++---------------- src/android/camera_device.h | 1 + 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 03dcdd520794..73cfab532cf5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1011,6 +1011,24 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } +FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) +{ + std::vector planes; + for (unsigned int i = 0; i < 3; i++) { + FrameBuffer::Plane plane; + plane.fd = FileDescriptor(camera3buffer->data[i]); + /* + * Setting length to zero here is OK as the length is only used + * to map the memory of the plane. Libcamera do not need to poke + * at the memory content queued by the HAL. + */ + plane.length = 0; + planes.push_back(std::move(plane)); + } + + return new FrameBuffer(std::move(planes)); +} + int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { StreamConfiguration *streamConfiguration = &config_->at(0); @@ -1064,22 +1082,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * Create a libcamera buffer using the dmabuf descriptors of the first * and (currently) only supported request buffer. */ - const buffer_handle_t camera3Handle = *camera3Buffers[0].buffer; - - std::vector planes; - for (int i = 0; i < 3; i++) { - FrameBuffer::Plane plane; - plane.fd = FileDescriptor(camera3Handle->data[i]); - /* - * Setting length to zero here is OK as the length is only used - * to map the memory of the plane. Libcamera do not need to poke - * at the memory content queued by the HAL. - */ - plane.length = 0; - planes.push_back(std::move(plane)); - } - - FrameBuffer *buffer = new FrameBuffer(std::move(planes)); + FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[0].buffer); if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; delete descriptor; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 5bd6cf416156..d7834d94f439 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -70,6 +70,7 @@ private: int initializeStreamConfigurations(); std::tuple calculateStaticMetadataSize(); + libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); libcamera::PixelFormat toPixelFormat(int format); From patchwork Mon Jul 6 15:38:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8656 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 57688BD794 for ; Mon, 6 Jul 2020 15:38:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1CB6460E48; Mon, 6 Jul 2020 17:38:19 +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="wOnWiF+4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9EF0D60E1D for ; Mon, 6 Jul 2020 17:38:14 +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 1E5B4A16; Mon, 6 Jul 2020 17:38:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049894; bh=a5CwUdAjxt3flUTMdLjOgunysTtRsVIh3WDEwpt9gzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wOnWiF+4abQ5Jt7e7VP2O5OM/CdbjL/N3LArpk0Jep4VXZpD0ugI+EYIV9pdCF4kw GdiSY/zizwrjyeXcx6tOdvYzHE622mMoZfdwJTG31ysK14ZGX9/B29IXiqxvSqii4h bhpU2Lhjga0Cys6X3h2pmwYcPhyIrL/jaO+45OYU= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:05 +0100 Message-Id: <20200706153808.2340919-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/8] android: camera_device: Create the Request and Camera3RequestDescriptor together 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" Move the construction of the Request higher in the code flow so that multiple buffers and streams can be added where required. The Request is now stored as a unique_ptr within the Camera3RequestDescriptor to enforce a shared lifetime between the objects, freeing the Request when the descriptor is destroyed. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 9 ++++++--- src/android/camera_device.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 73cfab532cf5..fb120e8007dc 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1066,6 +1066,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques Camera3RequestDescriptor *descriptor = new Camera3RequestDescriptor(camera3Request->frame_number, camera3Request->num_output_buffers); + + Request *request = + camera_->createRequest(reinterpret_cast(descriptor)); + + descriptor->request = std::unique_ptr(request); + for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { /* * Keep track of which stream the request belongs to and store @@ -1089,14 +1095,11 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques return -ENOMEM; } - Request *request = - camera_->createRequest(reinterpret_cast(descriptor)); request->addBuffer(stream, buffer); int ret = camera_->queueRequest(request); if (ret) { LOG(HAL, Error) << "Failed to queue request"; - delete request; delete descriptor; return ret; } diff --git a/src/android/camera_device.h b/src/android/camera_device.h index d7834d94f439..018491d70c0a 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -61,6 +61,7 @@ private: uint32_t frameNumber; uint32_t numBuffers; camera3_stream_buffer_t *buffers; + std::unique_ptr request; }; struct Camera3StreamConfiguration { From patchwork Mon Jul 6 15:38:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8657 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 CED8EBD790 for ; Mon, 6 Jul 2020 15:38:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B6FC60E05; Mon, 6 Jul 2020 17:38:19 +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="CA9VduAY"; 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 133F3603AA for ; Mon, 6 Jul 2020 17:38:15 +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 878FFAC6; Mon, 6 Jul 2020 17:38:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049894; bh=8tv5PQqv/Yx+1Wzz2el9uY49tJROHNRFpvPnlLk3iCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CA9VduAYM+P1WGlJshZH5w3n6za22qMK+3JC06ZDYeOrXH1cXSq16XFSAd5kqEIPM b880bF5LoVxgmJRA57Af1hDvzpZRuhk1PRccWqvaQf3ytlfdfSoO+QKnHOvFOl2OVD 2Ku4jesUTTj0qN9Qx4YIufgGi2aLawHKgePDueeM= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:06 +0100 Message-Id: <20200706153808.2340919-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/8] android: camera_device: Maintain a vector of CameraStream 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" Introduce a vector storing a CameraStream to track and maintain state between an Android stream (camera3_stream_t) and a libcamera Stream. Only the index of the libcamera stream is stored, to facilitate identifying the correct index for both the StreamConfiguration and Stream vectors. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 21 +++++++++++++++++++-- src/android/camera_device.h | 10 ++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index fb120e8007dc..b86973959177 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -952,6 +952,20 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return -EINVAL; } + /* + * Clear and remove any existing configuration from previous calls, and + * ensure the required entries are available without further + * re-allcoation. + */ + streams_.clear(); + streams_.reserve(stream_list->num_streams); + + /* + * Track actually created streams, as there may not be a 1:1 mapping of + * camera3 streams to libcamera streams. + */ + unsigned int streamIndex = 0; + for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; @@ -974,6 +988,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streamConfiguration.pixelFormat = format; config_->addConfiguration(streamConfiguration); + + streams_[i].index = streamIndex++; } switch (config_->validate()) { @@ -991,10 +1007,11 @@ 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]; - StreamConfiguration &streamConfiguration = config_->at(i); + CameraStream *cameraStream = &streams_[i]; + StreamConfiguration &cfg = config_->at(cameraStream->index); /* Use the bufferCount confirmed by the validation process. */ - stream->max_buffers = streamConfiguration.bufferCount; + stream->max_buffers = cfg.bufferCount; } /* diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 018491d70c0a..f23d1b328472 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -25,6 +25,15 @@ class CameraMetadata; +struct CameraStream { + /* + * The index of the libcamera StreamConfiguration as added during + * configureStreams(). A single libcamera Stream may be used to deliver + * one or more streams to the Android framework. + */ + unsigned int index; +}; + class CameraDevice : protected libcamera::Loggable { public: @@ -91,6 +100,7 @@ private: std::vector streamConfigurations_; std::map formatsMap_; + std::vector streams_; int facing_; int orientation_; From patchwork Mon Jul 6 15:38:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8658 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 3B47ABD794 for ; Mon, 6 Jul 2020 15:38:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0B57F60E2B; Mon, 6 Jul 2020 17:38:20 +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="SBHo2bJ0"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A9A4603AB for ; Mon, 6 Jul 2020 17:38:15 +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 F3287D6E; Mon, 6 Jul 2020 17:38:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049895; bh=SFmhJM4PiStO69y+rjFhH2oJ7DSqd9i/3GUHXjVI1lA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBHo2bJ0jc3ZqYbLWP+fln3MPJS4sEvvHF2ljyc3UhcZYx0sIWdqbfHVyFA5OraEn f/YNDYsw9WedaxAVE04M+s8vqtP73Zdt474HnRfksH+BijWdtKhbzvF/3BU6EtWm/w upNJt5/dpBl5U+bdpQvSHR8sRu7eYbKQOyLqsbgA= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:07 +0100 Message-Id: <20200706153808.2340919-8-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 7/8] android: camera_device: Add buffers for each stream to Requests 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" Construct a FrameBuffer for every buffer given in the camera3Request and add it to the libcamera Request on the appropriate stream. The correct stream is obtained from the private data of the camera3_stream associated with the camera3_buffer. Comments regarding supporting only one buffer are now removed. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 54 +++++++++++++++++++---------------- src/android/camera_device.h | 1 + 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index b86973959177..f368726091f4 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -98,6 +98,7 @@ CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( : frameNumber(frameNumber), numBuffers(numBuffers) { buffers = new camera3_stream_buffer_t[numBuffers]; + frameBuffers.reserve(numBuffers); } CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor() @@ -990,6 +991,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) config_->addConfiguration(streamConfiguration); streams_[i].index = streamIndex++; + stream->priv = static_cast(&streams_[i]); } switch (config_->validate()) { @@ -1048,9 +1050,6 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { - StreamConfiguration *streamConfiguration = &config_->at(0); - Stream *stream = streamConfiguration->stream(); - if (camera3Request->num_output_buffers != 1) { LOG(HAL, Error) << "Invalid number of output buffers: " << camera3Request->num_output_buffers; @@ -1090,29 +1089,34 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->request = std::unique_ptr(request); for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { + CameraStream *cameraStream = static_cast(camera3Buffers[i].stream->priv); + /* * Keep track of which stream the request belongs to and store * the native buffer handles. - * - * \todo Currently we only support one capture buffer. Copy - * all of them to be ready once we'll support more. */ descriptor->buffers[i].stream = camera3Buffers[i].stream; descriptor->buffers[i].buffer = camera3Buffers[i].buffer; - } - /* - * Create a libcamera buffer using the dmabuf descriptors of the first - * and (currently) only supported request buffer. - */ - FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[0].buffer); - if (!buffer) { - LOG(HAL, Error) << "Failed to create buffer"; - delete descriptor; - return -ENOMEM; - } + /* + * Create a libcamera buffer using the dmabuf descriptors of the + * first and (currently) only supported request buffer. + * The FrameBuffer is directly associated with the + * Camera3RequestDescriptor for lifetime management only. + */ + FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[i].buffer); + if (!buffer) { + LOG(HAL, Error) << "Failed to create buffer"; + delete descriptor; + return -ENOMEM; + } + descriptor->frameBuffers.emplace_back(buffer); - request->addBuffer(stream, buffer); + StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index); + Stream *stream = streamConfiguration->stream(); + + request->addBuffer(stream, buffer); + } int ret = camera_->queueRequest(request); if (ret) { @@ -1127,7 +1131,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques void CameraDevice::requestComplete(Request *request) { const std::map &buffers = request->buffers(); - FrameBuffer *buffer = buffers.begin()->second; camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK; std::unique_ptr resultMetadata; @@ -1145,10 +1148,6 @@ void CameraDevice::requestComplete(Request *request) captureResult.frame_number = descriptor->frameNumber; captureResult.num_output_buffers = descriptor->numBuffers; for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { - /* - * \todo Currently we only support one capture buffer. Prepare - * all of them to be ready once we'll support more. - */ descriptor->buffers[i].acquire_fence = -1; descriptor->buffers[i].release_fence = -1; descriptor->buffers[i].status = status; @@ -1156,6 +1155,14 @@ void CameraDevice::requestComplete(Request *request) captureResult.output_buffers = const_cast(descriptor->buffers); + /* + * \todo The timestamp used for the metadata is currently always taken + * from the first buffer (which may be the first stream) in the Request. + * It might be appropriate to return a 'correct' (as determined by + * pipeline handlers) timestamp in the Request itself. + */ + FrameBuffer *buffer = buffers.begin()->second; + if (status == CAMERA3_BUFFER_STATUS_OK) { notifyShutter(descriptor->frameNumber, buffer->metadata().timestamp); @@ -1180,7 +1187,6 @@ void CameraDevice::requestComplete(Request *request) callbacks_->process_capture_result(callbacks_, &captureResult); delete descriptor; - delete buffer; } std::string CameraDevice::logPrefix() const diff --git a/src/android/camera_device.h b/src/android/camera_device.h index f23d1b328472..aa828b97d8f0 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -71,6 +71,7 @@ private: uint32_t numBuffers; camera3_stream_buffer_t *buffers; std::unique_ptr request; + std::vector> frameBuffers; }; struct Camera3StreamConfiguration { From patchwork Mon Jul 6 15:38:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8659 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 9FAE2BD790 for ; Mon, 6 Jul 2020 15:38:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 62C5D60E37; Mon, 6 Jul 2020 17:38:20 +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="DDJZ6eES"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E835C60E43 for ; Mon, 6 Jul 2020 17:38:15 +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 6C4ECA16; Mon, 6 Jul 2020 17:38:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594049895; bh=PBdLF9d9XJ9Ifeo73geGqBk2Gs4+P2YX4dlHv7Td2us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DDJZ6eESK29m+BNkli9Kp7H3iKSnB148tv8xg4Bk8NJEbYNO6v8IpD558WQWDYyAU uJuZDkCLExjayw9G6Qz9ah6Mz+Iu5RkKQLjuMD30TrKjjfTDRjp5mn08NNgRhfBoBh RFDdWv0SI6yDtuil1YwKI+c+mEc60SQapasdz8BM= From: Kieran Bingham To: libcamera devel Date: Mon, 6 Jul 2020 16:38:08 +0100 Message-Id: <20200706153808.2340919-9-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> References: <20200706153808.2340919-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 8/8] android: camera_device: Remove single buffer restriction. 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" A capture request is no longer limited to a single output buffer. Remove the limitation, but (for now) keep the check to ensure that at least one buffer is always provided. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f368726091f4..e7ed873d64c0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1050,9 +1050,8 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { - if (camera3Request->num_output_buffers != 1) { - LOG(HAL, Error) << "Invalid number of output buffers: " - << camera3Request->num_output_buffers; + if (!camera3Request->num_output_buffers) { + LOG(HAL, Error) << "No output buffers provided"; return -EINVAL; }