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 | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 14 | #include <linux/volte_drv.h>
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 15 |
|
| 16 | extern int sc_audio_set_voice_device_mode(int dev_mode);
|
| 17 | extern int sc_audio_get_voice_device_mode(int *p_dev_mode);
|
| 18 | extern int sc_audio_set_rx_voice_vol(int vol);
|
| 19 | extern int sc_audio_get_rx_voice_vol(int * p_vol);
|
| 20 | extern int sc_audio_set_tx_voice_vol(int vol);
|
| 21 | extern int sc_audio_get_tx_voice_vol(int *p_vol);
|
| 22 | extern int sc_audio_set_tx_voice_mute_state(int mute );
|
| 23 | extern int sc_audio_get_tx_voice_mute_state(int *p_mute);
|
| 24 | extern int sc_audio_set_rx_voice_mute_state(int mute);
|
| 25 | extern int sc_audio_get_rx_voice_mute_state(int *p_mute);
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 26 | extern int sc_audio_set_rx_voice_vol_gain(int gain);
|
| 27 | extern int sc_audio_get_rx_voice_vol_gain(int * p_gain);
|
| 28 | extern int sc_audio_set_tx_voice_vol_gain(int gain);
|
| 29 | extern int sc_audio_get_tx_voice_vol_gain(int * p_gain);
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 30 | //extern int sc_audio_set_loopback_enable_state(int enable);
|
| 31 | //extern int sc_audio_get_loopback_enable_state(int *p_enable);
|
| 32 | int ap_audio_set_loopback_enable(int dev_mode,int enable);
|
| 33 | int ap_audio_get_loopback_enable(int *p_enable);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 34 |
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 35 | static unsigned char *recv_voice_nvrw_buf = NULL;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 36 | static int voice_ipc_fd = -1;
|
| 37 | 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] | 38 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 39 | int cap_alsa_voice_open(int vmode)
|
| 40 | {
|
| 41 | int ret = 0;
|
| 42 | int msg_handle = 0;
|
| 43 | MSG_BUF msg;
|
| 44 | LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
|
| 45 | int module_id = MODULE_ID_VOICE_CLIENT;
|
| 46 | int dst_id = MODULE_ID_VOICE_SERVER;
|
| 47 | int msg_cmd = MSG_CMD_CAP_VALSA_OPEN;
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 48 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 49 | //´´½¨ÏûÏ¢¶ÓÁÐ
|
| 50 | msg_handle = msgget(module_id, IPC_CREAT|0600);
|
| 51 |
|
| 52 | //·¢ËÍÏûÏ¢
|
| 53 | ret = ipc_send_message(module_id, dst_id, msg_cmd, sizeof(int), (unsigned char *)(&vmode), 0);
|
| 54 | if(0 != ret){
|
| 55 | printf("%s: send msg error(%d)!\n", __func__, ret);
|
| 56 | msgctl(msg_handle,IPC_RMID,0);
|
| 57 | return ret;
|
| 58 | }
|
| 59 | printf("%s: send msg success(%d)!\n", __func__, ret);
|
| 60 |
|
| 61 | //½ÓÊÕÏûÏ¢
|
| 62 | while(1)
|
| 63 | {
|
| 64 | memset(&msg, 0x00, sizeof(MSG_BUF));
|
| 65 |
|
| 66 | //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
|
| 67 | ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
|
| 68 | if(0 > ret){
|
| 69 | continue;
|
| 70 | }
|
| 71 |
|
| 72 | //Æ¥Åäµ½ÊÇMSG_CMD_CAP_VALSA_OPENʱ²Å´¦Àí
|
| 73 | if(msg_cmd == msg.usMsgCmd){
|
| 74 | ret = *((int *)msg.aucDataBuf);
|
| 75 | msgctl(msg_handle,IPC_RMID,0);
|
| 76 | printf("%s: receive msg success(%d)!\n", __func__, ret);
|
| 77 | break;
|
| 78 | }
|
| 79 | }
|
| 80 |
|
| 81 | return ret;
|
| 82 | }
|
| 83 |
|
| 84 | int cap_alsa_voice_close(int vmode)
|
| 85 | {
|
| 86 | int ret = 0;
|
| 87 | int msg_handle = 0;
|
| 88 | MSG_BUF msg;
|
| 89 | LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
|
| 90 | int module_id = MODULE_ID_VOICE_CLIENT;
|
| 91 | int dst_id = MODULE_ID_VOICE_SERVER;
|
| 92 | int msg_cmd = MSG_CMD_CAP_VALSA_CLOSE;
|
| 93 |
|
| 94 | //´´½¨ÏûÏ¢¶ÓÁÐ
|
| 95 | msg_handle = msgget(module_id, IPC_CREAT|0600);
|
| 96 |
|
| 97 | //·¢ËÍÏûÏ¢
|
| 98 | ret = ipc_send_message(module_id, dst_id, msg_cmd, sizeof(int), (unsigned char *)(&vmode), 0);
|
| 99 | if(0 != ret){
|
| 100 | printf("%s: send msg error(%d)!\n", __func__, ret);
|
| 101 | msgctl(msg_handle,IPC_RMID,0);
|
| 102 | return ret;
|
| 103 | }
|
| 104 | printf("%s: send msg success(%d)!\n", __func__, ret);
|
| 105 |
|
| 106 | //½ÓÊÕÏûÏ¢
|
| 107 | while(1)
|
| 108 | {
|
| 109 | memset(&msg, 0x00, sizeof(MSG_BUF));
|
| 110 |
|
| 111 | //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
|
| 112 | ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
|
| 113 | if(0 > ret){
|
| 114 | continue;
|
| 115 | }
|
| 116 |
|
| 117 | //Æ¥Åäµ½ÊÇMSG_CMD_CAP_VALSA_CLOSEʱ²Å´¦Àí
|
| 118 | if(msg_cmd == msg.usMsgCmd){
|
| 119 | ret = *((int *)msg.aucDataBuf);
|
| 120 | msgctl(msg_handle,IPC_RMID,0);
|
| 121 | printf("%s: receive msg success(%d)!\n", __func__, ret);
|
| 122 | break;
|
| 123 | }
|
| 124 | }
|
| 125 |
|
| 126 | return ret;
|
| 127 | }
|
| 128 |
|
| 129 | int ipc_cap_alsa_voice_open(int vmode)
|
| 130 | {
|
| 131 | int ret = 0;
|
| 132 | int func_id = IPC_CAP_ALSA_VOICE_OPEN;
|
| 133 | voice_ctrl_recvmsg[func_id].func_id = VOICE_WAIT_MSG_FROM_CAP;
|
| 134 |
|
| 135 | ret = Voice_Ctrl_Rpmsg_Send(func_id, &vmode);
|
| 136 |
|
| 137 | if (0 >= ret){
|
| 138 | printf("%s: Voice_Ctrl_Rpmsg_Send error, return %d!\n", __func__, ret);
|
| 139 | return VOICEIPC_ERROR;
|
| 140 | }
|
| 141 | printf("%s: Voice_Ctrl_Rpmsg_Send success, write_len=%d!\n", __func__, ret);
|
| 142 |
|
| 143 | while(func_id != voice_ctrl_recvmsg[func_id].func_id){
|
| 144 | usleep(1);
|
| 145 | }
|
| 146 |
|
| 147 | memcpy(&ret, voice_ctrl_recvmsg[func_id].param, voice_ctrl_recvmsg[func_id].param_len);
|
| 148 | printf("%s: ipc receive success, ret=%d!\n", __func__, ret);
|
| 149 |
|
| 150 | return ret;
|
| 151 | }
|
| 152 |
|
| 153 | int ipc_cap_alsa_voice_close(int vmode)
|
| 154 | {
|
| 155 | int ret = 0;
|
| 156 | int func_id = IPC_CAP_ALSA_VOICE_CLOSE;
|
| 157 | voice_ctrl_recvmsg[func_id].func_id = VOICE_WAIT_MSG_FROM_CAP;
|
| 158 |
|
| 159 | ret = Voice_Ctrl_Rpmsg_Send(func_id, &vmode);
|
| 160 |
|
| 161 | if (0 >= ret){
|
| 162 | printf("%s: Voice_Ctrl_Rpmsg_Send error, return %d!\n", __func__, ret);
|
| 163 | return VOICEIPC_ERROR;
|
| 164 | }
|
| 165 | printf("%s: Voice_Ctrl_Rpmsg_Send success, write_len=%d!\n", __func__, ret);
|
| 166 |
|
| 167 | while(func_id != voice_ctrl_recvmsg[func_id].func_id){
|
| 168 | usleep(1);
|
| 169 | }
|
| 170 |
|
| 171 | memcpy(&ret, voice_ctrl_recvmsg[func_id].param, voice_ctrl_recvmsg[func_id].param_len);
|
| 172 | printf("%s: ipc receive success, ret=%d!\n", __func__, ret);
|
| 173 |
|
| 174 | return ret;
|
| 175 | }
|
| 176 |
|
| 177 | void ipc_set_voice_device_mode_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 178 | {
|
| 179 | int ret = VOICEIPC_OK;
|
| 180 | int msg_len = 0;
|
| 181 | int dev_mode = 0;
|
| 182 |
|
| 183 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 184 | dev_mode = *((int *)msg.param);
|
| 185 | ret = sc_audio_set_voice_device_mode(dev_mode);
|
| 186 |
|
| 187 | //msg.func_idä¸å
|
| 188 | msg.param_len = sizeof(int);
|
| 189 | memcpy(msg.param, &ret, msg.param_len);
|
| 190 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 191 |
|
| 192 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 193 |
|
| 194 | if (0 >= ret){
|
| 195 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 196 | }
|
| 197 | }
|
| 198 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 199 | void ipc_get_voice_device_mode_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 200 | {
|
| 201 | int ret = VOICEIPC_OK;
|
| 202 | int msg_len = 0;
|
| 203 | int *p_dev_mode = NULL;
|
| 204 |
|
| 205 | p_dev_mode = (int *)msg.param;
|
| 206 | ret = sc_audio_get_voice_device_mode(p_dev_mode);
|
| 207 |
|
| 208 | //msg.func_idä¸å
|
| 209 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 210 | if(0 == ret)
|
| 211 | memcpy(msg.param, p_dev_mode, msg.param_len);
|
| 212 | else
|
| 213 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 214 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 215 |
|
| 216 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 217 |
|
| 218 | if (0 >= ret){
|
| 219 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 220 | }
|
| 221 | }
|
| 222 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 223 | void ipc_set_rx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 224 | {
|
| 225 | int ret = VOICEIPC_OK;
|
| 226 | int msg_len = 0;
|
| 227 | int vol = 0;
|
| 228 |
|
| 229 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 230 | vol = *((int *)msg.param);
|
| 231 | ret = sc_audio_set_rx_voice_vol(vol);
|
| 232 |
|
| 233 | //msg.func_idä¸å
|
| 234 | msg.param_len = sizeof(int);
|
| 235 | memcpy(msg.param, &ret, msg.param_len);
|
| 236 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 237 |
|
| 238 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 239 |
|
| 240 | if (0 >= ret){
|
| 241 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 242 | }
|
| 243 | }
|
| 244 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 245 | void ipc_get_rx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 246 | {
|
| 247 | int ret = VOICEIPC_OK;
|
| 248 | int msg_len = 0;
|
| 249 | int *p_vol = NULL;
|
| 250 |
|
| 251 | p_vol = (int *)msg.param;
|
| 252 | ret = sc_audio_get_rx_voice_vol(p_vol);
|
| 253 |
|
| 254 | //msg.func_idä¸å
|
| 255 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 256 | if(0 == ret)
|
| 257 | memcpy(msg.param, p_vol, msg.param_len);
|
| 258 | else
|
| 259 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 260 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 261 |
|
| 262 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 263 |
|
| 264 | if (0 >= ret){
|
| 265 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 266 | }
|
| 267 | }
|
| 268 |
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 269 | void ipc_set_rx_voice_vol_gain_rcv(voice_ipc_control_msg msg)
|
| 270 | {
|
| 271 | int ret = VOICEIPC_OK;
|
| 272 | int msg_len = 0;
|
| 273 | int gain = 0;
|
| 274 |
|
| 275 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 276 | gain = *((int *)msg.param);
|
| 277 | ret = sc_audio_set_rx_voice_vol_gain(gain);
|
| 278 |
|
| 279 | //msg.func_idä¸å
|
| 280 | msg.param_len = sizeof(int);
|
| 281 | memcpy(msg.param, &ret, msg.param_len);
|
| 282 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 283 |
|
| 284 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 285 |
|
| 286 | if (0 >= ret){
|
| 287 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 288 | }
|
| 289 | }
|
| 290 |
|
| 291 | void ipc_get_rx_voice_vol_gain_rcv(voice_ipc_control_msg msg)
|
| 292 | {
|
| 293 | int ret = VOICEIPC_OK;
|
| 294 | int msg_len = 0;
|
| 295 | int *p_vol = NULL;
|
| 296 |
|
| 297 | p_vol = (int *)msg.param;
|
| 298 | ret = sc_audio_get_rx_voice_vol_gain(p_vol);
|
| 299 |
|
| 300 | //msg.func_idä¸å
|
| 301 | msg.param_len = sizeof(int);
|
| 302 | if(0 == ret)
|
| 303 | memcpy(msg.param, p_vol, msg.param_len);
|
| 304 | else
|
| 305 | memcpy(msg.param, &ret, msg.param_len);
|
| 306 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 307 |
|
| 308 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 309 |
|
| 310 | if (0 >= ret){
|
| 311 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 312 | }
|
| 313 | }
|
| 314 |
|
| 315 | void ipc_set_tx_voice_vol_gain_rcv(voice_ipc_control_msg msg)
|
| 316 | {
|
| 317 | int ret = VOICEIPC_OK;
|
| 318 | int msg_len = 0;
|
| 319 | int gain = 0;
|
| 320 |
|
| 321 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 322 | gain = *((int *)msg.param);
|
| 323 | ret = sc_audio_set_tx_voice_vol_gain(gain);
|
| 324 |
|
| 325 | //msg.func_idä¸å
|
| 326 | msg.param_len = sizeof(int);
|
| 327 | memcpy(msg.param, &ret, msg.param_len);
|
| 328 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 329 |
|
| 330 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 331 |
|
| 332 | if (0 >= ret){
|
| 333 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 334 | }
|
| 335 | }
|
| 336 |
|
| 337 | void ipc_get_tx_voice_vol_gain_rcv(voice_ipc_control_msg msg)
|
| 338 | {
|
| 339 | int ret = VOICEIPC_OK;
|
| 340 | int msg_len = 0;
|
| 341 | int *p_vol = NULL;
|
| 342 |
|
| 343 | p_vol = (int *)msg.param;
|
| 344 | ret = sc_audio_get_tx_voice_vol_gain(p_vol);
|
| 345 |
|
| 346 | //msg.func_idä¸å
|
| 347 | msg.param_len = sizeof(int);
|
| 348 | if(0 == ret)
|
| 349 | memcpy(msg.param, p_vol, msg.param_len);
|
| 350 | else
|
| 351 | memcpy(msg.param, &ret, msg.param_len);
|
| 352 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 353 |
|
| 354 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 355 |
|
| 356 | if (0 >= ret){
|
| 357 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 358 | }
|
| 359 | }
|
| 360 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 361 | void ipc_set_tx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 362 | {
|
| 363 | int ret = VOICEIPC_OK;
|
| 364 | int msg_len = 0;
|
| 365 | int vol = 0;
|
| 366 |
|
| 367 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 368 | vol = *((int *)msg.param);
|
| 369 | ret = sc_audio_set_tx_voice_vol(vol);
|
| 370 |
|
| 371 | //msg.func_idä¸å
|
| 372 | msg.param_len = sizeof(int);
|
| 373 | memcpy(msg.param, &ret, msg.param_len);
|
| 374 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 375 |
|
| 376 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 377 |
|
| 378 | if (0 >= ret){
|
| 379 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 380 | }
|
| 381 | }
|
| 382 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 383 | void ipc_get_tx_voice_vol_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 384 | {
|
| 385 | int ret = VOICEIPC_OK;
|
| 386 | int msg_len = 0;
|
| 387 | int *p_vol = NULL;
|
| 388 |
|
| 389 | p_vol = (int *)msg.param;
|
| 390 | ret = sc_audio_get_tx_voice_vol(p_vol);
|
| 391 |
|
| 392 | //msg.func_idä¸å
|
| 393 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 394 | if(0 == ret)
|
| 395 | memcpy(msg.param, p_vol, msg.param_len);
|
| 396 | else
|
| 397 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 398 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 399 |
|
| 400 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 401 |
|
| 402 | if (0 >= ret){
|
| 403 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 404 | }
|
| 405 | }
|
| 406 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 407 | 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] | 408 | {
|
| 409 | int ret = VOICEIPC_OK;
|
| 410 | int msg_len = 0;
|
| 411 | int mute = 0;
|
| 412 |
|
| 413 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 414 | mute = *((int *)msg.param);
|
| 415 | ret = sc_audio_set_tx_voice_mute_state(mute);
|
| 416 |
|
| 417 | //msg.func_idä¸å
|
| 418 | msg.param_len = sizeof(int);
|
| 419 | memcpy(msg.param, &ret, msg.param_len);
|
| 420 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 421 |
|
| 422 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 423 |
|
| 424 | if (0 >= ret){
|
| 425 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 426 | }
|
| 427 | }
|
| 428 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 429 | 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] | 430 | {
|
| 431 | int ret = VOICEIPC_OK;
|
| 432 | int msg_len = 0;
|
| 433 | int *p_mute = NULL;
|
| 434 |
|
| 435 | p_mute = (int *)msg.param;
|
| 436 | ret = sc_audio_get_tx_voice_mute_state(p_mute);
|
| 437 |
|
| 438 | //msg.func_idä¸å
|
| 439 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 440 | if(0 == ret)
|
| 441 | memcpy(msg.param, p_mute, msg.param_len);
|
| 442 | else
|
| 443 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 444 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 445 |
|
| 446 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 447 |
|
| 448 | if (0 >= ret){
|
| 449 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 450 | }
|
| 451 | }
|
| 452 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 453 | 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] | 454 | {
|
| 455 | int ret = VOICEIPC_OK;
|
| 456 | int msg_len = 0;
|
| 457 | int mute = 0;
|
| 458 |
|
| 459 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
| 460 | mute = *((int *)msg.param);
|
| 461 | ret = sc_audio_set_rx_voice_mute_state(mute);
|
| 462 |
|
| 463 | //msg.func_idä¸å
|
| 464 | msg.param_len = sizeof(int);
|
| 465 | memcpy(msg.param, &ret, msg.param_len);
|
| 466 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 467 |
|
| 468 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 469 |
|
| 470 | if (0 >= ret){
|
| 471 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 472 | }
|
| 473 | }
|
| 474 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 475 | 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] | 476 | {
|
| 477 | int ret = VOICEIPC_OK;
|
| 478 | int msg_len = 0;
|
| 479 | int *p_mute = NULL;
|
| 480 |
|
| 481 | p_mute = (int *)msg.param;
|
| 482 | ret = sc_audio_get_rx_voice_mute_state(p_mute);
|
| 483 |
|
| 484 | //msg.func_idä¸å
|
| 485 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 486 | if(0 == ret)
|
| 487 | memcpy(msg.param, p_mute, msg.param_len);
|
| 488 | else
|
| 489 | memcpy(msg.param, &ret, msg.param_len);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 490 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 491 |
|
| 492 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 493 |
|
| 494 | if (0 >= ret){
|
| 495 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 496 | }
|
| 497 | }
|
| 498 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 499 | void ipc_set_loopback_enable_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 500 | {
|
| 501 | int ret = VOICEIPC_OK;
|
| 502 | int msg_len = 0;
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 503 | int dev_mode = 0,enable = 0;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 504 |
|
| 505 | //memcpy(&dev_mode, msg.param, msg.param_len);
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 506 | //enable = *((int *)msg.param);
|
| 507 | memcpy(&dev_mode, msg.param, sizeof(int));
|
| 508 | memcpy(&enable, msg.param+sizeof(int), sizeof(int));
|
| 509 |
|
| 510 | //ret = sc_audio_set_loopback_enable_state(enable);
|
| 511 | ret = ap_audio_set_loopback_enable(dev_mode,enable);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 512 |
|
| 513 | //msg.func_idä¸å
|
| 514 | msg.param_len = sizeof(int);
|
| 515 | memcpy(msg.param, &ret, msg.param_len);
|
| 516 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 517 |
|
| 518 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 519 |
|
| 520 | if (0 >= ret){
|
| 521 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 522 | }
|
| 523 | }
|
| 524 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 525 | void ipc_get_loopback_enable_state_rcv(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 526 | {
|
| 527 | int ret = VOICEIPC_OK;
|
| 528 | int msg_len = 0;
|
| 529 | int *p_enable = NULL;
|
| 530 |
|
| 531 | p_enable = (int *)msg.param;
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame] | 532 | //ret = sc_audio_get_loopback_enable_state(p_enable);
|
| 533 | ret = ap_audio_get_loopback_enable(p_enable);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 534 | //msg.func_idä¸å
|
| 535 | msg.param_len = sizeof(int);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 536 | if(0 == ret)
|
| 537 | memcpy(msg.param, p_enable, msg.param_len);
|
| 538 | else
|
| 539 | memcpy(msg.param, &ret, msg.param_len);
|
| 540 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 541 |
|
| 542 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 543 |
|
| 544 | if (0 >= ret){
|
| 545 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 546 | }
|
| 547 | }
|
| 548 |
|
| 549 | #ifdef _USE_VOICE_ALSA
|
| 550 | void ipc_ap_alsa_voice_open_rcv(voice_ipc_control_msg msg)
|
| 551 | {
|
| 552 | int ret = VOICEIPC_OK;
|
| 553 | int msg_len = 0;
|
| 554 | int vmode = 0;
|
| 555 |
|
| 556 | vmode = *((int *)msg.param);
|
| 557 | ret = alsa_voice_open(vmode);
|
| 558 |
|
| 559 | //msg.func_idä¸å
|
| 560 | msg.param_len = sizeof(int);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 561 | memcpy(msg.param, &ret, msg.param_len);
|
| 562 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 563 |
|
| 564 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 565 |
|
| 566 | if (0 >= ret){
|
| 567 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 568 | }
|
| 569 | }
|
| 570 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 571 | void ipc_ap_alsa_voice_close_rcv(voice_ipc_control_msg msg)
|
| 572 | {
|
| 573 | int ret = VOICEIPC_OK;
|
| 574 | int msg_len = 0;
|
| 575 | int vmode = 0;
|
| 576 |
|
| 577 | vmode = *((int *)msg.param);
|
| 578 | ret = alsa_voice_close(vmode);
|
| 579 |
|
| 580 | //msg.func_idä¸å
|
| 581 | msg.param_len = sizeof(int);
|
| 582 | memcpy(msg.param, &ret, msg.param_len);
|
| 583 | msg_len = VOICE_HEAD_LEN + msg.param_len;
|
| 584 |
|
| 585 | ret = write(voice_ipc_fd, &msg, msg_len);
|
| 586 |
|
| 587 | if (0 >= ret){
|
| 588 | printf("%s: write error(%d)!\n", __func__, ret);
|
| 589 | }
|
| 590 | }
|
| 591 | #endif
|
| 592 |
|
| 593 | void voice_ipc_recv_proc(voice_ipc_control_msg msg)
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 594 | {
|
| 595 | switch(msg.func_id){
|
| 596 | case IPC_SET_VOICE_DEVICE_MODE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 597 | ipc_set_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 598 | break;
|
| 599 | case IPC_GET_VOICE_DEVICE_MODE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 600 | ipc_get_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 601 | break;
|
| 602 | case IPC_SET_RX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 603 | ipc_set_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 604 | break;
|
| 605 | case IPC_GET_RX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 606 | ipc_get_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 607 | break;
|
xf.li | f233062 | 2024-05-15 18:17:18 -0700 | [diff] [blame] | 608 | case IPC_SET_RX_VOICE_VOL_GAIN:
|
| 609 | ipc_set_rx_voice_vol_gain_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
| 610 | break;
|
| 611 | case IPC_GET_RX_VOICE_VOL_GAIN:
|
| 612 | ipc_get_rx_voice_vol_gain_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
| 613 | break;
|
| 614 | case IPC_SET_TX_VOICE_VOL_GAIN:
|
| 615 | ipc_set_tx_voice_vol_gain_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
| 616 | break;
|
| 617 | case IPC_GET_TX_VOICE_VOL_GAIN:
|
| 618 | ipc_get_tx_voice_vol_gain_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
| 619 | break;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 620 | case IPC_SET_TX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 621 | ipc_set_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 622 | break;
|
| 623 | case IPC_GET_TX_VOICE_VOL:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 624 | ipc_get_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 625 | break;
|
| 626 | case IPC_SET_TX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 627 | 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] | 628 | break;
|
| 629 | case IPC_GET_TX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 630 | 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] | 631 | break;
|
| 632 | case IPC_SET_RX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 633 | 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] | 634 | break;
|
| 635 | case IPC_GET_RX_VOICE_MUTE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 636 | 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] | 637 | break;
|
| 638 | case IPC_SET_LOOPBACK_ENABLE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 639 | ipc_set_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 640 | break;
|
| 641 | case IPC_GET_LOOPBACK_ENABLE_STATE:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 642 | ipc_get_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 643 | break;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 644 | #ifdef _USE_VOICE_ALSA
|
| 645 | case IPC_AP_ALSA_VOICE_OPEN:
|
| 646 | ipc_ap_alsa_voice_open_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
| 647 | break;
|
| 648 | case IPC_AP_ALSA_VOICE_CLOSE:
|
| 649 | ipc_ap_alsa_voice_close_rcv(voice_ctrl_recvmsg[msg.func_id]);
|
| 650 | break;
|
| 651 | #endif
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 652 | default:
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 653 | break;
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 654 | }
|
| 655 | }
|
| 656 |
|
| 657 | void Voice_Ctrl_Rpmsg_Recv(void)
|
| 658 | {
|
| 659 | int read_len = 0;
|
| 660 | voice_ipc_control_msg tmpbuf = {0};
|
| 661 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 662 | while(1){
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 663 | 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] | 664 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 665 | if (0 >= read_len){
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 666 | sleep(1);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 667 | continue;
|
| 668 | }
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 669 | printf("%s: voice_ipc_fd=%d, read_len=%d\n", __func__, voice_ipc_fd, read_len);
|
| 670 |
|
| 671 | //Êý¾Ý¶ÁÈ¡ÍêºóÔٸıäfuc_id
|
| 672 | if(0 != tmpbuf.param_len){
|
| 673 | memcpy(voice_ctrl_recvmsg[tmpbuf.func_id].param, tmpbuf.param, tmpbuf.param_len);
|
| 674 | }
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 675 | voice_ctrl_recvmsg[tmpbuf.func_id].param_len = tmpbuf.param_len;
|
| 676 | voice_ctrl_recvmsg[tmpbuf.func_id].func_id = tmpbuf.func_id;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 677 | 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] | 678 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 679 | voice_ipc_recv_proc(voice_ctrl_recvmsg[tmpbuf.func_id]);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 680 | }
|
| 681 | }
|
| 682 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 683 | int Voice_Ctrl_Rpmsg_Send(int func_id, int *msg)
|
| 684 | {
|
| 685 | voice_ipc_control_msg tmpbuf = {0};
|
| 686 | int tmpbuf_len = 0;
|
| 687 | int write_len = 0;
|
| 688 |
|
| 689 | tmpbuf.func_id = func_id;
|
| 690 |
|
| 691 | if(NULL == msg){
|
| 692 | tmpbuf.param_len = 0;
|
| 693 | }else{
|
| 694 | tmpbuf.param_len = sizeof(int);
|
| 695 | memcpy(tmpbuf.param, msg, tmpbuf.param_len);
|
| 696 | }
|
| 697 |
|
| 698 | tmpbuf_len = VOICE_HEAD_LEN + tmpbuf.param_len;
|
| 699 |
|
| 700 | //printf("Voice_Ctrl_Rpmsg_Send, voice_ipc_fd = %d\n", voice_ipc_fd);
|
| 701 | write_len = write(voice_ipc_fd, &tmpbuf, tmpbuf_len);
|
| 702 |
|
| 703 | return write_len;
|
| 704 | }
|
| 705 |
|
| 706 | int voice_ipc_init(void) //ééåå§å?
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 707 | {
|
| 708 | voice_ipc_fd = open(VOICE_IPC_CONTROL_CHANNEL, O_RDWR);
|
| 709 |
|
| 710 | if(0 > voice_ipc_fd){
|
| 711 | printf("%s: open the channel(%s) error!\n", __func__, VOICE_IPC_CONTROL_CHANNEL);
|
| 712 | return VOICEIPC_ERROR;
|
| 713 | }
|
| 714 |
|
| 715 | if(0 > ioctl(voice_ipc_fd, RPMSG_CREATE_CHANNEL, VOICE_IPC_CONTROL_CHANNEL_SIZE)){
|
| 716 | printf("%s: ioctl RPMSG_CREATE_CHANNEL fail!\n", __func__);
|
| 717 | close(voice_ipc_fd);
|
| 718 | voice_ipc_fd = -1;
|
| 719 | return VOICEIPC_ERROR;
|
| 720 | }
|
| 721 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 722 | if(0 > ioctl(voice_ipc_fd, RPMSG_SET_INT_FLAG, NULL)){ //å䏿?
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 723 | printf("%s: ioctl RPMSG_SET_INT_FLAG fail!\n", __func__);
|
| 724 | close(voice_ipc_fd);
|
| 725 | voice_ipc_fd = -1;
|
| 726 | return VOICEIPC_ERROR;
|
| 727 | }
|
| 728 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 729 | if(0 > ioctl(voice_ipc_fd, RPMSG_CLEAR_POLL_FLAG, NULL)){ //é»å¡æ¹å¼è¯»æ°æ?
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 730 | printf("%s: ioctl RPMSG_CLEAR_POLL_FLAG fail!\n", __func__);
|
| 731 | close(voice_ipc_fd);
|
| 732 | voice_ipc_fd = -1;
|
| 733 | return VOICEIPC_ERROR;
|
| 734 | }
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 735 |
|
| 736 | printf("voice_ipc_init %s create success! voice_ipc_fd = %d\n", VOICE_IPC_CONTROL_CHANNEL, voice_ipc_fd);
|
| 737 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 738 | return VOICEIPC_OK;
|
| 739 | }
|
| 740 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 741 | int recv_msg_proc(MSG_BUF msg)
|
| 742 | {
|
| 743 | int ret = 0;
|
| 744 | int vmode = 0;
|
| 745 | int module_id = MODULE_ID_VOICE_SERVER;
|
| 746 | int dst_id = MODULE_ID_VOICE_CLIENT;
|
| 747 |
|
| 748 | switch(msg.usMsgCmd){
|
| 749 | case MSG_CMD_CAP_VALSA_OPEN:
|
| 750 | vmode = *((int *)msg.aucDataBuf);
|
| 751 | ret = ipc_cap_alsa_voice_open(vmode);
|
| 752 | //dst_id = MODULE_ID_CAP_VALSA_OPEN;
|
| 753 | ret = ipc_send_message(module_id, dst_id, msg.usMsgCmd, sizeof(int), (unsigned char *)(&ret), 0);
|
| 754 | if(0 != ret){
|
| 755 | printf("%s: ipc_send_message error, return %d!\n", __func__, ret);
|
| 756 | }
|
| 757 | break;
|
| 758 | case MSG_CMD_CAP_VALSA_CLOSE:
|
| 759 | vmode = *((int *)msg.aucDataBuf);
|
| 760 | ret = ipc_cap_alsa_voice_close(vmode);
|
| 761 | //dst_id = MODULE_ID_CAP_VALSA_CLOSE;
|
| 762 | ret = ipc_send_message(module_id, dst_id, msg.usMsgCmd, sizeof(int), (unsigned char *)(&ret), 0);
|
| 763 | if(0 != ret){
|
| 764 | printf("%s: ipc_send_message error, return %d!\n", __func__, ret);
|
| 765 | }
|
| 766 | break;
|
| 767 | default:
|
| 768 | printf("%s: msg.usMsgCmd=%d, not support!\n", __func__, msg.usMsgCmd);
|
| 769 | break;
|
| 770 | }
|
| 771 |
|
| 772 | return ret;
|
| 773 | }
|
| 774 |
|
| 775 | void recv_cap_voice_alsa(void)
|
| 776 | {
|
| 777 | int ret = 0;
|
| 778 | int msg_handle = 0;
|
| 779 | MSG_BUF msg;
|
| 780 | LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
|
| 781 | int module_id = MODULE_ID_VOICE_SERVER;
|
| 782 |
|
| 783 | //´´½¨ÏûÏ¢¶ÓÁÐ
|
| 784 | msg_handle = msgget(module_id, IPC_CREAT|0600);
|
| 785 |
|
| 786 | //½ÓÊÕÏûÏ¢
|
| 787 | while(1)
|
| 788 | {
|
| 789 | memset(&msg, 0x00, sizeof(MSG_BUF));
|
| 790 |
|
| 791 | //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
|
| 792 | ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
|
| 793 |
|
| 794 | if(0 > ret){
|
| 795 | continue;
|
| 796 | }
|
| 797 |
|
| 798 | recv_msg_proc(msg);
|
| 799 | }
|
| 800 | }
|
| 801 |
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 802 | void recv_update_voice_nvrw_ipc(void)
|
| 803 | {
|
| 804 | int read_len = 0;
|
| 805 | int ret = -1;
|
| 806 | int fd = -1;
|
| 807 |
|
| 808 | recv_voice_nvrw_buf = (unsigned char*)malloc(VOICE_HEAD_LEN + VOICE_NVRW_MAX_LEN);
|
| 809 | if(!recv_voice_nvrw_buf){
|
| 810 | printf("%s: recv_voice_nvrw_buf malloc fail!\n", __func__);
|
| 811 | return;
|
| 812 | }
|
| 813 |
|
| 814 | while(1){
|
| 815 | read_len = read(voice_ipc_fd, recv_voice_nvrw_buf, VOICE_HEAD_LEN + VOICE_NVRW_MAX_LEN);
|
| 816 | if (0 >= read_len){
|
| 817 | sleep(1);
|
| 818 | continue;
|
| 819 | }
|
| 820 |
|
| 821 | printf("%s: read_len = %d, func_id = %d, param_len = %d!\n", __func__, read_len, \
|
| 822 | *((int*)recv_voice_nvrw_buf), *((int*)recv_voice_nvrw_buf + 1));
|
| 823 |
|
| 824 | #if 0
|
| 825 | printf("%s: param[0]=%02x,param[1]=%02x,param[2]=%02x,param[3]=%02x,param[4]=%02x,param[5]=%02x,param[6]=%02x!\n", \
|
| 826 | __func__, recv_voice_nvrw_buf.param[0], recv_voice_nvrw_buf.param[1], recv_voice_nvrw_buf.param[2], \
|
| 827 | recv_voice_nvrw_buf.param[3], recv_voice_nvrw_buf.param[4], recv_voice_nvrw_buf.param[5], recv_voice_nvrw_buf.param[6]);
|
| 828 |
|
| 829 | int writesize = 0;
|
| 830 | FILE *ptest = fopen("/mnt/userdata/voice_nv_test_ap.bin", "wb");
|
| 831 | if(!ptest){
|
| 832 | printf("%s: Unable to create file '/mnt/userdata/voice_nv_test_ap.bin'!\n", __func__);
|
| 833 | }
|
| 834 |
|
| 835 | writesize = fwrite(recv_voice_nvrw_buf.param, 1, recv_voice_nvrw_buf.param_len, ptest);
|
| 836 | printf("%s: writesize = %d!\n", __func__, writesize);
|
| 837 |
|
| 838 | if(NULL != ptest){
|
| 839 | fclose(ptest);
|
| 840 | }
|
| 841 | #endif
|
| 842 |
|
| 843 | fd = open(VOICE_DEV_NAME, O_RDWR);
|
| 844 |
|
| 845 | if(0 > fd){
|
| 846 | printf("%s: open voice device error!\n", __func__);
|
| 847 | }
|
| 848 | else{
|
| 849 | ret = ioctl(fd, VOICE_IOCTL_SET_VOICE_NVRW, recv_voice_nvrw_buf);
|
| 850 | printf("%s: ioctl /dev/voice_device end, ret=%d!\n", __func__, ret);
|
| 851 | close(fd);
|
| 852 | }
|
| 853 |
|
| 854 | break;
|
| 855 | }
|
| 856 |
|
| 857 | if(recv_voice_nvrw_buf){
|
| 858 | free(recv_voice_nvrw_buf);
|
| 859 | recv_voice_nvrw_buf = NULL;
|
| 860 | }
|
| 861 |
|
| 862 | return;
|
| 863 | }
|
| 864 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 865 | int main(int argc, char **argv)
|
| 866 | {
|
| 867 | int ret = 0;
|
| 868 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 869 | //ipcͨµÀ³õʼ»¯
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 870 | ret = voice_ipc_init();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 871 | if(0 > ret){
|
| 872 | printf("voice_ipc_init %s error!\n", VOICE_IPC_CONTROL_CHANNEL);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 873 | return -1;
|
| 874 | }
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 875 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 876 | //ipc³õʼ»¯ºó£¬´´½¨msgÏûÏ¢½ÓÊÕÏß³Ì
|
| 877 | pthread_t recv_thread_tid;
|
| 878 | if(0 != pthread_create(&recv_thread_tid, NULL, (void *)recv_cap_voice_alsa, NULL)){
|
| 879 | printf("recv_cap_voice_alsa create error!\n");
|
| 880 | }
|
| 881 |
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 882 | sleep(4); //µÈ´ýcap²àÒôƵºË¼äͨµÀ½¨Á¢Íê³É
|
| 883 |
|
| 884 | //ipc³õʼ»¯ºó£¬Ö±½Ó»ñÈ¡cap²àvoice nv
|
| 885 | recv_update_voice_nvrw_ipc();
|
| 886 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 887 | Voice_Ctrl_Rpmsg_Recv();
|
| 888 |
|
| 889 | return 0;
|
| 890 | }
|
| 891 |
|
| 892 | #endif
|