[Feature][ZXW-241]merge P56U01 version

Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I7985538dde6951dd824c36149bf9a1e3ca23c734
diff --git a/ap/lib/libvoice/include/voice_ipc.h b/ap/lib/libvoice/include/voice_ipc.h
index 3b58efb..0041d73 100755
--- a/ap/lib/libvoice/include/voice_ipc.h
+++ b/ap/lib/libvoice/include/voice_ipc.h
@@ -6,10 +6,12 @@
 #define VOICE_WAIT_MSG_FROM_CAP -2 //waitting msg from cap

 

 #define VOICE_IPC_CONTROL_CHANNEL "/dev/rpmsg6"

-#define VOICE_IPC_CONTROL_CHANNEL_SIZE 256

+//#define VOICE_IPC_CONTROL_CHANNEL_SIZE 256

+#define VOICE_IPC_CONTROL_CHANNEL_SIZE (8 * 1024 + 256) //À©´óÒԱ㴫Êävoice_nvrw.bin

 

 #define VOICE_HEAD_LEN (2 * sizeof(int))

 #define VOICE_CONTROL_MAX_LEN 32

+#define VOICE_NVRW_MAX_LEN (8 * 1024)

 

 enum  voice_ipc_func_type{

 	IPC_SET_VOICE_DEVICE_MODE = 0,

@@ -28,6 +30,7 @@
     IPC_AP_ALSA_VOICE_CLOSE = 13,

     IPC_CAP_ALSA_VOICE_OPEN = 14,

     IPC_CAP_ALSA_VOICE_CLOSE = 15,

+    IPC_UPDATE_VOICE_NVRW = 16,

 

     IPC_VOICE_FUNC_MAX

 };

diff --git a/ap/lib/libvoice/include/voice_lib.h b/ap/lib/libvoice/include/voice_lib.h
index 8831759..4023dc3 100755
--- 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
 
-
+#define VOICE_DEV_NAME "/dev/voice_device"
 
 
  typedef enum
diff --git a/ap/lib/libvoice/voice.c b/ap/lib/libvoice/voice.c
index 16da46c..61b9c1e 100755
--- a/ap/lib/libvoice/voice.c
+++ b/ap/lib/libvoice/voice.c
@@ -27,7 +27,7 @@
 

 

 

-#define VOICE_DEV_NAME "/dev/voice_device"

+//#define VOICE_DEV_NAME "/dev/voice_device"

 

 

 

diff --git a/ap/lib/libvoice/voiceipc.c b/ap/lib/libvoice/voiceipc.c
index de88327..a3f5569 100755
--- a/ap/lib/libvoice/voiceipc.c
+++ b/ap/lib/libvoice/voiceipc.c
@@ -11,6 +11,7 @@
 #include "linux/rpmsg_zx29.h"

 #include "softap_api.h"

 #include "pthread.h"

+#include <linux/volte_drv.h>

 

 extern int sc_audio_set_voice_device_mode(int dev_mode);

 extern int sc_audio_get_voice_device_mode(int *p_dev_mode);

@@ -27,6 +28,7 @@
 int ap_audio_set_loopback_enable(int dev_mode,int enable);

 int ap_audio_get_loopback_enable(int *p_enable);

 

+static unsigned char *recv_voice_nvrw_buf = NULL;

 static int voice_ipc_fd = -1;

 static voice_ipc_control_msg voice_ctrl_recvmsg[IPC_VOICE_FUNC_MAX] = {0};

 

@@ -39,7 +41,7 @@
     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);

     

@@ -550,8 +552,7 @@
     voice_ipc_control_msg tmpbuf = {0};

     

     while(1){

-        read_len = 0;

-		read_len = read(voice_ipc_fd, &tmpbuf, (VOICE_HEAD_LEN + VOICE_CONTROL_MAX_LEN));

+        read_len = read(voice_ipc_fd, &tmpbuf, (VOICE_HEAD_LEN + VOICE_CONTROL_MAX_LEN));

         

         if (0 >= read_len){

             sleep(1);

@@ -690,6 +691,69 @@
     }

 }

 

+void recv_update_voice_nvrw_ipc(void)

+{

+    int read_len = 0;

+    int ret = -1;

+    int fd = -1;

+

+    recv_voice_nvrw_buf = (unsigned char*)malloc(VOICE_HEAD_LEN + VOICE_NVRW_MAX_LEN);

+    if(!recv_voice_nvrw_buf){

+        printf("%s: recv_voice_nvrw_buf malloc fail!\n", __func__);

+        return;

+    }

+    

+    while(1){

+        read_len = read(voice_ipc_fd, recv_voice_nvrw_buf, VOICE_HEAD_LEN + VOICE_NVRW_MAX_LEN);

+        if (0 >= read_len){

+            sleep(1);

+			continue;

+		}

+

+        printf("%s: read_len = %d, func_id = %d, param_len = %d!\n", __func__, read_len, \

+        *((int*)recv_voice_nvrw_buf), *((int*)recv_voice_nvrw_buf + 1));

+        

+#if 0

+        printf("%s: param[0]=%02x,param[1]=%02x,param[2]=%02x,param[3]=%02x,param[4]=%02x,param[5]=%02x,param[6]=%02x!\n", \

+            __func__, recv_voice_nvrw_buf.param[0], recv_voice_nvrw_buf.param[1], recv_voice_nvrw_buf.param[2], \

+            recv_voice_nvrw_buf.param[3], recv_voice_nvrw_buf.param[4], recv_voice_nvrw_buf.param[5], recv_voice_nvrw_buf.param[6]);

+        

+        int writesize = 0;

+        FILE *ptest = fopen("/mnt/userdata/voice_nv_test_ap.bin", "wb");

+        if(!ptest){

+            printf("%s: Unable to create file '/mnt/userdata/voice_nv_test_ap.bin'!\n", __func__);

+        }

+

+        writesize = fwrite(recv_voice_nvrw_buf.param, 1, recv_voice_nvrw_buf.param_len, ptest);

+        printf("%s: writesize = %d!\n", __func__, writesize);

+        

+        if(NULL != ptest){

+            fclose(ptest);

+        }

+#endif

+        

+    	fd = open(VOICE_DEV_NAME, O_RDWR);

+

+        if(0 > fd){

+            printf("%s: open voice device error!\n", __func__);

+        }

+        else{

+            ret = ioctl(fd, VOICE_IOCTL_SET_VOICE_NVRW, recv_voice_nvrw_buf);

+            printf("%s: ioctl /dev/voice_device end, ret=%d!\n", __func__, ret);

+            close(fd);

+        }

+        

+        break;

+    }

+

+    if(recv_voice_nvrw_buf){

+        free(recv_voice_nvrw_buf);

+        recv_voice_nvrw_buf = NULL;

+    }

+    

+    return;

+}

+

 int main(int argc, char **argv)

 {

     int ret = 0;

@@ -707,7 +771,11 @@
 		printf("recv_cap_voice_alsa create error!\n");

 	}

 

-    sleep(4);

+    sleep(4); //µÈ´ýcap²àÒôƵºË¼äͨµÀ½¨Á¢Íê³É

+

+    //ipc³õʼ»¯ºó£¬Ö±½Ó»ñÈ¡cap²àvoice nv

+    recv_update_voice_nvrw_ipc();

+    

     Voice_Ctrl_Rpmsg_Recv();

     

     return 0;