blob: fbc8bf1d1f6c3dc09587dd4c8c4dab33759aff1a [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*****************************************************************************
2** °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
3**
4** ÎļþÃû³Æ: voice.c
5** Îļþ±êʶ:
6** ÄÚÈÝÕªÒª:
7** ʹÓ÷½·¨:
8**
9** ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
10** -----------------------------------------------------------------------------
11** 2019/09/25 V1.0 Create xxq ´´½¨
12**
13* ******************************************************************************/
14
15#include <stdio.h>
16#include <unistd.h>
17#include <string.h>
18#include <stdlib.h>
19
20#include <stdint.h>
21#include <linux/volte_drv.h>
22#include <sys/ioctl.h>
23#include <fcntl.h>
24#include <tinyalsa/audio_mixer_ctrl.h>
xf.libdd93d52023-05-12 07:10:14 -070025#include "voice_lib.h"
26
lh9ed821d2023-04-07 01:36:19 -070027
28#define VOICE_DEV_NAME "/dev/voice_device"
29
30
31
32typedef struct {
33 int fd;
34 unsigned int state; // 0 close;1 open
35 T_Voice_Para vpara;
36} T_voiceInfo;
37
38T_voiceInfo *voiceinfo = NULL;
39
40static int slic_flag = 0;
41static int slic_flag_already = 0;// 0 not get ,1 already get
42
43struct pcm *volte_pcm_voice_out = NULL;
44struct pcm *volte_pcm_voice_in = NULL;
45
46#if 0
47
48
49T_Voice_Para gsmhwpara = {
50 8000, //8000;16000
51 0, //// 0 gsm;1 td;2 wcdma;3 lte
52 0//0 hardware dsp;1 soft amr lib
53};
54
55T_Voice_Para tdnbhwpara = {
56 8000, //8000;16000
57 1, //// 0 gsm;1 td;2 wcdma;3 lte
58 0,//0 amr-nb;1 amr-wb
59 0//0 hardware dsp;1 soft amr lib
60};
61
62T_Voice_Para tdnbsfpara = {
63 8000, //8000;16000
64 1, //// 0 gsm;1 td;2 wcdma;3 lte
65 0,//0 amr-nb;1 amr-wb
66 1//0 hardware dsp;1 soft amr lib
67};
68
69T_Voice_Para tdwbsfpara = {
70 8000, //8000;16000
71 1, //// 0 gsm;1 td;2 wcdma;3 lte
72 1,//0 amr-nb;1 amr-wb
73 1//0 hardware dsp;1 soft amr lib
74};
75
76
77#endif
78//static volatile int voiceinfo.fd = 0;
79
80
81int voice_open(T_Voice_Para *para)
82{
83 int ret = 0;
84 if (!para) {
85
86 printf("voice: open para is NULL.\n");
87
88 return -1;
89 }
90
91 voiceinfo = calloc(1, sizeof(T_voiceInfo));
92 if (!voiceinfo) {
93
94 printf("voice: open calloc fail!\n");
95 return -1;
96 }
97
98 voiceinfo->vpara = *para;
99
100 voiceinfo->fd = open(VOICE_DEV_NAME, O_RDONLY);
101 if (voiceinfo->fd < 0) {
102 printf("voice lib: open voice device error.\n");
103 free(voiceinfo);
104 return -1;
105
106 }
107
108
109 ret = ioctl(voiceinfo->fd, VOICE_IOCTL_START, para);
110 if (ret) {
111 printf("voice lib: voice start fd=%d,ret=%d.\n", voiceinfo->fd, ret);
112 goto err;
113 }
114 printf("voice open end !\n");
115
116 return 0;
117
118err:
119 close(voiceinfo->fd);
120 free(voiceinfo);
121 printf("voice open err end !\n");
122 return -1;
123
124
125}
126
127
128int voice_close(T_Voice_Para *para)
129{
130 int ret = 0;
131
132 if (!voiceinfo) {
133
134 printf("voice: close voiceinfo is NUll!\n");
135 return 0;
136 }
137
138 ret = ioctl(voiceinfo->fd, VOICE_IOCTL_STOP, para);
139
140 if (ret) {
141 printf("voice lib: voice stop fd=%d,ret=%d.\n", voiceinfo->fd, ret);
142 }
143
144 if (voiceinfo->fd >= 0) {
145 close(voiceinfo->fd);
146 }
147 voiceinfo->fd = -1;
148
149 free(voiceinfo);
150 voiceinfo = NULL;
151
152 printf("voice close end !\n");
153
154 return 0;
155}
156int voice_Vploop(int *path)
157{
158 int ret = 0;
159 int fd = -1;
160 printf("voice_Vploop: start path=%d!\n",*path);
161 fd = open(VOICE_DEV_NAME, O_RDONLY);
162 if (fd < 0) {
163 printf("voice_Vploop: open voice device error.\n");
164 return -1;
165 }
166 ret = ioctl(fd, VOICE_IOCTL_VPLOOP, path);
167 if (ret) {
168 printf("voice_Vploop: ret=%d,path=%p.\n", ret, path);
169 close(fd);
170 return -1;
171 }
172 close(fd);
173 return 0;
174
175}
176
177int voice_GetSlicFlag(void)
178{
179 int ret = 0;
180 int fd = -1;
181 int flag = 0;
182 printf("voice_GetSlicFlag: start!\n");
183 fd = open(VOICE_DEV_NAME, O_RDONLY);
184 if (fd < 0) {
185 printf("voice_GetSlicFlag: open voice device error.\n");
186 return -1;
187 }
188 ret = ioctl(fd, VOICE_IOCTL_GET_SLIC_USE_FLAG, &flag);
189 if (ret) {
190 printf("voice_GetSlicFlag: ret=%d,flag=%d.\n", ret, flag);
191 close(fd);
192 return -1;
193 }
194 close(fd);
195 slic_flag_already = 1;
196 return flag;
197
198}
199
200int zDrvVolte_PreOpen(T_ZDrvVolte_Cfg *cfgParam)
201{
202
203
204 struct mixer *voice_mixer = NULL;
205 struct pcm_config config_voice = {0};
206 printf(" voice lib zDrvVolte_PreOpen!\n");
207
208 if (slic_flag_already == 1) {
209 printf(" voice slic flag already get, slic_flag=%d!\n", slic_flag);
210 if (slic_flag == 1) {
211 return 0;
212 }
213
214 } else {
215 slic_flag = voice_GetSlicFlag();
216 printf(" voice slic flag get, slic_flag=%d!\n", slic_flag);
217 if (slic_flag == 1) {
218 return 0;
219 }
220 }
xf.libdd93d52023-05-12 07:10:14 -0700221#ifdef _ALSA_CODEC_IN_CAP
222
223 printf("%s: i2s and codec not need config,return!\n",__func__);
224 return 0;
225#endif
lh9ed821d2023-04-07 01:36:19 -0700226
227
228 //open mixer dev for codec control
229 voice_mixer = mixer_open(0);
230 if (!voice_mixer) {
231 printf("zte voice_mixer open failed!\n");
232 return -1;
233 }
234
235 //config mixer dev
236 mix_set_voice_path(voice_mixer, T_OUTPUT_SPEAKER);
237 mix_set_voice_vol(voice_mixer, T_VOICE_VOL_3_LEVEL);
238
239 //close mixer
240 mixer_close(voice_mixer);
241 voice_mixer = NULL;
242
243 //open pcm dev for data tranf
244 config_voice.channels = cfgParam->channel_count;
245 config_voice.rate = cfgParam->clock_rate;
246 //buffer num
247 config_voice.period_count = 3;
248 //buffer size
249 config_voice.period_size = cfgParam->samples_per_frame * cfgParam->bits_per_sample / 8;
250 //16-bit signed
251 config_voice.format = PCM_FORMAT_S16_LE;
252
253 //card 0 dev 1
254 //23G card 0 dev 2
255 volte_pcm_voice_out = pcm_open(0, 1, PCM_OUT, &config_voice);
256 if (!pcm_is_ready(volte_pcm_voice_out)) {
257 printf("zte volte_pcm_voice_out open failed!\n");
258 goto err_ret;
259 }
260
261 volte_pcm_voice_in = pcm_open(0, 1, PCM_IN, &config_voice);
262 if (!pcm_is_ready(volte_pcm_voice_in)) {
263 printf("zte volte_pcm_voice_in open failed!\n");
264 goto err_ret;
265 }
266
267 if (0 != pcm_prepare(volte_pcm_voice_out)) {
268 printf("zte volte_pcm_voice_out pcm_prepare failed!\n");
269 goto err_ret;
270 }
271
272 if (0 != pcm_prepare(volte_pcm_voice_in)) {
273 printf("zte volte_pcm_voice_in pcm_prepare failed!\n");
274 goto err_ret;
275 }
276 return 0;
277err_ret:
278
279 pcm_close(volte_pcm_voice_out);
280 volte_pcm_voice_out = NULL;
281
282 if (volte_pcm_voice_in) {
283 pcm_close(volte_pcm_voice_in);
284 volte_pcm_voice_in = NULL;
285 }
286 return -1;
287
288}
289
290void zDrvVolte_PreClose(void)
291{
292
293 printf(" voice lib zDrvVolte_PreClose!\n");
294
295 if (slic_flag_already == 1) {
296 printf(" voice slic flag already get, slic_flag=%d!\n", slic_flag);
297 if (slic_flag == 1) {
298 return ;
299 }
300
301 } else {
302 slic_flag = voice_GetSlicFlag();
303 printf(" voice slic flag get, slic_flag=%d!\n", slic_flag);
304 if (slic_flag == 1) {
305 return ;
306 }
307 }
xf.libdd93d52023-05-12 07:10:14 -0700308#ifdef _ALSA_CODEC_IN_CAP
309 printf("%s: i2s and codec not need config,return!\n",__func__);
310 return ;
311#endif
lh9ed821d2023-04-07 01:36:19 -0700312
313
314 if (volte_pcm_voice_out) {
315 pcm_close(volte_pcm_voice_out);
316 volte_pcm_voice_out = NULL;
317 }
318 if (volte_pcm_voice_in) {
319 pcm_close(volte_pcm_voice_in);
320 volte_pcm_voice_in = NULL;
321 }
322}
323
324
325
326
327