From patchwork Mon Jul 6 23:02:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8661 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 95D13BD792 for ; Mon, 6 Jul 2020 23:02:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED61660E05; Tue, 7 Jul 2020 01:02:46 +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="e9gLOfZ1"; 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 32A78603AD for ; Tue, 7 Jul 2020 01:02:45 +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 964FFD6E; Tue, 7 Jul 2020 01:02:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076564; bh=Ryw+qOixyBuEMieEDC/DJyE24i6nMiEbmEfegzYOkVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e9gLOfZ1ZjIbrEgL/np/x5ocTGuIUluQKdFIb6UuO/wioIXZmrBuoZz4tPSb0rGzQ C0J/+QN+VILO54cXnYLZIQImt0q7lLG6JEVWOBC78sTdukr4hAyqMCbqbrjkLZOMLP ceQQ9xU34JdSlTbhmnGNaT5TKVWUUGGSje6a1XAg= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:33 +0100 Message-Id: <20200706230240.2482100-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 23:02:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8662 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 B805ABD792 for ; Mon, 6 Jul 2020 23:02:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E9EC60E91; Tue, 7 Jul 2020 01:02:49 +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="loLZdm1/"; 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 0577D60E2B for ; Tue, 7 Jul 2020 01:02:46 +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 0DB60D98; Tue, 7 Jul 2020 01:02:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076565; bh=sMhLp06T6QO0sZZzIFLbIjnWFqMx2rxp+l/GxwKKhHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=loLZdm1/Bd68mJZvhgnXsoe0u5IaUT4p/EgQWVBFWOtoIqi8lqOt33jntJ+B1SrIp XcU384M/Zae+oJ4n77KrQcQFi3DIV8q2erjcAskL0RMYDF7FAm4D6YaLHTpf9aK5/i NaFkV+q8WAWdSAwhsvMHevqOo+kbfC6zwlyBskLA= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:34 +0100 Message-Id: <20200706230240.2482100-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 23:02:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8663 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 6FEFEBD792 for ; Mon, 6 Jul 2020 23:02:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2E011603AD; Tue, 7 Jul 2020 01:02:50 +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="B1Mk8mUH"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F731603AD for ; Tue, 7 Jul 2020 01:02:47 +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 BA9D0AC6; Tue, 7 Jul 2020 01:02:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076567; bh=Ptc5zwAay6Z3ejmiQwbWhpduyqCOONZtcScINP8ZE9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B1Mk8mUHAdOmqrH5B/HW1IwIAbDpxrIPUmuOwi0ocQz+lWb+yR0lgURe3+nuxX6ZH xOWgiYJzYQg2ERZ1HHyI66CLJHZ2rypE3YsiIQVUhdiXicWKWdi81pThXH1iVapxZK MIoUyUqnDLEj6YvrnoKmxZEJ8Rj5qpTWRfcevzRI= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:35 +0100 Message-Id: <20200706230240.2482100-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 23:02:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8664 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 E8DB9BD792 for ; Mon, 6 Jul 2020 23:02:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 95E9B60E8D; Tue, 7 Jul 2020 01:02:50 +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="GXo0ylAJ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC15160E0D for ; Tue, 7 Jul 2020 01:02:47 +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 68587D6E; Tue, 7 Jul 2020 01:02:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076567; bh=FIgZ7tdHmAgZPdqa+5fkin4TBMksUd11jEpciokXp24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GXo0ylAJsBaHH3nBuQ5ZudqlDSxlynZwRmNsvF1my1GyhvJuaAKkzW66WZU+O9Nae 9Pl5WVeFPmcDRjtbqhhkYMiNTUdf2M0y4UYw1uMuOgx1NRT4zHQYYgAxDy8hi67AWs 8pkWMxv0v5oOa71Qmrbro+ZXtEkBXYgY0ATfPn70= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:36 +0100 Message-Id: <20200706230240.2482100-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 23:02:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8665 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 4190DBD794 for ; Mon, 6 Jul 2020 23:02:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0D3E060E9B; Tue, 7 Jul 2020 01:02:51 +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="VXQkzf3W"; 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 54CF4603AD for ; Tue, 7 Jul 2020 01:02:48 +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 CC308E37; Tue, 7 Jul 2020 01:02:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076568; bh=1fhzmDPa0naBtLkW2HhqcHA0NOpYOhlbutWLgc7D8LE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXQkzf3WL0EzLYieqqP6S9RqUqKFWXXYQJX73nYUmIGmyAyq3+SxO/D2qofhvVZfn eiYtk00W6AhhZPgle3r8H1tv4JjFfxlX00tpPhwTogth0MWxTYwMvsDwIPtKbXhndh dSV6zBraPrOVxL3NekE5lVgCXMuVr+TwdZ3WApDE= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:37 +0100 Message-Id: <20200706230240.2482100-6-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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. Signed-off-by: Kieran Bingham Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 73cfab532cf5..4e77a92dbea5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1066,6 +1066,10 @@ 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)); + for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { /* * Keep track of which stream the request belongs to and store @@ -1085,12 +1089,11 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[0].buffer); if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; + delete request; delete descriptor; return -ENOMEM; } - Request *request = - camera_->createRequest(reinterpret_cast(descriptor)); request->addBuffer(stream, buffer); int ret = camera_->queueRequest(request); From patchwork Mon Jul 6 23:02:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8666 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 B0D26BD792 for ; Mon, 6 Jul 2020 23:02:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7CB9F60E8A; Tue, 7 Jul 2020 01:02:51 +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="KnuRSbiA"; 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 C5DB860E0D for ; Tue, 7 Jul 2020 01:02:48 +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 4713DAC6; Tue, 7 Jul 2020 01:02:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076568; bh=cLGX7nA7gV6Ro1W5SB2+kH6vXWqqaZUO6ffVkLKfPyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KnuRSbiAUpUyP/UwXZrF8pYswafBIKVmblRYBdkd/0BmU7oI+ItpqjFU/8U1WJeOl 9EDmWLlhers8Z8PUCBsMyilFQwiFyQ7lRSzf9D9nreZBTiM6ui6ETUURfRGSQYw4WS dD7WzA6CrscPRHy6/NAXF7BnwAvV5+xeb3qhcHJU= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:38 +0100 Message-Id: <20200706230240.2482100-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 4e77a92dbea5..6d060e0c40e5 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 d7834d94f439..d00f617b09a6 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: @@ -90,6 +99,7 @@ private: std::vector streamConfigurations_; std::map formatsMap_; + std::vector streams_; int facing_; int orientation_; From patchwork Mon Jul 6 23:02:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8667 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 1F11DBD794 for ; Mon, 6 Jul 2020 23:02:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DD9EA60E88; Tue, 7 Jul 2020 01:02:51 +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="qmDOsRbD"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 47EA1603AD for ; Tue, 7 Jul 2020 01:02:49 +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 B7C16D6E; Tue, 7 Jul 2020 01:02:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076569; bh=+FO5DmWHqWFlDyA7b0Cxg8sFQGBG6ld2gqETh9Nmp9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qmDOsRbDBk4Bg6fqo5ODPhY1Rf4ZvWsgM3PXo9PPfADwcBcSYkuw0JLccahx7r0+x /V9RN36I4bOEyFJ6kyyoPloqMR5lbnAMOlbbKOq1ePW4eM8xALjelaNCyRh8/WFyC4 xZrOyAMAIB2HYK1Lf2k8Y0fqb2EA7cGBwN5l/9bA= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:39 +0100 Message-Id: <20200706230240.2482100-8-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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, and FrameBuffers have their lifetime tracked in the Camera3RequestDescriptor to ensure they are released when the Request is completed. 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 6d060e0c40e5..b13729e84abf 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; @@ -1088,30 +1087,35 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques camera_->createRequest(reinterpret_cast(descriptor)); 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"; + /* + * 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 request; - delete descriptor; - return -ENOMEM; - } + 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 d00f617b09a6..5b8b9c3e26e2 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -70,6 +70,7 @@ private: uint32_t frameNumber; uint32_t numBuffers; camera3_stream_buffer_t *buffers; + std::vector> frameBuffers; }; struct Camera3StreamConfiguration { From patchwork Mon Jul 6 23:02:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8668 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 78815BD792 for ; Mon, 6 Jul 2020 23:02:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 43DD560EA5; Tue, 7 Jul 2020 01:02:52 +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="UyYjfFAK"; 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 B503660E93 for ; Tue, 7 Jul 2020 01:02:49 +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 2E629D98; Tue, 7 Jul 2020 01:02:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594076569; bh=wNkIVJ+85VHhGpNWaNuTCq9mFioRD4RQauKUpGssb0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyYjfFAKSrKoelDpwGrU4rYJqv2V9Q8VsEqYYRDqKdxyUiYHQ0cGUDFq83yiLoUpQ bNS9isgCQeS4oD48Z8b5zwNirSJtcjNSZ5j07LD3I61NOtZ4V6FtwgxEpEd2A0BoIW xuMaEReDHEqQYLrv8olJhRHxE59cosKCxpKtTC94= From: Kieran Bingham To: libcamera devel Date: Tue, 7 Jul 2020 00:02:40 +0100 Message-Id: <20200706230240.2482100-9-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> References: <20200706230240.2482100-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 b13729e84abf..95a7368d8ebc 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; }