1 /*
2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <sys/ioctl.h>
25 #include "sdk.h"
26 #include "sample_comm_ive.h"
27 #include "sample_ive_main.h"
28
29 static char **s_ppChCmdArgv = NULL;
30
31 #define SAMPLE_IVE_CANNY_ARG_MAX_NUM 3
32 #define SAMPLE_IVE_ARG_MAX_NUM 3
33 #define SAMPLE_IVE_ARG_MIN_NUM 2
34 #define SAMPLE_IVE_IDX_0 0
35 #define SAMPLE_IVE_IDX_1 1
36 #define SAMPLE_IVE_IDX_2 2
37 #define SAMPLE_IVE_HELP_SIZE 2
38
39 /* function : to process abnormal case */
40 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
SAMPLE_IVE_HandleSig(HI_S32 s32Signo)41 static HI_VOID SAMPLE_IVE_HandleSig(HI_S32 s32Signo)
42 {
43 if (s32Signo == SIGINT || s32Signo == SIGTERM) {
44 switch (*s_ppChCmdArgv[1]) {
45 case '0':
46 SAMPLE_IVE_Od_HandleSig();
47 break;
48 case '1':
49 SAMPLE_IVE_Md_HandleSig();
50 break;
51 case '2':
52 SAMPLE_IVE_Canny_HandleSig();
53 break;
54 case '3':
55 SAMPLE_IVE_Gmm2_HandleSig();
56 break;
57 case '4':
58 SAMPLE_IVE_TestMemory_HandleSig();
59 break;
60 case '5':
61 SAMPLE_IVE_Sobel_HandleSig();
62 break;
63 case '6':
64 SAMPLE_IVE_St_Lk_HandleSig();
65 break;
66 case '7':
67 SAMPLE_IVE_Kcf_HandleSig();
68 break;
69 case '8':
70 SAMPLE_IVE_PerspTrans_HandleSig();
71 break;
72 default:
73 break;
74 }
75 }
76 }
77 #endif
78
79 /* function : show usage */
SAMPLE_IVE_Usage(HI_CHAR * pchPrgName)80 static HI_VOID SAMPLE_IVE_Usage(HI_CHAR *pchPrgName)
81 {
82 printf("Usage : %s <index> [complete] \n", pchPrgName);
83 printf("index:\n");
84 printf("\t 0)Occlusion detected.(VI->VPSS->IVE->VO_HDMI).\n");
85 printf("\t 1)Motion detected.(VI->VPSS->IVE->VGS->VO_HDMI).\n");
86 printf("\t 2)Canny,<complete>:0, part canny;1,complete canny.(FILE->IVE->FILE).\n");
87 printf("\t 3)Gmm2.(FILE->IVE->FILE).\n");
88 printf("\t 4)MemoryTest.(FILE->IVE->FILE).\n");
89 printf("\t 5)Sobel.(FILE->IVE->FILE).\n");
90 printf("\t 6)St Lk.(FILE->IVE->FILE).\n");
91 printf("\t 7)Kcf track.(VI->VPSS->IVE->VO_HDMI).\n");
92 printf("\t 8)PerspTrans.(FILE->IVE->FILE).\n");
93 }
94
95 /* function : ive sample */
96 #if defined(__HuaweiLite__) && (!defined(__OHOS__))
app_main(int argc,char * argv[])97 int app_main(int argc, char *argv[])
98 #else
99 int main(int argc, char *argv[])
100 #endif
101 {
102 int ret = HI_SUCCESS;
103 sdk_init();
104
105 if (argc < SAMPLE_IVE_ARG_MIN_NUM || argc > SAMPLE_IVE_ARG_MAX_NUM) { /* 2, 3: arg count */
106 SAMPLE_IVE_Usage(argv[0]);
107 ret = HI_FAILURE;
108 goto end;
109 }
110 s_ppChCmdArgv = argv;
111 #if (!defined(__HuaweiLite__)) || defined(__OHOS__)
112 struct sigaction sa;
113 (hi_void)memset_s(&sa, sizeof(struct sigaction), 0, sizeof(struct sigaction));
114 sa.sa_handler = SAMPLE_IVE_HandleSig;
115 sa.sa_flags = 0;
116 sigaction(SIGINT, &sa, NULL);
117 sigaction(SIGTERM, &sa, NULL);
118 #endif
119
120 if (strncmp(argv[1], "-h", SAMPLE_IVE_HELP_SIZE) == 0) { /* 2: maximum number of characters to compare */
121 SAMPLE_IVE_Usage(argv[0]);
122 ret = HI_FAILURE;
123 goto end;
124 }
125 switch (*argv[1]) {
126 case '0':
127 SAMPLE_IVE_Od();
128 break;
129 case '1':
130 SAMPLE_IVE_Md();
131 break;
132 case '2':
133 if ((argc < SAMPLE_IVE_CANNY_ARG_MAX_NUM) ||
134 ((*argv[SAMPLE_IVE_IDX_2] != '0') && (*argv[SAMPLE_IVE_IDX_2] != '1'))) {
135 SAMPLE_IVE_Usage(argv[0]);
136 ret = HI_FAILURE;
137 goto end;
138 }
139 SAMPLE_IVE_Canny(*argv[SAMPLE_IVE_IDX_2]); /* 2: arg index */
140 break;
141 case '3':
142 SAMPLE_IVE_Gmm2();
143 break;
144 case '4':
145 SAMPLE_IVE_TestMemory();
146 break;
147 case '5':
148 SAMPLE_IVE_Sobel();
149 break;
150 case '6':
151 SAMPLE_IVE_St_Lk();
152 break;
153 case '7':
154 SAMPLE_IVE_Kcf();
155 break;
156 case '8':
157 SAMPLE_IVE_PerspTrans();
158 break;
159 default:
160 SAMPLE_IVE_Usage(argv[0]);
161 break;
162 }
163
164 end:
165 sdk_exit();
166 return ret;
167 }
168