From patchwork Mon Oct 11 07:35:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 14082 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 8D8F4C3243 for ; Mon, 11 Oct 2021 07:35:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 47A6568F61; Mon, 11 Oct 2021 09:35:29 +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="AfdA0riu"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2449B68F4F for ; Mon, 11 Oct 2021 09:35:28 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.107]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3C6E12BD; Mon, 11 Oct 2021 09:35:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1633937727; bh=77mH4GT/iT5pP6gMmtYzgEvBNsw/EzvFIkiylzj+P1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AfdA0riud6DdHqPAL6Zl9r8mhRINbXZQv6/qkBZiqnjoT2FeKmuJaH/xRu78x5O+3 psLhBzDetwmTLSZsn/57ZFDphLVG0FRtuRUi6DWyIycEfg+RW7n4Y+AUxBofs2IFMK fuSSxxWYGUZtwEJyMyRGOOx8+TdbTiSYdzBxOTtM= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Oct 2021 13:05:05 +0530 Message-Id: <20211011073505.243864-8-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211011073505.243864-1-umang.jain@ideasonboard.com> References: <20211011073505.243864-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 7/7] android: camera_device: Synchronise completion and cleanup of requests 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" Synchronise a way where queued requests in descriptors_ do not end up with Camera3RequestDescriptor::Status::Pending forever. To ensure this, stop the camera worker first, which will not let any new requests queue up to the libcamera::Camera. It is then followed by libcamera::Camera::stop() which is synchronous and will ensure all requests in-flight gets completed (and requestComplete() handler is called for all of them). Since CameraDevice::requestComplete() handler can even queue post-processing requests to CameraStream::PostProcessorWorker, ensure the worker is stopped and all those post-processing requests too, are purged as per CameraStream::flush() implemented earlier. All this operations is encapsulated in a a helper function CameraDevice::stopCamera() which can be used in stop() and flush() scenarios. Signed-off-by: Umang Jain --- src/android/camera_device.cpp | 34 ++++++++++++++++++++++++++++------ src/android/camera_device.h | 1 + 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 3541a74b..9433dde7 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -424,13 +424,37 @@ int CameraDevice::open(const hw_module_t *hardwareModule) void CameraDevice::close() { - streams_.clear(); - stop(); + streams_.clear(); + camera_->release(); } +void CameraDevice::stopCamera() +{ + /* + * Stopping the worker will prevent any new requests queued to + * libcamera::Camera. + */ + worker_.stop(); + + /* + * libcamera::Camera::stop() will synchronously complete all requests + * thereby, ensuring requestComplete() signal handler is executed for + * all requests which are in-flight. + */ + camera_->stop(); + + /* + * While libcamera::Camera::stop() is completing in-flight requests, + * some of those request might queue post-processing of a stream. + * Purge the post-processsing queue in this case so that the descriptors + * can be processed and get offloaded from descriptors_. + */ + for (auto &stream : streams_) + stream.flush(); +} void CameraDevice::flush() { { @@ -441,8 +465,7 @@ void CameraDevice::flush() state_ = State::Flushing; } - worker_.stop(); - camera_->stop(); + stopCamera(); MutexLocker stateLock(stateMutex_); state_ = State::Stopped; @@ -454,8 +477,7 @@ void CameraDevice::stop() if (state_ == State::Stopped) return; - worker_.stop(); - camera_->stop(); + stopCamera(); descriptors_ = {}; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 0ce6caeb..20eae704 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -115,6 +115,7 @@ private: }; void stop(); + void stopCamera(); std::unique_ptr createFrameBuffer(const buffer_handle_t camera3buffer,