{"id":14164,"url":"https://patchwork.libcamera.org/api/1.1/patches/14164/?format=json","web_url":"https://patchwork.libcamera.org/patch/14164/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20211018132923.476242-4-umang.jain@ideasonboard.com>","date":"2021-10-18T13:29:15","name":"[libcamera-devel,03/11] android: camera_device: Build capture_result dynamically","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"726524bc904263ca99f801e8aa3e44654530f7ab","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/1.1/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":{"id":12,"url":"https://patchwork.libcamera.org/api/1.1/users/12/?format=json","username":"uajain","first_name":"Umang","last_name":"Jain","email":"umang.jain@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/14164/mbox/","series":[{"id":2636,"url":"https://patchwork.libcamera.org/api/1.1/series/2636/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2636","date":"2021-10-18T13:29:12","name":"android: Overhaul request handling","version":1,"mbox":"https://patchwork.libcamera.org/series/2636/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14164/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14164/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 0112AC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Oct 2021 13:29:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B753B68F58;\n\tMon, 18 Oct 2021 15:29:39 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5945A68F5D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Oct 2021 15:29:37 +0200 (CEST)","from perceval.ideasonboard.com (unknown [103.238.109.14])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 470F48C6;\n\tMon, 18 Oct 2021 15:29:36 +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=\"Bw6FHcsC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1634563777;\n\tbh=fWstsiPj+w0dOPcWopYX900f/DDTQwtiBZbsnrUHnn4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Bw6FHcsC5p0AhrwZWUlLLL00qMRjh4agxfckNmp5ZeSG4CF5gouCq7RG/yqgzu/8r\n\td/uis13du0LpWfBrF0gYuEJ7bgBk4V4i/881W3eVLEZ3MMqcli0K3m6xjU/KTEOCgB\n\t1rSU5Y4n/98jRCDgr+FxiXfQqhguwGyBHaA/lJU4=","From":"Umang Jain <umang.jain@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 18 Oct 2021 18:59:15 +0530","Message-Id":"<20211018132923.476242-4-umang.jain@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","In-Reply-To":"<20211018132923.476242-1-umang.jain@ideasonboard.com>","References":"<20211018132923.476242-1-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 03/11] 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>\n---\n src/android/camera_device.cpp | 43 ++++++++++++++++-------------------\n src/android/camera_request.h  |  2 +-\n 2 files changed, 21 insertions(+), 24 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex b4ab5da1..c6ae8930 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -830,19 +830,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@@ -1090,9 +1082,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@@ -1113,8 +1102,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@@ -1128,7 +1115,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@@ -1165,12 +1151,12 @@ 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\tdescriptor->resultMetadata_ = std::make_unique<CameraMetadata>(0, 0);\n \t}\n \n \t/* Handle post-processing. */\n@@ -1192,7 +1178,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@@ -1207,7 +1193,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@@ -1225,8 +1210,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","03/11"]}