{"id":17093,"url":"https://patchwork.libcamera.org/api/patches/17093/?format=json","web_url":"https://patchwork.libcamera.org/patch/17093/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220812090838.1784703-8-hanlinchen@chromium.org>","date":"2022-08-12T09:08:38","name":"[libcamera-devel,v2,7/7] android: function flush() waits for all requests completed before return","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6bc921e3349e9fe86540f0a6f94b9bf384ad78da","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/people/98/?format=json","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17093/mbox/","series":[{"id":3408,"url":"https://patchwork.libcamera.org/api/series/3408/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3408","date":"2022-08-12T09:08:31","name":"Implement Android Partial Result Featrue","version":2,"mbox":"https://patchwork.libcamera.org/series/3408/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17093/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17093/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B295DC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 12 Aug 2022 09:09:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 651E36333B;\n\tFri, 12 Aug 2022 11:09:05 +0200 (CEST)","from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com\n\t[IPv6:2607:f8b0:4864:20::62d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1B7C363326\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Aug 2022 11:09:03 +0200 (CEST)","by mail-pl1-x62d.google.com with SMTP id 17so241447plj.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 12 Aug 2022 02:09:03 -0700 (PDT)","from localhost ([2401:fa00:1:17:1705:d284:d114:2e24])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\t125-20020a620683000000b0052d3ea78858sm1082031pfg.127.2022.08.12.02.09.00\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 12 Aug 2022 02:09:01 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660295345;\n\tbh=hj4y2etmQvTa2zfgoufeaZVpycvrNRjZWyY8FheEp7Q=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=Q1Tt6u3qiECT5VO0JWvWymxQz/MtTCYqhqyRyvHYR4Lz2p2MFqs7lzSXRJqEd+J/y\n\tQokw/Fw3ReptJM1JgPkXEVSXr6piTkbaqKIBsl+/ujcGV1urb1Jy57QWkSQzT7VCPn\n\t9g4b+903MqPRAl1fO/wpz8g7j6dZyFMYiRBpSFmyAPSJkrBV2rGqA0qrn65YtxIbbJ\n\twq7FS/dw6AdgwvNFybUQ452rd7AMsJAAkC2SC6ptK+XxJz2vCbAMTdWuyZlpDYc+Ck\n\t/sWSMc2j+7JaN/LrXKoFWIQnxzLXzvulqFK6D1TlgrKExIrCktW+onS9uBhihvvyEw\n\tE2EbHBxHbOkng==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc;\n\tbh=OsOnH9HZxPNXSKbjxXufN+4s2HjN2Z6vEES5lBQtYVI=;\n\tb=hefMcY0dniXZBVss2fHzjA19utSHHbzNF+FNI2l3VMHJypH++ihczLWhMnjh6KpXOR\n\tzSUoRhmmxKAa2LnNUsMNga+Kj1mC3/ai/XC6Pnu0zsHDlqJgoajO/FiuZZ/+X6gdAxHD\n\tDhKwn3CywDisLMemxf3NrBrqpdG3xziJTDpo0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"hefMcY0d\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc;\n\tbh=OsOnH9HZxPNXSKbjxXufN+4s2HjN2Z6vEES5lBQtYVI=;\n\tb=2E4ysklOkqmUlWQ4qJKTQ92KEezvoOIoWZ7sGIkxME/LoXX2itNirL5SCChB+qdYvw\n\tyeCHHEhoumfub2+jVtyhO1oBhZCkkt8HMrKMH/WRBG37gd2EWDk4FtmFQuQ0okYcHCU2\n\tFO4UYwGH+c01uGKj1wGYxW5//Zd4cL9d5CxwSMeRV/TfgYH4lD5BE5emqM4VwG1tCM5p\n\t3QjZ+4fl3iH7lTvjNnW2eORkAEGNakFWLP36nGgl70JGQ7WH8CyEfZSpILK4nUUKwHuQ\n\t6+9nlCvSXQQvf01wTnbJBov+sWz74mwknvIQCtTV50bVEg8BErq4LCi9LO06voXIPUQy\n\t0c6w==","X-Gm-Message-State":"ACgBeo0av7evGM8N3T6LfbsIcAz7wdDn54Uognhu9RQe10mDIXxh5rjh\n\tkkdFu0XzbnLiJl9vM+znBJeia81v6sqwoQ==","X-Google-Smtp-Source":"AA6agR7sqZoBcoyQnTDioXD9uMk3ZTQvgfV9rc6hotlhk47PMJQS2tVUVYnOsEKSqvxZQSsjx3CayA==","X-Received":"by 2002:a17:902:c405:b0:170:88b3:c108 with SMTP id\n\tk5-20020a170902c40500b0017088b3c108mr3112877plk.172.1660295341554; \n\tFri, 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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 7/7] android: function flush() waits\n\tfor all requests completed before return","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Han-Lin Chen via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Han-Lin Chen <hanlinchen@chromium.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Android requires that flush() only returns when there are no more outstanding\nbuffers or requests left in the HAL. Add a contition variable to wait for all\npending requests are completed before returning the call.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\n---\n src/android/camera_device.cpp | 23 ++++++++++++++++++++---\n src/android/camera_device.h   |  2 ++\n 2 files changed, 22 insertions(+), 3 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex c999b198..2672a5eb 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -428,8 +428,20 @@ void CameraDevice::flush()\n \n \tcamera_->stop();\n \n-\tMutexLocker stateLock(stateMutex_);\n-\tstate_ = State::Stopped;\n+\t{\n+\t\tMutexLocker locker(pendingRequestMutex_);\n+\t\tpendingRequestsCv_.wait(\n+\t\t\tlocker,\n+\t\t\t[&]() LIBCAMERA_TSA_REQUIRES(pendingRequestMutex_) {\n+\t\t\t\treturn pendingRequests_.empty();\n+\t\t\t});\n+\t\tASSERT(pendingRequests_.empty());\n+\t}\n+\n+\t{\n+\t\tMutexLocker stateLock(stateMutex_);\n+\t\tstate_ = State::Stopped;\n+\t}\n }\n \n void CameraDevice::stop()\n@@ -1480,7 +1492,6 @@ void CameraDevice::completeResultDescriptor(Camera3ResultDescriptor *result)\n \tcompleteRequestDescriptor(result->request_);\n }\n \n-\n /**\n  * \\brief Complete the Camera3RequestDescriptor\n  * \\param[in] descriptor The Camera3RequestDescriptor\n@@ -1526,6 +1537,12 @@ void CameraDevice::completeRequestDescriptor(Camera3RequestDescriptor *request)\n \n \t\tpendingRequests_.pop_front();\n \t}\n+\n+\tif (pendingRequests_.empty()) {\n+\t\tlocker.unlock();\n+\t\tpendingRequestsCv_.notify_one();\n+\t\treturn;\n+\t}\n }\n \n void CameraDevice::setBufferStatus(StreamBuffer &streamBuffer,\ndiff --git a/src/android/camera_device.h b/src/android/camera_device.h\nindex 613e419f..aa976db2 100644\n--- a/src/android/camera_device.h\n+++ b/src/android/camera_device.h\n@@ -135,6 +135,8 @@ private:\n \tstd::map<CameraStream *, std::list<StreamBuffer *>> pendingStreamBuffers_\n \t\tLIBCAMERA_TSA_GUARDED_BY(pendingRequestMutex_);\n \n+\tlibcamera::ConditionVariable pendingRequestsCv_;\n+\n \tstd::string maker_;\n \tstd::string model_;\n \n","prefixes":["libcamera-devel","v2","7/7"]}