From patchwork Mon Sep 27 21:36:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 13957 X-Patchwork-Delegate: jacopo@jmondi.org 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 80BBEBDC71 for ; Mon, 27 Sep 2021 21:36:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E04B6918D; Mon, 27 Sep 2021 23:36:19 +0200 (CEST) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 52FDA69189 for ; Mon, 27 Sep 2021 23:36:17 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id A933FC0002; Mon, 27 Sep 2021 21:36:16 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 27 Sep 2021 23:36:59 +0200 Message-Id: <20210927213700.25365-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210927213700.25365-1-jacopo@jmondi.org> References: <20210927213700.25365-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] android: Post-pone fences reset in capture result 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" When a request has been completed and a new capture_result is created we assumed all fences had been waited on, hence we set both the release and acquisition fences to -1. As no buffer is queued to libcamera::Camera for streams of type Mapped, their acquisition fences went ignored. Prepare to fix that by by moving fences resetting after post-processing, that will be instrumented to handle fences in the next patch. Also correct the release_fence handling for failed captures, as the framework requires the release fences to be set to the acquire fence value if the acquire fence has not been waited on. Signed-off-by: Jacopo Mondi Reviewed-by: Hirokazu Honda --- src/android/camera_device.cpp | 44 ++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 21844e5114a9..3c9609d74402 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1098,22 +1098,10 @@ void CameraDevice::requestComplete(Request *request) } Camera3RequestDescriptor &descriptor = node.mapped(); - /* - * Prepare the capture result for the Android camera stack. - * - * The buffer status is set to OK and later changed to ERROR if - * post-processing/compression fails. - */ camera3_capture_result_t captureResult = {}; captureResult.frame_number = descriptor.frameNumber_; captureResult.num_output_buffers = descriptor.buffers_.size(); - for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { - buffer.acquire_fence = -1; - 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 @@ -1128,8 +1116,27 @@ void CameraDevice::requestComplete(Request *request) CAMERA3_MSG_ERROR_REQUEST); captureResult.partial_result = 0; - for (camera3_stream_buffer_t &buffer : descriptor.buffers_) + for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { + CameraStream *cameraStream = + static_cast(buffer.stream->priv); + + /* + * Streams of type Direct have been queued to the + * libcamera::Camera and their acquisition fences has + * already been waited on by the CameraWorker. + * + * For other stream types signal to the framework the + * acquisition fence has not been waited on, by setting + * the release fence to its value. + */ + if (cameraStream->type() == CameraStream::Type::Direct) + buffer.release_fence = -1; + else + buffer.release_fence = buffer.acquire_fence; + + buffer.acquire_fence = -1; buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + } callbacks_->process_capture_result(callbacks_, &captureResult); return; @@ -1196,6 +1203,17 @@ void CameraDevice::requestComplete(Request *request) } } + /* + * Finalize the capture result by setting fences and buffer status + * before executing the callback. + */ + for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { + buffer.acquire_fence = -1; + buffer.release_fence = -1; + buffer.status = CAMERA3_BUFFER_STATUS_OK; + } + captureResult.partial_result = 1; + captureResult.result = resultMetadata->get(); callbacks_->process_capture_result(callbacks_, &captureResult); }