forked from shobana-mcw/MIVisionX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loom_shell.cpp
1980 lines (1946 loc) · 84.2 KB
/
loom_shell.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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "loom_shell.h"
#include "loom_shell_util.h"
#include <stdarg.h>
#if _WIN32
#include <direct.h>
#include <Windows.h>
#else
#include <unistd.h>
#include <strings.h>
#define _strnicmp strncasecmp
#define _stricmp strcasecmp
#define _chdir chdir
#endif
void stitch_log_callback(const char * message)
{
printf("%s", message);
fflush(stdout);
}
CLoomShellParser::CLoomShellParser()
{
// initialize default counts
decl_ls_disabled = false;
decl_vx_disabled = false;
decl_cl_disabled = false;
decl_buf_disabled = false;
num_context_ = DEFAULT_LS_CONTEXT_COUNT;
num_openvx_context_ = DEFAULT_VX_CONTEXT_COUNT;
num_opencl_context_ = DEFAULT_CL_CONTEXT_COUNT;
num_opencl_buf_ = DEFAULT_CL_BUFFER_COUNT;
// set log callback
lsGlobalSetLogCallback(stitch_log_callback);
// name of contexts
strcpy(name_ls, "ls");
strcpy(name_vx, "vx");
strcpy(name_cl, "cl");
strcpy(name_buf, "buf");
// create array for contexts, cmd_queues, and buffers
context_ = new ls_context[num_context_]();
openvx_context_ = new vx_context[num_openvx_context_]();
opencl_context_ = new cl_context[num_opencl_context_]();
openvx_context_allocated_ = new bool[num_openvx_context_]();
opencl_context_allocated_ = new bool[num_opencl_context_]();
opencl_buf_mem_ = new cl_mem[num_opencl_buf_]();
// misc
memset(attr_buf_, 0, sizeof(attr_buf_));
}
CLoomShellParser::~CLoomShellParser()
{
if (context_) delete[] context_;
if (opencl_buf_mem_) delete[] opencl_buf_mem_;
if (openvx_context_) delete[] openvx_context_;
if (opencl_context_) delete[] opencl_context_;
if (openvx_context_allocated_) delete[] openvx_context_allocated_;
if (opencl_context_allocated_) delete[] opencl_context_allocated_;
}
const char * CLoomShellParser::ParseIndex(const char * s, const char * prefix, vx_uint32& index, vx_uint32 count)
{
// skip prefix
if (prefix) {
s = ParseSkipPattern(s, prefix);
if (!s) return nullptr;
}
if (count < 2) index = 0;
else {
// skip initial bracket
if (*s++ != '[') return nullptr;
// get index
s = ParseUInt(s, index);
if (!s) return nullptr;
// skip last bracked
if (*s++ != ']') return nullptr;
}
return s;
}
const char * CLoomShellParser::ParseUInt(const char * s, vx_uint32& value)
{
bool gotValue = false;
vx_uint32 multiplier = 1;
while (*s >= '0' && *s <= '9') {
for (value = 0; *s >= '0' && *s <= '9'; s++) {
value = value * 10 + (*s - '0');
gotValue = true;
}
value *= multiplier;
if (*s == '*') {
// continue processing after multiplication
s++;
multiplier = value;
}
}
if (!gotValue) return nullptr;
return s;
}
const char * CLoomShellParser::ParseInt(const char * s, vx_int32& value)
{
bool negative = false, gotValue = false;
if (*s == '-' || *s == '+') {
negative = (*s == '-') ? true : false;
s++;
}
for (value = 0; *s >= '0' && *s <= '9'; s++) {
value = value * 10 + (*s - '0');
gotValue = true;
}
if (negative)
value = -value;
if (!gotValue) return nullptr;
return s;
}
const char * CLoomShellParser::ParseFloat(const char * s, vx_float32& value)
{
bool negative = false, gotValue = false;
if (*s == '-' || *s == '+') {
negative = (*s == '-') ? true : false;
s++;
}
for (value = 0.0f; *s >= '0' && *s <= '9'; s++) {
value = value * 10.0f + (vx_float32)(*s - '0');
gotValue = true;
}
if (*s == '.') {
vx_float32 f = 1.0f;
for (s++; *s >= '0' && *s <= '9'; s++) {
value = value * 10.0f + (vx_float32)(*s - '0');
f = f * 10.0f;
gotValue = true;
}
value /= f;
}
if (negative)
value = -value;
if (!gotValue) return nullptr;
return s;
}
const char * CLoomShellParser::ParseWord(const char * s, char * value, size_t size)
{
bool gotValue = false;
// copy word until separator (i.e., SPACE or end paranthesis or end brace)
for (size_t len = 1; len < size && *s && *s != ' ' && *s != ';' && *s != ',' && *s != '{' && *s != '(' && *s != '[' && *s != ']' && *s != ')' && *s != '}'; len++) {
*value++ = *s++;
gotValue = true;
}
*value = '\0';
if (!gotValue) return nullptr;
return s;
}
const char * CLoomShellParser::ParseString(const char * s, char * value, size_t size)
{
// skip initial quote
if (*s++ != '"') return nullptr;
// copy string
for (size_t len = 1; len < size && *s && *s != '"'; len++)
*value++ = *s++;
*value = '\0';
// skip last quote
if (*s++ != '"') return nullptr;
return s;
}
const char * CLoomShellParser::ParseSkipPattern(const char * s, const char * pattern)
{
// skip whitespace
while (*s && *s == ' ')
s++;
// skip pattern
for (; *pattern; pattern++, s++) {
if (*pattern != *s)
return nullptr;
}
// skip whitespace
while (*s && *s == ' ')
s++;
return s;
}
const char * CLoomShellParser::ParseSkip(const char * s, const char * charList)
{
// skip whitespace
while (*s && *s == ' ')
s++;
// skip pattern
for (; *charList; charList++) {
if (*charList != *s)
return nullptr;
s++;
if (*s == ' ') s++;
}
// skip whitespace
while (*s && *s == ' ')
s++;
return s;
}
const char * CLoomShellParser::ParseEndOfLine(const char * s)
{
// skip whitespace and ';'
bool foundSemicolon = false;
while (*s && *s == ' ') s++;
if (*s == ';') {
foundSemicolon = true;
s++;
}
while (*s && *s == ' ') s++;
// check for end-of-line
if (*s != '\0') {
Error("ERROR: unexpected character '%c' at the end", *s);
return nullptr;
}
if (!foundSemicolon) {
Error("ERROR: missing ';' at the end", *s);
return nullptr;
}
return s;
}
const char * CLoomShellParser::ParseContextWithErrorCheck(const char * s, vx_uint32& index, const char * syntaxError)
{
s = ParseIndex(s, name_ls, index, num_context_);
if (!s) {
Error(syntaxError);
return nullptr;
}
if (index >= num_context_) {
Error("ERROR: context out-of-range: expects: 0..%d", num_context_ - 1);
return nullptr;
}
if (!context_[index]) {
Error("ERROR: %s[%d] doesn't exist", name_ls, index);
return nullptr;
}
return s;
}
const char * CLoomShellParser::ParseFormat(const char * s, vx_df_image& format)
{
char word[64];
s = ParseWord(s, word, sizeof(word));
if (s) {
if (!_stricmp(word, "VX_DF_IMAGE_RGB")) format = VX_DF_IMAGE_RGB;
else if (!_stricmp(word, "VX_DF_IMAGE_RGBX")) format = VX_DF_IMAGE_RGBX;
else if (!_stricmp(word, "VX_DF_IMAGE_UYVY")) format = VX_DF_IMAGE_UYVY;
else if (!_stricmp(word, "VX_DF_IMAGE_YUYV")) format = VX_DF_IMAGE_YUYV;
else {
if (strlen(word) != 4) {
Error("ERROR: image format should have FOUR characters");
return nullptr;
}
format = VX_DF_IMAGE(word[0], word[1], word[2], word[3]);
}
}
return s;
}
int CLoomShellParser::ReleaseAllResources()
{
if (ClearCmdqCache())
Terminate(1, "ERROR: ClearCmdqCache() failed\n");
if (opencl_buf_mem_) {
for (vx_uint32 i = 0; i < num_opencl_context_; i++) {
if (opencl_buf_mem_[i]) {
cl_int status = clReleaseMemObject(opencl_buf_mem_[i]);
if (status < 0) Terminate(1, "ERROR: clReleaseMemObject(%s[%d]) failed (%d)\n", name_buf, i, status);
opencl_buf_mem_[i] = nullptr;
Message("..released %s[%d]\n", name_buf, i);
}
}
}
if (context_) {
for (vx_uint32 i = 0; i < num_context_; i++) {
if (context_[i]) {
vx_status status = lsReleaseContext(&context_[i]);
if (status < 0) Terminate(1, "ERROR: lsReleaseContext(%s[%d]) failed (%d)\n", name_ls, i, status);
Message("..released %s[%d]\n", name_ls, i);
}
}
}
if (openvx_context_ && openvx_context_allocated_) {
for (vx_uint32 i = 0; i < num_openvx_context_; i++) {
if (openvx_context_[i]) {
if (openvx_context_allocated_[i]) {
vx_status status = vxReleaseContext(&openvx_context_[i]);
if (status < 0) Terminate(1, "ERROR: vxReleaseContext(%s[%d]) failed (%d)\n", name_vx, i, status);
Message("..released %s[%d]\n", name_vx, i);
}
else {
openvx_context_[i] = nullptr;
}
}
}
}
if (opencl_context_ && opencl_context_allocated_) {
for (vx_uint32 i = 0; i < num_opencl_context_; i++) {
if (opencl_context_[i]) {
if (opencl_context_allocated_[i]) {
cl_int status = clReleaseContext(opencl_context_[i]);
if (status < 0) Terminate(1, "ERROR: clReleaseContext(%s[%d]) failed (%d)\n", name_cl, i, status);
Message("..released %s[%d]\n", name_cl, i);
}
opencl_context_[i] = nullptr;
}
}
}
return 0;
}
int CLoomShellParser::OnCommand()
{
#define SYNTAX_CHECK(call) s = call; if(!s) return Error(invalidSyntax);
#define SYNTAX_CHECK_WITH_MESSAGE(call,msg) s = call; if(!s) return Error(msg);
const char *s = cmd_.c_str();
// get command and skip whitespace
char command[64];
s = ParseWord(s, command, sizeof(command)); if (!s || !command[0]) return Error("ERROR: valid command missing");
s = ParseSkip(s, "");
// process command
if (!_stricmp(command, name_ls)) {
// parse the command
vx_uint32 contextIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: ls[#] = lsCreateContext()";
SYNTAX_CHECK(ParseIndex(s, "", contextIndex, num_context_));
SYNTAX_CHECK(ParseSkip(s, "="));
SYNTAX_CHECK(ParseSkipPattern(s, "lsCreateContext"));
SYNTAX_CHECK(ParseSkip(s, "()"));
SYNTAX_CHECK(ParseEndOfLine(s));
if (contextIndex >= num_context_) return Error("ERROR: context out-of-range: expects: 0..%d", num_context_ - 1);
if (context_[contextIndex]) return Error("ERROR: context %s[%d] already exists", name_ls, contextIndex);
// process the command
context_[contextIndex] = lsCreateContext();
if (!context_[contextIndex]) return Error("ERROR: lsCreateContext() failed");
Message("..lsCreateContext: created context %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsReleaseContext")) {
// parse the command
vx_uint32 contextIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsReleaseContext(&ls[#])";
SYNTAX_CHECK(ParseSkip(s, "(&"));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsReleaseContext(&context_[contextIndex]);
if (status) return Error("ERROR: lsReleaseContext(%s[%d]) failed (%d)", name_ls, contextIndex, status);
Message("..lsReleaseContext: released context %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOpenVXContext")) {
// parse the command
vx_uint32 contextIndex = 0, vxIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOpenVXContext(ls[#],vx[#])";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseIndex(s, name_vx, vxIndex, num_openvx_context_));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
if (vxIndex >= num_openvx_context_) return Error("ERROR: OpenVX context out-of-range: expects: 0..%d", num_openvx_context_ - 1);
// process the command
vx_status status = lsSetOpenVXContext(context_[contextIndex], openvx_context_[vxIndex]);
if (status) return Error("ERROR: lsSetOpenVXContext(%s[%d],%s[%d]) failed (%d)", name_ls, contextIndex, name_vx, vxIndex, status);
Message("..lsSetOpenVXContext: set OpenVX context %s[%d] for %s[%d]\n", name_vx, vxIndex, name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOpenCLContext")) {
// parse the command
vx_uint32 contextIndex = 0, clIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOpenCLContext(ls[#],cl[#])";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseIndex(s, name_cl, clIndex, num_opencl_context_));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
if (clIndex >= num_opencl_context_) return Error("ERROR: OpenCL context out-of-range: expects: 0..%d", num_opencl_context_ - 1);
// process the command
vx_status status = lsSetOpenCLContext(context_[contextIndex], opencl_context_[clIndex]);
if (status) return Error("ERROR: lsSetOpenCLContext(%s[%d],%s[%d]) failed (%d)", name_ls, contextIndex, name_cl, clIndex, status);
Message("..lsSetOpenCLContext: set OpenCL context %s[%d] for %s[%d]\n", name_cl, clIndex, name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetRigParams")) {
// parse the command
vx_uint32 contextIndex = 0;
rig_params rig_par = { 0 };
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetRigParams(context,&rig_par)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ",&"));
SYNTAX_CHECK(ParseSkip(s, ""));
if (*s == '{') {
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, "{"), "ERROR: missing '{'");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, rig_par.yaw), "ERROR: invalid yaw value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing pitch value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, rig_par.pitch), "ERROR: invalid pitch value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing roll value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, rig_par.roll), "ERROR: invalid roll value");
SYNTAX_CHECK(ParseSkip(s, ""));
if (*s == ',') {
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing d value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, rig_par.d), "ERROR: invalid d value");
}
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, "})"), "ERROR: missing '})'");
SYNTAX_CHECK(ParseEndOfLine(s));
}
else {
char parName[64];
SYNTAX_CHECK(ParseWord(s, parName, sizeof(parName)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
if (rigParList.find(parName) == rigParList.end()) return Error("ERROR: rig_params %s not defined", parName);
memcpy(&rig_par, &rigParList[parName], sizeof(rig_par));
}
// process the command
vx_status status = lsSetRigParams(context_[contextIndex], &rig_par);
if (status) return Error("ERROR: lsSetRigParams(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetRigParams: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetCameraConfig")) {
// parse the command
vx_uint32 contextIndex = 0, camera_rows = 0, camera_cols = 0, buffer_width = 0, buffer_height = 0; vx_df_image buffer_format = VX_DF_IMAGE_VIRT;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetCameraConfig(ls[#],rows,cols,format,width,height)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, camera_rows));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, camera_cols));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseFormat(s, buffer_format));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_width));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_height));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetCameraConfig(context_[contextIndex], camera_rows, camera_cols,
buffer_format, buffer_width, buffer_height);
if (status) return Error("ERROR: lsSetCameraConfig(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetCameraConfig: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOutputConfig")) {
// parse the command
vx_uint32 contextIndex = 0, buffer_width = 0, buffer_height = 0; vx_df_image buffer_format = VX_DF_IMAGE_VIRT;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOutputConfig(ls[#],format,width,height)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseFormat(s, buffer_format));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_width));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_height));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetOutputConfig(context_[contextIndex],
buffer_format, buffer_width, buffer_height);
if (status) return Error("ERROR: lsSetOutputConfig(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOutputConfig: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOverlayConfig")) {
// parse the command
vx_uint32 contextIndex = 0, overlay_rows = 0, overlay_cols = 0, buffer_width = 0, buffer_height = 0; vx_df_image buffer_format = VX_DF_IMAGE_VIRT;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOverlayConfig(ls[#],rows,cols,format,width,height)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, overlay_rows));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, overlay_cols));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseFormat(s, buffer_format));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_width));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_height));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetOverlayConfig(context_[contextIndex], overlay_rows, overlay_cols,
buffer_format, buffer_width, buffer_height);
if (status) return Error("ERROR: lsSetOverlayConfig(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOverlayConfig: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetCameraParams") || !_stricmp(command, "lsSetOverlayParams")) {
bool isCamera = !_stricmp(command, "lsSetCameraParams") ? true : false;
// parse the command
vx_uint32 contextIndex = 0, index = 0;
camera_params camera_par = { 0 };
const char * invalidSyntax = isCamera ?
"ERROR: invalid syntax: expects: lsSetCameraParams(ls[#],index,&cam_par)" :
"ERROR: invalid syntax: expects: lsSetOverlayParams(ls[#],index,&cam_par)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, index));
SYNTAX_CHECK(ParseSkip(s, ",&"));
SYNTAX_CHECK(ParseSkip(s, ""));
if (*s == '{') {
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, "{{"), "ERROR: missing '{{'");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.focal.yaw), "ERROR: invalid yaw value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing pitch value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.focal.pitch), "ERROR: invalid pitch value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing roll value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.focal.roll), "ERROR: invalid roll value");
SYNTAX_CHECK(ParseSkip(s, ""));
if (*s == ',') {
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing tx value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.focal.tx), "ERROR: invalid tx value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing ty value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.focal.ty), "ERROR: invalid ty value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing tz value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.focal.tz), "ERROR: invalid tz value");
}
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, "},{"), "ERROR: missing separator before lens_type");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.hfov), "ERROR: invalid hfov value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing haw value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.haw), "ERROR: invalid haw value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing r_crop value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.r_crop), "ERROR: invalid r_crop value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing du0 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.du0), "ERROR: invalid du0 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing dv0 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.dv0), "ERROR: invalid dv0 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing lens_type value");
char lensType[64];
SYNTAX_CHECK_WITH_MESSAGE(ParseWord(s, lensType, sizeof(lensType)), "ERROR: invalid lens_type value");
if (!_stricmp(lensType, "ptgui_lens_rectilinear")) camera_par.lens.lens_type = ptgui_lens_rectilinear;
else if (!_stricmp(lensType, "ptgui_lens_fisheye_ff")) camera_par.lens.lens_type = ptgui_lens_fisheye_ff;
else if (!_stricmp(lensType, "ptgui_lens_fisheye_circ")) camera_par.lens.lens_type = ptgui_lens_fisheye_circ;
else if (!_stricmp(lensType, "adobe_lens_rectilinear")) camera_par.lens.lens_type = adobe_lens_rectilinear;
else if (!_stricmp(lensType, "adobe_lens_fisheye")) camera_par.lens.lens_type = adobe_lens_fisheye;
else return Error("ERROR: invalid lens_type value: see help for valid values");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing k1 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.k1), "ERROR: invalid k1 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing k2 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.k2), "ERROR: invalid k2 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, ","), "ERROR: missing k3 value");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.k3), "ERROR: invalid k3 value");
for (vx_uint32 i = 0; i < 7; i++) {
s = ParseSkip(s, ""); if (*s != ',') break;
s = ParseSkip(s, ",");
SYNTAX_CHECK_WITH_MESSAGE(ParseFloat(s, camera_par.lens.reserved[i]), "ERROR: invalid reserved field value");
}
SYNTAX_CHECK_WITH_MESSAGE(ParseSkip(s, "}})"), "ERROR: missing '}})'");
SYNTAX_CHECK(ParseEndOfLine(s));
}
else {
char parName[64];
SYNTAX_CHECK(ParseWord(s, parName, sizeof(parName)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
if (camParList.find(parName) == camParList.end()) return Error("ERROR: camera_params %s not defined", parName);
memcpy(&camera_par, &camParList[parName], sizeof(camera_par));
}
// process the command
if (isCamera) {
vx_status status = lsSetCameraParams(context_[contextIndex], index, &camera_par);
if (status) return Error("ERROR: lsSetCameraParams(%s[%d],%d,*) failed (%d)", name_ls, contextIndex, index, status);
Message("..lsSetCameraParams: successful for %s[%d] and camera#%d\n", name_ls, contextIndex, index);
}
else {
vx_status status = lsSetOverlayParams(context_[contextIndex], index, &camera_par);
if (status) return Error("ERROR: lsSetOverlayParams(%s[%d],%d,*) failed (%d)", name_ls, contextIndex, index, status);
Message("..lsSetOverlayParams: successful for %s[%d] and overlay#%d\n", name_ls, contextIndex, index);
}
}
else if (!_stricmp(command, "lsSetCameraBufferStride")) {
// parse the command
vx_uint32 contextIndex = 0, buffer_stride_in_bytes = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetCameraBufferStride(ls[#],stride_in_bytes)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_stride_in_bytes));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetCameraBufferStride(context_[contextIndex], buffer_stride_in_bytes);
if (status) return Error("ERROR: lsSetCameraBufferStride(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetCameraBufferStride: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOutputBufferStride")) {
// parse the command
vx_uint32 contextIndex = 0, buffer_stride_in_bytes = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOutputBufferStride(ls[#],stride_in_bytes)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_stride_in_bytes));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetOutputBufferStride(context_[contextIndex], buffer_stride_in_bytes);
if (status) return Error("ERROR: lsSetOutputBufferStride(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOutputBufferStride: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOverlayBufferStride")) {
// parse the command
vx_uint32 contextIndex = 0, buffer_stride_in_bytes = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOverlayBufferStride(ls[#],stride_in_bytes)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, buffer_stride_in_bytes));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetOverlayBufferStride(context_[contextIndex], buffer_stride_in_bytes);
if (status) return Error("ERROR: lsSetOverlayBufferStride(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOverlayBufferStride: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetCameraModule")) {
// parse the command
vx_uint32 contextIndex = 0;
char module[256], kernelName[64], kernelArguments[1024];
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetCameraModule(ls[#],\"module\",\"kernelName\",\"kernelArguments\")";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, module, sizeof(module)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelName, sizeof(kernelName)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelArguments, sizeof(kernelArguments)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetCameraModule(context_[contextIndex], module, kernelName, kernelArguments);
if (status) return Error("ERROR: lsSetCameraModule(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetCameraModule: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOutputModule")) {
// parse the command
vx_uint32 contextIndex = 0;
char module[256], kernelName[64], kernelArguments[1024];
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOutputModule(ls[#],\"module\",\"kernelName\",\"kernelArguments\")";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, module, sizeof(module)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelName, sizeof(kernelName)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelArguments, sizeof(kernelArguments)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetOutputModule(context_[contextIndex], module, kernelName, kernelArguments);
if (status) return Error("ERROR: lsSetOutputModule(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOutputModule: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetOverlayModule")) {
// parse the command
vx_uint32 contextIndex = 0;
char module[256], kernelName[64], kernelArguments[1024];
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOverlayModule(ls[#],\"module\",\"kernelName\",\"kernelArguments\")";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, module, sizeof(module)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelName, sizeof(kernelName)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelArguments, sizeof(kernelArguments)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetOverlayModule(context_[contextIndex], module, kernelName, kernelArguments);
if (status) return Error("ERROR: lsSetOverlayModule(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOverlayModule: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetViewingModule")) {
// parse the command
vx_uint32 contextIndex = 0;
char module[256], kernelName[64], kernelArguments[1024];
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetViewingModule(ls[#],\"module\",\"kernelName\",\"kernelArguments\")";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, module, sizeof(module)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelName, sizeof(kernelName)));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, kernelArguments, sizeof(kernelArguments)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsSetViewingModule(context_[contextIndex], module, kernelName, kernelArguments);
if (status) return Error("ERROR: lsSetViewingModule(%s[%d],*) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetViewingModule: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsInitialize")) {
// parse the command
vx_uint32 contextIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsInitialize(ls[#])";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
double clk2msec = 1000.0 / GetClockFrequency();
int64_t clk = GetClockCounter();
vx_status status = lsInitialize(context_[contextIndex]);
double msec = clk2msec * (GetClockCounter() - clk);
if (status) return Error("ERROR: lsInitialize(%s[%d]) failed (%d)", name_ls, contextIndex, status);
Message("..lsInitialize: successful for %s[%d] (%7.3lf ms)\n", name_ls, contextIndex, msec);
}
else if (!_stricmp(command, "lsReinitialize")) {
// parse the command
vx_uint32 contextIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsReinitialize(ls[#])";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
double clk2msec = 1000.0 / GetClockFrequency();
int64_t clk = GetClockCounter();
vx_status status = lsReinitialize(context_[contextIndex]);
double msec = clk2msec * (GetClockCounter() - clk);
if (status) return Error("ERROR: lsReinitialize(%s[%d]) failed (%d)", name_ls, contextIndex, status);
Message("..lsReinitialize: successful for %s[%d] (%7.3lf ms)\n", name_ls, contextIndex, msec);
}
else if (!_stricmp(command, "lsScheduleFrame")) {
// parse the command
vx_uint32 contextIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsScheduleFrame(ls[#])";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsScheduleFrame(context_[contextIndex]);
if (status) return Error("ERROR: lsScheduleFrame(%s[%d]) failed (%d)", name_ls, contextIndex, status);
Message("..lsScheduleFrame: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsWaitForCompletion")) {
// parse the command
vx_uint32 contextIndex = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsWaitForCompletion(ls[#])";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
vx_status status = lsWaitForCompletion(context_[contextIndex]);
if (status) return Error("ERROR: lsWaitForCompletion(%s[%d]) failed (%d)", name_ls, contextIndex, status);
Message("..lsWaitForCompletion: successful for %s[%d]\n", name_ls, contextIndex);
}
else if (!_stricmp(command, "lsSetCameraBuffer")) {
// parse the command
vx_uint32 contextIndex = 0, bufIndex = 0;
vx_uint32 num_buffers;
bool useNull = false;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetCameraBuffer(ls[#],&buf[#]|NULL)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
if (!_stricmp(s, ",null)")) {
useNull = true;
}
else {
SYNTAX_CHECK(ParseSkip(s, ",&"));
SYNTAX_CHECK(ParseIndex(s, name_buf, bufIndex, num_opencl_buf_));
if (*s == ','){
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, num_buffers));
}
SYNTAX_CHECK(ParseSkip(s, ")"));
}
SYNTAX_CHECK(ParseEndOfLine(s));
if (bufIndex >= num_opencl_buf_) return Error("ERROR: OpenCL buffer out-of-range: expects: 0..%d", num_opencl_buf_ - 1);
// process the command
if (useNull) {
vx_status status = lsSetCameraBuffer(context_[contextIndex], nullptr);
if (status) return Error("ERROR: lsSetCameraBuffer(%s[%d],NULL) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetCameraBuffer: set NULL for %s[%d]\n", name_ls, contextIndex);
}
else {
vx_status status = lsSetCameraBuffer(context_[contextIndex], &opencl_buf_mem_[bufIndex]);
if (status) return Error("ERROR: lsSetCameraBuffer(%s[%d],%s[%d]) failed (%d)", name_ls, contextIndex, name_buf, bufIndex, status);
Message("..lsSetCameraBuffer: set OpenCL buffer %s[%d] for %s[%d]\n", name_buf, bufIndex, name_ls, contextIndex);
}
}
else if (!_stricmp(command, "lsSetOutputBuffer")) {
// parse the command
vx_uint32 contextIndex = 0, bufIndex = 0;
vx_uint32 num_buffers;
bool useNull = false;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOutputBuffer(ls[#],&buf[#]|NULL)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
if (!_stricmp(s, ",null)")) {
useNull = true;
}
else {
SYNTAX_CHECK(ParseSkip(s, ",&"));
SYNTAX_CHECK(ParseIndex(s, name_buf, bufIndex, num_opencl_buf_));
if (*s == ','){
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, num_buffers));
}
SYNTAX_CHECK(ParseSkip(s, ")"));
}
SYNTAX_CHECK(ParseEndOfLine(s));
if (bufIndex >= num_opencl_buf_) return Error("ERROR: OpenCL buffer out-of-range: expects: 0..%d", num_opencl_buf_ - 1);
// process the command
if (useNull) {
vx_status status = lsSetOutputBuffer(context_[contextIndex], nullptr);
if (status) return Error("ERROR: lsSetOutputBuffer(%s[%d],NULL) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOutputBuffer: set NULL for %s[%d]\n", name_ls, contextIndex);
}
else {
vx_status status = lsSetOutputBuffer(context_[contextIndex], &opencl_buf_mem_[bufIndex]);
if (status) return Error("ERROR: lsSetOutputBuffer(%s[%d],%s[%d]) failed (%d)", name_ls, contextIndex, name_buf, bufIndex, status);
Message("..lsSetOutputBuffer: set OpenCL buffer %s[%d] for %s[%d]\n", name_buf, bufIndex, name_ls, contextIndex);
}
}
else if (!_stricmp(command, "lsSetOverlayBuffer")) {
// parse the command
vx_uint32 contextIndex = 0, bufIndex = 0;
vx_uint32 num_buffers;
bool useNull = false;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetOverlayBuffer(ls[#],&buf[#]|NULL)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
if (!_stricmp(s, ",null)")) {
useNull = true;
}
else {
SYNTAX_CHECK(ParseSkip(s, ",&"));
SYNTAX_CHECK(ParseIndex(s, name_buf, bufIndex, num_opencl_buf_));
if (*s == ','){
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, num_buffers));
}
SYNTAX_CHECK(ParseSkip(s, ")"));
}
SYNTAX_CHECK(ParseEndOfLine(s));
if (bufIndex >= num_opencl_buf_) return Error("ERROR: OpenCL buffer out-of-range: expects: 0..%d", num_opencl_buf_ - 1);
// process the command
if (useNull) {
vx_status status = lsSetOverlayBuffer(context_[contextIndex], nullptr);
if (status) return Error("ERROR: lsSetOverlayBuffer(%s[%d],NULL) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetOverlayBuffer: set NULL for %s[%d]\n", name_ls, contextIndex);
}
else {
vx_status status = lsSetOverlayBuffer(context_[contextIndex], &opencl_buf_mem_[bufIndex]);
if (status) return Error("ERROR: lsSetOverlayBuffer(%s[%d],%s[%d]) failed (%d)", name_ls, contextIndex, name_buf, bufIndex, status);
Message("..lsSetOverlayBuffer: set OpenCL buffer %s[%d] for %s[%d]\n", name_buf, bufIndex, name_ls, contextIndex);
}
}
else if (!_stricmp(command, "lsSetChromaKeyBuffer")) {
// parse the command
vx_uint32 contextIndex = 0, bufIndex = 0;
vx_uint32 num_buffers;
bool useNull = false;
const char * invalidSyntax = "ERROR: invalid syntax: expects: lsSetChromaKeyBuffer(ls[#],&buf[#]|NULL)";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
if (!_stricmp(s, ",null)")) {
useNull = true;
}
else {
SYNTAX_CHECK(ParseSkip(s, ",&"));
SYNTAX_CHECK(ParseIndex(s, name_buf, bufIndex, num_opencl_buf_));
if (*s == ','){
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, num_buffers));
}
SYNTAX_CHECK(ParseSkip(s, ")"));
}
SYNTAX_CHECK(ParseEndOfLine(s));
if (bufIndex >= num_opencl_buf_) return Error("ERROR: OpenCL buffer out-of-range: expects: 0..%d", num_opencl_buf_ - 1);
// process the command
if (useNull) {
vx_status status = lsSetChromaKeyBuffer(context_[contextIndex], nullptr);
if (status) return Error("ERROR: lsSetChromaKeyBuffer(%s[%d],NULL) failed (%d)", name_ls, contextIndex, status);
Message("..lsSetChromaKeyBuffer: set NULL for %s[%d]\n", name_ls, contextIndex);
}
else {
vx_status status = lsSetChromaKeyBuffer(context_[contextIndex], &opencl_buf_mem_[bufIndex]);
if (status) return Error("ERROR: lsSetChromaKeyBuffer(%s[%d],%s[%d]) failed (%d)", name_ls, contextIndex, name_buf, bufIndex, status);
Message("..lsSetChromaKeyBuffer: set OpenCL buffer %s[%d] for %s[%d]\n", name_buf, bufIndex, name_ls, contextIndex);
}
}
else if (!_stricmp(command, "setGlobalAttribute")) {
// parse the command
vx_uint32 attr_offset = 0; float value = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: setGlobalAttribute(offset,value);";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseUInt(s, attr_offset));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseFloat(s, value));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
if (setGlobalAttribute(attr_offset, value) != VX_SUCCESS)
return -1;
}
else if (!_stricmp(command, "setAttribute")) {
// parse the command
vx_uint32 contextIndex = 0, attr_offset = 0; float value = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: setAttribute(context,offset,value);";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, attr_offset));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseFloat(s, value));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
if (setAttribute(context_[contextIndex], attr_offset, value) != VX_SUCCESS)
return -1;
}
else if (!_stricmp(command, "showGlobalAttributes")) {
// parse the command
vx_uint32 attr_offset = 0, attr_count = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: showGlobalAttributes(offset,count);";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseUInt(s, attr_offset));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, attr_count));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
if (showGlobalAttributes(attr_offset, attr_count) != VX_SUCCESS)
return -1;
}
else if (!_stricmp(command, "showAttributes")) {
// parse the command
vx_uint32 contextIndex = 0, attr_offset = 0, attr_count = 0;
const char * invalidSyntax = "ERROR: invalid syntax: expects: showAttributes(context,offset,count);";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, attr_offset));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, attr_count));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
if (showAttributes(context_[contextIndex], attr_offset, attr_count) != VX_SUCCESS)
return -1;
}
else if (!_stricmp(command, "loadAttributes") || !_stricmp(command, "saveAttributes")) {
// parse the command
vx_uint32 contextIndex = 0, attr_offset = 0, attr_count = 0;
char fileName[256] = { 0 };
const char * invalidSyntax = !_stricmp(command, "loadAttributes") ?
"ERROR: invalid syntax: expects: loadAttributes(context,offset,count,\"attr.txt\");" :
"ERROR: invalid syntax: expects: saveAttributes(context,offset,count,\"attr.txt\");";
SYNTAX_CHECK(ParseSkip(s, "("));
SYNTAX_CHECK(ParseContextWithErrorCheck(s, contextIndex, invalidSyntax));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, attr_offset));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseUInt(s, attr_count));
SYNTAX_CHECK(ParseSkip(s, ","));
SYNTAX_CHECK(ParseString(s, fileName, sizeof(fileName)));
SYNTAX_CHECK(ParseSkip(s, ")"));
SYNTAX_CHECK(ParseEndOfLine(s));
// process the command
if (!_stricmp(command, "loadAttributes")) {
if (loadAttributes(context_[contextIndex], attr_offset, attr_count, fileName) != VX_SUCCESS)
return -1;
}
else {
if (saveAttributes(context_[contextIndex], attr_offset, attr_count, fileName) != VX_SUCCESS)