xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | #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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 10 | #include "voice_lib.h"
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 11 | #include "linux/rpmsg_zx29.h"
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 12 | #include "softap_api.h"
|
| 13 | #include "pthread.h"
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 14 |
|
| 15 | extern int sc_audio_set_voice_device_mode(int dev_mode);
|
| 16 | extern int sc_audio_get_voice_device_mode(int *p_dev_mode);
|
| 17 | extern int sc_audio_set_rx_voice_vol(int vol);
|
| 18 | extern int sc_audio_get_rx_voice_vol(int * p_vol);
|
| 19 | extern int sc_audio_set_tx_voice_vol(int vol);
|
| 20 | extern int sc_audio_get_tx_voice_vol(int *p_vol);
|
| 21 | extern int sc_audio_set_tx_voice_mute_state(int mute );
|
| 22 | extern int sc_audio_get_tx_voice_mute_state(int *p_mute);
|
| 23 | extern int sc_audio_set_rx_voice_mute_state(int mute);
|
| 24 | extern int sc_audio_get_rx_voice_mute_state(int *p_mute);
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 25 | //extern int sc_audio_set_loopback_enable_state(int enable);
|
| 26 | //extern int sc_audio_get_loopback_enable_state(int *p_enable);
|
| 27 | int ap_audio_set_loopback_enable(int dev_mode,int enable);
|
| 28 | int ap_audio_get_loopback_enable(int *p_enable);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 29 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 30 | static int voice_ipc_fd = -1;
|
| 31 | static voice_ipc_control_msg voice_ctrl_recvmsg[IPC_VOICE_FUNC_MAX] = {0};
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 32 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 33 | int 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 |
|
| 78 | int 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 |
|
| 123 | int 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 |
|
| 147 | int 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 |
|
| 171 | void ipc_set_voice_device_mode_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 172 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 193 | void ipc_get_voice_device_mode_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 194 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 204 | if(0 == ret)
|
| 205 | memcpy(msg.param, p_dev_mode, msg.param_len);
|
| 206 | else
|
| 207 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 208 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 217 | void ipc_set_rx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 218 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 239 | void ipc_get_rx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 240 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 250 | if(0 == ret)
|
| 251 | memcpy(msg.param, p_vol, msg.param_len);
|
| 252 | else
|
| 253 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 254 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 263 | void ipc_set_tx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 264 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 285 | void ipc_get_tx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 286 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 296 | if(0 == ret)
|
| 297 | memcpy(msg.param, p_vol, msg.param_len);
|
| 298 | else
|
| 299 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 300 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 309 | void ipc_set_tx_voice_mute_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 310 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 331 | void ipc_get_tx_voice_mute_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 332 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 342 | if(0 == ret)
|
| 343 | memcpy(msg.param, p_mute, msg.param_len);
|
| 344 | else
|
| 345 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 346 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 355 | void ipc_set_rx_voice_mute_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 356 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 377 | void ipc_get_rx_voice_mute_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 378 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 388 | if(0 == ret)
|
| 389 | memcpy(msg.param, p_mute, msg.param_len);
|
| 390 | else
|
| 391 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 392 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 401 | void ipc_set_loopback_enable_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 402 | {
|
| 403 | int ret = VOICEIPC_OK;
|
| 404 | int msg_len = 0;
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 405 | int dev_mode = 0,enable = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 406 |
|
| 407 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 408 | //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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 414 |
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 427 | void ipc_get_loopback_enable_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 428 | {
|
| 429 | int ret = VOICEIPC_OK;
|
| 430 | int msg_len = 0;
|
| 431 | int *p_enable = NULL;
|
| 432 |
|
| 433 | p_enable = (int *)msg.param;
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 434 | //ret = sc_audio_get_loopback_enable_state(p_enable);
|
| 435 | ret = ap_audio_get_loopback_enable(p_enable);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 436 | //msg.func_idä¸å
|
| 437 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 438 | 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
|
| 452 | void 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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 463 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 473 | void 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 |
|
| 495 | void voice_ipc_recv_proc(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 496 | {
|
| 497 | switch(msg.func_id){
|
| 498 | case IPC_SET_VOICE_DEVICE_MODE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 499 | ipc_set_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 500 | break;
|
| 501 | case IPC_GET_VOICE_DEVICE_MODE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 502 | ipc_get_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 503 | break;
|
| 504 | case IPC_SET_RX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 505 | ipc_set_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 506 | break;
|
| 507 | case IPC_GET_RX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 508 | ipc_get_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 509 | break;
|
| 510 | case IPC_SET_TX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 511 | ipc_set_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 512 | break;
|
| 513 | case IPC_GET_TX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 514 | ipc_get_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 515 | break;
|
| 516 | case IPC_SET_TX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 517 | ipc_set_tx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 518 | break;
|
| 519 | case IPC_GET_TX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 520 | ipc_get_tx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 521 | break;
|
| 522 | case IPC_SET_RX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 523 | ipc_set_rx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 524 | break;
|
| 525 | case IPC_GET_RX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 526 | ipc_get_rx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 527 | break;
|
| 528 | case IPC_SET_LOOPBACK_ENABLE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 529 | ipc_set_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 530 | break;
|
| 531 | case IPC_GET_LOOPBACK_ENABLE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 532 | ipc_get_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 533 | break;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 534 | #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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 542 | default:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 543 | break;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 544 | }
|
| 545 | }
|
| 546 |
|
| 547 | void Voice_Ctrl_Rpmsg_Recv(void)
|
| 548 | {
|
| 549 | int read_len = 0;
|
| 550 | voice_ipc_control_msg tmpbuf = {0};
|
| 551 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 552 | while(1){
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 553 | read_len = 0;
|
| 554 | read_len = read(voice_ipc_fd, &tmpbuf, (VOICE_HEAD_LEN + VOICE_CONTROL_MAX_LEN));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 555 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 556 | if (0 >= read_len){
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 557 | sleep(1);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 558 | continue;
|
| 559 | }
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 560 | 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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 566 | voice_ctrl_recvmsg[tmpbuf.func_id].param_len = tmpbuf.param_len;
|
| 567 | voice_ctrl_recvmsg[tmpbuf.func_id].func_id = tmpbuf.func_id;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 568 | printf("%s: tmpbuf.param_len=%d, tmpbuf.func_id=%d\n", __func__, tmpbuf.param_len, tmpbuf.func_id);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 569 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 570 | voice_ipc_recv_proc(voice_ctrl_recvmsg[tmpbuf.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 571 | }
|
| 572 | }
|
| 573 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 574 | int 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 |
|
| 597 | int voice_ipc_init(void) //ééåå§å?
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 598 | {
|
| 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 613 | if(0 > ioctl(voice_ipc_fd, RPMSG_SET_INT_FLAG, NULL)){ //å䏿?
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 614 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 620 | if(0 > ioctl(voice_ipc_fd, RPMSG_CLEAR_POLL_FLAG, NULL)){ //é»å¡æ¹å¼è¯»æ°æ?
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 621 | 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.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 626 |
|
| 627 | printf("voice_ipc_init %s create success! voice_ipc_fd = %d\n", VOICE_IPC_CONTROL_CHANNEL, voice_ipc_fd);
|
| 628 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 629 | return VOICEIPC_OK;
|
| 630 | }
|
| 631 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 632 | int 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 |
|
| 666 | void 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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 693 | int main(int argc, char **argv)
|
| 694 | {
|
| 695 | int ret = 0;
|
| 696 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 697 | //ipcͨµÀ³õʼ»¯
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 698 | ret = voice_ipc_init();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 699 | if(0 > ret){
|
| 700 | printf("voice_ipc_init %s error!\n", VOICE_IPC_CONTROL_CHANNEL);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 701 | return -1;
|
| 702 | }
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 703 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 704 | //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.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 711 | Voice_Ctrl_Rpmsg_Recv();
|
| 712 |
|
| 713 | return 0;
|
| 714 | }
|
| 715 |
|
| 716 | #endif
|