-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_comm_isp.c
428 lines (365 loc) · 12.5 KB
/
sample_comm_isp.c
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
/******************************************************************************
Some simple Hisilicon Hi35xx isp functions.
Copyright (C), 2010-2011, Hisilicon Tech. Co., Ltd.
******************************************************************************
Modification: 2011-2 Created
******************************************************************************/
#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* End of #ifdef __cplusplus */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <math.h>
#include <unistd.h>
#include <signal.h>
#include "sample_comm.h"
static pthread_t gs_IspPid = 0;
static HI_BOOL gbIspInited = HI_FALSE;
/******************************************************************************
* funciton : ISP init
******************************************************************************/
HI_S32 SAMPLE_COMM_ISP_Init(WDR_MODE_E enWDRMode)
{
ISP_DEV IspDev = 0;
HI_S32 s32Ret;
ISP_PUB_ATTR_S stPubAttr;
ALG_LIB_S stLib;
#if 0
/* 0. set cmos iniparser file path */
s32Ret = sensor_set_inifile_path("configs/");
if (s32Ret != HI_SUCCESS)
{
printf("%s: set cmos iniparser file path failed with %#x!\n", \
__FUNCTION__, s32Ret);
return s32Ret;
}
#endif
/* 1. sensor register callback */
s32Ret = sensor_register_callback();
if (s32Ret != HI_SUCCESS)
{
printf("%s: sensor_register_callback failed with %#x!\n", \
__FUNCTION__, s32Ret);
return s32Ret;
}
/* 2. register hisi ae lib */
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AE_LIB_NAME);
s32Ret = HI_MPI_AE_Register(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_AE_Register failed!\n", __FUNCTION__);
return s32Ret;
}
/* 3. register hisi awb lib */
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AWB_LIB_NAME);
s32Ret = HI_MPI_AWB_Register(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_AWB_Register failed!\n", __FUNCTION__);
return s32Ret;
}
/* 4. register hisi af lib */
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AF_LIB_NAME);
s32Ret = HI_MPI_AF_Register(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_AF_Register failed!\n", __FUNCTION__);
return s32Ret;
}
/* 5. isp mem init */
s32Ret = HI_MPI_ISP_MemInit(IspDev);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_ISP_Init failed!\n", __FUNCTION__);
return s32Ret;
}
/* 6. isp set WDR mode */
ISP_WDR_MODE_S stWdrMode;
stWdrMode.enWDRMode = enWDRMode;
s32Ret = HI_MPI_ISP_SetWDRMode(0, &stWdrMode);
if (HI_SUCCESS != s32Ret)
{
printf("start ISP WDR failed!\n");
return s32Ret;
}
/* 7. isp set pub attributes */
/* note : different sensor, different ISP_PUB_ATTR_S define.
if the sensor you used is different, you can change
ISP_PUB_ATTR_S definition */
switch(SENSOR_TYPE)
{
case APTINA_9M034_DC_720P_30FPS:
case APTINA_AR0130_DC_720P_30FPS:
stPubAttr.enBayer = BAYER_GRBG;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1280;
stPubAttr.stWndRect.u32Height = 720;
break;
case SONY_IMX222_DC_1080P_30FPS:
stPubAttr.enBayer = BAYER_RGGB;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 200;
stPubAttr.stWndRect.s32Y = 20;
stPubAttr.stWndRect.u32Width = 1920;
stPubAttr.stWndRect.u32Height = 1080;
break;
case SONY_IMX222_DC_720P_30FPS:
stPubAttr.enBayer = BAYER_RGGB;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 200;
stPubAttr.stWndRect.s32Y = 20;
stPubAttr.stWndRect.u32Width = 1280;
stPubAttr.stWndRect.u32Height = 720;
break;
case APTINA_AR0230_HISPI_1080P_30FPS:
stPubAttr.enBayer = BAYER_GRBG;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1920;
stPubAttr.stWndRect.u32Height = 1080;
break;
case PANASONIC_MN34222_MIPI_1080P_30FPS:
stPubAttr.enBayer = BAYER_GRBG;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1920;
stPubAttr.stWndRect.u32Height = 1080;
break;
case OMNIVISION_OV9712_DC_720P_30FPS:
stPubAttr.enBayer = BAYER_BGGR;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1280;
stPubAttr.stWndRect.u32Height = 720;
break;
case OMNIVISION_OV9732_DC_720P_30FPS:
stPubAttr.enBayer = BAYER_BGGR;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1280;
stPubAttr.stWndRect.u32Height = 720;
break;
case OMNIVISION_OV9750_MIPI_720P_30FPS:
case OMNIVISION_OV9752_MIPI_720P_30FPS:
stPubAttr.enBayer = BAYER_BGGR;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1280;
stPubAttr.stWndRect.u32Height = 720;
break;
case OMNIVISION_OV2718_MIPI_1080P_25FPS:
stPubAttr.enBayer = BAYER_BGGR;
stPubAttr.f32FrameRate = 25;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1920;
stPubAttr.stWndRect.u32Height = 1080;
break;
default:
stPubAttr.enBayer = BAYER_GRBG;
stPubAttr.f32FrameRate = 30;
stPubAttr.stWndRect.s32X = 0;
stPubAttr.stWndRect.s32Y = 0;
stPubAttr.stWndRect.u32Width = 1920;
stPubAttr.stWndRect.u32Height = 1080;
break;
}
s32Ret = HI_MPI_ISP_SetPubAttr(IspDev, &stPubAttr);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_ISP_SetPubAttr failed with %#x!\n", __FUNCTION__, s32Ret);
return s32Ret;
}
/* 8. isp init */
s32Ret = HI_MPI_ISP_Init(IspDev);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_ISP_Init failed!\n", __FUNCTION__);
return s32Ret;
}
gbIspInited = HI_TRUE;
return HI_SUCCESS;
}
HI_VOID* Test_ISP_Run(HI_VOID *param)
{
ISP_DEV IspDev = 0;
HI_MPI_ISP_Run(IspDev);
return HI_NULL;
}
/******************************************************************************
* funciton : ISP Run
******************************************************************************/
HI_S32 SAMPLE_COMM_ISP_Run()
{
#if 1
#if (CHIP_ID == CHIP_HI3516C_V200)
if (0 != pthread_create(&gs_IspPid, 0, (void* (*)(void*))Test_ISP_Run, NULL))
{
printf("%s: create isp running thread failed!\n", __FUNCTION__);
return HI_FAILURE;
}
usleep(1000);
#else
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 4096 * 1024);
if (0 != pthread_create(&gs_IspPid, &attr, (void* (*)(void*))Test_ISP_Run, NULL))
{
printf("%s: create isp running thread failed!\n", __FUNCTION__);
pthread_attr_destroy(&attr);
return HI_FAILURE;
}
usleep(1000);
pthread_attr_destroy(&attr);
#endif
#else
/* configure thread priority */
if (1)
{
#include <sched.h>
pthread_attr_t attr;
struct sched_param param;
int newprio = 50;
pthread_attr_init(&attr);
if (1)
{
int policy = 0;
int min, max;
pthread_attr_getschedpolicy(&attr, &policy);
printf("-->default thread use policy is %d --<\n", policy);
pthread_attr_setschedpolicy(&attr, SCHED_RR);
pthread_attr_getschedpolicy(&attr, &policy);
printf("-->current thread use policy is %d --<\n", policy);
switch (policy)
{
case SCHED_FIFO:
printf("-->current thread use policy is SCHED_FIFO --<\n");
break;
case SCHED_RR:
printf("-->current thread use policy is SCHED_RR --<\n");
break;
case SCHED_OTHER:
printf("-->current thread use policy is SCHED_OTHER --<\n");
break;
default:
printf("-->current thread use policy is UNKNOW --<\n");
break;
}
min = sched_get_priority_min(policy);
max = sched_get_priority_max(policy);
printf("-->current thread policy priority range (%d ~ %d) --<\n", min, max);
}
pthread_attr_getschedparam(&attr, ¶m);
printf("-->default isp thread priority is %d , next be %d --<\n", param.sched_priority, newprio);
param.sched_priority = newprio;
pthread_attr_setschedparam(&attr, ¶m);
if (0 != pthread_create(&gs_IspPid, &attr, (void* (*)(void*))HI_MPI_ISP_Run, NULL))
{
printf("%s: create isp running thread failed!\n", __FUNCTION__);
return HI_FAILURE;
}
pthread_attr_destroy(&attr);
}
#endif
return HI_SUCCESS;
}
/******************************************************************************
* funciton : change between linear and wdr mode
******************************************************************************/
HI_S32 SAMPLE_COMM_ISP_ChangeSensorMode(HI_U8 u8Mode)
{
ISP_DEV IspDev = 0;
HI_S32 s32Ret;
ISP_WDR_MODE_S stWDRMode;
stWDRMode.enWDRMode = u8Mode;
s32Ret = HI_MPI_ISP_SetWDRMode(IspDev, &stWDRMode);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_ISP_SetWDRMode failed with %#x!\n",
__FUNCTION__, s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
/******************************************************************************
* funciton : stop ISP, and stop isp thread
******************************************************************************/
HI_VOID SAMPLE_COMM_ISP_Stop()
{
ISP_DEV IspDev = 0;
HI_S32 s32Ret;
ALG_LIB_S stLib;
if (!gbIspInited)
{
return;
}
HI_MPI_ISP_Exit(IspDev);
if (gs_IspPid)
{
pthread_join(gs_IspPid, 0);
gs_IspPid = 0;
}
gbIspInited = HI_FALSE;
/* unregister hisi af lib */
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AF_LIB_NAME);
s32Ret = HI_MPI_AF_UnRegister(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_AF_UnRegister failed!\n", __FUNCTION__);
return;
}
/* unregister hisi awb lib */
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AWB_LIB_NAME);
s32Ret = HI_MPI_AWB_UnRegister(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_AWB_UnRegister failed!\n", __FUNCTION__);
return;
}
/* unregister hisi ae lib */
stLib.s32Id = 0;
strcpy(stLib.acLibName, HI_AE_LIB_NAME);
s32Ret = HI_MPI_AE_UnRegister(IspDev, &stLib);
if (s32Ret != HI_SUCCESS)
{
printf("%s: HI_MPI_AE_UnRegister failed!\n", __FUNCTION__);
return;
}
/* sensor unregister callback */
s32Ret = sensor_unregister_callback();
if (s32Ret != HI_SUCCESS)
{
printf("%s: sensor_unregister_callback failed with %#x!\n", \
__FUNCTION__, s32Ret);
return;
}
return;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */