From 55434ceeb2f914159ba6ab7e20a9f7614d926e12 Mon Sep 17 00:00:00 2001 From: MistEO Date: Thu, 30 Nov 2023 23:58:12 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96minicap=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Screencap/Minicap/MinicapStream.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/MaaAdbControlUnit/Screencap/Minicap/MinicapStream.cpp b/source/MaaAdbControlUnit/Screencap/Minicap/MinicapStream.cpp index 97bf12347..00fe443d8 100644 --- a/source/MaaAdbControlUnit/Screencap/Minicap/MinicapStream.cpp +++ b/source/MaaAdbControlUnit/Screencap/Minicap/MinicapStream.cpp @@ -50,22 +50,25 @@ bool MinicapStream::init(int swidth, int sheight) return false; } - std::string outputBuffer; - int i = 50; - while (--i) { + bool ok = false; + + std::string buffer; + constexpr int kMaxTry = 50; + for (int i = 0; i < kMaxTry; ++i) { auto res = process_handle_->read(5); - if (res.length() > 0) { - LogInfo << "minicap stdout:" << res; - outputBuffer.append(res); + if (!res.empty()) { + LogDebug << "minicap stdout:" << res; + buffer.append(res); } - if (outputBuffer.find("Allocating") != std::string::npos) { + if (buffer.find("Allocating") != std::string::npos) { + ok = true; break; } using namespace std::chrono_literals; std::this_thread::sleep_for(100ms); } - - if (i == 0) { + if (!ok) { + LogError << "minicap stdout:" << buffer; return false; }