grandi 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +150 -77
  2. package/dist/index.d.mts +418 -33
  3. package/dist/index.mjs +188 -3
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +34 -32
  6. package/binding.gyp +0 -200
  7. package/lib/.clang-format +0 -297
  8. package/lib/grandi.cc +0 -96
  9. package/lib/grandi_find.cc +0 -365
  10. package/lib/grandi_find.h +0 -41
  11. package/lib/grandi_receive.cc +0 -1155
  12. package/lib/grandi_receive.h +0 -63
  13. package/lib/grandi_routing.cc +0 -460
  14. package/lib/grandi_routing.h +0 -37
  15. package/lib/grandi_send.cc +0 -960
  16. package/lib/grandi_send.h +0 -45
  17. package/lib/grandi_util.cc +0 -323
  18. package/lib/grandi_util.h +0 -137
  19. package/prebuilds/darwin-arm64/grandi.node +0 -0
  20. package/prebuilds/darwin-arm64/libndi.dylib +0 -0
  21. package/prebuilds/darwin-x64/grandi.node +0 -0
  22. package/prebuilds/darwin-x64/libndi.dylib +0 -0
  23. package/prebuilds/linux-arm/grandi.node +0 -0
  24. package/prebuilds/linux-arm/libndi.so.6 +0 -0
  25. package/prebuilds/linux-arm64/grandi.node +0 -0
  26. package/prebuilds/linux-arm64/libndi.so.6 +0 -0
  27. package/prebuilds/linux-ia32/grandi.node +0 -0
  28. package/prebuilds/linux-ia32/libndi.so.6 +0 -0
  29. package/prebuilds/linux-x64/grandi.node +0 -0
  30. package/prebuilds/linux-x64/libndi.so.6 +0 -0
  31. package/prebuilds/win32-ia32/Processing.NDI.Lib.x86.dll +0 -0
  32. package/prebuilds/win32-ia32/grandi.node +0 -0
  33. package/prebuilds/win32-x64/Processing.NDI.Lib.x64.dll +0 -0
  34. package/prebuilds/win32-x64/grandi.node +0 -0
  35. package/scripts/preinstall.mjs +0 -429
  36. package/src/index.ts +0 -141
  37. package/src/node-gyp-build.d.ts +0 -5
  38. package/src/types.ts +0 -228
@@ -1,365 +0,0 @@
1
- /*
2
- ** Copyright (c) 2022 Dr. Ralf S. Engelschall <rse@engelschall.com>
3
- **
4
- ** Licensed under the Apache License, Version 2.0 (the "License");
5
- ** you may not use this file except in compliance with the License.
6
- ** You may obtain a copy of the License at
7
- **
8
- ** http://www.apache.org/licenses/LICENSE-2.0
9
- **
10
- ** Unless required by applicable law or agreed to in writing, software
11
- ** distributed under the License is distributed on an "AS IS" BASIS,
12
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- ** See the License for the specific language governing permissions and
14
- ** limitations under the License.
15
- */
16
-
17
- /* standard includes */
18
- #include <string>
19
-
20
- /* NDI API */
21
- #include <Processing.NDI.Lib.h>
22
- #ifdef _WIN32
23
- #ifdef _WIN64
24
- #pragma comment(lib, "Processing.NDI.Lib.x64.lib")
25
- #else // _WIN64
26
- #pragma comment(lib, "Processing.NDI.Lib.x86.lib")
27
- #endif // _WIN64
28
- #endif // _WIN32
29
-
30
- /* own library API */
31
- #include "grandi_util.h"
32
- #include "grandi_find.h"
33
-
34
- /* own module API */
35
- napi_value find_destroy(napi_env, napi_callback_info);
36
- napi_value find_sources(napi_env, napi_callback_info);
37
- napi_value find_wait(napi_env, napi_callback_info);
38
-
39
- /* wrapper structure for embedded value */
40
- typedef struct embeddedValue {
41
- void *value;
42
- } embeddedValue_t;
43
-
44
- /* callback for destroying embedded value */
45
- void finalizeFind(napi_env env, void *data, void *hint) {
46
- embeddedValue_t *embeddedValue = (embeddedValue_t *)data;
47
- if (embeddedValue != nullptr) {
48
- NDIlib_find_instance_t find =
49
- (NDIlib_find_instance_t)(embeddedValue->value);
50
- if (find != nullptr)
51
- NDIlib_find_destroy(find);
52
- embeddedValue->value = nullptr;
53
- }
54
- free(data);
55
- }
56
-
57
- /* callback for executing method find() */
58
- void findExecute(napi_env env, void *data) {
59
- findCarrier *c = (findCarrier *)data;
60
- NDIlib_find_create_t findConfig;
61
- findConfig.show_local_sources = c->show_local_sources;
62
- findConfig.p_groups = c->groups;
63
- findConfig.p_extra_ips = c->extra_ips;
64
- c->find = NDIlib_find_create_v2(&findConfig);
65
- if (!c->find) {
66
- c->status = GRANDI_FIND_CREATE_FAIL;
67
- c->errorMsg = "Failed to create NDI find instance.";
68
- return;
69
- }
70
- }
71
-
72
- /* callback for completing method find() */
73
- void findComplete(napi_env env, napi_status asyncStatus, void *data) {
74
- findCarrier *c = (findCarrier *)data;
75
-
76
- /* check status */
77
- if (asyncStatus != napi_ok) {
78
- c->status = asyncStatus;
79
- c->errorMsg = "Async find instance creation failed to complete.";
80
- }
81
- REJECT_STATUS;
82
-
83
- /* create result object */
84
- napi_value result;
85
- c->status = napi_create_object(env, &result);
86
- REJECT_STATUS;
87
-
88
- /* embed the native find object */
89
- napi_value embedded;
90
- embeddedValue_t *embeddedValue =
91
- (embeddedValue_t *)malloc(sizeof(embeddedValue_t));
92
- embeddedValue->value = c->find;
93
- c->status = napi_create_external(env, embeddedValue, finalizeFind, nullptr,
94
- &embedded);
95
- REJECT_STATUS;
96
- c->status = napi_set_named_property(env, result, "embedded", embedded);
97
- REJECT_STATUS;
98
-
99
- /* attach the "destroy()" method */
100
- napi_value fn;
101
- c->status = napi_create_function(env, "destroy", NAPI_AUTO_LENGTH,
102
- find_destroy, nullptr, &fn);
103
- REJECT_STATUS;
104
- c->status = napi_set_named_property(env, result, "destroy", fn);
105
- REJECT_STATUS;
106
-
107
- /* attach the "sources()" method */
108
- c->status = napi_create_function(env, "sources", NAPI_AUTO_LENGTH,
109
- find_sources, nullptr, &fn);
110
- REJECT_STATUS;
111
- c->status = napi_set_named_property(env, result, "sources", fn);
112
- REJECT_STATUS;
113
-
114
- /* attach the "wait()" method */
115
- c->status = napi_create_function(env, "wait", NAPI_AUTO_LENGTH, find_wait,
116
- nullptr, &fn);
117
- REJECT_STATUS;
118
- c->status = napi_set_named_property(env, result, "wait", fn);
119
- REJECT_STATUS;
120
-
121
- /* resolve the promise */
122
- napi_status status;
123
- status = napi_resolve_deferred(env, c->_deferred, result);
124
- FLOATING_STATUS;
125
-
126
- /* cleanup */
127
- tidyCarrier(env, c);
128
- }
129
-
130
- /* the API method "find()" */
131
- napi_value find(napi_env env, napi_callback_info info) {
132
- findCarrier *c = new findCarrier;
133
- napi_valuetype type;
134
-
135
- /* create result promise */
136
- napi_value promise;
137
- c->status = napi_create_promise(env, &c->_deferred, &promise);
138
- REJECT_RETURN;
139
-
140
- /* fetch argument */
141
- size_t argc = 1;
142
- napi_value args[1];
143
- c->status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
144
- REJECT_RETURN;
145
- if (argc != (size_t)1)
146
- REJECT_ERROR_RETURN("Find must be created with an object.",
147
- GRANDI_INVALID_ARGS);
148
- c->status = napi_typeof(env, args[0], &type);
149
- REJECT_RETURN;
150
- bool isArray;
151
- c->status = napi_is_array(env, args[0], &isArray);
152
- REJECT_RETURN;
153
- if ((type != napi_object) || isArray)
154
- REJECT_ERROR_RETURN("Single argument must be an object, not an array.",
155
- GRANDI_INVALID_ARGS);
156
- napi_value config = args[0];
157
-
158
- /* fetch "showLocalSources" property */
159
- napi_value showLocalSources;
160
- c->status = napi_get_named_property(env, config, "showLocalSources",
161
- &showLocalSources);
162
- REJECT_RETURN;
163
- c->status = napi_typeof(env, showLocalSources, &type);
164
- if (type != napi_undefined) {
165
- if (type != napi_boolean)
166
- REJECT_ERROR_RETURN(
167
- "Optional showLocalSources property must be a boolean when present.",
168
- GRANDI_INVALID_ARGS);
169
- c->status =
170
- napi_get_value_bool(env, showLocalSources, &c->show_local_sources);
171
- REJECT_RETURN;
172
- }
173
-
174
- /* fetch "groups" property */
175
- napi_value groups;
176
- c->status = napi_get_named_property(env, config, "groups", &groups);
177
- REJECT_RETURN;
178
- c->status = napi_typeof(env, groups, &type);
179
- if (type != napi_undefined) {
180
- if (type != napi_string)
181
- REJECT_ERROR_RETURN(
182
- "Optional groups property must be a string when present.",
183
- GRANDI_INVALID_ARGS);
184
- size_t groupsl;
185
- c->status = napi_get_value_string_utf8(env, groups, nullptr, 0, &groupsl);
186
- REJECT_RETURN;
187
- c->groups = (char *)malloc(groupsl + 1);
188
- c->status = napi_get_value_string_utf8(env, groups, c->groups, groupsl + 1,
189
- &groupsl);
190
- REJECT_RETURN;
191
- }
192
-
193
- /* fetch "extraIPs" property */
194
- napi_value extraIPs;
195
- c->status = napi_get_named_property(env, config, "extraIPs", &extraIPs);
196
- REJECT_RETURN;
197
- c->status = napi_typeof(env, extraIPs, &type);
198
- if (type != napi_undefined) {
199
- if (type != napi_string)
200
- REJECT_ERROR_RETURN(
201
- "Optional extraIPs property must be a string when present.",
202
- GRANDI_INVALID_ARGS);
203
- size_t extraIPsl;
204
- c->status =
205
- napi_get_value_string_utf8(env, extraIPs, nullptr, 0, &extraIPsl);
206
- REJECT_RETURN;
207
- c->extra_ips = (char *)malloc(extraIPsl + 1);
208
- c->status = napi_get_value_string_utf8(env, extraIPs, c->extra_ips,
209
- extraIPsl + 1, &extraIPsl);
210
- REJECT_RETURN;
211
- }
212
-
213
- /* create an internal async resource */
214
- napi_value resource_name;
215
- c->status =
216
- napi_create_string_utf8(env, "Find", NAPI_AUTO_LENGTH, &resource_name);
217
- REJECT_RETURN;
218
- c->status = napi_create_async_work(env, NULL, resource_name, findExecute,
219
- findComplete, c, &c->_request);
220
- REJECT_RETURN;
221
- c->status = napi_queue_async_work(env, c->_request);
222
- REJECT_RETURN;
223
-
224
- return promise;
225
- }
226
-
227
- /* API method "find.destroy()" */
228
- napi_value find_destroy(napi_env env, napi_callback_info info) {
229
- bool success = false;
230
- napi_value thisValue;
231
- size_t argc = 0;
232
- if (napi_get_cb_info(env, info, &argc, nullptr, &thisValue, nullptr) !=
233
- napi_ok)
234
- goto done;
235
-
236
- napi_value embeddedValue;
237
- if (napi_get_named_property(env, thisValue, "embedded", &embeddedValue) !=
238
- napi_ok)
239
- goto done;
240
-
241
- napi_valuetype result;
242
- if (napi_typeof(env, embeddedValue, &result) != napi_ok)
243
- goto done;
244
-
245
- if (result == napi_external) {
246
- embeddedValue_t *embeddedData;
247
- if (napi_get_value_external(env, embeddedValue, (void **)&embeddedData) !=
248
- napi_ok)
249
- goto done;
250
-
251
- if (embeddedData != nullptr) {
252
- NDIlib_find_instance_t find =
253
- (NDIlib_find_instance_t)(embeddedData->value);
254
- if (find != nullptr)
255
- NDIlib_find_destroy(find);
256
- embeddedData->value = nullptr;
257
- }
258
- success = true;
259
- }
260
-
261
- done:
262
- napi_value resultValue;
263
- if (napi_get_boolean(env, success, &resultValue) != napi_ok)
264
- napi_get_boolean(env, false, &resultValue);
265
- return resultValue;
266
- }
267
-
268
- /* API method "find.sources()" */
269
- napi_value find_sources(napi_env env, napi_callback_info info) {
270
- napi_status status;
271
-
272
- /* fetch arguments */
273
- size_t argc = 1;
274
- napi_value args[1];
275
- napi_value thisValue;
276
- status = napi_get_cb_info(env, info, &argc, args, &thisValue, nullptr);
277
- CHECK_STATUS;
278
-
279
- /* fetch embedded NDI native find object */
280
- napi_value embeddedValue;
281
- status = napi_get_named_property(env, thisValue, "embedded", &embeddedValue);
282
- CHECK_STATUS;
283
- embeddedValue_t *embeddedData;
284
- status = napi_get_value_external(env, embeddedValue, (void **)&embeddedData);
285
- CHECK_STATUS;
286
- NDIlib_find_instance_t find = (NDIlib_find_instance_t)(embeddedData->value);
287
-
288
- /* call NDI API functionality */
289
- uint32_t no_sources;
290
- const NDIlib_source_t *sources =
291
- NDIlib_find_get_current_sources(find, &no_sources);
292
-
293
- /* return result */
294
- napi_value result;
295
- status = napi_create_array(env, &result);
296
- CHECK_STATUS;
297
- napi_value item;
298
- for (uint32_t i = 0; i < no_sources; i++) {
299
- napi_value name, uri;
300
- status = napi_create_string_utf8(env, sources[i].p_ndi_name,
301
- NAPI_AUTO_LENGTH, &name);
302
- CHECK_STATUS;
303
- if (sources[i].p_url_address != nullptr) {
304
- status = napi_create_string_utf8(env, sources[i].p_url_address,
305
- NAPI_AUTO_LENGTH, &uri);
306
- CHECK_STATUS;
307
- } else {
308
- status = napi_get_null(env, &uri);
309
- CHECK_STATUS;
310
- }
311
- status = napi_create_object(env, &item);
312
- CHECK_STATUS;
313
- status = napi_set_named_property(env, item, "name", name);
314
- CHECK_STATUS;
315
- status = napi_set_named_property(env, item, "urlAddress", uri);
316
- CHECK_STATUS;
317
- status = napi_set_element(env, result, i, item);
318
- CHECK_STATUS;
319
- }
320
-
321
- return result;
322
- }
323
-
324
- /* API method "find.wait()" */
325
- napi_value find_wait(napi_env env, napi_callback_info info) {
326
- napi_status status;
327
-
328
- /* fetch arguments */
329
- size_t argc = 2;
330
- napi_value args[2];
331
- napi_value thisValue;
332
- status = napi_get_cb_info(env, info, &argc, args, &thisValue, nullptr);
333
- CHECK_STATUS;
334
-
335
- /* fetch embedded NDI native find object */
336
- napi_value embeddedValue;
337
- status = napi_get_named_property(env, thisValue, "embedded", &embeddedValue);
338
- CHECK_STATUS;
339
- embeddedValue_t *embeddedData;
340
- status = napi_get_value_external(env, embeddedValue, (void **)&embeddedData);
341
- CHECK_STATUS;
342
- NDIlib_find_instance_t find = (NDIlib_find_instance_t)(embeddedData->value);
343
-
344
- /* handle optional "wait" argument */
345
- uint32_t wait = 10000;
346
- if (argc == 2) {
347
- napi_valuetype type;
348
- status = napi_typeof(env, args[1], &type);
349
- CHECK_STATUS;
350
- if (type == napi_number) {
351
- status = napi_get_value_uint32(env, args[1], &wait);
352
- CHECK_STATUS;
353
- }
354
- }
355
-
356
- /* call NDI API functionality */
357
- bool ok = NDIlib_find_wait_for_sources(find, wait);
358
-
359
- /* return a boolean result */
360
- napi_value result;
361
- status = napi_get_boolean(env, ok, &result);
362
- CHECK_STATUS;
363
-
364
- return result;
365
- }
package/lib/grandi_find.h DELETED
@@ -1,41 +0,0 @@
1
- /*
2
- ** Copyright (c) 2022 Dr. Ralf S. Engelschall <rse@engelschall.com>
3
- **
4
- ** Licensed under the Apache License, Version 2.0 (the "License");
5
- ** you may not use this file except in compliance with the License.
6
- ** You may obtain a copy of the License at
7
- **
8
- ** http://www.apache.org/licenses/LICENSE-2.0
9
- **
10
- ** Unless required by applicable law or agreed to in writing, software
11
- ** distributed under the License is distributed on an "AS IS" BASIS,
12
- ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- ** See the License for the specific language governing permissions and
14
- ** limitations under the License.
15
- */
16
-
17
- #ifndef GRANDI_FIND_H
18
- #define GRANDI_FIND_H
19
-
20
- #include "node_api.h"
21
- #include "grandi_util.h"
22
-
23
- napi_value find(napi_env, napi_callback_info);
24
-
25
- struct findCarrier : carrier {
26
- bool show_local_sources = true;
27
- char *groups = nullptr;
28
- char *extra_ips = nullptr;
29
- NDIlib_find_instance_t find;
30
- uint32_t wait = 10000;
31
- uint32_t no_sources = 0;
32
- const NDIlib_source_t *sources;
33
- ~findCarrier() {
34
- if (groups != nullptr)
35
- free(groups);
36
- if (extra_ips != nullptr)
37
- free(extra_ips);
38
- }
39
- };
40
-
41
- #endif /* GRANDI_FIND_H */