| 138 | } |
| 139 | |
| 140 | bool ScreencapAgent::init() |
| 141 | { |
| 142 | LogFunc; |
| 143 | |
| 144 | if (active_unit_) { |
| 145 | LogError << "already initialized" << VAR(active_unit_); |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | for (auto it = units_.begin(); it != units_.end();) { |
| 150 | if (it->second->init()) { |
| 151 | ++it; |
| 152 | } |
| 153 | else { |
| 154 | it = units_.erase(it); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | active_unit_ = speed_test(); |
| 159 | if (!active_unit_) { |
| 160 | LogError << "No available screencap method"; |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | units_.clear(); |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | std::optional<cv::Mat> ScreencapAgent::screencap() |
| 169 | { |