1
+ #pragma once
2
+
3
+ #include "cvi_common.h"
4
+
5
+ #define CVI_AUD_CHN_NUM 3
6
+
7
+ typedef enum {
8
+ CVI_AUD_BIT_8 ,
9
+ CVI_AUD_BIT_16 ,
10
+ CVI_AUD_BIT_24 ,
11
+ CVI_AUD_BIT_32
12
+ } cvi_aud_bit ;
13
+
14
+ typedef enum {
15
+ CVI_AUD_I2ST_INNERCODEC ,
16
+ CVI_AUD_I2ST_INNERHDMI ,
17
+ CVI_AUD_I2ST_EXTERN
18
+ } cvi_aud_i2st ;
19
+
20
+ typedef enum {
21
+ CVI_AUD_INTF_I2S_MASTER ,
22
+ CVI_AUD_INTF_I2S_SLAVE ,
23
+ CVI_AUD_INTF_PCM_SLAVE_STD ,
24
+ CVI_AUD_INTF_PCM_SLAVE_NSTD ,
25
+ CVI_AUD_INTF_PCM_MASTER_STD ,
26
+ CVI_AUD_INTF_PCM_MASTER_NSTD ,
27
+ CVI_AUD_INTF_END
28
+ } cvi_aud_intf ;
29
+
30
+ typedef struct {
31
+ // Accept industry standards from
32
+ // 8000 to 64000Hz
33
+ int rate ;
34
+ cvi_aud_bit bit ;
35
+ cvi_aud_intf intf ;
36
+ int stereoOn ;
37
+ // 8-to-16 bit, expand mode
38
+ unsigned int expandOn ;
39
+ unsigned int frmNum ;
40
+ unsigned int packNumPerFrm ;
41
+ unsigned int chnNum ;
42
+ unsigned int syncRxClkOn ;
43
+ cvi_aud_i2st i2sType ;
44
+ } cvi_aud_cnf ;
45
+
46
+ typedef struct {
47
+ cvi_aud_bit bit ;
48
+ int stereoOn ;
49
+ char * addr [2 ];
50
+ unsigned long long phy [2 ];
51
+ unsigned long long timestamp ;
52
+ unsigned int sequence ;
53
+ unsigned int length ;
54
+ unsigned int poolId [2 ];
55
+ } cvi_aud_frm ;
56
+
57
+ typedef struct {
58
+ cvi_aud_frm frame ;
59
+ char isValid ;
60
+ char isSysBound ;
61
+ } cvi_aud_efrm ;
62
+
63
+ typedef struct {
64
+ void * handle ;
65
+
66
+ int (* fnDisableDevice )(int device );
67
+ int (* fnEnableDevice )(int device );
68
+ int (* fnSetDeviceConfig )(int device , cvi_aud_cnf * config );
69
+
70
+ int (* fnDisableChannel )(int device , int channel );
71
+ int (* fnEnableChannel )(int device , int channel );
72
+
73
+ int (* fnFreeFrame )(int device , int channel , cvi_aud_frm * frame , cvi_aud_efrm * encFrame );
74
+ int (* fnGetFrame )(int device , int channel , cvi_aud_frm * frame , cvi_aud_efrm * encFrame , int millis );
75
+ } cvi_aud_impl ;
76
+
77
+ static int cvi_aud_load (cvi_aud_impl * aud_lib ) {
78
+ if (!(aud_lib -> handle = dlopen ("libcvi_audio.so" , RTLD_LAZY | RTLD_GLOBAL )))
79
+ HAL_ERROR ("cvi_aud" , "Failed to load library!\nError: %s\n" , dlerror ());
80
+
81
+ if (!(aud_lib -> fnDisableDevice = (int (* )(int device ))
82
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_Disable" )))
83
+ return EXIT_FAILURE ;
84
+
85
+ if (!(aud_lib -> fnEnableDevice = (int (* )(int device ))
86
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_Enable" )))
87
+ return EXIT_FAILURE ;
88
+
89
+ if (!(aud_lib -> fnSetDeviceConfig = (int (* )(int device , cvi_aud_cnf * config ))
90
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_SetPubAttr" )))
91
+ return EXIT_FAILURE ;
92
+
93
+ if (!(aud_lib -> fnDisableChannel = (int (* )(int device , int channel ))
94
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_DisableChn" )))
95
+ return EXIT_FAILURE ;
96
+
97
+ if (!(aud_lib -> fnEnableChannel = (int (* )(int device , int channel ))
98
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_EnableChn" )))
99
+ return EXIT_FAILURE ;
100
+
101
+ if (!(aud_lib -> fnFreeFrame = (int (* )(int device , int channel , cvi_aud_frm * frame , cvi_aud_efrm * encFrame ))
102
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_ReleaseFrame" )))
103
+ return EXIT_FAILURE ;
104
+
105
+ if (!(aud_lib -> fnGetFrame = (int (* )(int device , int channel , cvi_aud_frm * frame , cvi_aud_efrm * encFrame , int millis ))
106
+ hal_symbol_load ("cvi_aud" , aud_lib -> handle , "CVI_AI_GetFrame" )))
107
+ return EXIT_FAILURE ;
108
+
109
+ return EXIT_SUCCESS ;
110
+ }
111
+
112
+ static void cvi_aud_unload (cvi_aud_impl * aud_lib ) {
113
+ if (aud_lib -> handle ) dlclose (aud_lib -> handle );
114
+ aud_lib -> handle = NULL ;
115
+ memset (aud_lib , 0 , sizeof (* aud_lib ));
116
+ }
0 commit comments