blob: 696c2eacea571483cddc9457826fca7d6cb396ff [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>
25
26#define VOICE_DEV_NAME "/dev/voice_device"
27
28
29
30typedef struct {
31 int fd;
32 unsigned int state; // 0 close;1 open
33 T_Voice_Para vpara;
34} T_voiceInfo;
35
36T_voiceInfo *voiceinfo = NULL;
37
38static int slic_flag = 0;
39static int slic_flag_already = 0;// 0 not get ,1 already get
40
41struct pcm *volte_pcm_voice_out = NULL;
42struct pcm *volte_pcm_voice_in = NULL;
43
44#if 0
45
46
47T_Voice_Para gsmhwpara = {
48 8000, //8000;16000
49 0, //// 0 gsm;1 td;2 wcdma;3 lte
50 0//0 hardware dsp;1 soft amr lib
51};
52
53T_Voice_Para tdnbhwpara = {
54 8000, //8000;16000
55 1, //// 0 gsm;1 td;2 wcdma;3 lte
56 0,//0 amr-nb;1 amr-wb
57 0//0 hardware dsp;1 soft amr lib
58};
59
60T_Voice_Para tdnbsfpara = {
61 8000, //8000;16000
62 1, //// 0 gsm;1 td;2 wcdma;3 lte
63 0,//0 amr-nb;1 amr-wb
64 1//0 hardware dsp;1 soft amr lib
65};
66
67T_Voice_Para tdwbsfpara = {
68 8000, //8000;16000
69 1, //// 0 gsm;1 td;2 wcdma;3 lte
70 1,//0 amr-nb;1 amr-wb
71 1//0 hardware dsp;1 soft amr lib
72};
73
74
75#endif
76//static volatile int voiceinfo.fd = 0;
77
78
79int voice_open(T_Voice_Para *para)
80{
81 int ret = 0;
82 if (!para) {
83
84 printf("voice: open para is NULL.\n");
85
86 return -1;
87 }
88
89 voiceinfo = calloc(1, sizeof(T_voiceInfo));
90 if (!voiceinfo) {
91
92 printf("voice: open calloc fail!\n");
93 return -1;
94 }
95
96 voiceinfo->vpara = *para;
97
98 voiceinfo->fd = open(VOICE_DEV_NAME, O_RDONLY);
99 if (voiceinfo->fd < 0) {
100 printf("voice lib: open voice device error.\n");
101 free(voiceinfo);
102 return -1;
103
104 }
105
106
107 ret = ioctl(voiceinfo->fd, VOICE_IOCTL_START, para);
108 if (ret) {
109 printf("voice lib: voice start fd=%d,ret=%d.\n", voiceinfo->fd, ret);
110 goto err;
111 }
112 printf("voice open end !\n");
113
114 return 0;
115
116err:
117 close(voiceinfo->fd);
118 free(voiceinfo);
119 printf("voice open err end !\n");
120 return -1;
121
122
123}
124
125
126int voice_close(T_Voice_Para *para)
127{
128 int ret = 0;
129
130 if (!voiceinfo) {
131
132 printf("voice: close voiceinfo is NUll!\n");
133 return 0;
134 }
135
136 ret = ioctl(voiceinfo->fd, VOICE_IOCTL_STOP, para);
137
138 if (ret) {
139 printf("voice lib: voice stop fd=%d,ret=%d.\n", voiceinfo->fd, ret);
140 }
141
142 if (voiceinfo->fd >= 0) {
143 close(voiceinfo->fd);
144 }
145 voiceinfo->fd = -1;
146
147 free(voiceinfo);
148 voiceinfo = NULL;
149
150 printf("voice close end !\n");
151
152 return 0;
153}
154int voice_Vploop(int *path)
155{
156 int ret = 0;
157 int fd = -1;
158 printf("voice_Vploop: start path=%d!\n",*path);
159 fd = open(VOICE_DEV_NAME, O_RDONLY);
160 if (fd < 0) {
161 printf("voice_Vploop: open voice device error.\n");
162 return -1;
163 }
164 ret = ioctl(fd, VOICE_IOCTL_VPLOOP, path);
165 if (ret) {
166 printf("voice_Vploop: ret=%d,path=%p.\n", ret, path);
167 close(fd);
168 return -1;
169 }
170 close(fd);
171 return 0;
172
173}
174
175int voice_GetSlicFlag(void)
176{
177 int ret = 0;
178 int fd = -1;
179 int flag = 0;
180 printf("voice_GetSlicFlag: start!\n");
181 fd = open(VOICE_DEV_NAME, O_RDONLY);
182 if (fd < 0) {
183 printf("voice_GetSlicFlag: open voice device error.\n");
184 return -1;
185 }
186 ret = ioctl(fd, VOICE_IOCTL_GET_SLIC_USE_FLAG, &flag);
187 if (ret) {
188 printf("voice_GetSlicFlag: ret=%d,flag=%d.\n", ret, flag);
189 close(fd);
190 return -1;
191 }
192 close(fd);
193 slic_flag_already = 1;
194 return flag;
195
196}
197
198int zDrvVolte_PreOpen(T_ZDrvVolte_Cfg *cfgParam)
199{
200
201
202 struct mixer *voice_mixer = NULL;
203 struct pcm_config config_voice = {0};
204 printf(" voice lib zDrvVolte_PreOpen!\n");
205
206 if (slic_flag_already == 1) {
207 printf(" voice slic flag already get, slic_flag=%d!\n", slic_flag);
208 if (slic_flag == 1) {
209 return 0;
210 }
211
212 } else {
213 slic_flag = voice_GetSlicFlag();
214 printf(" voice slic flag get, slic_flag=%d!\n", slic_flag);
215 if (slic_flag == 1) {
216 return 0;
217 }
218 }
219
220
221 //open mixer dev for codec control
222 voice_mixer = mixer_open(0);
223 if (!voice_mixer) {
224 printf("zte voice_mixer open failed!\n");
225 return -1;
226 }
227
228 //config mixer dev
229 mix_set_voice_path(voice_mixer, T_OUTPUT_SPEAKER);
230 mix_set_voice_vol(voice_mixer, T_VOICE_VOL_3_LEVEL);
231
232 //close mixer
233 mixer_close(voice_mixer);
234 voice_mixer = NULL;
235
236 //open pcm dev for data tranf
237 config_voice.channels = cfgParam->channel_count;
238 config_voice.rate = cfgParam->clock_rate;
239 //buffer num
240 config_voice.period_count = 3;
241 //buffer size
242 config_voice.period_size = cfgParam->samples_per_frame * cfgParam->bits_per_sample / 8;
243 //16-bit signed
244 config_voice.format = PCM_FORMAT_S16_LE;
245
246 //card 0 dev 1
247 //23G card 0 dev 2
248 volte_pcm_voice_out = pcm_open(0, 1, PCM_OUT, &config_voice);
249 if (!pcm_is_ready(volte_pcm_voice_out)) {
250 printf("zte volte_pcm_voice_out open failed!\n");
251 goto err_ret;
252 }
253
254 volte_pcm_voice_in = pcm_open(0, 1, PCM_IN, &config_voice);
255 if (!pcm_is_ready(volte_pcm_voice_in)) {
256 printf("zte volte_pcm_voice_in open failed!\n");
257 goto err_ret;
258 }
259
260 if (0 != pcm_prepare(volte_pcm_voice_out)) {
261 printf("zte volte_pcm_voice_out pcm_prepare failed!\n");
262 goto err_ret;
263 }
264
265 if (0 != pcm_prepare(volte_pcm_voice_in)) {
266 printf("zte volte_pcm_voice_in pcm_prepare failed!\n");
267 goto err_ret;
268 }
269 return 0;
270err_ret:
271
272 pcm_close(volte_pcm_voice_out);
273 volte_pcm_voice_out = NULL;
274
275 if (volte_pcm_voice_in) {
276 pcm_close(volte_pcm_voice_in);
277 volte_pcm_voice_in = NULL;
278 }
279 return -1;
280
281}
282
283void zDrvVolte_PreClose(void)
284{
285
286 printf(" voice lib zDrvVolte_PreClose!\n");
287
288 if (slic_flag_already == 1) {
289 printf(" voice slic flag already get, slic_flag=%d!\n", slic_flag);
290 if (slic_flag == 1) {
291 return ;
292 }
293
294 } else {
295 slic_flag = voice_GetSlicFlag();
296 printf(" voice slic flag get, slic_flag=%d!\n", slic_flag);
297 if (slic_flag == 1) {
298 return ;
299 }
300 }
301
302
303 if (volte_pcm_voice_out) {
304 pcm_close(volte_pcm_voice_out);
305 volte_pcm_voice_out = NULL;
306 }
307 if (volte_pcm_voice_in) {
308 pcm_close(volte_pcm_voice_in);
309 volte_pcm_voice_in = NULL;
310 }
311}
312
313
314
315
316