-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_comm_vpss.c
380 lines (325 loc) · 10.6 KB
/
sample_comm_vpss.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
/******************************************************************************
Some simple Hisilicon Hi35xx video input 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"
/******************************************************************************
* function : Set vpss system memory location
******************************************************************************/
HI_S32 SAMPLE_COMM_VPSS_MemConfig()
{
HI_CHAR * pcMmzName;
MPP_CHN_S stMppChnVpss;
HI_S32 s32Ret, i;
/*vpss group max is 64, not need config vpss chn.*/
for(i=0;i<64;i++)
{
stMppChnVpss.enModId = HI_ID_VPSS;
stMppChnVpss.s32DevId = i;
stMppChnVpss.s32ChnId = 0;
if(0 == (i%2))
{
pcMmzName = NULL;
}
else
{
pcMmzName = "ddr1";
}
/*vpss*/
s32Ret = HI_MPI_SYS_SetMemConf(&stMppChnVpss, pcMmzName);
if (HI_SUCCESS != s32Ret)
{
SAMPLE_PRT("Vpss HI_MPI_SYS_SetMemConf ERR !\n");
return HI_FAILURE;
}
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VPSS_StartGroup(VPSS_GRP VpssGrp, VPSS_GRP_ATTR_S *pstVpssGrpAttr)
{
HI_S32 s32Ret;
VPSS_NR_PARAM_U unNrParam = {{0}};
if (VpssGrp < 0 || VpssGrp > VPSS_MAX_GRP_NUM)
{
printf("VpssGrp%d is out of rang. \n", VpssGrp);
return HI_FAILURE;
}
if (HI_NULL == pstVpssGrpAttr)
{
printf("null ptr,line%d. \n", __LINE__);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, pstVpssGrpAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_CreateGrp failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*** set vpss 3DNR param ***/
s32Ret = HI_MPI_VPSS_GetNRParam(VpssGrp, &unNrParam);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_SetNRParam(VpssGrp, &unNrParam);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VPSS_EnableChn(VPSS_GRP VpssGrp, VPSS_CHN VpssChn,
VPSS_CHN_ATTR_S *pstVpssChnAttr,
VPSS_CHN_MODE_S *pstVpssChnMode,
VPSS_EXT_CHN_ATTR_S *pstVpssExtChnAttr)
{
HI_S32 s32Ret;
if (VpssGrp < 0 || VpssGrp > VPSS_MAX_GRP_NUM)
{
printf("VpssGrp%d is out of rang[0,%d]. \n", VpssGrp, VPSS_MAX_GRP_NUM);
return HI_FAILURE;
}
if (VpssChn < 0 || VpssChn > VPSS_MAX_CHN_NUM)
{
printf("VpssChn%d is out of rang[0,%d]. \n", VpssChn, VPSS_MAX_CHN_NUM);
return HI_FAILURE;
}
if (HI_NULL == pstVpssChnAttr && HI_NULL == pstVpssExtChnAttr)
{
printf("null ptr,line%d. \n", __LINE__);
return HI_FAILURE;
}
if (VpssChn < VPSS_MAX_PHY_CHN_NUM)
{
s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, pstVpssChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x\n", s32Ret);
return HI_FAILURE;
}
}
else
{
s32Ret = HI_MPI_VPSS_SetExtChnAttr(VpssGrp, VpssChn, pstVpssExtChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return HI_FAILURE;
}
}
if (VpssChn < VPSS_MAX_PHY_CHN_NUM && HI_NULL != pstVpssChnMode)
{
s32Ret = HI_MPI_VPSS_SetChnMode(VpssGrp, VpssChn, pstVpssChnMode);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return HI_FAILURE;
}
}
s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_EnableChn failed with %#x\n", s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VPSS_StopGroup(VPSS_GRP VpssGrp)
{
HI_S32 s32Ret;
if (VpssGrp < 0 || VpssGrp > VPSS_MAX_GRP_NUM)
{
printf("VpssGrp%d is out of rang[0,%d]. \n", VpssGrp, VPSS_MAX_GRP_NUM);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_StopGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_DestroyGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VPSS_DisableChn(VPSS_GRP VpssGrp, VPSS_CHN VpssChn)
{
HI_S32 s32Ret;
if (VpssGrp < 0 || VpssGrp > VPSS_MAX_GRP_NUM)
{
printf("VpssGrp%d is out of rang[0,%d]. \n", VpssGrp, VPSS_MAX_GRP_NUM);
return HI_FAILURE;
}
if (VpssChn < 0 || VpssChn > VPSS_MAX_CHN_NUM)
{
printf("VpssChn%d is out of rang[0,%d]. \n", VpssChn, VPSS_MAX_CHN_NUM);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_DisableChn(VpssGrp, VpssChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("%s failed with %#x\n", __FUNCTION__, s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
/*****************************************************************************
* function : start vpss. VPSS chn with frame
*****************************************************************************/
HI_S32 SAMPLE_COMM_VPSS_Start(HI_S32 s32GrpCnt, SIZE_S *pstSize, HI_S32 s32ChnCnt,VPSS_GRP_ATTR_S *pstVpssGrpAttr)
{
VPSS_GRP VpssGrp;
VPSS_CHN VpssChn;
VPSS_GRP_ATTR_S stGrpAttr = {0};
VPSS_CHN_ATTR_S stChnAttr = {0};
VPSS_NR_PARAM_U unNrParam = {{0}};
HI_S32 s32Ret;
HI_S32 i, j;
/*** Set Vpss Grp Attr ***/
if(NULL == pstVpssGrpAttr)
{
stGrpAttr.u32MaxW = pstSize->u32Width;
stGrpAttr.u32MaxH = pstSize->u32Height;
stGrpAttr.bIeEn = HI_FALSE;
stGrpAttr.bNrEn = HI_TRUE;
stGrpAttr.bHistEn = HI_FALSE;
stGrpAttr.enDieMode = VPSS_DIE_MODE_NODIE;
stGrpAttr.enPixFmt = SAMPLE_PIXEL_FORMAT;
}
else
{
memcpy(&stGrpAttr,pstVpssGrpAttr,sizeof(VPSS_GRP_ATTR_S));
}
for(i=0; i<s32GrpCnt; i++)
{
VpssGrp = i;
/*** create vpss group ***/
s32Ret = HI_MPI_VPSS_CreateGrp(VpssGrp, &stGrpAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_CreateGrp failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*** set vpss param ***/
s32Ret = HI_MPI_VPSS_GetNRParam(VpssGrp, &unNrParam);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_SetNRParam(VpssGrp, &unNrParam);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
/*** enable vpss chn, with frame ***/
for(j=0; j<s32ChnCnt; j++)
{
VpssChn = j;
/* Set Vpss Chn attr */
stChnAttr.bSpEn = HI_FALSE;
stChnAttr.bBorderEn = HI_TRUE;
stChnAttr.stBorder.u32Color = 0xff00;
stChnAttr.stBorder.u32LeftWidth = 2;
stChnAttr.stBorder.u32RightWidth = 2;
stChnAttr.stBorder.u32TopWidth = 2;
stChnAttr.stBorder.u32BottomWidth = 2;
s32Ret = HI_MPI_VPSS_SetChnAttr(VpssGrp, VpssChn, &stChnAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_SetChnAttr failed with %#x\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VPSS_EnableChn(VpssGrp, VpssChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_EnableChn failed with %#x\n", s32Ret);
return HI_FAILURE;
}
}
/*** start vpss group ***/
s32Ret = HI_MPI_VPSS_StartGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("HI_MPI_VPSS_StartGrp failed with %#x\n", s32Ret);
return HI_FAILURE;
}
}
return HI_SUCCESS;
}
/*****************************************************************************
* function : disable vi dev
*****************************************************************************/
HI_S32 SAMPLE_COMM_VPSS_Stop(HI_S32 s32GrpCnt, HI_S32 s32ChnCnt)
{
HI_S32 i, j;
HI_S32 s32Ret = HI_SUCCESS;
VPSS_GRP VpssGrp;
VPSS_CHN VpssChn;
for(i=0; i<s32GrpCnt; i++)
{
VpssGrp = i;
s32Ret = HI_MPI_VPSS_StopGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
for(j=0; j<s32ChnCnt; j++)
{
VpssChn = j;
s32Ret = HI_MPI_VPSS_DisableChn(VpssGrp, VpssChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
s32Ret = HI_MPI_VPSS_DestroyGrp(VpssGrp);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
return HI_SUCCESS;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */