From patchwork Tue Oct 19 11:47:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14175 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 F22E7C324C for ; Tue, 19 Oct 2021 11:48:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF7B768F5C; Tue, 19 Oct 2021 13:48: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="YmZXM2ZQ"; 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 9303E604FE for ; Tue, 19 Oct 2021 13:48:12 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AB5012A; Tue, 19 Oct 2021 13:48:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644092; bh=bYHmkfzBcEi93zcs6ElAxBO3tlvXUUjYCDz0DUMYluY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YmZXM2ZQE1c/JmpcoMiPMD0r5wkyY6LWhxhGL7ktdssAM4tEOKe2Tl/KrmI/lfKua zn2Qs6hre7moixtdyMYhNBzxkA+Mrwl/KNFM2hOqwyUby4m829Mk+zpx/cxN+867Qi cBR9VaZZnP5/a9bm2+tbd4OaaKqeirINpXyFpJvM= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:51 +0530 Message-Id: <20211019114802.665980-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/12] camera_device: Remove private scope of Camera3RequestDescriptor 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" Camera3RequestDescriptor is a utility structure that groups information about a capture request. It can be and will be extended to preserve the context of a capture overall. Since the context of a capture needs to be shared among other classes (for e.g. CameraStream) having a private definition of the struct in CameraDevice class doesn't help. Hence, de-scope the structure so that it can be shared with other components (through references or pointers). Splitting the structure to a separate file will help avoiding circular dependencies when using it through the HAL implementation. Signed-off-by: Umang Jain Signed-off-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 43 ++++--------------------------- src/android/camera_device.h | 27 ++------------------ src/android/camera_request.cpp | 45 +++++++++++++++++++++++++++++++++ src/android/camera_request.h | 46 ++++++++++++++++++++++++++++++++++ src/android/meson.build | 1 + 5 files changed, 99 insertions(+), 63 deletions(-) create mode 100644 src/android/camera_request.cpp create mode 100644 src/android/camera_request.h diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index fe29b7bc..3689940d 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -6,9 +6,6 @@ */ #include "camera_device.h" -#include "camera_hal_config.h" -#include "camera_ops.h" -#include "post_processor.h" #include #include @@ -27,6 +24,11 @@ #include "system/graphics.h" +#include "camera_hal_config.h" +#include "camera_ops.h" +#include "camera_request.h" +#include "post_processor.h" + using namespace libcamera; LOG_DECLARE_CATEGORY(HAL) @@ -213,41 +215,6 @@ bool validateCropRotate(const camera3_stream_configuration_t &streamList) } /* namespace */ -/* - * \struct Camera3RequestDescriptor - * - * A utility structure that groups information about a capture request to be - * later re-used at request complete time to notify the framework. - */ - -CameraDevice::Camera3RequestDescriptor::Camera3RequestDescriptor( - Camera *camera, const camera3_capture_request_t *camera3Request) -{ - frameNumber_ = camera3Request->frame_number; - - /* Copy the camera3 request stream information for later access. */ - const uint32_t numBuffers = camera3Request->num_output_buffers; - buffers_.resize(numBuffers); - for (uint32_t i = 0; i < numBuffers; i++) - buffers_[i] = camera3Request->output_buffers[i]; - - /* - * FrameBuffer instances created by wrapping a camera3 provided dmabuf - * are emplaced in this vector of unique_ptr<> for lifetime management. - */ - frameBuffers_.reserve(numBuffers); - - /* Clone the controls associated with the camera3 request. */ - settings_ = CameraMetadata(camera3Request->settings); - - /* - * Create the CaptureRequest, stored as a unique_ptr<> to tie its - * lifetime to the descriptor. - */ - request_ = std::make_unique(camera, - reinterpret_cast(this)); -} - /* * \class CameraDevice * diff --git a/src/android/camera_device.h b/src/android/camera_device.h index b7d774fe..86224aa1 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -33,7 +33,9 @@ #include "camera_worker.h" #include "jpeg/encoder.h" +struct Camera3RequestDescriptor; struct CameraConfigData; + class CameraDevice : protected libcamera::Loggable { public: @@ -73,31 +75,6 @@ private: CameraDevice(unsigned int id, std::shared_ptr camera); - struct Camera3RequestDescriptor { - enum class Status { - Pending, - Success, - Error, - }; - - Camera3RequestDescriptor() = default; - ~Camera3RequestDescriptor() = default; - Camera3RequestDescriptor(libcamera::Camera *camera, - const camera3_capture_request_t *camera3Request); - Camera3RequestDescriptor &operator=(Camera3RequestDescriptor &&) = default; - - bool isPending() const { return status_ == Status::Pending; } - - uint32_t frameNumber_ = 0; - std::vector buffers_; - std::vector> frameBuffers_; - CameraMetadata settings_; - std::unique_ptr request_; - - camera3_capture_result_t captureResult_ = {}; - Status status_ = Status::Pending; - }; - enum class State { Stopped, Flushing, diff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp new file mode 100644 index 00000000..93e546bf --- /dev/null +++ b/src/android/camera_request.cpp @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019-2021, Google Inc. + * + * camera_request.cpp - libcamera Android Camera Request Descriptor + */ + +#include "camera_request.h" + +using namespace libcamera; + +/* + * \struct Camera3RequestDescriptor + * + * A utility structure that groups information about a capture request to be + * later re-used at request complete time to notify the framework. + */ + +Camera3RequestDescriptor::Camera3RequestDescriptor( + Camera *camera, const camera3_capture_request_t *camera3Request) +{ + frameNumber_ = camera3Request->frame_number; + + /* Copy the camera3 request stream information for later access. */ + const uint32_t numBuffers = camera3Request->num_output_buffers; + buffers_.resize(numBuffers); + for (uint32_t i = 0; i < numBuffers; i++) + buffers_[i] = camera3Request->output_buffers[i]; + + /* + * FrameBuffer instances created by wrapping a camera3 provided dmabuf + * are emplaced in this vector of unique_ptr<> for lifetime management. + */ + frameBuffers_.reserve(numBuffers); + + /* Clone the controls associated with the camera3 request. */ + settings_ = CameraMetadata(camera3Request->settings); + + /* + * Create the CaptureRequest, stored as a unique_ptr<> to tie its + * lifetime to the descriptor. + */ + request_ = std::make_unique(camera, + reinterpret_cast(this)); +} diff --git a/src/android/camera_request.h b/src/android/camera_request.h new file mode 100644 index 00000000..1346f6fa --- /dev/null +++ b/src/android/camera_request.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019-2021, Google Inc. + * + * camera_request.h - libcamera Android Camera Request Descriptor + */ +#ifndef __ANDROID_CAMERA_REQUEST_H__ +#define __ANDROID_CAMERA_REQUEST_H__ + +#include +#include + +#include +#include + +#include + +#include "camera_metadata.h" +#include "camera_worker.h" + +struct Camera3RequestDescriptor { + enum class Status { + Pending, + Success, + Error, + }; + + Camera3RequestDescriptor() = default; + ~Camera3RequestDescriptor() = default; + Camera3RequestDescriptor(libcamera::Camera *camera, + const camera3_capture_request_t *camera3Request); + Camera3RequestDescriptor &operator=(Camera3RequestDescriptor &&) = default; + + bool isPending() const { return status_ == Status::Pending; } + + uint32_t frameNumber_ = 0; + std::vector buffers_; + std::vector> frameBuffers_; + CameraMetadata settings_; + std::unique_ptr request_; + + camera3_capture_result_t captureResult_ = {}; + Status status_ = Status::Pending; +}; + +#endif /* __ANDROID_CAMERA_REQUEST_H__ */ diff --git a/src/android/meson.build b/src/android/meson.build index 7d1e7e85..332b177c 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -45,6 +45,7 @@ android_hal_sources = files([ 'camera_hal_manager.cpp', 'camera_metadata.cpp', 'camera_ops.cpp', + 'camera_request.cpp', 'camera_stream.cpp', 'camera_worker.cpp', 'jpeg/encoder_libjpeg.cpp', From patchwork Tue Oct 19 11:47:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14176 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 5DE62C324C for ; Tue, 19 Oct 2021 11:48:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A30C68F60; Tue, 19 Oct 2021 13:48: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="gpJh2n5Z"; 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 A87E5604FE for ; Tue, 19 Oct 2021 13:48:14 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5529212A; Tue, 19 Oct 2021 13:48:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644094; bh=OuXtvyGtTPInpPDdLC4YZsaWGHSEYQbAcgVzmXN1tQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gpJh2n5Zek9HNLsWvXw+AXJUwNgdAkc5FQ0UrwLgbgXEuJv3ftpbrJyV6ZAj8M27i jLM574TyBmm3fgir5D0Ezs7kH43eCaz6MstSWaxGQvOxrGx5eK6wI3q6cTSttz7cr7 AGaYPgNA+vjPU/y7x0qQWamDBNNYuuY8sVuCJT0s= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:52 +0530 Message-Id: <20211019114802.665980-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/12] android: camera_request: Turn struct into a class 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" From: Laurent Pinchart The Camera3RequestDescriptor structure is growing into an object with member functions. Turn it into a class, uninline the destructor to reduce code size, explicitly disable copy as requests are not copyable, and delete the default constructor to force all instances to be fully constructed. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.h | 2 +- src/android/camera_request.cpp | 8 +++++--- src/android/camera_request.h | 13 +++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 86224aa1..863cf414 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -33,7 +33,7 @@ #include "camera_worker.h" #include "jpeg/encoder.h" -struct Camera3RequestDescriptor; +class Camera3RequestDescriptor; struct CameraConfigData; class CameraDevice : protected libcamera::Loggable diff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp index 93e546bf..16a632b3 100644 --- a/src/android/camera_request.cpp +++ b/src/android/camera_request.cpp @@ -10,10 +10,10 @@ using namespace libcamera; /* - * \struct Camera3RequestDescriptor + * \class Camera3RequestDescriptor * - * A utility structure that groups information about a capture request to be - * later re-used at request complete time to notify the framework. + * A utility class that groups information about a capture request to be later + * reused at request complete time to notify the framework. */ Camera3RequestDescriptor::Camera3RequestDescriptor( @@ -43,3 +43,5 @@ Camera3RequestDescriptor::Camera3RequestDescriptor( request_ = std::make_unique(camera, reinterpret_cast(this)); } + +Camera3RequestDescriptor::~Camera3RequestDescriptor() = default; diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 1346f6fa..79dfdb58 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -18,18 +20,18 @@ #include "camera_metadata.h" #include "camera_worker.h" -struct Camera3RequestDescriptor { +class Camera3RequestDescriptor +{ +public: enum class Status { Pending, Success, Error, }; - Camera3RequestDescriptor() = default; - ~Camera3RequestDescriptor() = default; Camera3RequestDescriptor(libcamera::Camera *camera, const camera3_capture_request_t *camera3Request); - Camera3RequestDescriptor &operator=(Camera3RequestDescriptor &&) = default; + ~Camera3RequestDescriptor(); bool isPending() const { return status_ == Status::Pending; } @@ -41,6 +43,9 @@ struct Camera3RequestDescriptor { camera3_capture_result_t captureResult_ = {}; Status status_ = Status::Pending; + +private: + LIBCAMERA_DISABLE_COPY(Camera3RequestDescriptor) }; #endif /* __ANDROID_CAMERA_REQUEST_H__ */ From patchwork Tue Oct 19 11:47:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14177 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 8C068C324C for ; Tue, 19 Oct 2021 11:48:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 44D4368F5B; Tue, 19 Oct 2021 13:48: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="WGnhijJl"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02ECD68F5B for ; Tue, 19 Oct 2021 13:48:17 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C62512A; Tue, 19 Oct 2021 13:48:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644096; bh=Vp6FzJ/7bMKJw0R1OjL1B4UrtnKEU8LtDGCwe5lZ70o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGnhijJlwu50d8RI4Qih3NeXD24eYMMtOVXGIuOHClrSWY6FO+hWivR5i+6t5tWv5 SufaBmiV9V3V6V/6X8pA99iviYTVz/vTd4q7YTMTYacD8CMOO+ifo0ou3T5f8Vd9KR sjqg31rJnUTn9BW7pBxAwSDp2F8EHzq/b68DXCms= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:53 +0530 Message-Id: <20211019114802.665980-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/12] android: camera_device: Build capture_result dynamically 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" From: Laurent Pinchart The camera3_capture_result_t is only needed to convey capture results to the camera service through the process_capture_result() callback. There's no need to store it in the Camera3RequestDescriptor. Build it dynamically in CameraDevice::sendCaptureResults() instead. This requires storing the result metadata created in CameraDevice::requestComplete() in the Camera3RequestDescriptor. A side effect of this change is that the request metadata lifetime will match the Camera3RequestDescriptor instead of being destroyed at the end of requestComplete(). This will be needed to support asynchronous post-processing, where the request completion will be signaled to the camera service asynchronously from requestComplete(). Signed-off-by: Laurent Pinchart Signed-off-by: Umang Jain Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 50 ++++++++++++++++++----------------- src/android/camera_request.h | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3689940d..38132cbd 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -801,19 +801,11 @@ void CameraDevice::abortRequest(Camera3RequestDescriptor *descriptor) const { notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST); - camera3_capture_result_t &result = descriptor->captureResult_; - result.num_output_buffers = descriptor->buffers_.size(); - result.frame_number = descriptor->frameNumber_; - result.partial_result = 0; - - std::vector resultBuffers(result.num_output_buffers); - for (auto [i, buffer] : utils::enumerate(resultBuffers)) { - buffer = descriptor->buffers_[i]; - buffer.release_fence = descriptor->buffers_[i].acquire_fence; + for (auto &buffer : descriptor->buffers_) { + buffer.release_fence = buffer.acquire_fence; buffer.acquire_fence = -1; buffer.status = CAMERA3_BUFFER_STATUS_ERROR; } - result.output_buffers = resultBuffers.data(); descriptor->status_ = Camera3RequestDescriptor::Status::Error; } @@ -1062,9 +1054,6 @@ void CameraDevice::requestComplete(Request *request) * The buffer status is set to OK and later changed to ERROR if * post-processing/compression fails. */ - camera3_capture_result_t &captureResult = descriptor->captureResult_; - captureResult.frame_number = descriptor->frameNumber_; - captureResult.num_output_buffers = descriptor->buffers_.size(); for (camera3_stream_buffer_t &buffer : descriptor->buffers_) { CameraStream *cameraStream = static_cast(buffer.stream->priv); @@ -1085,8 +1074,6 @@ void CameraDevice::requestComplete(Request *request) buffer.release_fence = -1; buffer.status = CAMERA3_BUFFER_STATUS_OK; } - captureResult.output_buffers = descriptor->buffers_.data(); - captureResult.partial_result = 1; /* * If the Request has failed, abort the request by notifying the error @@ -1100,7 +1087,6 @@ void CameraDevice::requestComplete(Request *request) notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST); - captureResult.partial_result = 0; for (camera3_stream_buffer_t &buffer : descriptor->buffers_) { /* * Signal to the framework it has to handle fences that @@ -1137,12 +1123,17 @@ void CameraDevice::requestComplete(Request *request) * Notify if the metadata generation has failed, but continue processing * buffers and return an empty metadata pack. */ - std::unique_ptr resultMetadata = getResultMetadata(*descriptor); - if (!resultMetadata) { + descriptor->resultMetadata_ = getResultMetadata(*descriptor); + if (!descriptor->resultMetadata_) { notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_RESULT); - /* The camera framework expects an empty metadata pack on error. */ - resultMetadata = std::make_unique(0, 0); + /* + * The camera framework expects an empty metadata pack on error. + * + * \todo Check that the post-processor code handles this situation + * correctly. + */ + descriptor->resultMetadata_ = std::make_unique(0, 0); } /* Handle post-processing. */ @@ -1164,7 +1155,7 @@ void CameraDevice::requestComplete(Request *request) int ret = cameraStream->process(*src, buffer, descriptor->settings_, - resultMetadata.get()); + descriptor->resultMetadata_.get()); /* * Return the FrameBuffer to the CameraStream now that we're * done processing it. @@ -1179,7 +1170,6 @@ void CameraDevice::requestComplete(Request *request) } } - captureResult.result = resultMetadata->get(); descriptor->status_ = Camera3RequestDescriptor::Status::Success; sendCaptureResults(); } @@ -1197,8 +1187,20 @@ void CameraDevice::sendCaptureResults() * impact on performance which should be measured. */ lock.unlock(); - callbacks_->process_capture_result(callbacks_, - &descriptor->captureResult_); + + camera3_capture_result_t captureResult = {}; + + captureResult.frame_number = descriptor->frameNumber_; + if (descriptor->resultMetadata_) + captureResult.result = descriptor->resultMetadata_->get(); + captureResult.num_output_buffers = descriptor->buffers_.size(); + captureResult.output_buffers = descriptor->buffers_.data(); + + if (descriptor->status_ == Camera3RequestDescriptor::Status::Success) + captureResult.partial_result = 1; + + callbacks_->process_capture_result(callbacks_, &captureResult); + lock.lock(); } } diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 79dfdb58..db13f624 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -40,8 +40,8 @@ public: std::vector> frameBuffers_; CameraMetadata settings_; std::unique_ptr request_; + std::unique_ptr resultMetadata_; - camera3_capture_result_t captureResult_ = {}; Status status_ = Status::Pending; private: From patchwork Tue Oct 19 11:47:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14178 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 07360C324C for ; Tue, 19 Oct 2021 11:48:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF51968F5A; Tue, 19 Oct 2021 13:48: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="OM4fLV1o"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F267C604FE for ; Tue, 19 Oct 2021 13:48:18 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A7E3E12A; Tue, 19 Oct 2021 13:48:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644098; bh=DFHFaDRCBauAYXkG9ClPj4uLX9MXAYU+z0uJ+o91dxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OM4fLV1ozJ+pHDlLWF4YHfLxbcCU9daf2t2CcwD6o8NO2mtGG7a013D1Jg28Wrk+k keK6krsBvW4LLx7LKZoVaUk+pK4DesWzIJEmaOX7L7cCDgrunDYatkC1+hW2gd8BMs lHUVRgzw2ZliF9ZyW8tNW8zx+ob5zkVRh81u+S7Q= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:54 +0530 Message-Id: <20211019114802.665980-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/12] android: camera_stream: Plumb process() with Camera3RequestDescriptor 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" Data (or broader context) required for post processing of a camera request is saved via Camera3RequestDescriptor. Instead of passing individual arguments to CameraStream::process(), pass the Camera3RequestDescriptor pointer to it. All the arguments necessary to run the post-processor can be accessed from the descriptor. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 5 ++--- src/android/camera_stream.cpp | 5 ++--- src/android/camera_stream.h | 5 ++--- src/android/jpeg/post_processor_jpeg.cpp | 6 ++++-- src/android/jpeg/post_processor_jpeg.h | 3 +-- src/android/post_processor.h | 5 ++--- src/android/yuv/post_processor_yuv.cpp | 3 +-- src/android/yuv/post_processor_yuv.h | 3 +-- 8 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 38132cbd..a8c66a79 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1153,9 +1153,8 @@ void CameraDevice::requestComplete(Request *request) continue; } - int ret = cameraStream->process(*src, buffer, - descriptor->settings_, - descriptor->resultMetadata_.get()); + int ret = cameraStream->process(*src, buffer, descriptor); + /* * Return the FrameBuffer to the CameraStream now that we're * done processing it. diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 3b96d2e9..8f47e4d8 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -144,8 +144,7 @@ int CameraStream::waitFence(int fence) int CameraStream::process(const FrameBuffer &source, camera3_stream_buffer_t &camera3Dest, - const CameraMetadata &requestMetadata, - CameraMetadata *resultMetadata) + Camera3RequestDescriptor *request) { /* Handle waiting on fences on the destination buffer. */ int fence = camera3Dest.acquire_fence; @@ -175,7 +174,7 @@ int CameraStream::process(const FrameBuffer &source, return -EINVAL; } - return postProcessor_->process(source, &dest, requestMetadata, resultMetadata); + return postProcessor_->process(source, &dest, request); } FrameBuffer *CameraStream::getBuffer() diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 03ecfa94..405b232d 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -19,8 +19,8 @@ #include #include +class Camera3RequestDescriptor; class CameraDevice; -class CameraMetadata; class PostProcessor; class CameraStream @@ -120,8 +120,7 @@ public: int configure(); int process(const libcamera::FrameBuffer &source, camera3_stream_buffer_t &camera3Buffer, - const CameraMetadata &requestMetadata, - CameraMetadata *resultMetadata); + Camera3RequestDescriptor *request); libcamera::FrameBuffer *getBuffer(); void putBuffer(libcamera::FrameBuffer *buffer); diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index f6d47f63..699576ef 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -11,6 +11,7 @@ #include "../camera_device.h" #include "../camera_metadata.h" +#include "../camera_request.h" #include "encoder_libjpeg.h" #include "exif.h" @@ -99,14 +100,15 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source, int PostProcessorJpeg::process(const FrameBuffer &source, CameraBuffer *destination, - const CameraMetadata &requestMetadata, - CameraMetadata *resultMetadata) + Camera3RequestDescriptor *request) { if (!encoder_) return 0; ASSERT(destination->numPlanes() == 1); + const CameraMetadata &requestMetadata = request->settings_; + CameraMetadata *resultMetadata = request->resultMetadata_.get(); camera_metadata_ro_entry_t entry; int ret; diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h index 6fd31022..0184d77e 100644 --- a/src/android/jpeg/post_processor_jpeg.h +++ b/src/android/jpeg/post_processor_jpeg.h @@ -24,8 +24,7 @@ public: const libcamera::StreamConfiguration &outcfg) override; int process(const libcamera::FrameBuffer &source, CameraBuffer *destination, - const CameraMetadata &requestMetadata, - CameraMetadata *resultMetadata) override; + Camera3RequestDescriptor *request) override; private: void generateThumbnail(const libcamera::FrameBuffer &source, diff --git a/src/android/post_processor.h b/src/android/post_processor.h index ab2b2c60..27eaef88 100644 --- a/src/android/post_processor.h +++ b/src/android/post_processor.h @@ -12,7 +12,7 @@ #include "camera_buffer.h" -class CameraMetadata; +class Camera3RequestDescriptor; class PostProcessor { @@ -23,8 +23,7 @@ public: const libcamera::StreamConfiguration &outCfg) = 0; virtual int process(const libcamera::FrameBuffer &source, CameraBuffer *destination, - const CameraMetadata &requestMetadata, - CameraMetadata *resultMetadata) = 0; + Camera3RequestDescriptor *request) = 0; }; #endif /* __ANDROID_POST_PROCESSOR_H__ */ diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp index 7b3b4960..8110a1f1 100644 --- a/src/android/yuv/post_processor_yuv.cpp +++ b/src/android/yuv/post_processor_yuv.cpp @@ -51,8 +51,7 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg, int PostProcessorYuv::process(const FrameBuffer &source, CameraBuffer *destination, - [[maybe_unused]] const CameraMetadata &requestMetadata, - [[maybe_unused]] CameraMetadata *metadata) + [[maybe_unused]] Camera3RequestDescriptor *request) { if (!isValidBuffers(source, *destination)) return -EINVAL; diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h index 12f7af07..a4e0ff5d 100644 --- a/src/android/yuv/post_processor_yuv.h +++ b/src/android/yuv/post_processor_yuv.h @@ -20,8 +20,7 @@ public: const libcamera::StreamConfiguration &outcfg) override; int process(const libcamera::FrameBuffer &source, CameraBuffer *destination, - const CameraMetadata &requestMetadata, - CameraMetadata *metadata) override; + Camera3RequestDescriptor *request) override; private: bool isValidBuffers(const libcamera::FrameBuffer &source, From patchwork Tue Oct 19 11:47:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14179 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 742A6C324C for ; Tue, 19 Oct 2021 11:48:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3743768F59; Tue, 19 Oct 2021 13:48: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="tYcudbQX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 893BA604FE for ; Tue, 19 Oct 2021 13:48:21 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D2C1812A; Tue, 19 Oct 2021 13:48:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644101; bh=ZdCFvEFMpdvApvGOrr3vA2fbqvGFEVLxWkdJHVqMk38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tYcudbQXWCFiUQdX3cPwc9F/GXecgto2xqVDjOrpPbmR4FG6MgoccfbkSMC98gV54 QVdph+nC7Lpl6pfoBXkP4YAWs1A4WKPRlQY8C7fXQwkj3ZpGSyvDg4mI5OaUWlkHCt mGIkeQ3bIoN8IqYFgWqbcX0wFEnhqoQ8MXo2WJ+s= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:55 +0530 Message-Id: <20211019114802.665980-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/12] android: camera_device: Create struct to track per stream buffer 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" The Camera3RequestDescriptor structure stores, for each stream, the camera3_stream_buffer_t and the libcamera FrameBuffer in two separate vectors. This complicates buffer handling, as the code needs to keep both vectors in sync. Create a new structure to group all data about per-stream buffers to simplify this. As a side effect, we need to create a local vector of camera3_stream_buffer_t in CameraDevice::sendCaptureResults() as the camera3_stream_buffer_t instances stored in the new structure in Camera3RequestDescriptor are not contiguous anymore. This is a small price to pay for easier handling of buffers, and will be refactored in subsequent commits anyway. Signed-off-by: Umang Jain Signed-off-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 75 ++++++++++++++++++---------------- src/android/camera_request.cpp | 9 +--- src/android/camera_request.h | 15 ++++++- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a8c66a79..74d9b952 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -802,9 +802,9 @@ void CameraDevice::abortRequest(Camera3RequestDescriptor *descriptor) const notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST); for (auto &buffer : descriptor->buffers_) { - buffer.release_fence = buffer.acquire_fence; - buffer.acquire_fence = -1; - buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + buffer.buffer.release_fence = buffer.buffer.acquire_fence; + buffer.buffer.acquire_fence = -1; + buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; } descriptor->status_ = Camera3RequestDescriptor::Status::Error; @@ -902,8 +902,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques LOG(HAL, Debug) << "Queueing request " << descriptor->request_->cookie() << " with " << descriptor->buffers_.size() << " streams"; - for (const auto &[i, camera3Buffer] : utils::enumerate(descriptor->buffers_)) { - camera3_stream *camera3Stream = camera3Buffer.stream; + for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) { + camera3_stream *camera3Stream = buffer.buffer.stream; CameraStream *cameraStream = static_cast(camera3Stream->priv); std::stringstream ss; @@ -920,7 +920,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * while fences for streams of type Internal and Mapped are * handled at post-processing time. */ - FrameBuffer *buffer = nullptr; + FrameBuffer *frameBuffer = nullptr; int acquireFence = -1; switch (cameraStream->type()) { case CameraStream::Type::Mapped: @@ -938,13 +938,12 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * associate it with the Camera3RequestDescriptor for * lifetime management only. */ - descriptor->frameBuffers_.push_back( - createFrameBuffer(*camera3Buffer.buffer, + buffer.frameBuffer = + createFrameBuffer(*buffer.buffer.buffer, cameraStream->configuration().pixelFormat, - cameraStream->configuration().size)); - - buffer = descriptor->frameBuffers_.back().get(); - acquireFence = camera3Buffer.acquire_fence; + cameraStream->configuration().size); + frameBuffer = buffer.frameBuffer.get(); + acquireFence = buffer.buffer.acquire_fence; LOG(HAL, Debug) << ss.str() << " (direct)"; break; @@ -956,18 +955,18 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * The buffer has to be returned to the CameraStream * once it has been processed. */ - buffer = cameraStream->getBuffer(); + frameBuffer = cameraStream->getBuffer(); LOG(HAL, Debug) << ss.str() << " (internal)"; break; } - if (!buffer) { - LOG(HAL, Error) << "Failed to create buffer"; + if (!frameBuffer) { + LOG(HAL, Error) << "Failed to create frame buffer"; return -ENOMEM; } - descriptor->request_->addBuffer(cameraStream->stream(), buffer, - acquireFence); + descriptor->request_->addBuffer(cameraStream->stream(), + frameBuffer, acquireFence); } /* @@ -1054,9 +1053,9 @@ void CameraDevice::requestComplete(Request *request) * The buffer status is set to OK and later changed to ERROR if * post-processing/compression fails. */ - for (camera3_stream_buffer_t &buffer : descriptor->buffers_) { + for (auto &buffer : descriptor->buffers_) { CameraStream *cameraStream = - static_cast(buffer.stream->priv); + static_cast(buffer.buffer.stream->priv); /* * Streams of type Direct have been queued to the @@ -1070,9 +1069,9 @@ void CameraDevice::requestComplete(Request *request) * fence to -1 once it has handled it and remove this check. */ if (cameraStream->type() == CameraStream::Type::Direct) - buffer.acquire_fence = -1; - buffer.release_fence = -1; - buffer.status = CAMERA3_BUFFER_STATUS_OK; + buffer.buffer.acquire_fence = -1; + buffer.buffer.release_fence = -1; + buffer.buffer.status = CAMERA3_BUFFER_STATUS_OK; } /* @@ -1087,15 +1086,15 @@ void CameraDevice::requestComplete(Request *request) notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST); - for (camera3_stream_buffer_t &buffer : descriptor->buffers_) { + for (auto &buffer : descriptor->buffers_) { /* * Signal to the framework it has to handle fences that * have not been waited on by setting the release fence * to the acquire fence value. */ - buffer.release_fence = buffer.acquire_fence; - buffer.acquire_fence = -1; - buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + buffer.buffer.release_fence = buffer.buffer.acquire_fence; + buffer.buffer.acquire_fence = -1; + buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; } descriptor->status_ = Camera3RequestDescriptor::Status::Error; @@ -1137,9 +1136,9 @@ void CameraDevice::requestComplete(Request *request) } /* Handle post-processing. */ - for (camera3_stream_buffer_t &buffer : descriptor->buffers_) { + for (auto &buffer : descriptor->buffers_) { CameraStream *cameraStream = - static_cast(buffer.stream->priv); + static_cast(buffer.buffer.stream->priv); if (cameraStream->type() == CameraStream::Type::Direct) continue; @@ -1147,13 +1146,13 @@ void CameraDevice::requestComplete(Request *request) FrameBuffer *src = request->findBuffer(cameraStream->stream()); if (!src) { LOG(HAL, Error) << "Failed to find a source stream buffer"; - buffer.status = CAMERA3_BUFFER_STATUS_ERROR; - notifyError(descriptor->frameNumber_, buffer.stream, + buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + notifyError(descriptor->frameNumber_, buffer.buffer.stream, CAMERA3_MSG_ERROR_BUFFER); continue; } - int ret = cameraStream->process(*src, buffer, descriptor); + int ret = cameraStream->process(*src, buffer.buffer, descriptor); /* * Return the FrameBuffer to the CameraStream now that we're @@ -1163,8 +1162,8 @@ void CameraDevice::requestComplete(Request *request) cameraStream->putBuffer(src); if (ret) { - buffer.status = CAMERA3_BUFFER_STATUS_ERROR; - notifyError(descriptor->frameNumber_, buffer.stream, + buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + notifyError(descriptor->frameNumber_, buffer.buffer.stream, CAMERA3_MSG_ERROR_BUFFER); } } @@ -1190,10 +1189,16 @@ void CameraDevice::sendCaptureResults() camera3_capture_result_t captureResult = {}; captureResult.frame_number = descriptor->frameNumber_; + if (descriptor->resultMetadata_) captureResult.result = descriptor->resultMetadata_->get(); - captureResult.num_output_buffers = descriptor->buffers_.size(); - captureResult.output_buffers = descriptor->buffers_.data(); + + std::vector resultBuffers; + for (const auto &buffer : descriptor->buffers_) + resultBuffers.emplace_back(buffer.buffer); + + captureResult.num_output_buffers = resultBuffers.size(); + captureResult.output_buffers = resultBuffers.data(); if (descriptor->status_ == Camera3RequestDescriptor::Status::Success) captureResult.partial_result = 1; diff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp index 16a632b3..614baed4 100644 --- a/src/android/camera_request.cpp +++ b/src/android/camera_request.cpp @@ -23,15 +23,10 @@ Camera3RequestDescriptor::Camera3RequestDescriptor( /* Copy the camera3 request stream information for later access. */ const uint32_t numBuffers = camera3Request->num_output_buffers; + buffers_.resize(numBuffers); for (uint32_t i = 0; i < numBuffers; i++) - buffers_[i] = camera3Request->output_buffers[i]; - - /* - * FrameBuffer instances created by wrapping a camera3 provided dmabuf - * are emplaced in this vector of unique_ptr<> for lifetime management. - */ - frameBuffers_.reserve(numBuffers); + buffers_[i].buffer = camera3Request->output_buffers[i]; /* Clone the controls associated with the camera3 request. */ settings_ = CameraMetadata(camera3Request->settings); diff --git a/src/android/camera_request.h b/src/android/camera_request.h index db13f624..a030febf 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -29,6 +29,16 @@ public: Error, }; + struct StreamBuffer { + camera3_stream_buffer_t buffer; + /* + * FrameBuffer instances created by wrapping a camera3 provided + * dmabuf are emplaced in this vector of unique_ptr<> for + * lifetime management. + */ + std::unique_ptr frameBuffer; + }; + Camera3RequestDescriptor(libcamera::Camera *camera, const camera3_capture_request_t *camera3Request); ~Camera3RequestDescriptor(); @@ -36,8 +46,9 @@ public: bool isPending() const { return status_ == Status::Pending; } uint32_t frameNumber_ = 0; - std::vector buffers_; - std::vector> frameBuffers_; + + std::vector buffers_; + CameraMetadata settings_; std::unique_ptr request_; std::unique_ptr resultMetadata_; From patchwork Tue Oct 19 11:47:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14180 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 E2845C324C for ; Tue, 19 Oct 2021 11:48:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B24C268F5C; Tue, 19 Oct 2021 13:48: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="fI0vX8kF"; 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 CF83A604FE for ; Tue, 19 Oct 2021 13:48:23 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4755312A; Tue, 19 Oct 2021 13:48:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644103; bh=YaOHftBnk6tAz7bEpv0cd6CGz0h22Q1fXu3gpWatf04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fI0vX8kFU4XWnUxKEPivuLbHRP+37rJrF/KkaS3T7c4xYnT4sB5JA3KcgpSJ6Htfl EXjXGlpJHnbCA7WYw1TsMhvXZNSiFIbE9g6EODWKB3fD5l0ycWmwKJ0UGphkxWDoPN rjufSi8jj6JVo6LB7Rb9VpXLR5qNr0fbYFDjcL5I= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:56 +0530 Message-Id: <20211019114802.665980-7-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/12] android: camera_stream: Pass StreamBuffer to process() 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" From: Laurent Pinchart Now that we have a proper structure to model a stream buffer, pass it to CameraStream::process() instead of the camera3_stream_buffer_t. This will allow accessing other members of StreamBuffer in subsequent commits. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 2 +- src/android/camera_stream.cpp | 14 +++++++------- src/android/camera_stream.h | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 74d9b952..80e11d4b 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1152,7 +1152,7 @@ void CameraDevice::requestComplete(Request *request) continue; } - int ret = cameraStream->process(*src, buffer.buffer, descriptor); + int ret = cameraStream->process(*src, buffer, descriptor); /* * Return the FrameBuffer to the CameraStream now that we're diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 8f47e4d8..f3cc77e7 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -143,15 +143,15 @@ int CameraStream::waitFence(int fence) } int CameraStream::process(const FrameBuffer &source, - camera3_stream_buffer_t &camera3Dest, + Camera3RequestDescriptor::StreamBuffer &dest, Camera3RequestDescriptor *request) { /* Handle waiting on fences on the destination buffer. */ - int fence = camera3Dest.acquire_fence; + int fence = dest.buffer.acquire_fence; if (fence != -1) { int ret = waitFence(fence); ::close(fence); - camera3Dest.acquire_fence = -1; + dest.buffer.acquire_fence = -1; if (ret < 0) { LOG(HAL, Error) << "Failed waiting for fence: " << fence << ": " << strerror(-ret); @@ -167,14 +167,14 @@ int CameraStream::process(const FrameBuffer &source, * separate thread. */ const StreamConfiguration &output = configuration(); - CameraBuffer dest(*camera3Dest.buffer, output.pixelFormat, output.size, - PROT_READ | PROT_WRITE); - if (!dest.isValid()) { + CameraBuffer destBuffer(*dest.buffer.buffer, output.pixelFormat, + output.size, PROT_READ | PROT_WRITE); + if (!destBuffer.isValid()) { LOG(HAL, Error) << "Failed to create destination buffer"; return -EINVAL; } - return postProcessor_->process(source, &dest, request); + return postProcessor_->process(source, &destBuffer, request); } FrameBuffer *CameraStream::getBuffer() diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 405b232d..197bd995 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -19,7 +19,8 @@ #include #include -class Camera3RequestDescriptor; +#include "camera_request.h" + class CameraDevice; class PostProcessor; @@ -119,7 +120,7 @@ public: int configure(); int process(const libcamera::FrameBuffer &source, - camera3_stream_buffer_t &camera3Buffer, + Camera3RequestDescriptor::StreamBuffer &dest, Camera3RequestDescriptor *request); libcamera::FrameBuffer *getBuffer(); void putBuffer(libcamera::FrameBuffer *buffer); From patchwork Tue Oct 19 11:47:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14181 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 34948C324C for ; Tue, 19 Oct 2021 11:48:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F396F68F59; Tue, 19 Oct 2021 13:48:27 +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="wqEfb5i+"; 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 0988368F61 for ; Tue, 19 Oct 2021 13:48:26 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9AB4912A; Tue, 19 Oct 2021 13:48:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644105; bh=1Y9oMUkhXf/KjCa3O8v3E2sUSMaJmgiLRBg9i2QDTig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wqEfb5i+yPWtyDPt9P3MZq2M8vKZSjI1YODgeC3N38uuV35gLTbDGmO55VYwEw/AA m1TJZRlXUdn9gef88k9jCUzLkkYmZUXXsOj+cWM5Z+zeImbjC20mLLXERMxy22qSOQ djeUjWlFJlzZpXi6xvYcskoinbYqrk851i0totzI= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:57 +0530 Message-Id: <20211019114802.665980-8-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/12] android: camera_stream: Return non-const pointer from camera3Stream() 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" From: Laurent Pinchart The camera3_stream_t instances are used to interact with the camera service, whose API uses non-const pointers. Replace the const reference returned by CameraStream::camera3Stream() with a non-const pointer. It turns out that nobody calls this function, but new users will be introduced in subsequent commits. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_stream.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 197bd995..85064268 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -114,7 +114,7 @@ public: camera3_stream_t *camera3Stream, unsigned int index); Type type() const { return type_; } - const camera3_stream_t &camera3Stream() const { return *camera3Stream_; } + camera3_stream_t *camera3Stream() const { return camera3Stream_; } const libcamera::StreamConfiguration &configuration() const; libcamera::Stream *stream() const; From patchwork Tue Oct 19 11:47:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14182 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 C3558C324C for ; Tue, 19 Oct 2021 11:48:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 724A468F5A; Tue, 19 Oct 2021 13:48:30 +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="VflYM/mQ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6BABC68F55 for ; Tue, 19 Oct 2021 13:48:28 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 22D3712A; Tue, 19 Oct 2021 13:48:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644108; bh=03ro7zyMD+rFVRW+23gsfLgxSj27kpdVUQo5A34z7s4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VflYM/mQdXDESSt/z2A5m2hnf8nP2d4hclAT8BwWJHx+2nRiZQWqJJoQBDANb2u7m OFTjDMwN573cc8MX8Z57KxW0IXIdvfRkHqntWDWJNyBDaj6DX66jgs2OUm12Bx+2GJ D8hBhz7j0LB0LQzjloUIMXeFS2FjKgD5pYgTqlc4= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:58 +0530 Message-Id: <20211019114802.665980-9-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/12] android: camera_device: Use abortRequest() instead of open-coding it 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" From: Laurent Pinchart Call abortRequest() in CameraDevice::requestComplete() instead of open-coding it. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 80e11d4b..0bb547ae 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -802,6 +802,11 @@ void CameraDevice::abortRequest(Camera3RequestDescriptor *descriptor) const notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST); for (auto &buffer : descriptor->buffers_) { + /* + * Signal to the framework it has to handle fences that have not + * been waited on by setting the release fence to the acquire + * fence value. + */ buffer.buffer.release_fence = buffer.buffer.acquire_fence; buffer.buffer.acquire_fence = -1; buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; @@ -1083,21 +1088,7 @@ void CameraDevice::requestComplete(Request *request) << " not successfully completed: " << request->status(); - notifyError(descriptor->frameNumber_, nullptr, - CAMERA3_MSG_ERROR_REQUEST); - - for (auto &buffer : descriptor->buffers_) { - /* - * Signal to the framework it has to handle fences that - * have not been waited on by setting the release fence - * to the acquire fence value. - */ - buffer.buffer.release_fence = buffer.buffer.acquire_fence; - buffer.buffer.acquire_fence = -1; - buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; - } - - descriptor->status_ = Camera3RequestDescriptor::Status::Error; + abortRequest(descriptor); sendCaptureResults(); return; From patchwork Tue Oct 19 11:47:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14183 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 50F8FC324C for ; Tue, 19 Oct 2021 11:48:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 11E5468F5D; Tue, 19 Oct 2021 13:48:32 +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="EoEPglu1"; 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 6268E604FF for ; Tue, 19 Oct 2021 13:48:30 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C0F312A; Tue, 19 Oct 2021 13:48:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644110; bh=nZfi2zYf9mf27qLb1pVADiGv4Tu6Cr41QbIdQsy5KSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EoEPglu1jmIQ+hnJgYjCejzs1akcG6g2Qbt0s8gI6Ui9WAPAtzWFv2lQiSxCaEonm lyqAWNKHwD8c36rjRZ+Dly6/bioV7RUgS2rrc3+BpefIItlxnsoOD6pDQVi+zYZXZa 7TCdNgcJ/wMsRYsOFa04CgM+N+RndZ8JCvcgI6Wg= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:17:59 +0530 Message-Id: <20211019114802.665980-10-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/12] android: camera_request: Don't embed full camera3_stream_buffer_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" From: Laurent Pinchart The camera3_stream_buffer_t structure is meant to communicate between the camera service and the HAL. They are short-live structures that don't outlive the .process_capture_request() operation (when queuing requests) or the .process_capture_result() callback. We currently store copies of the camera3_stream_buffer_t passed to .process_capture_request() in Camera3RequestDescriptor::StreamBuffer to store the structure members that the HAL need, and reuse them when calling the .process_capture_result() callback. This is conceptually not right, as the camera3_stream_buffer_t pass to the callback are not the same objects as the ones received in .process_capture_request(). Store individual fields of the camera3_stream_buffer_t in StreamBuffer instead of copying the whole structure. This gives the HAL full control of how data is stored, and properly decouples request queueing from result reporting. Signed-off-by: Laurent Pinchart Signed-off-by: Umang Jain Reviewed-by: Umang Jain Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 73 ++++++++++++++++++---------------- src/android/camera_request.cpp | 19 +++++++-- src/android/camera_request.h | 12 +++--- src/android/camera_stream.cpp | 6 +-- 4 files changed, 63 insertions(+), 47 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 0bb547ae..0a2d3826 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -801,16 +801,8 @@ void CameraDevice::abortRequest(Camera3RequestDescriptor *descriptor) const { notifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST); - for (auto &buffer : descriptor->buffers_) { - /* - * Signal to the framework it has to handle fences that have not - * been waited on by setting the release fence to the acquire - * fence value. - */ - buffer.buffer.release_fence = buffer.buffer.acquire_fence; - buffer.buffer.acquire_fence = -1; - buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; - } + for (auto &buffer : descriptor->buffers_) + buffer.status = Camera3RequestDescriptor::Status::Error; descriptor->status_ = Camera3RequestDescriptor::Status::Error; } @@ -908,8 +900,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques << " with " << descriptor->buffers_.size() << " streams"; for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) { - camera3_stream *camera3Stream = buffer.buffer.stream; - CameraStream *cameraStream = static_cast(camera3Stream->priv); + CameraStream *cameraStream = buffer.stream; + camera3_stream_t *camera3Stream = cameraStream->camera3Stream(); std::stringstream ss; ss << i << " - (" << camera3Stream->width << "x" @@ -944,11 +936,11 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * lifetime management only. */ buffer.frameBuffer = - createFrameBuffer(*buffer.buffer.buffer, + createFrameBuffer(*buffer.camera3Buffer, cameraStream->configuration().pixelFormat, cameraStream->configuration().size); frameBuffer = buffer.frameBuffer.get(); - acquireFence = buffer.buffer.acquire_fence; + acquireFence = buffer.fence; LOG(HAL, Debug) << ss.str() << " (direct)"; break; @@ -1055,12 +1047,11 @@ void CameraDevice::requestComplete(Request *request) /* * Prepare the capture result for the Android camera stack. * - * The buffer status is set to OK and later changed to ERROR if + * The buffer status is set to Success and later changed to Error if * post-processing/compression fails. */ for (auto &buffer : descriptor->buffers_) { - CameraStream *cameraStream = - static_cast(buffer.buffer.stream->priv); + CameraStream *stream = buffer.stream; /* * Streams of type Direct have been queued to the @@ -1073,10 +1064,9 @@ void CameraDevice::requestComplete(Request *request) * \todo Instrument the CameraWorker to set the acquire * fence to -1 once it has handled it and remove this check. */ - if (cameraStream->type() == CameraStream::Type::Direct) - buffer.buffer.acquire_fence = -1; - buffer.buffer.release_fence = -1; - buffer.buffer.status = CAMERA3_BUFFER_STATUS_OK; + if (stream->type() == CameraStream::Type::Direct) + buffer.fence = -1; + buffer.status = Camera3RequestDescriptor::Status::Success; } /* @@ -1128,33 +1118,32 @@ void CameraDevice::requestComplete(Request *request) /* Handle post-processing. */ for (auto &buffer : descriptor->buffers_) { - CameraStream *cameraStream = - static_cast(buffer.buffer.stream->priv); + CameraStream *stream = buffer.stream; - if (cameraStream->type() == CameraStream::Type::Direct) + if (stream->type() == CameraStream::Type::Direct) continue; - FrameBuffer *src = request->findBuffer(cameraStream->stream()); + FrameBuffer *src = request->findBuffer(stream->stream()); if (!src) { LOG(HAL, Error) << "Failed to find a source stream buffer"; - buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; - notifyError(descriptor->frameNumber_, buffer.buffer.stream, + buffer.status = Camera3RequestDescriptor::Status::Error; + notifyError(descriptor->frameNumber_, stream->camera3Stream(), CAMERA3_MSG_ERROR_BUFFER); continue; } - int ret = cameraStream->process(*src, buffer, descriptor); + int ret = stream->process(*src, buffer, descriptor); /* * Return the FrameBuffer to the CameraStream now that we're * done processing it. */ - if (cameraStream->type() == CameraStream::Type::Internal) - cameraStream->putBuffer(src); + if (stream->type() == CameraStream::Type::Internal) + stream->putBuffer(src); if (ret) { - buffer.buffer.status = CAMERA3_BUFFER_STATUS_ERROR; - notifyError(descriptor->frameNumber_, buffer.buffer.stream, + buffer.status = Camera3RequestDescriptor::Status::Error; + notifyError(descriptor->frameNumber_, stream->camera3Stream(), CAMERA3_MSG_ERROR_BUFFER); } } @@ -1185,8 +1174,24 @@ void CameraDevice::sendCaptureResults() captureResult.result = descriptor->resultMetadata_->get(); std::vector resultBuffers; - for (const auto &buffer : descriptor->buffers_) - resultBuffers.emplace_back(buffer.buffer); + resultBuffers.reserve(descriptor->buffers_.size()); + + for (const auto &buffer : descriptor->buffers_) { + camera3_buffer_status status = CAMERA3_BUFFER_STATUS_ERROR; + + if (buffer.status == Camera3RequestDescriptor::Status::Success) + status = CAMERA3_BUFFER_STATUS_OK; + + /* + * Pass the buffer fence back to the camera framework as + * a release fence. This instructs the framework to wait + * on the acquire fence in case we haven't done so + * ourselves for any reason. + */ + resultBuffers.push_back({ buffer.stream->camera3Stream(), + buffer.camera3Buffer, status, + -1, buffer.fence }); + } captureResult.num_output_buffers = resultBuffers.size(); captureResult.output_buffers = resultBuffers.data(); diff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp index 614baed4..faa85ada 100644 --- a/src/android/camera_request.cpp +++ b/src/android/camera_request.cpp @@ -7,6 +7,8 @@ #include "camera_request.h" +#include + using namespace libcamera; /* @@ -22,11 +24,20 @@ Camera3RequestDescriptor::Camera3RequestDescriptor( frameNumber_ = camera3Request->frame_number; /* Copy the camera3 request stream information for later access. */ - const uint32_t numBuffers = camera3Request->num_output_buffers; + const Span buffers{ + camera3Request->output_buffers, + camera3Request->num_output_buffers + }; + + buffers_.reserve(buffers.size()); + + for (const camera3_stream_buffer_t &buffer : buffers) { + CameraStream *stream = + static_cast(buffer.stream->priv); - buffers_.resize(numBuffers); - for (uint32_t i = 0; i < numBuffers; i++) - buffers_[i].buffer = camera3Request->output_buffers[i]; + buffers_.push_back({ stream, buffer.buffer, nullptr, + buffer.acquire_fence, Status::Pending }); + } /* Clone the controls associated with the camera3 request. */ settings_ = CameraMetadata(camera3Request->settings); diff --git a/src/android/camera_request.h b/src/android/camera_request.h index a030febf..05dabf89 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -20,6 +20,8 @@ #include "camera_metadata.h" #include "camera_worker.h" +class CameraStream; + class Camera3RequestDescriptor { public: @@ -30,13 +32,11 @@ public: }; struct StreamBuffer { - camera3_stream_buffer_t buffer; - /* - * FrameBuffer instances created by wrapping a camera3 provided - * dmabuf are emplaced in this vector of unique_ptr<> for - * lifetime management. - */ + CameraStream *stream; + buffer_handle_t *camera3Buffer; std::unique_ptr frameBuffer; + int fence; + Status status; }; Camera3RequestDescriptor(libcamera::Camera *camera, diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index f3cc77e7..9b5cd0c4 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -147,11 +147,11 @@ int CameraStream::process(const FrameBuffer &source, Camera3RequestDescriptor *request) { /* Handle waiting on fences on the destination buffer. */ - int fence = dest.buffer.acquire_fence; + int fence = dest.fence; if (fence != -1) { int ret = waitFence(fence); ::close(fence); - dest.buffer.acquire_fence = -1; + dest.fence = -1; if (ret < 0) { LOG(HAL, Error) << "Failed waiting for fence: " << fence << ": " << strerror(-ret); @@ -167,7 +167,7 @@ int CameraStream::process(const FrameBuffer &source, * separate thread. */ const StreamConfiguration &output = configuration(); - CameraBuffer destBuffer(*dest.buffer.buffer, output.pixelFormat, + CameraBuffer destBuffer(*dest.camera3Buffer, output.pixelFormat, output.size, PROT_READ | PROT_WRITE); if (!destBuffer.isValid()) { LOG(HAL, Error) << "Failed to create destination buffer"; From patchwork Tue Oct 19 11:48:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14184 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 C064EC324C for ; Tue, 19 Oct 2021 11:48:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B37168F5A; Tue, 19 Oct 2021 13:48:34 +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="VZzldmAE"; 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 64E2768F61 for ; Tue, 19 Oct 2021 13:48:32 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D418A15; Tue, 19 Oct 2021 13:48:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644112; bh=hzyrnRmtK+7yLQt8L1dTC7TqQFLgf24o9wlvJXzzBCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VZzldmAExw8ChqQiUjuVGWtXKSSfY9nWwlg3tysp2uWaPdym04r/Aj9fkAreda7lS +HIEUqIUeLD95grtpQSYf0CK6cY6DGJi13GHDAtIS1Zt07U4kjulu+MDsGCQkC6Evo oITLtlacFgpcYlkyPviIcHek+jk/I794SksilTmA= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:18:00 +0530 Message-Id: <20211019114802.665980-11-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/12] android: camera_stream: Don't close fence if wait fails 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" From: Laurent Pinchart The camera HAL APIs requires that any acquire fence that hasn't been waited on to be sent back to the framework as a release fence. The CameraDevice already copies the acquire fence to the release fence when signaling request completion, but the CameraStream incorrectly closes the fence when a wait fails and sets it to -1. Fix it. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_stream.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 9b5cd0c4..8e6ccb83 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -147,16 +147,16 @@ int CameraStream::process(const FrameBuffer &source, Camera3RequestDescriptor *request) { /* Handle waiting on fences on the destination buffer. */ - int fence = dest.fence; - if (fence != -1) { - int ret = waitFence(fence); - ::close(fence); - dest.fence = -1; + if (dest.fence != -1) { + int ret = waitFence(dest.fence); if (ret < 0) { LOG(HAL, Error) << "Failed waiting for fence: " - << fence << ": " << strerror(-ret); + << dest.fence << ": " << strerror(-ret); return ret; } + + ::close(dest.fence); + dest.fence = -1; } if (!postProcessor_) From patchwork Tue Oct 19 11:48:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14185 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 44B62C324C for ; Tue, 19 Oct 2021 11:48:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0788368F59; Tue, 19 Oct 2021 13:48:36 +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="G4fc48JF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A83C668F5B for ; Tue, 19 Oct 2021 13:48:34 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 244E512A; Tue, 19 Oct 2021 13:48:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644114; bh=+2iv9AcdAop1GHr1p6p2XOkrbZvLF8eoj0tQrRjYMdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G4fc48JFscvLkTjJsxLP8D2mFTg0GrvkvEZUqdLi5z6m3fvRY49Q0hib4Ayc8epM1 MNIS8nn0jh7p8ct2Mx7qE20EDz7ASz9lwSSvaMUaihtwjSigepS4IpRWowd2KcH3RL CTiqj9ShWiWMePl+dbGxtmmoKAKBs+S+ZtbSeraA= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:18:01 +0530 Message-Id: <20211019114802.665980-12-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/12] android: camera_stream: Define explicit move constructor and destructors 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" From: Laurent Pinchart There's no need for the move constructor and the destructor to be inline. Define them explicitly, with default implementations. This allows usage of the CameraStream class without a complete definition of the PostProcessor class. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Jacopo Mondi --- src/android/camera_stream.cpp | 4 ++++ src/android/camera_stream.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 8e6ccb83..f44a2717 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -56,6 +56,10 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice, { } +CameraStream::CameraStream(CameraStream &&other) = default; + +CameraStream::~CameraStream() = default; + const StreamConfiguration &CameraStream::configuration() const { return config_->at(index_); diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 85064268..f242336e 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -112,6 +112,8 @@ public: CameraStream(CameraDevice *const cameraDevice, libcamera::CameraConfiguration *config, Type type, camera3_stream_t *camera3Stream, unsigned int index); + CameraStream(CameraStream &&other); + ~CameraStream(); Type type() const { return type_; } camera3_stream_t *camera3Stream() const { return camera3Stream_; } From patchwork Tue Oct 19 11:48:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14186 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 A3081C324C for ; Tue, 19 Oct 2021 11:48:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 61E6A68F59; Tue, 19 Oct 2021 13:48:38 +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="wlPat/J/"; 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 8368268F55 for ; Tue, 19 Oct 2021 13:48:36 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.98]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7B1CA12A; Tue, 19 Oct 2021 13:48:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1634644116; bh=OKHlpiQ4ufljWLwJsdj0P40bJWU4e/CM8uUImxAy9f8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wlPat/J/LJQtc6vIkXc0RxA9sr/+fZqNjzMWZPHFr6EFoC2+Ev3qyeoiCbKa1QQQ/ qEmZRQXs/ga5+TMADNrwHA3dYt2kR+mj7xmdMlati3evXHgQJP6o69v5li3pTQb+97 LyhTKepgv8n4okwQUX4Y5csMrPseX0Cvb4IEJZlI= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 19 Oct 2021 17:18:02 +0530 Message-Id: <20211019114802.665980-13-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211019114802.665980-1-umang.jain@ideasonboard.com> References: <20211019114802.665980-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 12/12] android: camera_metadata: Rename get() to getMetadata() 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" Rename CameraMetadata::get() to CameraMetadata::getMetadata() to avoid confusion with std::unique_ptr::get() when CameraMetadata is used with a std::unique_ptr. No functional changes intended in this patch. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 9 +++++---- src/android/camera_metadata.cpp | 8 ++++---- src/android/camera_metadata.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 0a2d3826..ea676409 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -440,7 +440,7 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) const camera_metadata_t *CameraDevice::getStaticMetadata() { - return capabilities_.staticMetadata()->get(); + return capabilities_.staticMetadata()->getMetadata(); } /* @@ -450,7 +450,7 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) { auto it = requestTemplates_.find(type); if (it != requestTemplates_.end()) - return it->second->get(); + return it->second->getMetadata(); /* Use the capture intent matching the requested template type. */ std::unique_ptr requestTemplate; @@ -496,7 +496,7 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type) captureIntent); requestTemplates_[type] = std::move(requestTemplate); - return requestTemplates_[type]->get(); + return requestTemplates_[type]->getMetadata(); } /* @@ -1171,7 +1171,8 @@ void CameraDevice::sendCaptureResults() captureResult.frame_number = descriptor->frameNumber_; if (descriptor->resultMetadata_) - captureResult.result = descriptor->resultMetadata_->get(); + captureResult.result = + descriptor->resultMetadata_->getMetadata(); std::vector resultBuffers; resultBuffers.reserve(descriptor->buffers_.size()); diff --git a/src/android/camera_metadata.cpp b/src/android/camera_metadata.cpp index 075b6a22..b3e515d2 100644 --- a/src/android/camera_metadata.cpp +++ b/src/android/camera_metadata.cpp @@ -33,7 +33,7 @@ CameraMetadata::CameraMetadata(const camera_metadata_t *metadata) } CameraMetadata::CameraMetadata(const CameraMetadata &other) - : CameraMetadata(other.get()) + : CameraMetadata(other.getMetadata()) { } @@ -51,7 +51,7 @@ CameraMetadata &CameraMetadata::operator=(const CameraMetadata &other) if (metadata_) free_camera_metadata(metadata_); - metadata_ = clone_camera_metadata(other.get()); + metadata_ = clone_camera_metadata(other.getMetadata()); valid_ = metadata_ != nullptr; return *this; @@ -220,12 +220,12 @@ bool CameraMetadata::updateEntry(uint32_t tag, const void *data, size_t count, return false; } -camera_metadata_t *CameraMetadata::get() +camera_metadata_t *CameraMetadata::getMetadata() { return valid_ ? metadata_ : nullptr; } -const camera_metadata_t *CameraMetadata::get() const +const camera_metadata_t *CameraMetadata::getMetadata() const { return valid_ ? metadata_ : nullptr; } diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index 60be416c..8555c7c3 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -85,8 +85,8 @@ public: return updateEntry(tag, data, count, sizeof(T)); } - camera_metadata_t *get(); - const camera_metadata_t *get() const; + camera_metadata_t *getMetadata(); + const camera_metadata_t *getMetadata() const; private: bool resize(size_t count, size_t size);