MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / screencap

Method screencap

source/MaaAdbControlUnit/Manager/AdbControlUnitMgr.cpp:129–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129bool AdbControlUnitMgr::screencap(cv::Mat& image)
130{
131 using namespace std::chrono_literals;
132
133 constexpr int kMaxReconnectTimes = 3;
134 constexpr int kMaxRescreencapTimes = 10;
135 constexpr auto kRescreencapDelay = 500ms;
136 constexpr auto kReconnectDelay = 5000ms;
137
138 for (int i = 0; i < kMaxReconnectTimes; ++i) {
139 // 先检查连接状态,断开则直接重连,避免无谓的截图失败重试
140 if (!connection_.is_alive()) {
141 LogWarn << "connection lost, re-connect";
142 connection_.kill_server();
143 if (!connect()) {
144 LogError << "re-connect failed" << VAR(i);
145 std::this_thread::sleep_for(i * kReconnectDelay);
146 continue;
147 }
148 }
149
150 for (int j = 0; j < kMaxRescreencapTimes; ++j) {
151 if (_screencap(image)) {
152 screencap_available_ = true;
153 return true;
154 }
155
156 if (!screencap_available_) {
157 // first time
158 return false;
159 }
160 LogWarn << "re-screencap" << VAR(j);
161 std::this_thread::sleep_for(j * kRescreencapDelay);
162 }
163
164 LogWarn << "screencap failed after retries, force re-connect" << VAR(i);
165 connection_.kill_server();
166 if (!connect()) {
167 LogError << "re-connect failed" << VAR(i);
168 std::this_thread::sleep_for(i * kReconnectDelay);
169 }
170 }
171
172 return false;
173}
174
175bool AdbControlUnitMgr::click(int x, int y)
176{

Callers

nothing calls this directly

Calls 3

connectFunction · 0.85
is_aliveMethod · 0.80
kill_serverMethod · 0.80

Tested by

no test coverage detected