[Feature][ZXW-41] merged 0601 version
Change-Id: I667af6bb09d65581d455b73f8984c160b2c67ad8
diff --git a/ap/lib/libvoice/Makefile b/ap/lib/libvoice/Makefile
index 31a4d66..a7f371a 100644
--- a/ap/lib/libvoice/Makefile
+++ b/ap/lib/libvoice/Makefile
@@ -54,7 +54,7 @@
# objects
#*******************************************************************************
ifeq ($(USE_VOICE_ALSA),yes)
-voiceipc_OBJECTS += voice_api.o voiceipc.o
+voiceipc_OBJECTS += alsa_call.o voice_api.o voiceipc.o
endif
@@ -69,6 +69,9 @@
SHAREDFLAG := -shared -lc
LDLIBS += -L$(LIB_DIR)/libtinyalsa
LDLIBS += -ltinyalsa
+LDLIBS += -lnvram_sc -L$(zte_lib_path)/libnvram
+LDLIBS += -lsoftap -L$(zte_lib_path)/libsoftap
+LDLIBS += -lsoft_timer_sc -L$(zte_lib_path)/libsoft_timer
ifeq ($(USE_VOICE_ALSA),yes)
all: $(LIB_STATIC) $(LIB_SHARED) $(EXEC_voiceipc)
diff --git a/ap/lib/libvoice/include/voice_ipc.h b/ap/lib/libvoice/include/voice_ipc.h
index abe83b2..3b58efb 100755
--- a/ap/lib/libvoice/include/voice_ipc.h
+++ b/ap/lib/libvoice/include/voice_ipc.h
@@ -1,4 +1,5 @@
#ifdef USE_CAP_SUPPORT
+#include "message.h"
#define VOICEIPC_OK 0
#define VOICEIPC_ERROR -1
@@ -10,7 +11,7 @@
#define VOICE_HEAD_LEN (2 * sizeof(int))
#define VOICE_CONTROL_MAX_LEN 32
-enum voice_ipc_func_type {
+enum voice_ipc_func_type{
IPC_SET_VOICE_DEVICE_MODE = 0,
IPC_GET_VOICE_DEVICE_MODE = 1,
IPC_SET_RX_VOICE_VOL = 2,
@@ -23,30 +24,57 @@
IPC_GET_RX_VOICE_MUTE_STATE = 9,
IPC_SET_LOOPBACK_ENABLE_STATE = 10,
IPC_GET_LOOPBACK_ENABLE_STATE = 11,
+ IPC_AP_ALSA_VOICE_OPEN = 12,
+ IPC_AP_ALSA_VOICE_CLOSE = 13,
+ IPC_CAP_ALSA_VOICE_OPEN = 14,
+ IPC_CAP_ALSA_VOICE_CLOSE = 15,
IPC_VOICE_FUNC_MAX
};
-typedef struct {
+enum voice_msg_cmd{
+ MSG_CMD_CAP_VALSA_OPEN = MSG_CMD_VOICE_BASE + 0x0, //37070
+ MSG_CMD_CAP_VALSA_CLOSE
+};
+
+typedef struct{
int func_id;
int param_len;
unsigned char param[VOICE_CONTROL_MAX_LEN];
}voice_ipc_control_msg;
-int voice_ipc_init(void);
-void Voice_Ctrl_Rpmsg_Recv(void);
+//msg
+int cap_alsa_voice_open(int vmode);
+int cap_alsa_voice_close(int vmode);
+int recv_msg_proc(MSG_BUF msg);
+void recv_cap_voice_alsa(void);
-void ipc_set_voice_device_mode(voice_ipc_control_msg msg);
-void ipc_get_voice_device_mode(voice_ipc_control_msg msg);
-void ipc_set_rx_voice_vol(voice_ipc_control_msg msg);
-void ipc_get_rx_voice_vol(voice_ipc_control_msg msg);
-void ipc_set_tx_voice_vol(voice_ipc_control_msg msg);
-void ipc_get_tx_voice_vol(voice_ipc_control_msg msg);
-void ipc_set_tx_voice_mute_state(voice_ipc_control_msg msg);
-void ipc_get_tx_voice_mute_state(voice_ipc_control_msg msg);
-void ipc_set_rx_voice_mute_state(voice_ipc_control_msg msg);
-void ipc_get_rx_voice_mute_state(voice_ipc_control_msg msg);
-void ipc_set_loopback_enable_state(voice_ipc_control_msg msg);
-void ipc_get_loopback_enable_state(voice_ipc_control_msg msg);
+//voice ipc interface
+int voice_ipc_init(void);
+int Voice_Ctrl_Rpmsg_Send(int func_id, int *msg);
+void Voice_Ctrl_Rpmsg_Recv(void);
+void voice_ipc_recv_proc(voice_ipc_control_msg msg);
+
+//send message to cap
+int ipc_cap_alsa_voice_open(int vmode);
+int ipc_cap_alsa_voice_close(int vmode);
+
+//receive message from cap
+void ipc_set_voice_device_mode_rcv(voice_ipc_control_msg msg);
+void ipc_get_voice_device_mode_rcv(voice_ipc_control_msg msg);
+void ipc_set_rx_voice_vol_rcv(voice_ipc_control_msg msg);
+void ipc_get_rx_voice_vol_rcv(voice_ipc_control_msg msg);
+void ipc_set_tx_voice_vol_rcv(voice_ipc_control_msg msg);
+void ipc_get_tx_voice_vol_rcv(voice_ipc_control_msg msg);
+void ipc_set_tx_voice_mute_state_rcv(voice_ipc_control_msg msg);
+void ipc_get_tx_voice_mute_state_rcv(voice_ipc_control_msg msg);
+void ipc_set_rx_voice_mute_state_rcv(voice_ipc_control_msg msg);
+void ipc_get_rx_voice_mute_state_rcv(voice_ipc_control_msg msg);
+void ipc_set_loopback_enable_state_rcv(voice_ipc_control_msg msg);
+void ipc_get_loopback_enable_state_rcv(voice_ipc_control_msg msg);
+#ifdef _USE_VOICE_ALSA
+void ipc_ap_alsa_voice_open_rcv(voice_ipc_control_msg msg);
+void ipc_ap_alsa_voice_close_rcv(voice_ipc_control_msg msg);
+#endif
#endif
diff --git a/ap/lib/libvoice/include/voice_lib.h b/ap/lib/libvoice/include/voice_lib.h
index 6788b77..572592e 100644
--- a/ap/lib/libvoice/include/voice_lib.h
+++ b/ap/lib/libvoice/include/voice_lib.h
@@ -15,7 +15,7 @@
#define AVOICE_4G_DEV_NUM 1
#define AVOICE_5G_DEV_NUM 1
-#ifdef _USE_VOICE_ALSA
+
typedef enum
@@ -29,6 +29,7 @@
AVOICE_5G_WB,
MAX_AVOICE_MODE
}T_Alsa_Voice_Mode;
+#ifdef _USE_VOICE_ALSA
int alsa_voice_open(int vmode);
int alsa_voice_close(int vmode);
diff --git a/ap/lib/libvoice/voice.c b/ap/lib/libvoice/voice.c
index fbc8bf1..33b3bed 100644
--- a/ap/lib/libvoice/voice.c
+++ b/ap/lib/libvoice/voice.c
@@ -23,6 +23,8 @@
#include <fcntl.h>
#include <tinyalsa/audio_mixer_ctrl.h>
#include "voice_lib.h"
+#include "voice_ipc.h"
+
#define VOICE_DEV_NAME "/dev/voice_device"
@@ -197,12 +199,15 @@
}
+static T_ZDrvVoice_Cfg s_cfgParam = {0};
+static int cur_vmode = MAX_AVOICE_MODE;
+
int zDrvVolte_PreOpen(T_ZDrvVolte_Cfg *cfgParam)
{
-
struct mixer *voice_mixer = NULL;
struct pcm_config config_voice = {0};
+ int ret = 0;
printf(" voice lib zDrvVolte_PreOpen!\n");
if (slic_flag_already == 1) {
@@ -218,17 +223,44 @@
return 0;
}
}
-#ifdef _ALSA_CODEC_IN_CAP
+#if defined(_ALSA_CODEC_IN_CAP) && defined(_USE_ALSA_AT_INTF)
- printf("%s: i2s and codec not need config,return!\n",__func__);
- return 0;
+
+ printf("%s: i2s and codec not need config,return!\n",__func__);
+ return 0;
+
+#elif defined(_ALSA_CODEC_IN_CAP)
+
+
+ if(cfgParam->clock_rate == 8000){
+
+ ret = cap_alsa_voice_open(AVOICE_4G_NB);
+ printf("%s:cap_alsa_voice_open clock_rate(%d) ret=%d!\n",__func__,cfgParam->clock_rate,ret);
+ cur_vmode = AVOICE_4G_NB;
+
+ }
+ else if(cfgParam->clock_rate == 16000){
+
+ ret = cap_alsa_voice_open(AVOICE_4G_WB);
+ printf("%s:cap_alsa_voice_open clock_rate(%d) ret=%d!\n",__func__,cfgParam->clock_rate,ret);
+ cur_vmode = AVOICE_4G_WB;
+ }
+ else{
+
+ printf("%s:cap_alsa_voice_open clock_rate(%d) not support!\n",__func__,cfgParam->clock_rate);
+ return -2;
+
+ }
+ s_cfgParam = *cfgParam;
+ return ret;
+
#endif
//open mixer dev for codec control
voice_mixer = mixer_open(0);
if (!voice_mixer) {
- printf("zte voice_mixer open failed!\n");
+ printf("voice_mixer open failed!\n");
return -1;
}
@@ -254,23 +286,23 @@
//23G card 0 dev 2
volte_pcm_voice_out = pcm_open(0, 1, PCM_OUT, &config_voice);
if (!pcm_is_ready(volte_pcm_voice_out)) {
- printf("zte volte_pcm_voice_out open failed!\n");
+ printf("volte_pcm_voice_out open failed!\n");
goto err_ret;
}
volte_pcm_voice_in = pcm_open(0, 1, PCM_IN, &config_voice);
if (!pcm_is_ready(volte_pcm_voice_in)) {
- printf("zte volte_pcm_voice_in open failed!\n");
+ printf("volte_pcm_voice_in open failed!\n");
goto err_ret;
}
if (0 != pcm_prepare(volte_pcm_voice_out)) {
- printf("zte volte_pcm_voice_out pcm_prepare failed!\n");
+ printf("volte_pcm_voice_out pcm_prepare failed!\n");
goto err_ret;
}
if (0 != pcm_prepare(volte_pcm_voice_in)) {
- printf("zte volte_pcm_voice_in pcm_prepare failed!\n");
+ printf("volte_pcm_voice_in pcm_prepare failed!\n");
goto err_ret;
}
return 0;
@@ -289,25 +321,49 @@
void zDrvVolte_PreClose(void)
{
+ int ret = 0;
printf(" voice lib zDrvVolte_PreClose!\n");
if (slic_flag_already == 1) {
printf(" voice slic flag already get, slic_flag=%d!\n", slic_flag);
if (slic_flag == 1) {
- return ;
+ return;
}
} else {
slic_flag = voice_GetSlicFlag();
printf(" voice slic flag get, slic_flag=%d!\n", slic_flag);
if (slic_flag == 1) {
- return ;
+ return;
}
}
-#ifdef _ALSA_CODEC_IN_CAP
+#if defined(_ALSA_CODEC_IN_CAP) && defined(_USE_ALSA_AT_INTF)
+
printf("%s: i2s and codec not need config,return!\n",__func__);
return ;
+#elif defined(_ALSA_CODEC_IN_CAP)
+ if(s_cfgParam.clock_rate == 8000){
+
+ ret = cap_alsa_voice_close(AVOICE_4G_NB);
+ printf("%s:cap_alsa_voice_close clock_rate(%d) ret=%d!\n",__func__,s_cfgParam.clock_rate,ret);
+
+ }
+ else if(s_cfgParam.clock_rate == 16000){
+
+ ret = cap_alsa_voice_close(AVOICE_4G_WB);
+ printf("%s:cap_alsa_voice_close clock_rate(%d) ret=%d!\n",__func__,s_cfgParam.clock_rate,ret);
+
+ }
+ else{
+
+ printf("%s:cap_alsa_voice_close clock_rate(%d) not support!\n",__func__,s_cfgParam.clock_rate);
+
+ }
+ return;
+
+
+
#endif
diff --git a/ap/lib/libvoice/voice_api.c b/ap/lib/libvoice/voice_api.c
index e6262fb..ba07e83 100755
--- a/ap/lib/libvoice/voice_api.c
+++ b/ap/lib/libvoice/voice_api.c
@@ -122,6 +122,7 @@
int sc_audio_get_voice_device_mode(int *p_dev_mode)
{
+ int ret = 0;
struct mixer *voice_mixer = NULL;
printf("%s: start!\n",__func__);
@@ -138,7 +139,7 @@
if((*p_dev_mode < T_OUTPUT_HANDSET ) ||(*p_dev_mode >= T_OUTPUT_MAX)){
printf("%s: dev_mode not support, *p_dev_mode=%d!\n",__func__, *p_dev_mode);
- //return -1;
+ ret = -1;
}
printf("%s: start *p_dev_mode=%d!\n",__func__, *p_dev_mode);
@@ -146,7 +147,7 @@
mixer_close(voice_mixer);
voice_mixer = NULL;
- return 0;
+ return ret;
}
@@ -187,6 +188,7 @@
int sc_audio_get_rx_voice_vol(int * p_vol)
{
+ int ret = 0;
struct mixer *voice_mixer = NULL;
printf("%s: start!\n",__func__);
@@ -204,7 +206,7 @@
if ((*p_vol < 0 ) ||(*p_vol > 11)){
printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
- //return -1;
+ ret = -1;
}
printf("%s: *p_vol=%d!\n",__func__, *p_vol);
@@ -213,7 +215,7 @@
voice_mixer = NULL;
- return 0;
+ return ret;
@@ -255,6 +257,7 @@
int sc_audio_get_tx_voice_vol(int *p_vol)
{
+ int ret = 0;
struct mixer *voice_mixer = NULL;
printf("%s: start!\n",__func__);
@@ -272,14 +275,14 @@
if((*p_vol < 0 ) ||(*p_vol > 5)){
printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
- //return -1;
+ ret = -1;
}
printf("%s: *p_vol=%d!\n",__func__, *p_vol);
//close mixer
mixer_close(voice_mixer);
voice_mixer = NULL;
- return 0;
+ return ret;
}
@@ -313,6 +316,7 @@
int sc_audio_get_tx_voice_mute_state(int *p_mute)
{
+ int ret = 0;
struct mixer *voice_mixer = NULL;
printf("%s: start!\n",__func__);
@@ -330,10 +334,8 @@
if((*p_mute != 0 ) &&(*p_mute != 1)) {
printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
- //close mixer
- mixer_close(voice_mixer);
- voice_mixer = NULL;
- return -1;
+
+ ret = -1;
}
printf("%s: *p_mute=%d!\n",__func__, *p_mute);
@@ -341,7 +343,7 @@
mixer_close(voice_mixer);
voice_mixer = NULL;
- return 0;
+ return ret;
}
@@ -378,7 +380,9 @@
}
-int sc_audio_get_rx_voice_mute_state(int *p_mute){
+int sc_audio_get_rx_voice_mute_state(int *p_mute)
+{
+ int ret = 0;
struct mixer *voice_mixer = NULL;
printf("%s: start!\n",__func__);
@@ -396,10 +400,7 @@
if((*p_mute != 0 ) &&(*p_mute != 1)) {
printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
- //close mixer
- mixer_close(voice_mixer);
- voice_mixer = NULL;
- return -1;
+ ret = -1;
}
printf("%s: *p_mute=%d!\n",__func__, *p_mute);
@@ -407,7 +408,7 @@
mixer_close(voice_mixer);
voice_mixer = NULL;
- return 0;
+ return ret;
}
diff --git a/ap/lib/libvoice/voiceipc.c b/ap/lib/libvoice/voiceipc.c
index 198fe19..998d7a5 100755
--- a/ap/lib/libvoice/voiceipc.c
+++ b/ap/lib/libvoice/voiceipc.c
@@ -7,7 +7,10 @@
#include <sys/ioctl.h>
#include <fcntl.h>
#include "voice_ipc.h"
+#include "voice_lib.h"
#include "linux/rpmsg_zx29.h"
+#include "softap_api.h"
+#include "pthread.h"
extern int sc_audio_set_voice_device_mode(int dev_mode);
extern int sc_audio_get_voice_device_mode(int *p_dev_mode);
@@ -22,10 +25,148 @@
extern int sc_audio_set_loopback_enable_state(int enable);
extern int sc_audio_get_loopback_enable_state(int *p_enable);
-int voice_ipc_fd = -1;
-voice_ipc_control_msg voice_ctrl_recvmsg[IPC_VOICE_FUNC_MAX] = {0};
+static int voice_ipc_fd = -1;
+static voice_ipc_control_msg voice_ctrl_recvmsg[IPC_VOICE_FUNC_MAX] = {0};
-void ipc_set_voice_device_mode(voice_ipc_control_msg msg)
+int cap_alsa_voice_open(int vmode)
+{
+ int ret = 0;
+ int msg_handle = 0;
+ MSG_BUF msg;
+ LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
+ int module_id = MODULE_ID_VOICE_CLIENT;
+ int dst_id = MODULE_ID_VOICE_SERVER;
+ int msg_cmd = MSG_CMD_CAP_VALSA_OPEN;
+
+ //´´½¨ÏûÏ¢¶ÓÁÐ
+ msg_handle = msgget(module_id, IPC_CREAT|0600);
+
+ //·¢ËÍÏûÏ¢
+ ret = ipc_send_message(module_id, dst_id, msg_cmd, sizeof(int), (unsigned char *)(&vmode), 0);
+ if(0 != ret){
+ printf("%s: send msg error(%d)!\n", __func__, ret);
+ msgctl(msg_handle,IPC_RMID,0);
+ return ret;
+ }
+ printf("%s: send msg success(%d)!\n", __func__, ret);
+
+ //½ÓÊÕÏûÏ¢
+ while(1)
+ {
+ memset(&msg, 0x00, sizeof(MSG_BUF));
+
+ //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
+ ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
+ if(0 > ret){
+ continue;
+ }
+
+ //Æ¥Åäµ½ÊÇMSG_CMD_CAP_VALSA_OPENʱ²Å´¦Àí
+ if(msg_cmd == msg.usMsgCmd){
+ ret = *((int *)msg.aucDataBuf);
+ msgctl(msg_handle,IPC_RMID,0);
+ printf("%s: receive msg success(%d)!\n", __func__, ret);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+int cap_alsa_voice_close(int vmode)
+{
+ int ret = 0;
+ int msg_handle = 0;
+ MSG_BUF msg;
+ LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
+ int module_id = MODULE_ID_VOICE_CLIENT;
+ int dst_id = MODULE_ID_VOICE_SERVER;
+ int msg_cmd = MSG_CMD_CAP_VALSA_CLOSE;
+
+ //´´½¨ÏûÏ¢¶ÓÁÐ
+ msg_handle = msgget(module_id, IPC_CREAT|0600);
+
+ //·¢ËÍÏûÏ¢
+ ret = ipc_send_message(module_id, dst_id, msg_cmd, sizeof(int), (unsigned char *)(&vmode), 0);
+ if(0 != ret){
+ printf("%s: send msg error(%d)!\n", __func__, ret);
+ msgctl(msg_handle,IPC_RMID,0);
+ return ret;
+ }
+ printf("%s: send msg success(%d)!\n", __func__, ret);
+
+ //½ÓÊÕÏûÏ¢
+ while(1)
+ {
+ memset(&msg, 0x00, sizeof(MSG_BUF));
+
+ //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
+ ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
+ if(0 > ret){
+ continue;
+ }
+
+ //Æ¥Åäµ½ÊÇMSG_CMD_CAP_VALSA_CLOSEʱ²Å´¦Àí
+ if(msg_cmd == msg.usMsgCmd){
+ ret = *((int *)msg.aucDataBuf);
+ msgctl(msg_handle,IPC_RMID,0);
+ printf("%s: receive msg success(%d)!\n", __func__, ret);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+int ipc_cap_alsa_voice_open(int vmode)
+{
+ int ret = 0;
+ int func_id = IPC_CAP_ALSA_VOICE_OPEN;
+ voice_ctrl_recvmsg[func_id].func_id = VOICE_WAIT_MSG_FROM_CAP;
+
+ ret = Voice_Ctrl_Rpmsg_Send(func_id, &vmode);
+
+ if (0 >= ret){
+ printf("%s: Voice_Ctrl_Rpmsg_Send error, return %d!\n", __func__, ret);
+ return VOICEIPC_ERROR;
+ }
+ printf("%s: Voice_Ctrl_Rpmsg_Send success, write_len=%d!\n", __func__, ret);
+
+ while(func_id != voice_ctrl_recvmsg[func_id].func_id){
+ usleep(1);
+ }
+
+ memcpy(&ret, voice_ctrl_recvmsg[func_id].param, voice_ctrl_recvmsg[func_id].param_len);
+ printf("%s: ipc receive success, ret=%d!\n", __func__, ret);
+
+ return ret;
+}
+
+int ipc_cap_alsa_voice_close(int vmode)
+{
+ int ret = 0;
+ int func_id = IPC_CAP_ALSA_VOICE_CLOSE;
+ voice_ctrl_recvmsg[func_id].func_id = VOICE_WAIT_MSG_FROM_CAP;
+
+ ret = Voice_Ctrl_Rpmsg_Send(func_id, &vmode);
+
+ if (0 >= ret){
+ printf("%s: Voice_Ctrl_Rpmsg_Send error, return %d!\n", __func__, ret);
+ return VOICEIPC_ERROR;
+ }
+ printf("%s: Voice_Ctrl_Rpmsg_Send success, write_len=%d!\n", __func__, ret);
+
+ while(func_id != voice_ctrl_recvmsg[func_id].func_id){
+ usleep(1);
+ }
+
+ memcpy(&ret, voice_ctrl_recvmsg[func_id].param, voice_ctrl_recvmsg[func_id].param_len);
+ printf("%s: ipc receive success, ret=%d!\n", __func__, ret);
+
+ return ret;
+}
+
+void ipc_set_voice_device_mode_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -47,7 +188,7 @@
}
}
-void ipc_get_voice_device_mode(voice_ipc_control_msg msg)
+void ipc_get_voice_device_mode_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -58,7 +199,10 @@
//msg.func_id不变
msg.param_len = sizeof(int);
- memcpy(msg.param, &ret, msg.param_len);
+ if(0 == ret)
+ memcpy(msg.param, p_dev_mode, msg.param_len);
+ else
+ memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
@@ -68,7 +212,7 @@
}
}
-void ipc_set_rx_voice_vol(voice_ipc_control_msg msg)
+void ipc_set_rx_voice_vol_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -90,7 +234,7 @@
}
}
-void ipc_get_rx_voice_vol(voice_ipc_control_msg msg)
+void ipc_get_rx_voice_vol_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -101,7 +245,10 @@
//msg.func_id不变
msg.param_len = sizeof(int);
- memcpy(msg.param, &ret, msg.param_len);
+ if(0 == ret)
+ memcpy(msg.param, p_vol, msg.param_len);
+ else
+ memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
@@ -111,7 +258,7 @@
}
}
-void ipc_set_tx_voice_vol(voice_ipc_control_msg msg)
+void ipc_set_tx_voice_vol_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -133,7 +280,7 @@
}
}
-void ipc_get_tx_voice_vol(voice_ipc_control_msg msg)
+void ipc_get_tx_voice_vol_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -144,7 +291,10 @@
//msg.func_id不变
msg.param_len = sizeof(int);
- memcpy(msg.param, &ret, msg.param_len);
+ if(0 == ret)
+ memcpy(msg.param, p_vol, msg.param_len);
+ else
+ memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
@@ -154,7 +304,7 @@
}
}
-void ipc_set_tx_voice_mute_state(voice_ipc_control_msg msg)
+void ipc_set_tx_voice_mute_state_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -176,7 +326,7 @@
}
}
-void ipc_get_tx_voice_mute_state(voice_ipc_control_msg msg)
+void ipc_get_tx_voice_mute_state_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -187,7 +337,10 @@
//msg.func_id不变
msg.param_len = sizeof(int);
- memcpy(msg.param, &ret, msg.param_len);
+ if(0 == ret)
+ memcpy(msg.param, p_mute, msg.param_len);
+ else
+ memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
@@ -197,7 +350,7 @@
}
}
-void ipc_set_rx_voice_mute_state(voice_ipc_control_msg msg)
+void ipc_set_rx_voice_mute_state_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -219,7 +372,7 @@
}
}
-void ipc_get_rx_voice_mute_state(voice_ipc_control_msg msg)
+void ipc_get_rx_voice_mute_state_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -230,7 +383,10 @@
//msg.func_id不变
msg.param_len = sizeof(int);
- memcpy(msg.param, &ret, msg.param_len);
+ if(0 == ret)
+ memcpy(msg.param, p_mute, msg.param_len);
+ else
+ memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
@@ -240,7 +396,7 @@
}
}
-void ipc_set_loopback_enable_state(voice_ipc_control_msg msg)
+void ipc_set_loopback_enable_state_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -262,7 +418,7 @@
}
}
-void ipc_get_loopback_enable_state(voice_ipc_control_msg msg)
+void ipc_get_loopback_enable_state_rcv(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
@@ -273,6 +429,31 @@
//msg.func_id不变
msg.param_len = sizeof(int);
+ if(0 == ret)
+ memcpy(msg.param, p_enable, msg.param_len);
+ else
+ memcpy(msg.param, &ret, msg.param_len);
+ msg_len = VOICE_HEAD_LEN + msg.param_len;
+
+ ret = write(voice_ipc_fd, &msg, msg_len);
+
+ if (0 >= ret){
+ printf("%s: write error(%d)!\n", __func__, ret);
+ }
+}
+
+#ifdef _USE_VOICE_ALSA
+void ipc_ap_alsa_voice_open_rcv(voice_ipc_control_msg msg)
+{
+ int ret = VOICEIPC_OK;
+ int msg_len = 0;
+ int vmode = 0;
+
+ vmode = *((int *)msg.param);
+ ret = alsa_voice_open(vmode);
+
+ //msg.func_id不变
+ msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
@@ -283,48 +464,77 @@
}
}
-void voice_msg_proc(voice_ipc_control_msg msg)
+void ipc_ap_alsa_voice_close_rcv(voice_ipc_control_msg msg)
+{
+ int ret = VOICEIPC_OK;
+ int msg_len = 0;
+ int vmode = 0;
+
+ vmode = *((int *)msg.param);
+ ret = alsa_voice_close(vmode);
+
+ //msg.func_id不变
+ msg.param_len = sizeof(int);
+ memcpy(msg.param, &ret, msg.param_len);
+ msg_len = VOICE_HEAD_LEN + msg.param_len;
+
+ ret = write(voice_ipc_fd, &msg, msg_len);
+
+ if (0 >= ret){
+ printf("%s: write error(%d)!\n", __func__, ret);
+ }
+}
+#endif
+
+void voice_ipc_recv_proc(voice_ipc_control_msg msg)
{
switch(msg.func_id){
case IPC_SET_VOICE_DEVICE_MODE:
- ipc_set_voice_device_mode(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_set_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_VOICE_DEVICE_MODE:
- ipc_get_voice_device_mode(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_get_voice_device_mode_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_RX_VOICE_VOL:
- ipc_set_rx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_set_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_RX_VOICE_VOL:
- ipc_get_rx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_get_rx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_TX_VOICE_VOL:
- ipc_set_tx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_set_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_TX_VOICE_VOL:
- ipc_get_tx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_get_tx_voice_vol_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_TX_VOICE_MUTE_STATE:
- ipc_set_tx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_set_tx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_TX_VOICE_MUTE_STATE:
- ipc_get_tx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_get_tx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_RX_VOICE_MUTE_STATE:
- ipc_set_rx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_set_rx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_RX_VOICE_MUTE_STATE:
- ipc_get_rx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_get_rx_voice_mute_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_LOOPBACK_ENABLE_STATE:
- ipc_set_loopback_enable_state(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_set_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_LOOPBACK_ENABLE_STATE:
- ipc_get_loopback_enable_state(voice_ctrl_recvmsg[msg.func_id]);
+ ipc_get_loopback_enable_state_rcv(voice_ctrl_recvmsg[msg.func_id]);
break;
+#ifdef _USE_VOICE_ALSA
+ case IPC_AP_ALSA_VOICE_OPEN:
+ ipc_ap_alsa_voice_open_rcv(voice_ctrl_recvmsg[msg.func_id]);
+ break;
+ case IPC_AP_ALSA_VOICE_CLOSE:
+ ipc_ap_alsa_voice_close_rcv(voice_ctrl_recvmsg[msg.func_id]);
+ break;
+#endif
default:
- printf("%s: msg func_id(%d) error\n", __func__, msg.func_id);
- break;
+ break;
}
}
@@ -333,23 +543,52 @@
int read_len = 0;
voice_ipc_control_msg tmpbuf = {0};
- for(;;){
+ while(1){
read_len = 0;
read_len = read(voice_ipc_fd, &tmpbuf, (VOICE_HEAD_LEN + VOICE_CONTROL_MAX_LEN));
+
if (0 >= read_len){
+ sleep(1);
continue;
}
-
- //最后再改变func_id,确保其他地方判断func_id改变后有数据可读
- memcpy(voice_ctrl_recvmsg[tmpbuf.func_id].param, tmpbuf.param, tmpbuf.param_len);
+ printf("%s: voice_ipc_fd=%d, read_len=%d\n", __func__, voice_ipc_fd, read_len);
+
+ //Êý¾Ý¶ÁÈ¡ÍêºóÔٸıäfuc_id
+ if(0 != tmpbuf.param_len){
+ memcpy(voice_ctrl_recvmsg[tmpbuf.func_id].param, tmpbuf.param, tmpbuf.param_len);
+ }
voice_ctrl_recvmsg[tmpbuf.func_id].param_len = tmpbuf.param_len;
voice_ctrl_recvmsg[tmpbuf.func_id].func_id = tmpbuf.func_id;
+ printf("%s: tmpbuf.param_len=%d, tmpbuf.func_id=%d\n", __func__, tmpbuf.param_len, tmpbuf.func_id);
- voice_msg_proc(voice_ctrl_recvmsg[tmpbuf.func_id]);
+ voice_ipc_recv_proc(voice_ctrl_recvmsg[tmpbuf.func_id]);
}
}
-int voice_ipc_init(void) //通道初始化
+int Voice_Ctrl_Rpmsg_Send(int func_id, int *msg)
+{
+ voice_ipc_control_msg tmpbuf = {0};
+ int tmpbuf_len = 0;
+ int write_len = 0;
+
+ tmpbuf.func_id = func_id;
+
+ if(NULL == msg){
+ tmpbuf.param_len = 0;
+ }else{
+ tmpbuf.param_len = sizeof(int);
+ memcpy(tmpbuf.param, msg, tmpbuf.param_len);
+ }
+
+ tmpbuf_len = VOICE_HEAD_LEN + tmpbuf.param_len;
+
+ //printf("Voice_Ctrl_Rpmsg_Send, voice_ipc_fd = %d\n", voice_ipc_fd);
+ write_len = write(voice_ipc_fd, &tmpbuf, tmpbuf_len);
+
+ return write_len;
+}
+
+int voice_ipc_init(void) //ééåå§å?
{
voice_ipc_fd = open(VOICE_IPC_CONTROL_CHANNEL, O_RDWR);
@@ -365,35 +604,104 @@
return VOICEIPC_ERROR;
}
- if(0 > ioctl(voice_ipc_fd, RPMSG_SET_INT_FLAG, NULL)){ //写中断
+ if(0 > ioctl(voice_ipc_fd, RPMSG_SET_INT_FLAG, NULL)){ //å䏿?
printf("%s: ioctl RPMSG_SET_INT_FLAG fail!\n", __func__);
close(voice_ipc_fd);
voice_ipc_fd = -1;
return VOICEIPC_ERROR;
}
- if(0 > ioctl(voice_ipc_fd, RPMSG_CLEAR_POLL_FLAG, NULL)){ //阻塞方式读数据
+ if(0 > ioctl(voice_ipc_fd, RPMSG_CLEAR_POLL_FLAG, NULL)){ //é»å¡æ¹å¼è¯»æ°æ?
printf("%s: ioctl RPMSG_CLEAR_POLL_FLAG fail!\n", __func__);
close(voice_ipc_fd);
voice_ipc_fd = -1;
return VOICEIPC_ERROR;
}
+
+ printf("voice_ipc_init %s create success! voice_ipc_fd = %d\n", VOICE_IPC_CONTROL_CHANNEL, voice_ipc_fd);
+
return VOICEIPC_OK;
}
+int recv_msg_proc(MSG_BUF msg)
+{
+ int ret = 0;
+ int vmode = 0;
+ int module_id = MODULE_ID_VOICE_SERVER;
+ int dst_id = MODULE_ID_VOICE_CLIENT;
+
+ switch(msg.usMsgCmd){
+ case MSG_CMD_CAP_VALSA_OPEN:
+ vmode = *((int *)msg.aucDataBuf);
+ ret = ipc_cap_alsa_voice_open(vmode);
+ //dst_id = MODULE_ID_CAP_VALSA_OPEN;
+ ret = ipc_send_message(module_id, dst_id, msg.usMsgCmd, sizeof(int), (unsigned char *)(&ret), 0);
+ if(0 != ret){
+ printf("%s: ipc_send_message error, return %d!\n", __func__, ret);
+ }
+ break;
+ case MSG_CMD_CAP_VALSA_CLOSE:
+ vmode = *((int *)msg.aucDataBuf);
+ ret = ipc_cap_alsa_voice_close(vmode);
+ //dst_id = MODULE_ID_CAP_VALSA_CLOSE;
+ ret = ipc_send_message(module_id, dst_id, msg.usMsgCmd, sizeof(int), (unsigned char *)(&ret), 0);
+ if(0 != ret){
+ printf("%s: ipc_send_message error, return %d!\n", __func__, ret);
+ }
+ break;
+ default:
+ printf("%s: msg.usMsgCmd=%d, not support!\n", __func__, msg.usMsgCmd);
+ break;
+ }
+
+ return ret;
+}
+
+void recv_cap_voice_alsa(void)
+{
+ int ret = 0;
+ int msg_handle = 0;
+ MSG_BUF msg;
+ LONG msg_size = sizeof(MSG_BUF)-sizeof(LONG);
+ int module_id = MODULE_ID_VOICE_SERVER;
+
+ //´´½¨ÏûÏ¢¶ÓÁÐ
+ msg_handle = msgget(module_id, IPC_CREAT|0600);
+
+ //½ÓÊÕÏûÏ¢
+ while(1)
+ {
+ memset(&msg, 0x00, sizeof(MSG_BUF));
+
+ //»ñÈ¡ÏûÏ¢¶ÓÁÐÏûÏ¢²¢´¦Àí
+ ret = msgrcv(msg_handle, &msg, msg_size, 0, 0);
+
+ if(0 > ret){
+ continue;
+ }
+
+ recv_msg_proc(msg);
+ }
+}
+
int main(int argc, char **argv)
{
int ret = 0;
+ //ipcͨµÀ³õʼ»¯
ret = voice_ipc_init();
-
- if(ret < 0){
- printf("voice_ipc_init error!\n");
+ if(0 > ret){
+ printf("voice_ipc_init %s error!\n", VOICE_IPC_CONTROL_CHANNEL);
return -1;
}
-
- printf("voice_ipc_init %s create success!\n", VOICE_IPC_CONTROL_CHANNEL);
+ //ipc³õʼ»¯ºó£¬´´½¨msgÏûÏ¢½ÓÊÕÏß³Ì
+ pthread_t recv_thread_tid;
+ if(0 != pthread_create(&recv_thread_tid, NULL, (void *)recv_cap_voice_alsa, NULL)){
+ printf("recv_cap_voice_alsa create error!\n");
+ }
+
+ sleep(4);
Voice_Ctrl_Rpmsg_Recv();
return 0;