forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpacket.cc
More file actions
316 lines (268 loc) · 10.5 KB
/
Copy pathpacket.cc
File metadata and controls
316 lines (268 loc) · 10.5 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
#include "mediapipe_api/framework/packet.h"
#include <string>
#include <utility>
MpReturnCode mp_Packet__(mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet();
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
void mp_Packet__delete(mediapipe::Packet* packet) { delete packet; }
MpReturnCode mp_Packet__At__Rt(mediapipe::Packet* packet, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
// not move but copy
*packet_out = new mediapipe::Packet{packet->At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
bool mp_Packet__IsEmpty(mediapipe::Packet* packet) { return packet->IsEmpty(); }
MpReturnCode mp_Packet__ValidateAsProtoMessageLite(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsProtoMessageLite()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__Timestamp(mediapipe::Packet* packet, mediapipe::Timestamp** timestamp_out) {
TRY
*timestamp_out = new mediapipe::Timestamp{packet->Timestamp()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__DebugString(mediapipe::Packet* packet, const char** str_out) {
TRY
*str_out = strcpy_to_heap(packet->DebugString());
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__RegisteredTypeName(mediapipe::Packet* packet, const char** str_out) {
TRY
*str_out = strcpy_to_heap(packet->RegisteredTypeName());
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__DebugTypeName(mediapipe::Packet* packet, const char** str_out) {
TRY
*str_out = strcpy_to_heap(packet->DebugTypeName());
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
// BoolPacket
MpReturnCode mp__MakeBoolPacket__b(bool value, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<bool>(value)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeBoolPacket_At__b_Rt(bool value, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<bool>(value).At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__GetBool(mediapipe::Packet* packet, bool* value_out) {
TRY_ALL
*value_out = packet->Get<bool>();
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__ValidateAsBool(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsType<bool>()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
// FloatPacket
MpReturnCode mp__MakeFloatPacket__f(float value, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<float>(value)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeFloatPacket_At__f_Rt(float value, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<float>(value).At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__GetFloat(mediapipe::Packet* packet, float* value_out) {
TRY_ALL
*value_out = packet->Get<float>();
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__ValidateAsFloat(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsType<float>()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
// IntPacket
MpReturnCode mp__MakeIntPacket__i(int value, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<int>(value)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeIntPacket_At__i_Rt(int value, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<int>(value).At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__GetInt(mediapipe::Packet* packet, int* value_out) {
TRY_ALL
*value_out = packet->Get<int>();
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__ValidateAsInt(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsType<int>()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
// FloatArrayPacket
MpReturnCode mp__MakeFloatArrayPacket__Pf_i(float* value, int size, mediapipe::Packet** packet_out) {
TRY
float* array = new float[size];
std::memcpy(array, value, size * sizeof(float));
*packet_out = new mediapipe::Packet{mediapipe::Adopt(reinterpret_cast<float(*)[]>(array))};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeFloatArrayPacket_At__Pf_i_Rt(float* value, int size, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
float* array = new float[size];
std::memcpy(array, value, size * sizeof(float));
*packet_out = new mediapipe::Packet{mediapipe::Adopt(reinterpret_cast<float(*)[]>(array)).At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__GetFloatArray_i(mediapipe::Packet* packet, int size, const float** value_out) {
TRY_ALL
auto src = packet->Get<float[]>();
auto dst = new float[size];
std::memcpy(dst, src, size * sizeof(float));
*value_out = dst;
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__ValidateAsFloatArray(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsType<float[]>()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
// FloatVectorPacket
MpReturnCode mp__MakeFloatVectorPacket__Pf_i(float* value, int size, mediapipe::Packet** packet_out) { return mp__MakeVectorPacket(value, size, packet_out); }
MpReturnCode mp__MakeFloatVectorPacket_At__Pf_i_Rt(float* value, int size, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
return mp__MakeVectorPacket_At(value, size, timestamp, packet_out);
}
MpReturnCode mp_Packet__GetFloatVector(mediapipe::Packet* packet, mp_api::StructArray<float>* value_out) {
return mp_Packet__GetStructVector(packet, value_out);
}
MpReturnCode mp_Packet__ValidateAsFloatVector(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsType<std::vector<float>>()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
// StringPacket
MpReturnCode mp__MakeStringPacket__PKc(const char* str, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<std::string>(std::string(str))};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeStringPacket_At__PKc_Rt(const char* str, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<std::string>(std::string(str)).At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeStringPacket__PKc_i(const char* str, int size, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<std::string>(std::string(str, size))};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp__MakeStringPacket_At__PKc_i_Rt(const char* str, int size, mediapipe::Timestamp* timestamp, mediapipe::Packet** packet_out) {
TRY
*packet_out = new mediapipe::Packet{mediapipe::MakePacket<std::string>(std::string(str, size)).At(*timestamp)};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_Packet__GetString(mediapipe::Packet* packet, const char** value_out) {
TRY_ALL
*value_out = strcpy_to_heap(packet->Get<std::string>());
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__GetByteString(mediapipe::Packet* packet, const char** value_out, int* size_out) {
TRY_ALL
auto& str = packet->Get<std::string>();
auto length = str.size();
auto bytes = new char[length];
memcpy(bytes, str.c_str(), length);
*value_out = bytes;
*size_out = length;
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__ConsumeString(mediapipe::Packet* packet, absl::StatusOr<std::string>** status_or_value_out) {
TRY_ALL
auto status_or_string = packet->Consume<std::string>();
if (status_or_string.ok()) {
*status_or_value_out = new absl::StatusOr<std::string>{std::move(*status_or_string.value().release())};
} else {
*status_or_value_out = new absl::StatusOr<std::string>{status_or_string.status()};
}
RETURN_CODE(MpReturnCode::Success);
CATCH_ALL
}
MpReturnCode mp_Packet__ValidateAsString(mediapipe::Packet* packet, absl::Status** status_out) {
TRY
*status_out = new absl::Status{packet->ValidateAsType<std::string>()};
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
/** SidePacket */
MpReturnCode mp_SidePacket__(SidePacket** side_packet_out) {
TRY
*side_packet_out = new SidePacket();
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
void mp_SidePacket__delete(SidePacket* side_packet) { delete side_packet; }
MpReturnCode mp_SidePacket__emplace__PKc_Rp(SidePacket* side_packet, const char* key, mediapipe::Packet* packet) {
TRY
side_packet->emplace(std::string(key), std::move(*packet));
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
MpReturnCode mp_SidePacket__at__PKc(SidePacket* side_packet, const char* key, mediapipe::Packet** packet_out) {
TRY
auto packet = side_packet->at(std::string(key));
// copy
*packet_out = new mediapipe::Packet{packet};
RETURN_CODE(MpReturnCode::Success);
#ifndef MEDIAPIPE_IGNORE_EXCEPTION
} catch (std::out_of_range&) {
*packet_out = nullptr;
RETURN_CODE(MpReturnCode::Success);
#endif
CATCH_EXCEPTION
}
MpReturnCode mp_SidePacket__erase__PKc(SidePacket* side_packet, const char* key, int* count_out) {
TRY
*count_out = side_packet->erase(std::string(key));
RETURN_CODE(MpReturnCode::Success);
CATCH_EXCEPTION
}
void mp_SidePacket__clear(SidePacket* side_packet) { side_packet->clear(); }
int mp_SidePacket__size(SidePacket* side_packet) { return side_packet->size(); }