From patchwork Mon Sep 20 17:37: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: 13873 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 7B01FBF01C for ; Mon, 20 Sep 2021 17:38:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3AE5269190; Mon, 20 Sep 2021 19:38:21 +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="IpDitSvj"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6034969199 for ; Mon, 20 Sep 2021 19:38:18 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.144]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5CB0A45E; Mon, 20 Sep 2021 19:38:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1632159498; bh=nLP58YsDKIF7yn5cRXa8rn+Hp3N35MqBoz+xB0SL5u4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpDitSvjIrqDaAx6x+sPbd+loqW0s49XeQHxV6NKzKvvCtpmjOHuGigSaU25V3u18 tnoBnRm0IW1oRRdPj2LpA/Dpwb//Vd3w4BFBgrlvBj/+3EGr1tK0/dHJfci28pL3OQ 186V6JOxvq82pDdvyN/QbQV31iGxmqK3FkYc1xxs= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Sep 2021 23:07:51 +0530 Message-Id: <20210920173752.1346190-10-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210920173752.1346190-1-umang.jain@ideasonboard.com> References: <20210920173752.1346190-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 09/10] android: camera_device: Send capture results inspecting the descriptor X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A Camera3RequestDescriptors is constructed and queued to descriptors_ queue as soon as an (incoming) capture request is received on the libcamera HAL. The capture request is picked up by HAL, in order to run it to completion. At completion, CameraDevice::requestComplete() gets invoked and capture results are populated and ready to be sent back to the framework. All the data and framebuffers associated with the request are alive and encapsulated inside this Camera3RequestDescriptor descriptor. By inspecting the ProcessStatus on the descriptor, we can now send capture results via the process_capture_result() callback. Hence, introduce a new private member function sendCaptureResults() which will be responsible to send capture results back to the framework by inspecting the descriptor on the queue. In subsequent commit, when the post processsor shall run async, sendCaptureResults() can be called from the post-processor's thread for e.g. streamProcessComplete() hence, introduce the mutex lock to avoid the races. Signed-off-by: Umang Jain --- src/android/camera_device.cpp | 47 +++++++++++++++++++++++++---------- src/android/camera_device.h | 4 +++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 4658e881..16ecdfc5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1078,7 +1078,7 @@ 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 = {}; + 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_) { @@ -1156,26 +1156,25 @@ void CameraDevice::requestComplete(Request *request) continue; } + if (cameraStream->type() == CameraStream::Type::Internal) + descriptor->internalBuffer_ = src; + descriptor->status_ = Camera3RequestDescriptor::ProcessStatus::Processing; cameraStream->process(src, *buffer.buffer, descriptor); - - /* - * Return the FrameBuffer to the CameraStream now that we're - * done processing it. - */ - if (cameraStream->type() == CameraStream::Type::Internal) - cameraStream->putBuffer(src); + return; } - captureResult.result = descriptor->resultMetadata_->get(); - callbacks_->process_capture_result(callbacks_, &captureResult); - - descriptors_.pop_front(); + /* + * Mark the status on the descriptor as success as no processing + * is neeeded. + */ + descriptor->status_ = Camera3RequestDescriptor::ProcessStatus::Success; + sendCaptureResults(); } -void CameraDevice::streamProcessingComplete([[maybe_unused]] CameraStream *cameraStream, +void CameraDevice::streamProcessingComplete(CameraStream *cameraStream, Camera3RequestDescriptor *request) { if (request->status_ == Camera3RequestDescriptor::ProcessStatus::Error) { @@ -1190,6 +1189,28 @@ void CameraDevice::streamProcessingComplete([[maybe_unused]] CameraStream *camer CAMERA3_MSG_ERROR_BUFFER); } } + + /* + * Return the FrameBuffer to the CameraStream now that we're + * done processing it. + */ + if (cameraStream->type() == CameraStream::Type::Internal) + cameraStream->putBuffer(request->internalBuffer_); + + sendCaptureResults(); +} + +void CameraDevice::sendCaptureResults() +{ + Camera3RequestDescriptor *d = descriptors_.front().get(); + if (d->status_ == Camera3RequestDescriptor::ProcessStatus::Processing || + d->status_ == Camera3RequestDescriptor::ProcessStatus::None) + return; + + MutexLocker lock(descriptorsMutex_); + d->captureResult_.result = d->resultMetadata_->get(); + callbacks_->process_capture_result(callbacks_, &(d->captureResult_)); + descriptors_.pop_front(); } std::string CameraDevice::logPrefix() const diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 60c134dc..0bd570a1 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -56,6 +56,9 @@ struct Camera3RequestDescriptor { std::unique_ptr request_; std::unique_ptr resultMetadata_; + camera3_capture_result_t captureResult_ = {}; + libcamera::FrameBuffer *internalBuffer_; + ProcessStatus status_; }; @@ -118,6 +121,7 @@ private: int processControls(Camera3RequestDescriptor *descriptor); std::unique_ptr getResultMetadata( const Camera3RequestDescriptor *descriptor) const; + void sendCaptureResults(); unsigned int id_; camera3_device_t camera3Device_;