forked from obsproject/obs-vst
-
Notifications
You must be signed in to change notification settings - Fork 3
/
grpc_vst_communicatorClient.cpp
203 lines (166 loc) · 5.47 KB
/
grpc_vst_communicatorClient.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "headers/grpc_vst_communicatorClient.h"
#include "headers/StlBuffer.h"
#include <aeffectx.h>
grpc_vst_communicatorClient::grpc_vst_communicatorClient(std::shared_ptr<Channel> channel) : stub_(grpc_vst_communicator::NewStub(channel))
{
m_connected = channel->WaitForConnected(std::chrono::system_clock::now() + std::chrono::seconds(3));
}
intptr_t grpc_vst_communicatorClient::dispatcher(AEffect *a, int b, int c, intptr_t d, void *ptr, float f, size_t ptr_size)
{
grpc_dispatcher_Request request;
request.set_param1(b);
request.set_param2(c);
request.set_param3(d);
request.set_param4(f);
request.set_ptr_value(int64_t(ptr));
request.set_ptr_size(int32_t(ptr_size));
if (ptr_size > 0) {
std::string str;
str.resize(ptr_size);
memcpy(str.data(), ptr, ptr_size);
request.set_ptr_data(str);
}
grpc_dispatcher_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_dispatcher(&context, request, &reply);
if (!status.ok())
m_connected = false;
if (ptr != nullptr) {
void **realDeal = (void **)ptr;
if (*realDeal == nullptr) {
*realDeal = malloc(reply.ptr_data().size());
memcpy(*realDeal, reply.ptr_data().data(), reply.ptr_data().size());
} else if (ptr_size != 0) {
if (ptr_size > reply.ptr_data().size())
ptr_size = reply.ptr_data().size();
memcpy(realDeal, reply.ptr_data().data(), ptr_size);
} else {
// Unsafe, we don't know how big ptr is
m_connected = false;
return 0;
}
}
a->magic = reply.magic();
a->numPrograms = reply.numprograms();
a->numParams = reply.numparams();
a->numInputs = reply.numinputs();
a->numOutputs = reply.numoutputs();
a->flags = reply.flags();
a->initialDelay = reply.initialdelay();
a->uniqueID = reply.uniqueid();
a->version = reply.version();
return reply.returnval();
}
void grpc_vst_communicatorClient::setParameter(AEffect *a, int b, float c)
{
grpc_setParameter_Request request;
request.set_param1(b);
request.set_param2(c);
grpc_setParameter_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_setParameter(&context, request, &reply);
if (!status.ok())
m_connected = false;
a->magic = reply.magic();
a->numPrograms = reply.numprograms();
a->numParams = reply.numparams();
a->numInputs = reply.numinputs();
a->numOutputs = reply.numoutputs();
a->flags = reply.flags();
a->initialDelay = reply.initialdelay();
a->uniqueID = reply.uniqueid();
a->version = reply.version();
}
float grpc_vst_communicatorClient::getParameter(AEffect *a, int b)
{
grpc_getParameter_Request request;
request.set_param1(b);
grpc_getParameter_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_getParameter(&context, request, &reply);
if (!status.ok())
m_connected = false;
a->magic = reply.magic();
a->numPrograms = reply.numprograms();
a->numParams = reply.numparams();
a->numInputs = reply.numinputs();
a->numOutputs = reply.numoutputs();
a->flags = reply.flags();
a->initialDelay = reply.initialdelay();
a->uniqueID = reply.uniqueid();
a->version = reply.version();
return reply.returnval();
}
void grpc_vst_communicatorClient::processReplacing(AEffect *a, float **adata, float **bdata, int frames, int arraySize)
{
std::string adataBuffer;
std::string bdataBuffer;
for (int c = 0; c < arraySize; c++) {
adataBuffer.append((char *)adata[c], frames * sizeof(float));
bdataBuffer.append((char *)bdata[c], frames * sizeof(float));
}
grpc_processReplacing_Request request;
request.set_arraysize(arraySize);
request.set_frames(frames);
request.set_adata(adataBuffer);
request.set_bdata(bdataBuffer);
grpc_processReplacing_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_processReplacing(&context, request, &reply);
if (!status.ok())
m_connected = false;
size_t read_idx_a = 0;
size_t read_idx_b = 0;
for (int c = 0; c < arraySize; c++) {
StlBuffer::pop_buffer(reply.adata(), read_idx_a, (char *)adata[c], frames * sizeof(float));
StlBuffer::pop_buffer(reply.bdata(), read_idx_b, (char *)bdata[c], frames * sizeof(float));
}
a->magic = reply.magic();
a->numPrograms = reply.numprograms();
a->numParams = reply.numparams();
a->numInputs = reply.numinputs();
a->numOutputs = reply.numoutputs();
a->flags = reply.flags();
a->initialDelay = reply.initialdelay();
a->uniqueID = reply.uniqueid();
a->version = reply.version();
}
void grpc_vst_communicatorClient::sendHwndMsg(AEffect * /*a*/, int msgType)
{
grpc_sendHwndMsg_Request request;
request.set_msgtype(msgType);
grpc_sendHwndMsg_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_sendHwndMsg(&context, request, &reply);
if (!status.ok())
m_connected = false;
}
void grpc_vst_communicatorClient::updateAEffect(AEffect *a)
{
grpc_updateAEffect_Request request;
request.set_nullreply(1);
grpc_updateAEffect_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_updateAEffect(&context, request, &reply);
if (!status.ok())
m_connected = false;
a->magic = reply.magic();
a->numPrograms = reply.numprograms();
a->numParams = reply.numparams();
a->numInputs = reply.numinputs();
a->numOutputs = reply.numoutputs();
a->flags = reply.flags();
a->initialDelay = reply.initialdelay();
a->uniqueID = reply.uniqueid();
a->version = reply.version();
}
void grpc_vst_communicatorClient::stopServer(AEffect * /*a*/)
{
grpc_stopServer_Request request;
request.set_nullreply(0);
grpc_stopServer_Reply reply;
ClientContext context;
Status status = stub_->com_grpc_stopServer(&context, request, &reply);
if (!status.ok())
m_connected = false;
}