From patchwork Tue Apr 6 09:13:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11842 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 AC484BD695 for ; Tue, 6 Apr 2021 09:13:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2288160517; Tue, 6 Apr 2021 11:13:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cF7i8yVu"; dkim-atps=neutral Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E2CD860517 for ; Tue, 6 Apr 2021 11:13:41 +0200 (CEST) Received: by mail-pl1-x633.google.com with SMTP id a6so3802955pls.1 for ; Tue, 06 Apr 2021 02:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0Bfvx94STaPlZ4O7KYc37woJ/yIFoNmkTlkh+7RzEOE=; b=cF7i8yVuiAL9b7RangQmjWGiy4DqEwRanXd7UVuv9GPPUq6UkjP4RpoZqJHQt9Coqo /bQXsovk5WvE1XkxdB/zK+vZq80Z76wNcNk6W1s712NoZoqL+qzZjg038dwSLd9MOSeU SBrOuKszzH8b3Yq2YsRIvQQnc2EYFkkvyD/4M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0Bfvx94STaPlZ4O7KYc37woJ/yIFoNmkTlkh+7RzEOE=; b=rCng95Hoh1t3XkMVBjLIB+/a3+PtdmIGhcYMKwF5+5W/yhjFfxQc9Ykd3WJfFdUL5a k/x3W8zKuVeL6ox4Pntic9ipVaSg4vT89Rbxhm1NI/k1DPMwpa0L7tdV6fMTe+Pfg7l6 f70P9Nv7G0h50nmG8dXjLkcgc9IcrguFXt3S5SqhYcPgfMW4W62fq6L0fNsoRz678wpl jqSvlLbEqI2r7RT4qb+VK7Z8xMhyLUwOk6iT0FOHNJCOk0FeiMWWod1o3Qa0bgBM6Rfk gtWCv/BZTPkG/WiymAlikYp1kPcUL4AwEbMvHPai9QE/NrhyVkvMcwnvi3BLWIWt6Zwi Z2uw== X-Gm-Message-State: AOAM531MSfnUja2AwBhM6HcQiZWe6yTg3Y+OF/n/gXkfSOUTP0xL8nag 1vgxOuWkxlKG2mVg975YGnk0CrC73snyKQ== X-Google-Smtp-Source: ABdhPJwC+mw2wxkcwhoKgS6vY2mHebC48pbbSwjeTB0ydLmnc/bJdMs3IOHaGiQCrwB2CgYI+KPj+g== X-Received: by 2002:a17:90a:8c06:: with SMTP id a6mr3418624pjo.106.1617700420264; Tue, 06 Apr 2021 02:13:40 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:4180:40db:6f79:a143]) by smtp.gmail.com with ESMTPSA id t1sm1880124pjo.45.2021.04.06.02.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 02:13:39 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Apr 2021 18:13:34 +0900 Message-Id: <20210406091334.3823748-1-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: Implement flush() 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" This implements camera3_device_ops::flush(). Signed-off-by: Hirokazu Honda --- src/android/camera_device.cpp | 48 +++++++++++++++++++++++++++++++---- src/android/camera_device.h | 3 +++ src/android/camera_ops.cpp | 3 ++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 4a3f6f8e..5a56fe4b 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -2029,20 +2029,22 @@ void CameraDevice::requestComplete(Request *request) camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK; std::unique_ptr resultMetadata; - decltype(descriptors_)::node_type node; + Camera3RequestDescriptor descriptor; { std::scoped_lock lock(mutex_); auto it = descriptors_.find(request->cookie()); if (it == descriptors_.end()) { LOG(HAL, Fatal) << "Unknown request: " << request->cookie(); - status = CAMERA3_BUFFER_STATUS_ERROR; return; } - node = descriptors_.extract(it); + descriptor = std::move(it->second); + /* Restore frameNumber_ because it is used in the case of flush + * timeout case. + */ + it->second.frameNumber_ = descriptor.frameNumber_; } - Camera3RequestDescriptor &descriptor = node.mapped(); if (request->status() != Request::RequestComplete) { LOG(HAL, Error) << "Request not successfully completed: " @@ -2122,7 +2124,43 @@ void CameraDevice::requestComplete(Request *request) descriptor.buffers_[0].stream); } - callbacks_->process_capture_result(callbacks_, &captureResult); + { + std::scoped_lock lock(mutex_); + if (descriptors_.erase(request->cookie()) == 0) { + // flush() cleans up the descriptor due to time out + // during a post processing. + return; + } + callbacks_->process_capture_result(callbacks_, &captureResult); + conditionVariable_.notify_one(); + } +} + +int CameraDevice::flush() +{ + std::unique_lock lock(mutex_); + /* flush() should return in less than one second. Sets the timeout to 900ms. */ + auto flushTimeout = + std::chrono::system_clock::now() + std::chrono::milliseconds(900); + bool completeAllRequests = conditionVariable_.wait_until( + lock, flushTimeout, [this]() { return descriptors_.empty(); }); + + if (!completeAllRequests) { + for (auto &node : descriptors_) { + auto &descriptor = node.second; + camera3_capture_result_t captureResult{}; + captureResult.frame_number = descriptor.frameNumber_; + for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { + buffer.acquire_fence = -1; + buffer.release_fence = -1; + buffer.status = CAMERA3_BUFFER_STATUS_ERROR; + } + callbacks_->process_capture_result(callbacks_, &captureResult); + } + descriptors_.clear(); + } + + return 0; } std::string CameraDevice::logPrefix() const diff --git a/src/android/camera_device.h b/src/android/camera_device.h index c63e8e21..dd5336ee 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -7,6 +7,7 @@ #ifndef __ANDROID_CAMERA_DEVICE_H__ #define __ANDROID_CAMERA_DEVICE_H__ +#include #include #include #include @@ -62,6 +63,7 @@ public: int configureStreams(camera3_stream_configuration_t *stream_list); int processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request); + int flush(); protected: std::string logPrefix() const override; @@ -128,6 +130,7 @@ private: std::vector streams_; std::mutex mutex_; /* Protect descriptors_ */ + std::condition_variable conditionVariable_; std::map descriptors_; std::string maker_; diff --git a/src/android/camera_ops.cpp b/src/android/camera_ops.cpp index 696e8043..1b73af13 100644 --- a/src/android/camera_ops.cpp +++ b/src/android/camera_ops.cpp @@ -68,7 +68,8 @@ static void hal_dev_dump([[maybe_unused]] const struct camera3_device *dev, static int hal_dev_flush([[maybe_unused]] const struct camera3_device *dev) { - return 0; + CameraDevice *camera = reinterpret_cast(dev->priv); + return camera->flush(); } int hal_dev_close(hw_device_t *hw_device)