From patchwork Fri Aug 12 09:08:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 17093 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 B295DC3272 for ; Fri, 12 Aug 2022 09:09:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 651E36333B; Fri, 12 Aug 2022 11:09:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660295345; bh=hj4y2etmQvTa2zfgoufeaZVpycvrNRjZWyY8FheEp7Q=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Q1Tt6u3qiECT5VO0JWvWymxQz/MtTCYqhqyRyvHYR4Lz2p2MFqs7lzSXRJqEd+J/y Qokw/Fw3ReptJM1JgPkXEVSXr6piTkbaqKIBsl+/ujcGV1urb1Jy57QWkSQzT7VCPn 9g4b+903MqPRAl1fO/wpz8g7j6dZyFMYiRBpSFmyAPSJkrBV2rGqA0qrn65YtxIbbJ wq7FS/dw6AdgwvNFybUQ452rd7AMsJAAkC2SC6ptK+XxJz2vCbAMTdWuyZlpDYc+Ck /sWSMc2j+7JaN/LrXKoFWIQnxzLXzvulqFK6D1TlgrKExIrCktW+onS9uBhihvvyEw E2EbHBxHbOkng== Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B7C363326 for ; Fri, 12 Aug 2022 11:09:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hefMcY0d"; dkim-atps=neutral Received: by mail-pl1-x62d.google.com with SMTP id 17so241447plj.10 for ; Fri, 12 Aug 2022 02:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=OsOnH9HZxPNXSKbjxXufN+4s2HjN2Z6vEES5lBQtYVI=; b=hefMcY0dniXZBVss2fHzjA19utSHHbzNF+FNI2l3VMHJypH++ihczLWhMnjh6KpXOR zSUoRhmmxKAa2LnNUsMNga+Kj1mC3/ai/XC6Pnu0zsHDlqJgoajO/FiuZZ/+X6gdAxHD DhKwn3CywDisLMemxf3NrBrqpdG3xziJTDpo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=OsOnH9HZxPNXSKbjxXufN+4s2HjN2Z6vEES5lBQtYVI=; b=2E4ysklOkqmUlWQ4qJKTQ92KEezvoOIoWZ7sGIkxME/LoXX2itNirL5SCChB+qdYvw yeCHHEhoumfub2+jVtyhO1oBhZCkkt8HMrKMH/WRBG37gd2EWDk4FtmFQuQ0okYcHCU2 FO4UYwGH+c01uGKj1wGYxW5//Zd4cL9d5CxwSMeRV/TfgYH4lD5BE5emqM4VwG1tCM5p 3QjZ+4fl3iH7lTvjNnW2eORkAEGNakFWLP36nGgl70JGQ7WH8CyEfZSpILK4nUUKwHuQ 6+9nlCvSXQQvf01wTnbJBov+sWz74mwknvIQCtTV50bVEg8BErq4LCi9LO06voXIPUQy 0c6w== X-Gm-Message-State: ACgBeo0av7evGM8N3T6LfbsIcAz7wdDn54Uognhu9RQe10mDIXxh5rjh kkdFu0XzbnLiJl9vM+znBJeia81v6sqwoQ== X-Google-Smtp-Source: AA6agR7sqZoBcoyQnTDioXD9uMk3ZTQvgfV9rc6hotlhk47PMJQS2tVUVYnOsEKSqvxZQSsjx3CayA== X-Received: by 2002:a17:902:c405:b0:170:88b3:c108 with SMTP id k5-20020a170902c40500b0017088b3c108mr3112877plk.172.1660295341554; Fri, 12 Aug 2022 02:09:01 -0700 (PDT) Received: from localhost ([2401:fa00:1:17:1705:d284:d114:2e24]) by smtp.gmail.com with UTF8SMTPSA id 125-20020a620683000000b0052d3ea78858sm1082031pfg.127.2022.08.12.02.09.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Aug 2022 02:09:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 12 Aug 2022 17:08:38 +0800 Message-Id: <20220812090838.1784703-8-hanlinchen@chromium.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220812090838.1784703-1-hanlinchen@chromium.org> References: <20220812090838.1784703-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/7] android: function flush() waits for all requests completed before return 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: , X-Patchwork-Original-From: Han-Lin Chen via libcamera-devel From: Hanlin Chen Reply-To: Han-Lin Chen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Android requires that flush() only returns when there are no more outstanding buffers or requests left in the HAL. Add a contition variable to wait for all pending requests are completed before returning the call. Signed-off-by: Han-Lin Chen --- src/android/camera_device.cpp | 23 ++++++++++++++++++++--- src/android/camera_device.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c999b198..2672a5eb 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -428,8 +428,20 @@ void CameraDevice::flush() camera_->stop(); - MutexLocker stateLock(stateMutex_); - state_ = State::Stopped; + { + MutexLocker locker(pendingRequestMutex_); + pendingRequestsCv_.wait( + locker, + [&]() LIBCAMERA_TSA_REQUIRES(pendingRequestMutex_) { + return pendingRequests_.empty(); + }); + ASSERT(pendingRequests_.empty()); + } + + { + MutexLocker stateLock(stateMutex_); + state_ = State::Stopped; + } } void CameraDevice::stop() @@ -1480,7 +1492,6 @@ void CameraDevice::completeResultDescriptor(Camera3ResultDescriptor *result) completeRequestDescriptor(result->request_); } - /** * \brief Complete the Camera3RequestDescriptor * \param[in] descriptor The Camera3RequestDescriptor @@ -1526,6 +1537,12 @@ void CameraDevice::completeRequestDescriptor(Camera3RequestDescriptor *request) pendingRequests_.pop_front(); } + + if (pendingRequests_.empty()) { + locker.unlock(); + pendingRequestsCv_.notify_one(); + return; + } } void CameraDevice::setBufferStatus(StreamBuffer &streamBuffer, diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 613e419f..aa976db2 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -135,6 +135,8 @@ private: std::map> pendingStreamBuffers_ LIBCAMERA_TSA_GUARDED_BY(pendingRequestMutex_); + libcamera::ConditionVariable pendingRequestsCv_; + std::string maker_; std::string model_;