{"id":14177,"url":"https://patchwork.libcamera.org/api/patches/14177/?format=json","web_url":"https://patchwork.libcamera.org/patch/14177/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211019114802.665980-4-umang.jain@ideasonboard.com>","date":"2021-10-19T11:47:53","name":"[libcamera-devel,v2,03/12] android: camera_device: Build capture_result dynamically","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"62b13da331532a0e0b79087d6709ebdb069bca12","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":{"id":12,"url":"https://patchwork.libcamera.org/api/users/12/?format=json","username":"uajain","first_name":"Umang","last_name":"Jain","email":"umang.jain@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/14177/mbox/","series":[{"id":2638,"url":"https://patchwork.libcamera.org/api/series/2638/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2638","date":"2021-10-19T11:47:50","name":"android: Overhaul request handling","version":2,"mbox":"https://patchwork.libcamera.org/series/2638/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14177/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14177/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8C068C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Oct 2021 11:48:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 44D4368F5B;\n\tTue, 19 Oct 2021 13:48:18 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 02ECD68F5B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Oct 2021 13:48:17 +0200 (CEST)","from perceval.ideasonboard.com (unknown [103.251.226.98])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C62512A;\n\tTue, 19 Oct 2021 13:48:15 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WGnhijJl\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634644096;\n\tbh=Vp6FzJ/7bMKJw0R1OjL1B4UrtnKEU8LtDGCwe5lZ70o=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=WGnhijJlwu50d8RI4Qih3NeXD24eYMMtOVXGIuOHClrSWY6FO+hWivR5i+6t5tWv5\n\tSufaBmiV9V3V6V/6X8pA99iviYTVz/vTd4q7YTMTYacD8CMOO+ifo0ou3T5f8Vd9KR\n\tsjqg31rJnUTn9BW7pBxAwSDp2F8EHzq/b68DXCms=","From":"Umang Jain <umang.jain@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 03/12] android: camera_device: Build\n\tcapture_result dynamically","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThe camera3_capture_result_t is only needed to convey capture results to\nthe camera service through the process_capture_result() callback.\nThere's no need to store it in the Camera3RequestDescriptor. Build it\ndynamically in CameraDevice::sendCaptureResults() instead.\n\nThis requires storing the result metadata created in\nCameraDevice::requestComplete() in the Camera3RequestDescriptor. A side\neffect of this change is that the request metadata lifetime will match\nthe Camera3RequestDescriptor instead of being destroyed at the end of\nrequestComplete(). This will be needed to support asynchronous\npost-processing, where the request completion will be signaled to the\ncamera service asynchronously from requestComplete().\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/android/camera_device.cpp | 50 ++++++++++++++++++-----------------\n src/android/camera_request.h  |  2 +-\n 2 files changed, 27 insertions(+), 25 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 3689940d..38132cbd 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -801,19 +801,11 @@ void CameraDevice::abortRequest(Camera3RequestDescriptor *descriptor) const\n {\n \tnotifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_REQUEST);\n \n-\tcamera3_capture_result_t &result = descriptor->captureResult_;\n-\tresult.num_output_buffers = descriptor->buffers_.size();\n-\tresult.frame_number = descriptor->frameNumber_;\n-\tresult.partial_result = 0;\n-\n-\tstd::vector<camera3_stream_buffer_t> resultBuffers(result.num_output_buffers);\n-\tfor (auto [i, buffer] : utils::enumerate(resultBuffers)) {\n-\t\tbuffer = descriptor->buffers_[i];\n-\t\tbuffer.release_fence = descriptor->buffers_[i].acquire_fence;\n+\tfor (auto &buffer : descriptor->buffers_) {\n+\t\tbuffer.release_fence = buffer.acquire_fence;\n \t\tbuffer.acquire_fence = -1;\n \t\tbuffer.status = CAMERA3_BUFFER_STATUS_ERROR;\n \t}\n-\tresult.output_buffers = resultBuffers.data();\n \n \tdescriptor->status_ = Camera3RequestDescriptor::Status::Error;\n }\n@@ -1062,9 +1054,6 @@ void CameraDevice::requestComplete(Request *request)\n \t * The buffer status is set to OK and later changed to ERROR if\n \t * post-processing/compression fails.\n \t */\n-\tcamera3_capture_result_t &captureResult = descriptor->captureResult_;\n-\tcaptureResult.frame_number = descriptor->frameNumber_;\n-\tcaptureResult.num_output_buffers = descriptor->buffers_.size();\n \tfor (camera3_stream_buffer_t &buffer : descriptor->buffers_) {\n \t\tCameraStream *cameraStream =\n \t\t\tstatic_cast<CameraStream *>(buffer.stream->priv);\n@@ -1085,8 +1074,6 @@ void CameraDevice::requestComplete(Request *request)\n \t\tbuffer.release_fence = -1;\n \t\tbuffer.status = CAMERA3_BUFFER_STATUS_OK;\n \t}\n-\tcaptureResult.output_buffers = descriptor->buffers_.data();\n-\tcaptureResult.partial_result = 1;\n \n \t/*\n \t * If the Request has failed, abort the request by notifying the error\n@@ -1100,7 +1087,6 @@ void CameraDevice::requestComplete(Request *request)\n \t\tnotifyError(descriptor->frameNumber_, nullptr,\n \t\t\t    CAMERA3_MSG_ERROR_REQUEST);\n \n-\t\tcaptureResult.partial_result = 0;\n \t\tfor (camera3_stream_buffer_t &buffer : descriptor->buffers_) {\n \t\t\t/*\n \t\t\t * Signal to the framework it has to handle fences that\n@@ -1137,12 +1123,17 @@ void CameraDevice::requestComplete(Request *request)\n \t * Notify if the metadata generation has failed, but continue processing\n \t * buffers and return an empty metadata pack.\n \t */\n-\tstd::unique_ptr<CameraMetadata> resultMetadata = getResultMetadata(*descriptor);\n-\tif (!resultMetadata) {\n+\tdescriptor->resultMetadata_ = getResultMetadata(*descriptor);\n+\tif (!descriptor->resultMetadata_) {\n \t\tnotifyError(descriptor->frameNumber_, nullptr, CAMERA3_MSG_ERROR_RESULT);\n \n-\t\t/* The camera framework expects an empty metadata pack on error. */\n-\t\tresultMetadata = std::make_unique<CameraMetadata>(0, 0);\n+\t\t/*\n+\t\t * The camera framework expects an empty metadata pack on error.\n+\t\t *\n+\t\t * \\todo Check that the post-processor code handles this situation\n+\t\t * correctly.\n+\t\t */\n+\t\tdescriptor->resultMetadata_ = std::make_unique<CameraMetadata>(0, 0);\n \t}\n \n \t/* Handle post-processing. */\n@@ -1164,7 +1155,7 @@ void CameraDevice::requestComplete(Request *request)\n \n \t\tint ret = cameraStream->process(*src, buffer,\n \t\t\t\t\t\tdescriptor->settings_,\n-\t\t\t\t\t\tresultMetadata.get());\n+\t\t\t\t\t\tdescriptor->resultMetadata_.get());\n \t\t/*\n \t\t * Return the FrameBuffer to the CameraStream now that we're\n \t\t * done processing it.\n@@ -1179,7 +1170,6 @@ void CameraDevice::requestComplete(Request *request)\n \t\t}\n \t}\n \n-\tcaptureResult.result = resultMetadata->get();\n \tdescriptor->status_ = Camera3RequestDescriptor::Status::Success;\n \tsendCaptureResults();\n }\n@@ -1197,8 +1187,20 @@ void CameraDevice::sendCaptureResults()\n \t\t * impact on performance which should be measured.\n \t\t */\n \t\tlock.unlock();\n-\t\tcallbacks_->process_capture_result(callbacks_,\n-\t\t\t\t\t\t   &descriptor->captureResult_);\n+\n+\t\tcamera3_capture_result_t captureResult = {};\n+\n+\t\tcaptureResult.frame_number = descriptor->frameNumber_;\n+\t\tif (descriptor->resultMetadata_)\n+\t\t\tcaptureResult.result = descriptor->resultMetadata_->get();\n+\t\tcaptureResult.num_output_buffers = descriptor->buffers_.size();\n+\t\tcaptureResult.output_buffers = descriptor->buffers_.data();\n+\n+\t\tif (descriptor->status_ == Camera3RequestDescriptor::Status::Success)\n+\t\t\tcaptureResult.partial_result = 1;\n+\n+\t\tcallbacks_->process_capture_result(callbacks_, &captureResult);\n+\n \t\tlock.lock();\n \t}\n }\ndiff --git a/src/android/camera_request.h b/src/android/camera_request.h\nindex 79dfdb58..db13f624 100644\n--- a/src/android/camera_request.h\n+++ b/src/android/camera_request.h\n@@ -40,8 +40,8 @@ public:\n \tstd::vector<std::unique_ptr<libcamera::FrameBuffer>> frameBuffers_;\n \tCameraMetadata settings_;\n \tstd::unique_ptr<CaptureRequest> request_;\n+\tstd::unique_ptr<CameraMetadata> resultMetadata_;\n \n-\tcamera3_capture_result_t captureResult_ = {};\n \tStatus status_ = Status::Pending;\n \n private:\n","prefixes":["libcamera-devel","v2","03/12"]}