blob: de88327a18dd11878b7834154ef2a9b04cb923f5 [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001#ifdef USE_CAP_SUPPORT
2#include <stdio.h>
3#include <unistd.h>
4#include <string.h>
5#include <stdlib.h>
6#include <stdint.h>
7#include <sys/ioctl.h>
8#include <fcntl.h>
9#include "voice_ipc.h"
xf.li742dd022023-06-08 01:43:32 -070010#include "voice_lib.h"
xf.libdd93d52023-05-12 07:10:14 -070011#include "linux/rpmsg_zx29.h"
xf.li742dd022023-06-08 01:43:32 -070012#include "softap_api.h"
13#include "pthread.h"
xf.libdd93d52023-05-12 07:10:14 -070014
15extern int sc_audio_set_voice_device_mode(int dev_mode);
16extern int sc_audio_get_voice_device_mode(int *p_dev_mode);
17extern int sc_audio_set_rx_voice_vol(int vol);
18extern int sc_audio_get_rx_voice_vol(int * p_vol);
19extern int sc_audio_set_tx_voice_vol(int vol);
20extern int sc_audio_get_tx_voice_vol(int *p_vol);
21extern int sc_audio_set_tx_voice_mute_state(int mute );
22extern int sc_audio_get_tx_voice_mute_state(int *p_mute);
23extern int sc_audio_set_rx_voice_mute_state(int mute);
24extern int sc_audio_get_rx_voice_mute_state(int *p_mute);
lh758261d2023-07-13 05:52:04 -070025//extern int sc_audio_set_loopback_enable_state(int enable);
26//extern int sc_audio_get_loopback_enable_state(int *p_enable);
27int ap_audio_set_loopback_enable(int dev_mode,int enable);
28int ap_audio_get_loopback_enable(int *p_enable);
xf.libdd93d52023-05-12 07:10:14 -070029
xf.li742dd022023-06-08 01:43:32 -070030static int voice_ipc_fd = -1;
31static voice_ipc_control_msg voice_ctrl_recvmsg[IPC_VOICE_FUNC_MAX] = {0};
xf.libdd93d52023-05-12 07:10:14 -070032
xf.li742dd022023-06-08 01:43:32 -070033int cap_alsa_voice_open(int vmode)
34{
35 int ret = 0;
36 int msg_handle = 0;
37 MSG_BUF msg;
38 LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
39 int module_id = MODULE_ID_VOICE_CLIENT;
40 int dst_id = MODULE_ID_VOICE_SERVER;
41 int msg_cmd = MSG_CMD_CAP_VALSA_OPEN;
42
43 //´´½¨ÏûÏ¢¶ÓÁÐ
44 msg_handle = msgget(module_id, IPC_CREAT|0600);
45
46 //·¢ËÍÏûÏ¢
47 ret = ipc_send_message(module_id, dst_id, msg_cmd, sizeof(int), (unsigned char *)(&vmode), 0);
48 if(0 != ret){
49 printf("%s: send msg error(%d)!\n", __func__, ret);
50 msgctl(msg_handle,IPC_RMID,0);
51 return ret;
52 }
53 printf("%s: send msg success(%d)!\n", __func__, ret);
54
55 //½ÓÊÕÏûÏ¢
56 while(1)
57 {
58 memset(&msg, 0x00, sizeof(MSG_BUF));
59
60 //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
61 ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
62 if(0 > ret){
63 continue;
64 }
65
66 //Æ¥Åäµ½ÊÇMSG_CMD_CAP_VALSA_OPENʱ²Å´¦Àí
67 if(msg_cmd == msg.usMsgCmd){
68 ret = *((int *)msg.aucDataBuf);
69 msgctl(msg_handle,IPC_RMID,0);
70 printf("%s: receive msg success(%d)!\n", __func__, ret);
71 break;
72 }
73 }
74
75 return ret;
76}
77
78int cap_alsa_voice_close(int vmode)
79{
80 int ret = 0;
81 int msg_handle = 0;
82 MSG_BUF msg;
83 LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
84 int module_id = MODULE_ID_VOICE_CLIENT;
85 int dst_id = MODULE_ID_VOICE_SERVER;
86 int msg_cmd = MSG_CMD_CAP_VALSA_CLOSE;
87
88 //´´½¨ÏûÏ¢¶ÓÁÐ
89 msg_handle = msgget(module_id, IPC_CREAT|0600);
90
91 //·¢ËÍÏûÏ¢
92 ret = ipc_send_message(module_id, dst_id, msg_cmd, sizeof(int), (unsigned char *)(&vmode), 0);
93 if(0 != ret){
94 printf("%s: send msg error(%d)!\n", __func__, ret);
95 msgctl(msg_handle,IPC_RMID,0);
96 return ret;
97 }
98 printf("%s: send msg success(%d)!\n", __func__, ret);
99
100 //½ÓÊÕÏûÏ¢
101 while(1)
102 {
103 memset(&msg, 0x00, sizeof(MSG_BUF));
104
105 //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
106 ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
107 if(0 > ret){
108 continue;
109 }
110
111 //Æ¥Åäµ½ÊÇMSG_CMD_CAP_VALSA_CLOSEʱ²Å´¦Àí
112 if(msg_cmd == msg.usMsgCmd){
113 ret = *((int *)msg.aucDataBuf);
114 msgctl(msg_handle,IPC_RMID,0);
115 printf("%s: receive msg success(%d)!\n", __func__, ret);
116 break;
117 }
118 }
119
120 return ret;
121}
122
123int ipc_cap_alsa_voice_open(int vmode)
124{
125 int ret = 0;
126 int func_id = IPC_CAP_ALSA_VOICE_OPEN;
127 voice_ctrl_recvmsg[func_id].func_id = VOICE_WAIT_MSG_FROM_CAP;
128
129 ret = Voice_Ctrl_Rpmsg_Send(func_id, &vmode);
130
131 if (0 >= ret){
132 printf("%s: Voice_Ctrl_Rpmsg_Send error, return %d!\n", __func__, ret);
133 return VOICEIPC_ERROR;
134 }
135 printf("%s: Voice_Ctrl_Rpmsg_Send success, write_len=%d!\n", __func__, ret);
136
137 while(func_id != voice_ctrl_recvmsg[func_id].func_id){
138 usleep(1);
139 }
140
141 memcpy(&ret, voice_ctrl_recvmsg[func_id].param, voice_ctrl_recvmsg[func_id].param_len);
142 printf("%s: ipc receive success, ret=%d!\n", __func__, ret);
143
144 return ret;
145}
146
147int ipc_cap_alsa_voice_close(int vmode)
148{
149 int ret = 0;
150 int func_id = IPC_CAP_ALSA_VOICE_CLOSE;
151 voice_ctrl_recvmsg[func_id].func_id = VOICE_WAIT_MSG_FROM_CAP;
152
153 ret = Voice_Ctrl_Rpmsg_Send(func_id, &vmode);
154
155 if (0 >= ret){
156 printf("%s: Voice_Ctrl_Rpmsg_Send error, return %d!\n", __func__, ret);
157 return VOICEIPC_ERROR;
158 }
159 printf("%s: Voice_Ctrl_Rpmsg_Send success, write_len=%d!\n", __func__, ret);
160
161 while(func_id != voice_ctrl_recvmsg[func_id].func_id){
162 usleep(1);
163 }
164
165 memcpy(&ret, voice_ctrl_recvmsg[func_id].param, voice_ctrl_recvmsg[func_id].param_len);
166 printf("%s: ipc receive success, ret=%d!\n", __func__, ret);
167
168 return ret;
169}
170
171void ipc_set_voice_device_mode_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700172{
173 int ret = VOICEIPC_OK;
174 int msg_len = 0;
175 int dev_mode = 0;
176
177 //memcpy(&dev_mode, msg.param, msg.param_len);
178 dev_mode = *((int *)msg.param);
179 ret = sc_audio_set_voice_device_mode(dev_mode);
180
181 //msg.func_id不变
182 msg.param_len = sizeof(int);
183 memcpy(msg.param, &ret, msg.param_len);
184 msg_len = VOICE_HEAD_LEN + msg.param_len;
185
186 ret = write(voice_ipc_fd, &msg, msg_len);
187
188 if (0 >= ret){
189 printf("%s: write error(%d)!\n", __func__, ret);
190 }
191}
192
xf.li742dd022023-06-08 01:43:32 -0700193void ipc_get_voice_device_mode_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700194{
195 int ret = VOICEIPC_OK;
196 int msg_len = 0;
197 int *p_dev_mode = NULL;
198
199 p_dev_mode = (int *)msg.param;
200 ret = sc_audio_get_voice_device_mode(p_dev_mode);
201
202 //msg.func_id不变
203 msg.param_len = sizeof(int);
xf.li742dd022023-06-08 01:43:32 -0700204 if(0 == ret)
205 memcpy(msg.param, p_dev_mode, msg.param_len);
206 else
207 memcpy(msg.param, &ret, msg.param_len);
xf.libdd93d52023-05-12 07:10:14 -0700208 msg_len = VOICE_HEAD_LEN + msg.param_len;
209
210 ret = write(voice_ipc_fd, &msg, msg_len);
211
212 if (0 >= ret){
213 printf("%s: write error(%d)!\n", __func__, ret);
214 }
215}
216
xf.li742dd022023-06-08 01:43:32 -0700217void ipc_set_rx_voice_vol_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700218{
219 int ret = VOICEIPC_OK;
220 int msg_len = 0;
221 int vol = 0;
222
223 //memcpy(&dev_mode, msg.param, msg.param_len);
224 vol = *((int *)msg.param);
225 ret = sc_audio_set_rx_voice_vol(vol);
226
227 //msg.func_id不变
228 msg.param_len = sizeof(int);
229 memcpy(msg.param, &ret, msg.param_len);
230 msg_len = VOICE_HEAD_LEN + msg.param_len;
231
232 ret = write(voice_ipc_fd, &msg, msg_len);
233
234 if (0 >= ret){
235 printf("%s: write error(%d)!\n", __func__, ret);
236 }
237}
238
xf.li742dd022023-06-08 01:43:32 -0700239void ipc_get_rx_voice_vol_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700240{
241 int ret = VOICEIPC_OK;
242 int msg_len = 0;
243 int *p_vol = NULL;
244
245 p_vol = (int *)msg.param;
246 ret = sc_audio_get_rx_voice_vol(p_vol);
247
248 //msg.func_id不变
249 msg.param_len = sizeof(int);
xf.li742dd022023-06-08 01:43:32 -0700250 if(0 == ret)
251 memcpy(msg.param, p_vol, msg.param_len);
252 else
253 memcpy(msg.param, &ret, msg.param_len);
xf.libdd93d52023-05-12 07:10:14 -0700254 msg_len = VOICE_HEAD_LEN + msg.param_len;
255
256 ret = write(voice_ipc_fd, &msg, msg_len);
257
258 if (0 >= ret){
259 printf("%s: write error(%d)!\n", __func__, ret);
260 }
261}
262
xf.li742dd022023-06-08 01:43:32 -0700263void ipc_set_tx_voice_vol_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700264{
265 int ret = VOICEIPC_OK;
266 int msg_len = 0;
267 int vol = 0;
268
269 //memcpy(&dev_mode, msg.param, msg.param_len);
270 vol = *((int *)msg.param);
271 ret = sc_audio_set_tx_voice_vol(vol);
272
273 //msg.func_id不变
274 msg.param_len = sizeof(int);
275 memcpy(msg.param, &ret, msg.param_len);
276 msg_len = VOICE_HEAD_LEN + msg.param_len;
277
278 ret = write(voice_ipc_fd, &msg, msg_len);
279
280 if (0 >= ret){
281 printf("%s: write error(%d)!\n", __func__, ret);
282 }
283}
284
xf.li742dd022023-06-08 01:43:32 -0700285void ipc_get_tx_voice_vol_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700286{
287 int ret = VOICEIPC_OK;
288 int msg_len = 0;
289 int *p_vol = NULL;
290
291 p_vol = (int *)msg.param;
292 ret = sc_audio_get_tx_voice_vol(p_vol);
293
294 //msg.func_id不变
295 msg.param_len = sizeof(int);
xf.li742dd022023-06-08 01:43:32 -0700296 if(0 == ret)
297 memcpy(msg.param, p_vol, msg.param_len);
298 else
299 memcpy(msg.param, &ret, msg.param_len);
xf.libdd93d52023-05-12 07:10:14 -0700300 msg_len = VOICE_HEAD_LEN + msg.param_len;
301
302 ret = write(voice_ipc_fd, &msg, msg_len);
303
304 if (0 >= ret){
305 printf("%s: write error(%d)!\n", __func__, ret);
306 }
307}
308
xf.li742dd022023-06-08 01:43:32 -0700309void ipc_set_tx_voice_mute_state_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700310{
311 int ret = VOICEIPC_OK;
312 int msg_len = 0;
313 int mute = 0;
314
315 //memcpy(&dev_mode, msg.param, msg.param_len);
316 mute = *((int *)msg.param);
317 ret = sc_audio_set_tx_voice_mute_state(mute);
318
319 //msg.func_id不变
320 msg.param_len = sizeof(int);
321 memcpy(msg.param, &ret, msg.param_len);
322 msg_len = VOICE_HEAD_LEN + msg.param_len;
323
324 ret = write(voice_ipc_fd, &msg, msg_len);
325
326 if (0 >= ret){
327 printf("%s: write error(%d)!\n", __func__, ret);
328 }
329}
330
xf.li742dd022023-06-08 01:43:32 -0700331void ipc_get_tx_voice_mute_state_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700332{
333 int ret = VOICEIPC_OK;
334 int msg_len = 0;
335 int *p_mute = NULL;
336
337 p_mute = (int *)msg.param;
338 ret = sc_audio_get_tx_voice_mute_state(p_mute);
339
340 //msg.func_id不变
341 msg.param_len = sizeof(int);
xf.li742dd022023-06-08 01:43:32 -0700342 if(0 == ret)
343 memcpy(msg.param, p_mute, msg.param_len);
344 else
345 memcpy(msg.param, &ret, msg.param_len);
xf.libdd93d52023-05-12 07:10:14 -0700346 msg_len = VOICE_HEAD_LEN + msg.param_len;
347
348 ret = write(voice_ipc_fd, &msg, msg_len);
349
350 if (0 >= ret){
351 printf("%s: write error(%d)!\n", __func__, ret);
352 }
353}
354
xf.li742dd022023-06-08 01:43:32 -0700355void ipc_set_rx_voice_mute_state_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700356{
357 int ret = VOICEIPC_OK;
358 int msg_len = 0;
359 int mute = 0;
360
361 //memcpy(&dev_mode, msg.param, msg.param_len);
362 mute = *((int *)msg.param);
363 ret = sc_audio_set_rx_voice_mute_state(mute);
364
365 //msg.func_id不变
366 msg.param_len = sizeof(int);
367 memcpy(msg.param, &ret, msg.param_len);
368 msg_len = VOICE_HEAD_LEN + msg.param_len;
369
370 ret = write(voice_ipc_fd, &msg, msg_len);
371
372 if (0 >= ret){
373 printf("%s: write error(%d)!\n", __func__, ret);
374 }
375}
376
xf.li742dd022023-06-08 01:43:32 -0700377void ipc_get_rx_voice_mute_state_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700378{
379 int ret = VOICEIPC_OK;
380 int msg_len = 0;
381 int *p_mute = NULL;
382
383 p_mute = (int *)msg.param;
384 ret = sc_audio_get_rx_voice_mute_state(p_mute);
385
386 //msg.func_id不变
387 msg.param_len = sizeof(int);
xf.li742dd022023-06-08 01:43:32 -0700388 if(0 == ret)
389 memcpy(msg.param, p_mute, msg.param_len);
390 else
391 memcpy(msg.param, &ret, msg.param_len);
xf.libdd93d52023-05-12 07:10:14 -0700392 msg_len = VOICE_HEAD_LEN + msg.param_len;
393
394 ret = write(voice_ipc_fd, &msg, msg_len);
395
396 if (0 >= ret){
397 printf("%s: write error(%d)!\n", __func__, ret);
398 }
399}
400
xf.li742dd022023-06-08 01:43:32 -0700401void ipc_set_loopback_enable_state_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700402{
403 int ret = VOICEIPC_OK;
404 int msg_len = 0;
lh758261d2023-07-13 05:52:04 -0700405 int dev_mode = 0,enable = 0;
xf.libdd93d52023-05-12 07:10:14 -0700406
407 //memcpy(&dev_mode, msg.param, msg.param_len);
lh758261d2023-07-13 05:52:04 -0700408 //enable = *((int *)msg.param);
409 memcpy(&dev_mode, msg.param, sizeof(int));
410 memcpy(&enable, msg.param+sizeof(int), sizeof(int));
411
412 //ret = sc_audio_set_loopback_enable_state(enable);
413 ret = ap_audio_set_loopback_enable(dev_mode,enable);
xf.libdd93d52023-05-12 07:10:14 -0700414
415 //msg.func_id不变
416 msg.param_len = sizeof(int);
417 memcpy(msg.param, &ret, msg.param_len);
418 msg_len = VOICE_HEAD_LEN + msg.param_len;
419
420 ret = write(voice_ipc_fd, &msg, msg_len);
421
422 if (0 >= ret){
423 printf("%s: write error(%d)!\n", __func__, ret);
424 }
425}
426
xf.li742dd022023-06-08 01:43:32 -0700427void ipc_get_loopback_enable_state_rcv(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700428{
429 int ret = VOICEIPC_OK;
430 int msg_len = 0;
431 int *p_enable = NULL;
432
433 p_enable = (int *)msg.param;
lh758261d2023-07-13 05:52:04 -0700434 //ret = sc_audio_get_loopback_enable_state(p_enable);
435 ret = ap_audio_get_loopback_enable(p_enable);
xf.libdd93d52023-05-12 07:10:14 -0700436 //msg.func_id不变
437 msg.param_len = sizeof(int);
xf.li742dd022023-06-08 01:43:32 -0700438 if(0 == ret)
439 memcpy(msg.param, p_enable, msg.param_len);
440 else
441 memcpy(msg.param, &ret, msg.param_len);
442 msg_len = VOICE_HEAD_LEN + msg.param_len;
443
444 ret = write(voice_ipc_fd, &msg, msg_len);
445
446 if (0 >= ret){
447 printf("%s: write error(%d)!\n", __func__, ret);
448 }
449}
450
451#ifdef _USE_VOICE_ALSA
452void ipc_ap_alsa_voice_open_rcv(voice_ipc_control_msg msg)
453{
454 int ret = VOICEIPC_OK;
455 int msg_len = 0;
456 int vmode = 0;
457
458 vmode = *((int *)msg.param);
459 ret = alsa_voice_open(vmode);
460
461 //msg.func_id不变
462 msg.param_len = sizeof(int);
xf.libdd93d52023-05-12 07:10:14 -0700463 memcpy(msg.param, &ret, msg.param_len);
464 msg_len = VOICE_HEAD_LEN + msg.param_len;
465
466 ret = write(voice_ipc_fd, &msg, msg_len);
467
468 if (0 >= ret){
469 printf("%s: write error(%d)!\n", __func__, ret);
470 }
471}
472
xf.li742dd022023-06-08 01:43:32 -0700473void ipc_ap_alsa_voice_close_rcv(voice_ipc_control_msg msg)
474{
475 int ret = VOICEIPC_OK;
476 int msg_len = 0;
477 int vmode = 0;
478
479 vmode = *((int *)msg.param);
480 ret = alsa_voice_close(vmode);
481
482 //msg.func_id不变
483 msg.param_len = sizeof(int);
484 memcpy(msg.param, &ret, msg.param_len);
485 msg_len = VOICE_HEAD_LEN + msg.param_len;
486
487 ret = write(voice_ipc_fd, &msg, msg_len);
488
489 if (0 >= ret){
490 printf("%s: write error(%d)!\n", __func__, ret);
491 }
492}
493#endif
494
495void voice_ipc_recv_proc(voice_ipc_control_msg msg)
xf.libdd93d52023-05-12 07:10:14 -0700496{
497 switch(msg.func_id){
498 case IPC_SET_VOICE_DEVICE_MODE:
xf.li742dd022023-06-08 01:43:32 -0700499 ipc_set_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700500 break;
501 case IPC_GET_VOICE_DEVICE_MODE:
xf.li742dd022023-06-08 01:43:32 -0700502 ipc_get_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700503 break;
504 case IPC_SET_RX_VOICE_VOL:
xf.li742dd022023-06-08 01:43:32 -0700505 ipc_set_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700506 break;
507 case IPC_GET_RX_VOICE_VOL:
xf.li742dd022023-06-08 01:43:32 -0700508 ipc_get_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700509 break;
510 case IPC_SET_TX_VOICE_VOL:
xf.li742dd022023-06-08 01:43:32 -0700511 ipc_set_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700512 break;
513 case IPC_GET_TX_VOICE_VOL:
xf.li742dd022023-06-08 01:43:32 -0700514 ipc_get_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700515 break;
516 case IPC_SET_TX_VOICE_MUTE_STATE:
xf.li742dd022023-06-08 01:43:32 -0700517 ipc_set_tx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700518 break;
519 case IPC_GET_TX_VOICE_MUTE_STATE:
xf.li742dd022023-06-08 01:43:32 -0700520 ipc_get_tx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700521 break;
522 case IPC_SET_RX_VOICE_MUTE_STATE:
xf.li742dd022023-06-08 01:43:32 -0700523 ipc_set_rx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700524 break;
525 case IPC_GET_RX_VOICE_MUTE_STATE:
xf.li742dd022023-06-08 01:43:32 -0700526 ipc_get_rx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700527 break;
528 case IPC_SET_LOOPBACK_ENABLE_STATE:
xf.li742dd022023-06-08 01:43:32 -0700529 ipc_set_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700530 break;
531 case IPC_GET_LOOPBACK_ENABLE_STATE:
xf.li742dd022023-06-08 01:43:32 -0700532 ipc_get_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700533 break;
xf.li742dd022023-06-08 01:43:32 -0700534#ifdef _USE_VOICE_ALSA
535 case IPC_AP_ALSA_VOICE_OPEN:
536 ipc_ap_alsa_voice_open_rcv(voice_ctrl_recvmsg[msg.func_id]);
537 break;
538 case IPC_AP_ALSA_VOICE_CLOSE:
539 ipc_ap_alsa_voice_close_rcv(voice_ctrl_recvmsg[msg.func_id]);
540 break;
541#endif
xf.libdd93d52023-05-12 07:10:14 -0700542 default:
xf.li742dd022023-06-08 01:43:32 -0700543 break;
xf.libdd93d52023-05-12 07:10:14 -0700544 }
545}
546
547void Voice_Ctrl_Rpmsg_Recv(void)
548{
549 int read_len = 0;
550 voice_ipc_control_msg tmpbuf = {0};
551
xf.li742dd022023-06-08 01:43:32 -0700552 while(1){
xf.libdd93d52023-05-12 07:10:14 -0700553 read_len = 0;
554 read_len = read(voice_ipc_fd, &tmpbuf, (VOICE_HEAD_LEN + VOICE_CONTROL_MAX_LEN));
xf.li742dd022023-06-08 01:43:32 -0700555
xf.libdd93d52023-05-12 07:10:14 -0700556 if (0 >= read_len){
xf.li742dd022023-06-08 01:43:32 -0700557 sleep(1);
xf.libdd93d52023-05-12 07:10:14 -0700558 continue;
559 }
xf.li742dd022023-06-08 01:43:32 -0700560 printf("%s: voice_ipc_fd=%d, read_len=%d\n", __func__, voice_ipc_fd, read_len);
561
562 //Êý¾Ý¶ÁÈ¡ÍêºóÔٸıäfuc_id
563 if(0 != tmpbuf.param_len){
564 memcpy(voice_ctrl_recvmsg[tmpbuf.func_id].param, tmpbuf.param, tmpbuf.param_len);
565 }
xf.libdd93d52023-05-12 07:10:14 -0700566 voice_ctrl_recvmsg[tmpbuf.func_id].param_len = tmpbuf.param_len;
567 voice_ctrl_recvmsg[tmpbuf.func_id].func_id = tmpbuf.func_id;
xf.li742dd022023-06-08 01:43:32 -0700568 printf("%s: tmpbuf.param_len=%d, tmpbuf.func_id=%d\n", __func__, tmpbuf.param_len, tmpbuf.func_id);
xf.libdd93d52023-05-12 07:10:14 -0700569
xf.li742dd022023-06-08 01:43:32 -0700570 voice_ipc_recv_proc(voice_ctrl_recvmsg[tmpbuf.func_id]);
xf.libdd93d52023-05-12 07:10:14 -0700571 }
572}
573
xf.li742dd022023-06-08 01:43:32 -0700574int Voice_Ctrl_Rpmsg_Send(int func_id, int *msg)
575{
576 voice_ipc_control_msg tmpbuf = {0};
577 int tmpbuf_len = 0;
578 int write_len = 0;
579
580 tmpbuf.func_id = func_id;
581
582 if(NULL == msg){
583 tmpbuf.param_len = 0;
584 }else{
585 tmpbuf.param_len = sizeof(int);
586 memcpy(tmpbuf.param, msg, tmpbuf.param_len);
587 }
588
589 tmpbuf_len = VOICE_HEAD_LEN + tmpbuf.param_len;
590
591 //printf("Voice_Ctrl_Rpmsg_Send, voice_ipc_fd = %d\n", voice_ipc_fd);
592 write_len = write(voice_ipc_fd, &tmpbuf, tmpbuf_len);
593
594 return write_len;
595}
596
597int voice_ipc_init(void) //通道初始åŒ?
xf.libdd93d52023-05-12 07:10:14 -0700598{
599 voice_ipc_fd = open(VOICE_IPC_CONTROL_CHANNEL, O_RDWR);
600
601 if(0 > voice_ipc_fd){
602 printf("%s: open the channel(%s) error!\n", __func__, VOICE_IPC_CONTROL_CHANNEL);
603 return VOICEIPC_ERROR;
604 }
605
606 if(0 > ioctl(voice_ipc_fd, RPMSG_CREATE_CHANNEL, VOICE_IPC_CONTROL_CHANNEL_SIZE)){
607 printf("%s: ioctl RPMSG_CREATE_CHANNEL fail!\n", __func__);
608 close(voice_ipc_fd);
609 voice_ipc_fd = -1;
610 return VOICEIPC_ERROR;
611 }
612
xf.li742dd022023-06-08 01:43:32 -0700613 if(0 > ioctl(voice_ipc_fd, RPMSG_SET_INT_FLAG, NULL)){ //写中æ–?
xf.libdd93d52023-05-12 07:10:14 -0700614 printf("%s: ioctl RPMSG_SET_INT_FLAG fail!\n", __func__);
615 close(voice_ipc_fd);
616 voice_ipc_fd = -1;
617 return VOICEIPC_ERROR;
618 }
619
xf.li742dd022023-06-08 01:43:32 -0700620 if(0 > ioctl(voice_ipc_fd, RPMSG_CLEAR_POLL_FLAG, NULL)){ //阻塞方式读数æ?
xf.libdd93d52023-05-12 07:10:14 -0700621 printf("%s: ioctl RPMSG_CLEAR_POLL_FLAG fail!\n", __func__);
622 close(voice_ipc_fd);
623 voice_ipc_fd = -1;
624 return VOICEIPC_ERROR;
625 }
xf.li742dd022023-06-08 01:43:32 -0700626
627 printf("voice_ipc_init %s create success! voice_ipc_fd = %d\n", VOICE_IPC_CONTROL_CHANNEL, voice_ipc_fd);
628
xf.libdd93d52023-05-12 07:10:14 -0700629 return VOICEIPC_OK;
630}
631
xf.li742dd022023-06-08 01:43:32 -0700632int recv_msg_proc(MSG_BUF msg)
633{
634 int ret = 0;
635 int vmode = 0;
636 int module_id = MODULE_ID_VOICE_SERVER;
637 int dst_id = MODULE_ID_VOICE_CLIENT;
638
639 switch(msg.usMsgCmd){
640 case MSG_CMD_CAP_VALSA_OPEN:
641 vmode = *((int *)msg.aucDataBuf);
642 ret = ipc_cap_alsa_voice_open(vmode);
643 //dst_id = MODULE_ID_CAP_VALSA_OPEN;
644 ret = ipc_send_message(module_id, dst_id, msg.usMsgCmd, sizeof(int), (unsigned char *)(&ret), 0);
645 if(0 != ret){
646 printf("%s: ipc_send_message error, return %d!\n", __func__, ret);
647 }
648 break;
649 case MSG_CMD_CAP_VALSA_CLOSE:
650 vmode = *((int *)msg.aucDataBuf);
651 ret = ipc_cap_alsa_voice_close(vmode);
652 //dst_id = MODULE_ID_CAP_VALSA_CLOSE;
653 ret = ipc_send_message(module_id, dst_id, msg.usMsgCmd, sizeof(int), (unsigned char *)(&ret), 0);
654 if(0 != ret){
655 printf("%s: ipc_send_message error, return %d!\n", __func__, ret);
656 }
657 break;
658 default:
659 printf("%s: msg.usMsgCmd=%d, not support!\n", __func__, msg.usMsgCmd);
660 break;
661 }
662
663 return ret;
664}
665
666void recv_cap_voice_alsa(void)
667{
668 int ret = 0;
669 int msg_handle = 0;
670 MSG_BUF msg;
671 LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
672 int module_id = MODULE_ID_VOICE_SERVER;
673
674 //´´½¨ÏûÏ¢¶ÓÁÐ
675 msg_handle = msgget(module_id, IPC_CREAT|0600);
676
677 //½ÓÊÕÏûÏ¢
678 while(1)
679 {
680 memset(&msg, 0x00, sizeof(MSG_BUF));
681
682 //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
683 ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
684
685 if(0 > ret){
686 continue;
687 }
688
689 recv_msg_proc(msg);
690 }
691}
692
xf.libdd93d52023-05-12 07:10:14 -0700693int main(int argc, char **argv)
694{
695 int ret = 0;
696
xf.li742dd022023-06-08 01:43:32 -0700697 //ipcͨµÀ³õʼ»¯
xf.libdd93d52023-05-12 07:10:14 -0700698 ret = voice_ipc_init();
xf.li742dd022023-06-08 01:43:32 -0700699 if(0 > ret){
700 printf("voice_ipc_init %s error!\n", VOICE_IPC_CONTROL_CHANNEL);
xf.libdd93d52023-05-12 07:10:14 -0700701 return -1;
702 }
xf.libdd93d52023-05-12 07:10:14 -0700703
xf.li742dd022023-06-08 01:43:32 -0700704 //ipc³õʼ»¯ºó£¬´´½¨msgÏûÏ¢½ÓÊÕÏß³Ì
705 pthread_t recv_thread_tid;
706 if(0 != pthread_create(&recv_thread_tid, NULL, (void *)recv_cap_voice_alsa, NULL)){
707 printf("recv_cap_voice_alsa create error!\n");
708 }
709
710 sleep(4);
xf.libdd93d52023-05-12 07:10:14 -0700711 Voice_Ctrl_Rpmsg_Recv();
712
713 return 0;
714}
715
716#endif