-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_comm_vo.c
347 lines (298 loc) · 10.5 KB
/
sample_comm_vo.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
/******************************************************************************
Some simple Hisilicon Hi3531 video output 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"
HI_S32 SAMPLE_COMM_VO_GetWH(VO_INTF_SYNC_E enIntfSync, HI_U32 *pu32W,HI_U32 *pu32H, HI_U32 *pu32Frm)
{
switch (enIntfSync)
{
case VO_OUTPUT_PAL : *pu32W = 720; *pu32H = 576; *pu32Frm = 25; break;
case VO_OUTPUT_NTSC : *pu32W = 720; *pu32H = 480; *pu32Frm = 30; break;
case VO_OUTPUT_576P50 : *pu32W = 720; *pu32H = 576; *pu32Frm = 50; break;
case VO_OUTPUT_480P60 : *pu32W = 720; *pu32H = 480; *pu32Frm = 60; break;
case VO_OUTPUT_800x600_60: *pu32W = 800; *pu32H = 600; *pu32Frm = 60; break;
case VO_OUTPUT_720P50 : *pu32W = 1280; *pu32H = 720; *pu32Frm = 50; break;
case VO_OUTPUT_720P60 : *pu32W = 1280; *pu32H = 720; *pu32Frm = 60; break;
case VO_OUTPUT_1080I50 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 50; break;
case VO_OUTPUT_1080I60 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 60; break;
case VO_OUTPUT_1080P24 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 24; break;
case VO_OUTPUT_1080P25 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 25; break;
case VO_OUTPUT_1080P30 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 30; break;
case VO_OUTPUT_1080P50 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 50; break;
case VO_OUTPUT_1080P60 : *pu32W = 1920; *pu32H = 1080; *pu32Frm = 60; break;
case VO_OUTPUT_1024x768_60: *pu32W = 1024; *pu32H = 768; *pu32Frm = 60; break;
case VO_OUTPUT_1280x1024_60: *pu32W = 1280; *pu32H = 1024; *pu32Frm = 60; break;
case VO_OUTPUT_1366x768_60: *pu32W = 1366; *pu32H = 768; *pu32Frm = 60; break;
case VO_OUTPUT_1440x900_60: *pu32W = 1440; *pu32H = 900; *pu32Frm = 60; break;
case VO_OUTPUT_1280x800_60: *pu32W = 1280; *pu32H = 800; *pu32Frm = 60; break;
case VO_OUTPUT_1600x1200_60: *pu32W = 1600; *pu32H = 1200; *pu32Frm = 60; break;
case VO_OUTPUT_1680x1050_60: *pu32W = 1680; *pu32H = 1050; *pu32Frm = 60; break;
case VO_OUTPUT_1920x1200_60: *pu32W = 1920; *pu32H = 1200; *pu32Frm = 60; break;
case VO_OUTPUT_320X240_60: *pu32W = 320; *pu32H = 240; *pu32Frm = 30; break;
case VO_OUTPUT_320X240_50: *pu32W = 320; *pu32H = 240; *pu32Frm = 50; break;
case VO_OUTPUT_240X320_50: *pu32W = 240; *pu32H = 320; *pu32Frm = 50; break;
case VO_OUTPUT_USER : *pu32W = 720; *pu32H = 576; *pu32Frm = 25; break;
default:
SAMPLE_PRT("vo enIntfSync not support!\n");
return HI_FAILURE;
}
return HI_SUCCESS;
}
/******************************************************************************
* function : Set system memory location
******************************************************************************/
HI_S32 SAMPLE_COMM_VO_MemConfig(VO_DEV VoDev, HI_CHAR *pcMmzName)
{
HI_S32 s32Ret = HI_SUCCESS;
MPP_CHN_S stMppChnVO;
/* config vo dev */
stMppChnVO.enModId = HI_ID_VOU;
stMppChnVO.s32DevId = VoDev;
stMppChnVO.s32ChnId = 0;
s32Ret = HI_MPI_SYS_SetMemConf(&stMppChnVO, pcMmzName);
if (s32Ret)
{
SAMPLE_PRT("HI_MPI_SYS_SetMemConf ERR !\n");
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VO_StartDev(VO_DEV VoDev, VO_PUB_ATTR_S *pstPubAttr)
{
HI_S32 s32Ret = HI_SUCCESS;
//printf("-----------------dev:%d\n", VoDev);
s32Ret = HI_MPI_VO_SetPubAttr(VoDev, pstPubAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VO_Enable(VoDev);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_StopDev(VO_DEV VoDev)
{
HI_S32 s32Ret = HI_SUCCESS;
s32Ret = HI_MPI_VO_Disable(VoDev);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_StartLayer(VO_LAYER VoLayer,const VO_VIDEO_LAYER_ATTR_S *pstLayerAttr, HI_BOOL bVgsBypass)
{
HI_S32 s32Ret = HI_SUCCESS;
if (!bVgsBypass)
{
s32Ret = HI_MPI_VO_SetDispBufLen(VoLayer, 3);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
s32Ret = HI_MPI_VO_SetVideoLayerAttr(VoLayer, pstLayerAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VO_EnableVideoLayer(VoLayer);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_StopLayer(VO_LAYER VoLayer)
{
HI_S32 s32Ret = HI_SUCCESS;
s32Ret = HI_MPI_VO_DisableVideoLayer(VoLayer);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_StartChn(VO_LAYER VoLayer, SAMPLE_VO_MODE_E enMode)
{
HI_S32 i;
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32WndNum = 0;
HI_U32 u32Square = 0;
HI_U32 u32Width = 0;
HI_U32 u32Height = 0;
VO_CHN_ATTR_S stChnAttr;
VO_VIDEO_LAYER_ATTR_S stLayerAttr;
switch (enMode)
{
case VO_MODE_1MUX:
u32WndNum = 1;
u32Square = 1;
break;
case VO_MODE_2MUX:
u32WndNum = 2;
u32Square = 2;
break;
default:
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VO_GetVideoLayerAttr(VoLayer, &stLayerAttr);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
u32Width = stLayerAttr.stImageSize.u32Width;
u32Height = stLayerAttr.stImageSize.u32Height;
printf("u32Width:%d, u32Square:%d\n", u32Width, u32Square);
for (i=0; i<u32WndNum; i++)
{
stChnAttr.stRect.s32X = ALIGN_BACK((u32Width/u32Square) * (i%u32Square), 2);
stChnAttr.stRect.s32Y = ALIGN_BACK((u32Height/u32Square) * (i/u32Square), 2);
stChnAttr.stRect.u32Width = ALIGN_BACK(u32Width/u32Square, 2);
stChnAttr.stRect.u32Height = ALIGN_BACK(u32Height/u32Square, 2);
stChnAttr.u32Priority = 0;
stChnAttr.bDeflicker = HI_FALSE;
s32Ret = HI_MPI_VO_SetChnAttr(VoLayer, i, &stChnAttr);
if (s32Ret != HI_SUCCESS)
{
printf("%s(%d):failed with %#x!\n",\
__FUNCTION__,__LINE__, s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VO_EnableChn(VoLayer, i);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_COMM_VO_StopChn(VO_LAYER VoLayer, SAMPLE_VO_MODE_E enMode)
{
HI_S32 i;
HI_S32 s32Ret = HI_SUCCESS;
HI_U32 u32WndNum = 0;
switch (enMode)
{
case VO_MODE_1MUX:
{
u32WndNum = 1;
break;
}
case VO_MODE_2MUX:
{
u32WndNum = 2;
break;
}
default:
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
for (i=0; i<u32WndNum; i++)
{
s32Ret = HI_MPI_VO_DisableChn(VoLayer, i);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_BindVpss(VO_LAYER VoLayer,VO_CHN VoChn,VPSS_GRP VpssGrp,VPSS_CHN VpssChn)
{
HI_S32 s32Ret = HI_SUCCESS;
MPP_CHN_S stSrcChn;
MPP_CHN_S stDestChn;
stSrcChn.enModId = HI_ID_VPSS;
stSrcChn.s32DevId = VpssGrp;
stSrcChn.s32ChnId = VpssChn;
stDestChn.enModId = HI_ID_VOU;
stDestChn.s32DevId = VoLayer;
stDestChn.s32ChnId = VoChn;
s32Ret = HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_UnBindVpss(VO_LAYER VoLayer,VO_CHN VoChn,VPSS_GRP VpssGrp,VPSS_CHN VpssChn)
{
HI_S32 s32Ret = HI_SUCCESS;
MPP_CHN_S stSrcChn;
MPP_CHN_S stDestChn;
stSrcChn.enModId = HI_ID_VPSS;
stSrcChn.s32DevId = VpssGrp;
stSrcChn.s32ChnId = VpssChn;
stDestChn.enModId = HI_ID_VOU;
stDestChn.s32DevId = VoLayer;
stDestChn.s32ChnId = VoChn;
s32Ret = HI_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
if (s32Ret != HI_SUCCESS)
{
SAMPLE_PRT("failed with %#x!\n", s32Ret);
return HI_FAILURE;
}
return s32Ret;
}
HI_S32 SAMPLE_COMM_VO_BindVi(VO_LAYER VoLayer, VO_CHN VoChn, VI_CHN ViChn)
{
MPP_CHN_S stSrcChn, stDestChn;
stSrcChn.enModId = HI_ID_VIU;
stSrcChn.s32DevId = 0;
stSrcChn.s32ChnId = ViChn;
stDestChn.enModId = HI_ID_VOU;
stDestChn.s32ChnId = VoChn;
stDestChn.s32DevId = VoLayer;
return HI_MPI_SYS_Bind(&stSrcChn, &stDestChn);
}
HI_S32 SAMPLE_COMM_VO_UnBindVi(VO_LAYER VoLayer, VO_CHN VoChn)
{
MPP_CHN_S stDestChn;
stDestChn.enModId = HI_ID_VOU;
stDestChn.s32DevId = VoLayer;
stDestChn.s32ChnId = VoChn;
return HI_MPI_SYS_UnBind(NULL, &stDestChn);
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */