forked from starimpact/myimpsrc2
/
sample_common.c
executable file
·2273 lines (2010 loc) · 62.4 KB
/
sample_common.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
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), 2001-2011, Hisilicon Tech. Co., Ltd.
******************************************************************************
File Name : sample_common.c
Version : Initial Draft
Author : Hisilicon multimedia software group
Created : 2009/07/04
Description : common functions for sample.
In default,
VI capture TV signals.
VO display on TV screen.
History :
1.Date : 2009/07/04
Author : Hi3520MPP
Modification: Created file.
2.Date : 2010/02/12
Author : Hi3520MPP
Modification: Add video loss detect demo
******************************************************************************/
#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_common.h"
#define TW2865_FILE "/dev/tw2865dev"
#define TW2864_A_FILE "/dev/tw2864adev"
#define TW2864_B_FILE "/dev/tw2864bdev"
#define TW2864_C_FILE "/dev/tw2864cdev"
#define TW2864_D_FILE "/dev/tw2864ddev"
#define ADV7441_DEV_FILE "/dev/adv7441"
/************!!!!attention:********
The test code havn't check whether vi dev is out of range(0-3)
*********************************/
#define G_VIDEV_START 0
/* video input into VI.
** Only valid when input from ADC, such as TW2864, TW2815, etc.
** VI samples that run for PAL will change to NTSC if modify it
** to VIDEO_ENCODING_MODE_NTSC.
*/
#if 1
VIDEO_NORM_E gs_enViNorm = VIDEO_ENCODING_MODE_PAL;
VO_INTF_SYNC_E gs_enSDTvMode = VO_OUTPUT_PAL;
#else
VIDEO_NORM_E gs_enViNorm = VIDEO_ENCODING_MODE_NTSC;
VO_INTF_SYNC_E gs_enSDTvMode = VO_OUTPUT_NTSC;
#endif
/************************************************************************************/
const HI_U8 g_SOI[2] = {0xFF, 0xD8};
const HI_U8 g_EOI[2] = {0xFF, 0xD9};
/*****************************************************************************
Prototype : SAMPLE_ADV7441_CfgV
Description : config ADV7441
Input : enFormat **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
*****************************************************************************/
HI_S32 SAMPLE_ADV7441_CfgV(ADV7441_VIDEO_FORMAT_E enFormat)
{
HI_S32 adv7441_fd;
adv7441_fd = open(ADV7441_DEV_FILE, O_RDWR);
if (adv7441_fd < 0)
{
printf("warning: open adv7441 dev failed\n");
return -1;
}
/*now enFormat support 0:VIDEO_FORMAT_720P_60HZ, 1: VIDEO_FORMAT_1080I_60HZ*/
if (ioctl(adv7441_fd, ADV7441_SET_VIDEO_FORMAT, &enFormat))
{
printf("set adv7441 video format failed\n");
close(adv7441_fd);
return -1;
}
close(adv7441_fd);
return 0;
}
/*****************************************************************************
Prototype : SAMPLE_TW2864_CfgV
Description : config video of tw2864
Input : enVideoMode **
enWorkMode **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
Remark : in default, TW2864 works in 4D1 mode.
*****************************************************************************/
HI_S32 SAMPLE_TW2864_CfgV(VI_WORK_MODE_E enViWorkMode)
{
HI_S32 i, j, s32Ret;
HI_S32 fd2864a = -1;
HI_S32 fd2864b = -1;
HI_S32 fd2864[2];
HI_S32 s32VideoMode;
tw2864_set_videomode stNorm;
fd2864a = open(TW2864_A_FILE, O_RDWR);
fd2864b = open(TW2864_B_FILE, O_RDWR);
if ((fd2864b < 0) || (fd2864a < 0))
{
printf("can't open tw2864,fd(%d,%d)\n", fd2864a, fd2864b);
return HI_FAILURE;
}
fd2864[0] = fd2864a;
fd2864[1] = fd2864b;
/*in driver tw2864,define as 0:auto;1:NTSC;2:PAL */
s32VideoMode = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 2 : 1;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 4; j++)
{
stNorm.ch = j;
stNorm.mode = s32VideoMode;
s32Ret = ioctl(fd2864[i], TW2864_SET_VIDEO_MODE, &stNorm);
if (0 != s32Ret)
{
printf("set 2864(%d) video mode fail;err:%x!\n", i, s32Ret);
return s32Ret;
}
}
}
close(fd2864a);
close(fd2864b);
printf("============================================\n");
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SAMPLE_TW2865_CfgV
Description : config video of tw2865
Input : enVideoMode **
enWorkMode **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
Remark : in default, TW2865 works in 4D1 mode.
*****************************************************************************/
HI_S32 SAMPLE_TW2865_CfgV(VIDEO_NORM_E enVideoMode,VI_WORK_MODE_E enWorkMode)
{
int fd, i;
int video_mode;
tw2865_video_norm stVideoMode;
tw2865_work_mode work_mode;
#ifdef hi3515
int chip_cnt = 2;
#else
int chip_cnt = 4;
#endif
fd = open(TW2865_FILE, O_RDWR);
if (fd < 0)
{
printf("open %s fail\n", TW2865_FILE);
return -1;
}
video_mode = (VIDEO_ENCODING_MODE_PAL == enVideoMode) ? TW2865_PAL : TW2865_NTSC ;
for (i=0; i<chip_cnt; i++)
{
stVideoMode.chip = i;
stVideoMode.mode = video_mode;
if (ioctl(fd, TW2865_SET_VIDEO_NORM, &stVideoMode))
{
printf("set tw2865(%d) video mode fail\n", i);
close(fd);
return -1;
}
}
for (i=0; i<chip_cnt; i++)
{
work_mode.chip = i;
if (VI_WORK_MODE_4D1 == enWorkMode)
{
work_mode.mode = TW2865_4D1_MODE;
}
else if (VI_WORK_MODE_2D1 == enWorkMode)
{
work_mode.mode = TW2865_2D1_MODE;
}
else
{
printf("work mode not support\n");
return -1;
}
ioctl(fd, TW2865_SET_WORK_MODE, &work_mode);
}
close(fd);
return 0;
}
/*****************************************************************************
Prototype : SAMPLE_MT9D131_CfgV
Description : config video of MT9D131
Input : val ** 1: VGA 4: 2.0M
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
History
*****************************************************************************/
HI_S32 SAMPLE_MT9D131_CfgV(HI_S32 val)
{
HI_S32 fd, tmp;
fd = open("/dev/mt9d131", O_RDWR);
if (fd < 0)
{
printf("open dev mt9d131 err\n");
return -1;
}
/*in driver mt9d131,IMAGESIZE only support :01:DC_VAL_VGA,04:DC_VAL_UXGA*/
tmp = val;
if (ioctl(fd, DC_SET_IMAGESIZE, &tmp))
{
perror("set mt9d131 size err");
return -1;
}
/*in driver mt9d131,POWERFREQ only support :01:DC_VAL_50HZ,02:DC_VAL_60HZ*/
tmp = DC_VAL_60HZ;
if (ioctl(fd, DC_SET_POWERFREQ, &tmp))
{
perror("set mt9d131 power freq err");
return -1;
}
printf("set mt9d131 %d ok\n", val);
close(fd);
return 0;
}
typedef struct
{
int start;
pthread_t Pid;
int chn_cnt;
} SAMPLE_VIDEO_LOSS;
static SAMPLE_VIDEO_LOSS s_stVideoLoss;
void *SampleVLossDetProc(void *parg)
{
int fd, i;
VI_DEV ViDev;
VI_CHN ViChn;
tw2865_video_loss video_loss;
SAMPLE_VIDEO_LOSS *ctl = (SAMPLE_VIDEO_LOSS*)parg;
fd = open(TW2865_FILE, O_RDWR);
if (fd < 0)
{
printf("open %s fail\n", TW2865_FILE);
ctl->start = 0;
return NULL;
}
while (ctl->start)
{
for (i = 0; i < ctl->chn_cnt; i++)
{
video_loss.chip = i/4;
video_loss.ch = i%4;
ioctl(fd, TW2865_GET_VIDEO_LOSS, &video_loss);
#ifdef hi3515
ViDev = (i/4)*2;
#else
ViDev = i/4;
#endif
ViChn = i%4;
if (video_loss.is_lost)
{
HI_MPI_VI_EnableUserPic(ViDev, ViChn);
}
else
{
HI_MPI_VI_DisableUserPic(ViDev, ViChn);
}
}
usleep(500000);
}
close(fd);
ctl->start = 0;
return NULL;
}
void SAMPLE_StartVLossDet(int chn_cnt)
{
s_stVideoLoss.start = 1;
s_stVideoLoss.chn_cnt = chn_cnt;
pthread_create(&s_stVideoLoss.Pid, 0, SampleVLossDetProc, &s_stVideoLoss);
}
void SAMPLE_StopVLossDet()
{
if (s_stVideoLoss.start)
{
s_stVideoLoss.start = 0;
pthread_join(s_stVideoLoss.start, 0);
}
}
/*****************************************************************************
Prototype : SAMPLE_InitMpp
Description : Init Mpp
Input : pstVbConf **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
History
1.Date : 2009/7/4
Author : c55300
Modification : Created function
*****************************************************************************/
HI_S32 SAMPLE_InitMPP(VB_CONF_S *pstVbConf)
{
MPP_SYS_CONF_S stSysConf = {0};
HI_MPI_SYS_Exit();
HI_MPI_VB_Exit();
if (HI_MPI_VB_SetConf(pstVbConf))
{
printf("HI_MPI_VB_SetConf failed!\n");
return -1;
}
if (HI_MPI_VB_Init())
{
printf("HI_MPI_VB_Init failed!\n");
return -1;
}
stSysConf.u32AlignWidth = 16;
if (HI_MPI_SYS_SetConf(&stSysConf))
{
printf("conf : system config failed!\n");
return -1;
}
if (HI_MPI_SYS_Init())
{
printf("sys init failed!\n");
return -1;
}
return 0;
}
/*****************************************************************************
Prototype : SAMPLE_ExitMpp
Description : Exit Mpp
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
*****************************************************************************/
HI_S32 SAMPLE_ExitMPP(HI_VOID)
{
if (HI_MPI_SYS_Exit())
{
printf("sys exit fail\n");
return -1;
}
if (HI_MPI_VB_Exit())
{
printf("vb exit fail\n");
return -1;
}
return 0;
}
/*****************************************************************************
Prototype : SampleVichnPerDev
Description : get number of channel of VI device with difference mode.
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
*****************************************************************************/
static HI_S32 SampleVichnPerDev(VI_INPUT_MODE_E enViInputMode, VI_WORK_MODE_E enViWorkMode)
{
if ((VI_MODE_BT656 == enViInputMode) && (VI_WORK_MODE_1D1 == enViWorkMode))
{
return 1;
}
else if ((VI_MODE_BT656 == enViInputMode) && (VI_WORK_MODE_2D1 == enViWorkMode))
{
return 2;
}
else if ((VI_MODE_BT656 == enViInputMode) && (VI_WORK_MODE_4D1 == enViWorkMode))
{
return 4;
}
else if ((VI_MODE_BT656 == enViInputMode) && (VI_WORK_MODE_4HALFD1 == enViWorkMode))
{
return 4;
}
else if ((VI_MODE_BT601 == enViInputMode) || (VI_MODE_DIGITAL_CAMERA == enViInputMode)
|| (VI_MODE_BT1120_PROGRESSIVE == enViInputMode) || (VI_MODE_BT1120_INTERLACED == enViInputMode))
{
return 1;
}
else
{
return 0;
}
}
/*****************************************************************************
Prototype : SAMPLE_GetViChnPerDev
Description : with different mode, vi device can enter different number of
channel. call this function to get.
Input : ViDev **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
History
Remark : vi device attribute must be set first.
*****************************************************************************/
HI_S32 SAMPLE_GetViChnPerDev(VI_DEV ViDev)
{
VI_PUB_ATTR_S stPubAttr;
HI_S32 s32ViChnPerDev;
HI_S32 s32Ret;
s32Ret = HI_MPI_VI_GetPubAttr(ViDev, &stPubAttr);
if (HI_SUCCESS != s32Ret)
{
printf("Get vi(%d) channel per dev fail\n", ViDev);
return 0;
}
s32ViChnPerDev = SampleVichnPerDev(stPubAttr.enInputMode, stPubAttr.enWorkMode);
return s32ViChnPerDev;
}
HI_S32 SAMPLE_PicSize2WH(PIC_SIZE_E enPicSize, HI_S32* s32Width, HI_S32* s32Height)
{
switch ( enPicSize )
{
case PIC_QCIF:
*s32Width = 176;
*s32Height = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 144 : 120;
break;
case PIC_CIF:
*s32Width = 352;
*s32Height = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 288 : 240;
break;
case PIC_2CIF:
*s32Width = 352;
*s32Height = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 576 : 480;
break;
case PIC_HD1:
*s32Width = 704;
*s32Height = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 288 : 240;
break;
case PIC_D1:
*s32Width = 704;
*s32Height = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 576 : 480;
break;
case PIC_QVGA:
*s32Width = 320;
*s32Height = 240;
break;
case PIC_VGA:
*s32Width = 640;
*s32Height = 480;
break;
case PIC_XGA:
*s32Width = 1024;
*s32Height = 768;
break;
case PIC_SXGA:
*s32Width = 1400;
*s32Height = 1050;
break;
case PIC_UXGA:
*s32Width = 1600;
*s32Height = 1200;
break;
case PIC_WSXGA:
*s32Width = 1680;
*s32Height = 1050;
break;
default:
printf("err pic size\n");
return HI_FAILURE;
}
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SampleParseVoOutput
Description : parse vo output, to decide dispaly widht,height and rate.
Input : enVoOutput **
Output : s32Width **
s32Height **
s32Rate **
Return Value :
Global Variable
Read Only :
Read & Write :
History
1.Date : 2009/7/27
Author : c55300
Modification : Created function
*****************************************************************************/
HI_S32 SampleParseVoOutput(VO_INTF_SYNC_E enVoOutput,
HI_S32* s32Width, HI_S32* s32Height, HI_S32* s32DisplayRate)
{
switch ( enVoOutput )
{
case VO_OUTPUT_PAL:
*s32Width = 720;
*s32Height = 576;
*s32DisplayRate = 25;
break;
case VO_OUTPUT_NTSC:
*s32Width = 720;
*s32Height = 480;
*s32DisplayRate = 30;
break;
case VO_OUTPUT_720P60:
*s32Width = 1280;
*s32Height = 720;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_1080I60:
*s32Width = 1920;
*s32Height = 1080;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_1080P30:
*s32Width = 1920;
*s32Height = 1080;
*s32DisplayRate = 30;
break;
case VO_OUTPUT_800x600_60:
*s32Width = 800;
*s32Height = 600;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_1024x768_60:
*s32Width = 1024;
*s32Height = 768;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_1280x1024_60:
*s32Width = 1280;
*s32Height = 1024;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_1366x768_60:
*s32Width = 1366;
*s32Height = 768;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_1440x900_60:
*s32Width = 1440;
*s32Height = 900;
*s32DisplayRate = 60;
break;
case VO_OUTPUT_USER:
printf("Why call me? You should set display size in VO_OUTPUT_USER.\n");
break;
default:
*s32Width = 720;
*s32Height = 576;
*s32DisplayRate = 25;
printf(" vo display size is (720, 576).\n");
break;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_StartViDev(VI_INPUT_MODE_E enInputMode)
{
HI_S32 s32Ret;
VI_DEV ViDev;
VI_PUB_ATTR_S stViDevAttr;
stViDevAttr.enInputMode = enInputMode;
if (VI_MODE_BT656 == stViDevAttr.enInputMode)
{
stViDevAttr.enWorkMode = VI_WORK_MODE_4D1;
}
else
{
printf("%s now not support this input mode\n", __FUNCTION__);
return HI_FAILURE;
}
SAMPLE_TW2865_CfgV(gs_enViNorm, VI_WORK_MODE_4D1);
for (ViDev=0; ViDev < VIU_MAX_DEV_NUM; ViDev++)
{
s32Ret = HI_MPI_VI_SetPubAttr(ViDev, &stViDevAttr);
if (s32Ret)
{
printf("set vi dev %d attr fail,%x\n", ViDev, s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VI_Enable(ViDev);
if (s32Ret)
{
printf("VI dev %d enable fail \n", ViDev);
return s32Ret;
}
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_StartViChn(VI_DEV ViDev, VI_CHN ViChn, PIC_SIZE_E enPicSize)
{
HI_S32 s32Ret;
VI_CHN_ATTR_S stViChnAttr;
stViChnAttr.stCapRect.u32Width = 704;
stViChnAttr.stCapRect.u32Height =
(VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 288 : 240;
stViChnAttr.stCapRect.s32X = 8;
stViChnAttr.stCapRect.s32Y = 0;
stViChnAttr.enViPixFormat = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
stViChnAttr.bHighPri = HI_FALSE;
stViChnAttr.bChromaResample = HI_FALSE;
/* different pic size has different capture method for BT656. */
stViChnAttr.enCapSel = (PIC_D1 == enPicSize || PIC_2CIF == enPicSize) ? \
VI_CAPSEL_BOTH : VI_CAPSEL_BOTTOM;
stViChnAttr.bDownScale = (PIC_D1 == enPicSize || PIC_HD1 == enPicSize) ? \
HI_FALSE : HI_TRUE;
s32Ret = HI_MPI_VI_SetChnAttr(ViDev, ViChn, &stViChnAttr);
if (s32Ret)
{
printf("set vi(%d,%d) attr fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_VI_EnableChn(ViDev, ViChn);
if (s32Ret)
{
printf("set vi(%d,%d) attr fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_StopViChn(VI_DEV ViDev, VI_CHN ViChn)
{
HI_S32 s32Ret;
s32Ret = HI_MPI_VI_DisableChn(ViDev, ViChn);
if (s32Ret)
{
printf("disable (%d,%d) fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SAMPLE_StartViByChn
Description : start vi. Just input how many channels you want to start.
It decide how many devices will be start. vi devices
begin from 0.
Input : s32ChnTotal ** how many vi channels you want to start.
pstViDevAttr ** attribute of vi device
pstViChnAttr ** attribute of vi channel
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
Remark : Used together with SAMPLE_StopViByChn().
All vi devices/channles must have the same attribute.
*****************************************************************************/
HI_S32 SAMPLE_StartViByChn(HI_S32 s32ChnTotal, VI_PUB_ATTR_S* pstViDevAttr, VI_CHN_ATTR_S* pstViChnAttr)
{
HI_S32 i;
VI_DEV ViDev,vi_start;
HI_S32 s32ChnPerDev;
HI_S32 s32DevTotal;
HI_S32 ViChn;
HI_S32 s32Ret;
HI_S32 s32ChnCnt;
HI_U32 u32SrcFrmRate;
s32ChnPerDev = SampleVichnPerDev(pstViDevAttr->enInputMode, pstViDevAttr->enWorkMode);
s32DevTotal = (s32ChnTotal - 1) / s32ChnPerDev + 1;
u32SrcFrmRate = (VIDEO_ENCODING_MODE_PAL == gs_enViNorm) ? 25 : 30;
s32ChnCnt = 0;
vi_start = G_VIDEV_START;
for (i = 0; i < s32DevTotal; i++)
{
#ifdef hi3515
ViDev = 2 * i;/* hi3515 fpga板 设备0和设备2使用4D1模式 设备1和设备3无效 */
#else
ViDev = i;
#endif
s32Ret = HI_MPI_VI_SetPubAttr(ViDev, pstViDevAttr);
if (s32Ret)
{
printf("set vi dev %d attr fail,%x\n", ViDev, s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VI_Enable(ViDev);
if (s32Ret)
{
printf("VI dev %d enable fail \n", ViDev);
return s32Ret;
}
printf("enable vi dev %d ok\n", ViDev);
for (ViChn = 0; ViChn < s32ChnPerDev; ViChn++)
{
s32Ret = HI_MPI_VI_SetChnAttr(ViDev, ViChn, pstViChnAttr);
if (s32Ret)
{
printf("set vi(%d,%d) attr fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_VI_EnableChn(ViDev, ViChn);
if (s32Ret)
{
printf("set vi(%d,%d) attr fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_VI_SetSrcFrameRate(ViDev, ViChn, u32SrcFrmRate);
if (s32Ret)
{
return s32Ret;
}
printf("enable vi(%d,%d) ok\n", ViDev, ViChn);
/* return when all channel ok. */
if(++s32ChnCnt >= s32ChnTotal)
{
return HI_SUCCESS;
}
}
}
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SAMPLE_StopViByChn
Description : stop vi. Just input how many channels you want to stop.
It decide how many devices will be stop. vi devices
begin from 0.
Input : s32ChnTotal ** how many vi channels you want to stop.
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
Remark : Used together with SAMPLE_StartViByChn().
All vi devices/channles must have the same attribute.
*****************************************************************************/
HI_S32 SAMPLE_StopViByChn(HI_S32 s32ChnTotal)
{
VI_DEV ViDev,vi_start;
HI_S32 s32ChnPerDev;
HI_S32 s32DevTotal;
HI_S32 ViChn;
HI_S32 s32Ret;
HI_S32 s32ChnCnt;
s32ChnPerDev = SAMPLE_GetViChnPerDev(0);
s32DevTotal = (s32ChnTotal - 1) / s32ChnPerDev + 1;
s32ChnCnt = 0;
vi_start = G_VIDEV_START;
for (ViDev = vi_start; ViDev <vi_start+ s32DevTotal; ViDev++)
{
for (ViChn = 0; ViChn < s32ChnPerDev; ViChn++)
{
s32Ret = HI_MPI_VI_DisableChn(ViDev, ViChn);
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_VI_DisableChn(%d,%d) fail, err code: 0x%08x\n",
ViDev, ViChn, s32Ret);
}
/* return when all channel ok. */
s32ChnCnt++;
}
HI_MPI_VI_Disable(ViDev);
if(s32ChnCnt >= s32ChnTotal)
{
return HI_SUCCESS;
}
}
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SAMPLE_StartViByDev
Description : start vi device and its channel.
Input : s32ChnTotal ** how many channel start on this device
ViDev ** which vi device you want to start
pstViDevAttr ** attribute of this device
pstViChnAttr ** attribute of all channels on this device
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
Remark : Used together with SAMPLE_StopViByDev().
*****************************************************************************/
HI_S32 SAMPLE_StartViByDev(HI_S32 s32ChnTotal, VI_DEV ViDev, VI_PUB_ATTR_S* pstViDevAttr, VI_CHN_ATTR_S* pstViChnAttr)
{
HI_S32 ViChn;
HI_S32 s32Ret;
s32Ret = HI_MPI_VI_SetPubAttr(ViDev, pstViDevAttr);
if (s32Ret)
{
printf("set vi dev %d attr fail,%x\n", ViDev, s32Ret);
return HI_FAILURE;
}
s32Ret = HI_MPI_VI_Enable(ViDev);
if (s32Ret)
{
printf("VI dev %d enable fail \n", ViDev);
return s32Ret;
}
printf("enable vi dev %d ok\n", ViDev);
for (ViChn = 0; (ViChn < s32ChnTotal); ViChn++)
{
s32Ret = HI_MPI_VI_SetChnAttr(ViDev, ViChn, pstViChnAttr);
if (s32Ret)
{
printf("set vi(%d,%d) attr fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
s32Ret = HI_MPI_VI_EnableChn(ViDev, ViChn);
if (s32Ret)
{
printf("set vi(%d,%d) attr fail,%x\n", ViDev, ViChn, s32Ret);
return s32Ret;
}
printf("enable vi(%d,%d) ok\n", ViDev, ViChn);
}
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SAMPLE_StopViByDev
Description : Stop vi device and all channls on this device.
Input : ViDev **
s32ChnTotal **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
Remark : Used together with SAMPLE_StartViByDev().
*****************************************************************************/
HI_S32 SAMPLE_StopViByDev(HI_S32 s32ChnTotal, VI_DEV ViDev)
{
HI_S32 ViChn;
HI_S32 s32Ret;
for (ViChn = 0; ViChn < s32ChnTotal; ViChn++)
{
s32Ret = HI_MPI_VI_DisableChn(ViDev, ViChn);
if (HI_SUCCESS != s32Ret)
{
printf("HI_MPI_VI_DisableChn(%d, %d) fail, err no: 0x%08x.\n",
ViDev, ViChn, s32Ret);
return HI_FAILURE;
}
}
s32Ret = HI_MPI_VI_Disable(ViDev);
if ( HI_SUCCESS != s32Ret )
{
printf("HI_MPI_VI_Disable(%d) fail, err no: 0x%08x.\n",
ViDev, s32Ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
/*****************************************************************************
Prototype : SAMPLE_StartVoDevice
Description : Start vo device as you specified.
Input : VoDev **
pstDevAttr **
Output : None
Return Value :
Global Variable
Read Only :
Read & Write :
*****************************************************************************/
HI_S32 SAMPLE_StartVoDevice(VO_DEV VoDev, VO_PUB_ATTR_S* pstDevAttr)
{
HI_S32 ret;
/*because we will change vo device attribution,
so we diable vo device first*/
ret = HI_MPI_VO_Disable(VoDev);
if (HI_SUCCESS != ret)
{
printf("HI_MPI_VO_Disable fail 0x%08x.\n", ret);
return HI_FAILURE;
}
ret = HI_MPI_VO_SetPubAttr(VoDev, pstDevAttr);
if (HI_SUCCESS != ret)
{
printf("HI_MPI_VO_SetPubAttr fail 0x%08x.\n", ret);
return HI_FAILURE;
}
ret = HI_MPI_VO_Enable(VoDev);
if (HI_SUCCESS != ret)
{
printf("HI_MPI_VO_Enable fail 0x%08x.\n", ret);
return HI_FAILURE;
}
return HI_SUCCESS;
}
HI_S32 SAMPLE_StartVoVideoLayer(VO_DEV VoDev, VO_VIDEO_LAYER_ATTR_S* pstVideoLayerAttr)
{
HI_S32 ret;