| 18 | #include "Screencap/RawWithGzip.h" |
| 19 | |
| 20 | MAA_CTRL_UNIT_NS_BEGIN |
| 21 | |
| 22 | ScreencapAgent::ScreencapAgent(MaaAdbScreencapMethod methods, const std::filesystem::path& agent_path) |
| 23 | { |
| 24 | std::unordered_set<Method> method_set; |
| 25 | if (methods & MaaAdbScreencapMethod_EncodeToFileAndPull) { |
| 26 | method_set.emplace(ScreencapAgent::Method::EncodeToFileAndPull); |
| 27 | } |
| 28 | if (methods & MaaAdbScreencapMethod_Encode) { |
| 29 | method_set.emplace(ScreencapAgent::Method::Encode); |
| 30 | } |
| 31 | if (methods & MaaAdbScreencapMethod_RawWithGzip) { |
| 32 | method_set.emplace(ScreencapAgent::Method::RawWithGzip); |
| 33 | } |
| 34 | if (methods & MaaAdbScreencapMethod_RawByNetcat) { |
| 35 | method_set.emplace(ScreencapAgent::Method::RawByNetcat); |
| 36 | } |
| 37 | if (methods & MaaAdbScreencapMethod_MinicapDirect) { |
| 38 | method_set.emplace(ScreencapAgent::Method::MinicapDirect); |
| 39 | } |
| 40 | if (methods & MaaAdbScreencapMethod_MinicapStream) { |
| 41 | method_set.emplace(ScreencapAgent::Method::MinicapStream); |
| 42 | } |
| 43 | if (methods & MaaAdbScreencapMethod_EmulatorExtras) { |
| 44 | #ifdef _WIN32 |
| 45 | method_set.emplace(ScreencapAgent::Method::MuMuPlayerExtras); |
| 46 | method_set.emplace(ScreencapAgent::Method::LDPlayerExtras); |
| 47 | method_set.emplace(ScreencapAgent::Method::AndrowsExtras); |
| 48 | #endif |
| 49 | #ifndef __ANDROID__ |
| 50 | method_set.emplace(ScreencapAgent::Method::AVDExtras); |
| 51 | #else |
| 52 | LogWarn << "EmulatorExtras is not supported on this platform"; |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | LogInfo << VAR(methods) << VAR(method_set) << VAR(agent_path); |
| 57 | |
| 58 | for (Method method : method_set) { |
| 59 | std::shared_ptr<ScreencapBase> unit = nullptr; |
| 60 | switch (method) { |
| 61 | case Method::RawByNetcat: |
| 62 | unit = std::make_shared<ScreencapRawByNetcat>(); |
| 63 | break; |
| 64 | case Method::RawWithGzip: |
| 65 | unit = std::make_shared<ScreencapRawWithGzip>(); |
| 66 | break; |
| 67 | case Method::Encode: |
| 68 | unit = std::make_shared<ScreencapEncode>(); |
| 69 | break; |
| 70 | case Method::EncodeToFileAndPull: |
| 71 | unit = std::make_shared<ScreencapEncodeToFileAndPull>(); |
| 72 | break; |
| 73 | case Method::MinicapDirect: { |
| 74 | auto minicap_path = agent_path / "minicap"; |
| 75 | if (!std::filesystem::exists(minicap_path)) { |
| 76 | LogWarn << "minicap path not exists" << VAR(minicap_path); |
| 77 | break; |