-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmojocall.h
136 lines (124 loc) · 5.08 KB
/
mojocall.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#pragma once
#include <mutex>
namespace mmmojo
{
//每一个组件的每一个请求都有一个自己的RequestId 组件会根据请求ID进行对应的操作
//WeChatOCR组件
enum RequestIdOCR3
{
OCRPush = 1,
};
enum RequestIdOCR4
{
HAND_SHAKE = 10001,
REQ_OCR = 10010,
RESP_OCR = 10011,
PUT_UserInfoMessage = 20012,
};
//WeChatUtility组件
enum RequestIdUtility
{
UtilityHiPush = 10001, //是Utility启动发送的
UtilityInitPullReq = 10002, //初始化请求
UtilityInitPullResp = 10003, //回复创建的都是Shared类型的info, 但是调用了SwapMMMojoWriteInfoCallback, 所以回调的还是Pull
UtilityResampleImagePullReq = 10010,
UtilityResampleImagePullResp = 10011,
UtilityDecodeImagePullReq = 10020,
UtilityDecodeImagePullResp = 10021,
UtilityPicQRScanPullReq = 10030, //10030是点击OCR时(也是打开图片时)发送的请求, 参数是图片路径
UtilityQRScanPullReq = 10031, //10031是截图框选时发送的请求, 参数应该是某种编码后的图片数据
UtilityQRScanPullResp = 10032, //这两种请求的返回ID都是10032
UtilityTextScanPushResp = 10040 //TextScan具体在扫什么不是很清楚 可能是用来判断图片上是否有文字
};
//ThumbPlayer组件
enum RequestIdPlayer
{
PlayerHiPush = 10001, //ThumbPlayer启动时发送的
PlayerInitPullReq = 10002, //PlayerMgr::Init
PlayerInitPullResp = 10003, //PlayerMgr::Init
PlayerInitPlayerCorePush = 10010,
PlayerCreatePlayerCorePullReq = 10011, //PlayerMgr::CreatePlayerCore
PlayerCreatePlayerCorePullResp = 10012, //PlayerMgr::CreatePlayerCore
PlayerDestroyPlayerCorePush = 10013, //PlayerMgr::DestroyCore
PlayerPrepareAsyncPush = 10014, //PlayerMgr::PrepareCore
PlayerStartPush = 10015, //PlayerMgr::StartCore
PlayerStopPush = 10016, //PlayerMgr::StopCore
PlayerPausePush = 10017, //PlayerMgr::PauseCore
PlayerResumePush = 10018, //PlayerMgr::ResumeCore
PlayerSetAudioMutePush = 10019, //PlayerMgr::AudioMuteCore
PlayerSeekToAsyncPush = 10020, //PlayerMgr::SeekToCore
PlayerGetCurrentPositionMsPullReq = 10021, //PlayerMgr::GetCurrentPositionMsCore
PlayerGetCurrentPositionMsPullResp = 10022, //PlayerMgr::GetCurrentPositionMsCore
PlayerSetVideoSurfacePush = 10023, //PlayerMgr::VideoSurfaceCore
PlayerSetAudioVolumePush = 10024, //PlayerMgr::AudioVolumeCore
PlayerSetDataSourcePush = 10025, //PlayerMgr::ReadyDataSourceCore
PlayerSetLoaderSourcePush = 10026, //PlayerMgr::DownloadDataSourceCore
PlayerSetRepeatPush = 10027, //PlayerMgr::RepeatCore
PlayerResizePush = 10028, //PlayerMgr::ResizeCore
PlayerSetPlaySpeedRatio = 10029, //PlayerMgr::SpeedRatioCore
PlayerInfoPush = 10030,
PlayerErrorPlayerPush = 10031,
PlayerVideoSizeChangedPush = 10032,
PlayerStopAsyncCompletedPush = 10033,
PlayerStateChangePush = 10034,
PlayerSeekCompletedPush = 10035,
PlayerCompletedPush = 10036,
PlayerStartTaskProxyPush = 10050,
PlayerStartRequestProxyPush = 10051,
PlayerCloseRequestProxyPush = 10052,
PlayerPollingDatProxyPullReq = 10053,
PlayerPollingDatProxyPullResp = 10054
};
}
class CMojoCall
{
public:
static constexpr int MJC_FAILED = -1;
static constexpr int MJC_PENDING = 0;
static constexpr int MJC_CONNECTED = 1;
protected:
HMODULE m_mod = NULL;
void* m_env = 0;
int m_state = MJC_PENDING;
std::mutex m_mutex_state; // mutex for conn.
std::condition_variable m_cv_state;
/**
* @brief 对应Chromium源码中的base::CommandLine->AppendSwitchNative方法 用于添加一个'开关(Switch)'.
* 例如 "user-lib-dir" => X:\Foo 这样会在命令行参数添加一个"--user-lib-dir=X:\Foo"
*/
std::map<string, wstring> m_args;
protected:
CMojoCall() = default;
virtual ~CMojoCall();
bool Init(LPCWSTR dir);
bool Start(LPCWSTR exepath);
void Stop();
virtual bool wait_connection(int timeout);
bool SendPbSerializedData(const void* pb_data, size_t data_size, int method, bool sync, uint32_t request_id);
//call backs.
virtual void ReadOnPush(uint32_t request_id, const void* request_info) {}
virtual void ReadOnPull(uint32_t request_id, const void* request_info) {}
virtual void ReadOnShared(uint32_t request_id, const void* request_info) {}
virtual void OnRemoteConnect(bool is_connected);
virtual void OnRemoteDisConnect();
virtual void OnRemoteProcessLaunched() {}
virtual void OnRemoteProcessLaunchFailed(int error_code);
virtual void OnRemoteError(const void* errorbuf, int errorsize) {
fprintf(stderr, "OnRemoteError: %.*s\n", errorsize, (const char*)errorbuf);
}
};
namespace util
{
template <class T, class FT>
requires std::is_pointer_v<FT>&& std::is_function_v<typename std::remove_pointer<FT>::type> && (std::is_pointer_v<T> || std::is_integral_v<T>)
struct auto_del_t {
T object;
FT caller;
auto_del_t(T obj, FT call) : object(obj), caller(call) {}
~auto_del_t() { if (caller) caller(object); }
auto_del_t(const auto_del_t&) = delete;
auto_del_t& operator=(const auto_del_t&) = delete;
auto_del_t(auto_del_t &&) noexcept = delete;
auto_del_t& operator=(auto_del_t&&) noexcept = delete;
};
}