Merge "[Feature][T106][task-view-97] add interface for voice call to rtp, a file is omit" into 15.11_rtp_temp
diff --git a/ap/lib/libatext/ext_audio_func.c b/ap/lib/libatext/ext_audio_func.c
index d12ed7d..e95b017 100755
--- a/ap/lib/libatext/ext_audio_func.c
+++ b/ap/lib/libatext/ext_audio_func.c
@@ -66,6 +66,19 @@
 	

 	MAX_CODEC_OUTPUT_PATH			   

 }T_ZDrv_CodecOutputPath;

+

+

+#ifdef _VBUFF_IN_SINGLE_CORE	

+extern int vbuffer_stream_start(void);

+extern int vbuffer_stream_stop(void);

+#endif

+

+#ifdef _USE_VOICE_AT

+

+extern int voice_SetVoiceBuffer(T_VoiceBuf_Para *vb);

+extern int voice_GetVoiceBuffer(T_VoiceBuf_Para *vb);

+#endif

+

 #ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT

 extern SINT32 halEarp_Open(VOID);

 extern SINT32 halEarp_Close(VOID);

@@ -525,6 +538,134 @@
 }

 #endif

 

+#ifdef _USE_VOICE_AT

+

+int extAt_Voice_Process_set (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)

+{

+	char *at_str = NULL;

+	UINT32 ret = DRV_SUCCESS;

+

+	int mode = 0;

+    int vp = 0;

+	

+	UINT16 onOff = 0;

+	at_str = at_paras;

+	printf("%s, at_paras:%s \n",__func__, at_paras);

+

+	ret = sscanf (at_str, "%d", &vp);

+	printf("%s: vp=%d,ret=%d\n",__func__,vp,ret);

+

+	if (ret == 1) {

+		

+		ret = voice_SetVoiceProcess(&vp);

+		printf("%s: alsa_voice_open,ret=%d\n",__func__,ret);

+		

+		if (ret == DRV_SUCCESS) {

+			*res_msg = at_ok_build();

+			*res_msglen = strlen (*res_msg);

+			return AT_END;

+		}

+	}

+	*res_msg = at_err_build(ATERR_PROC_FAILED);

+	*res_msglen = strlen (*res_msg);

+	

+	return AT_END;

+}

+

+

+

+int extAt_Voice_Process_get(int at_fd,char * at_paras,void **res_msg,int * res_msglen)

+{

+

+

+

+    char  vp_str[32] = {0};

+    printf("%s: %s\n",__func__,at_paras);

+    int vp = voice_GetVoiceProcess();

+	if( vp < 0)

+    {

+        *res_msg = at_err_build(ATERR_PROC_FAILED);	

+		*res_msglen = strlen(*res_msg);

+		return AT_END;

+    }

+    printf("%s: vp=%d",__func__,vp);

+	

+    snprintf(vp_str, 32,"%d\r\n",vp);

+	

+	*res_msg = at_query_result_build("AT+VOICEPROCESS",vp_str);

+	*res_msglen = strlen(*res_msg);

+    return AT_END;

+

+}

+

+

+

+

+int extAt_VoiceBuffer_Set (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)

+{

+	char *at_str = NULL;

+	UINT32 ret = DRV_SUCCESS;

+

+	int enable = 0;

+    int type = 0;

+	T_VoiceBuf_Para vb;

+	at_str = at_paras;

+	printf("%s, at_paras:%s \n",__func__, at_paras);

+

+	//ret = sscanf (at_str, "%d", &vp);

+	

+	ret = sscanf (at_str, "%d,%d", &enable,&type);

+	printf("%s: enable=%d type=%d,ret=%d\n",__func__,enable,type,ret);

+

+	if (ret == 2) {

+		vb.enable = enable;

+		vb.type = type;

+		

+	    ret = voice_SetVoiceBuffer(&vb);

+		printf("%s: voice_SetVoiceBuffer,ret=%d\n",__func__,ret);

+		

+		if (ret == DRV_SUCCESS) {

+			*res_msg = at_ok_build();

+			*res_msglen = strlen (*res_msg);

+			return AT_END;

+		}

+	}

+	*res_msg = at_err_build(ATERR_PROC_FAILED);

+	*res_msglen = strlen (*res_msg);

+	

+	return AT_END;

+}

+

+

+int extAt_VoiceBuffer_Get(int at_fd,char * at_paras,void **res_msg,int * res_msglen)

+{

+	UINT32 ret = DRV_SUCCESS;

+

+	T_VoiceBuf_Para vb;

+

+

+    char  vp_str[32] = {0};

+    printf("%s: %s\n",__func__,at_paras);

+    ret = voice_GetVoiceBuffer(&vb);

+	if( ret < 0)

+    {

+        *res_msg = at_err_build(ATERR_PROC_FAILED);	

+		*res_msglen = strlen(*res_msg);

+		return AT_END;

+    }

+    printf("%s: fs=%d enable=%d type=%d",__func__,vb.fs,vb.enable,vb.type);

+	

+    snprintf(vp_str, 32,"%d %d %d\r\n",vb.fs,vb.enable,vb.type);

+	

+	*res_msg = at_query_result_build("AT+VOICE_BUFFER",vp_str);

+	*res_msglen = strlen(*res_msg);

+    return AT_END;

+

+}

+

+

+#endif

+

 #ifdef _VBUFF_IN_SINGLE_CORE

 int extAt_VBUFFER_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)

 {

@@ -587,13 +728,23 @@
 	register_serv_func2("VALSA=", 0, 0, 0, extAt_VALSA_act_func, NULL);

 	register_serv_func2("VPATH=", 0, 0, 0, extAt_VPATH_act_func, NULL);

     register_serv_func2("CAP_VALSA=", 0, 0, 0, extAt_CAP_VALSA_act_func, NULL);

-	

 #endif

 

 #ifdef _VBUFF_IN_SINGLE_CORE

     register_serv_func2("VBUFFER=", 0, 0, 0, extAt_VBUFFER_act_func, NULL);

 #endif

 

+#ifdef _USE_VOICE_AT

+register_serv_func2("VOICE_PROCESS=",0,0,0,extAt_Voice_Process_set, NULL);

+register_serv_func2("VOICE_PROCESS?",0,0,0,extAt_Voice_Process_get, NULL);

+

+register_serv_func2("VOICE_BUFFER=",0,0,0,extAt_VoiceBuffer_Set, NULL);

+register_serv_func2("VOICE_BUFFER?",0,0,0,extAt_VoiceBuffer_Get, NULL);	

+#endif

+

+

+

+

 }

 

 #endif

diff --git a/ap/lib/libps/220A1_vehicle_dc/drv/amr.a b/ap/lib/libps/220A1_vehicle_dc/drv/amr.a
index 01399c1..2078afc 100755
--- a/ap/lib/libps/220A1_vehicle_dc/drv/amr.a
+++ b/ap/lib/libps/220A1_vehicle_dc/drv/amr.a
Binary files differ
diff --git a/ap/lib/libps/220A1_vehicle_dc/drv/audio_base.a b/ap/lib/libps/220A1_vehicle_dc/drv/audio_base.a
index 5147df5..820bf26 100755
--- a/ap/lib/libps/220A1_vehicle_dc/drv/audio_base.a
+++ b/ap/lib/libps/220A1_vehicle_dc/drv/audio_base.a
Binary files differ
diff --git a/ap/lib/libps/220A1_vehicle_dc/drv/chip.a b/ap/lib/libps/220A1_vehicle_dc/drv/chip.a
index b089432..a894c29 100755
--- a/ap/lib/libps/220A1_vehicle_dc/drv/chip.a
+++ b/ap/lib/libps/220A1_vehicle_dc/drv/chip.a
Binary files differ
diff --git a/ap/lib/libps/220A1_vehicle_dc/drv/drv_sdk.a b/ap/lib/libps/220A1_vehicle_dc/drv/drv_sdk.a
index b3ff588..b7a6a70 100755
--- a/ap/lib/libps/220A1_vehicle_dc/drv/drv_sdk.a
+++ b/ap/lib/libps/220A1_vehicle_dc/drv/drv_sdk.a
Binary files differ
diff --git a/ap/lib/libps/220A1_vehicle_dc/drv/public.a b/ap/lib/libps/220A1_vehicle_dc/drv/public.a
index c6e5c8c..73af441 100755
--- a/ap/lib/libps/220A1_vehicle_dc/drv/public.a
+++ b/ap/lib/libps/220A1_vehicle_dc/drv/public.a
Binary files differ
diff --git a/ap/lib/libps/220A1_vehicle_dc/drv/webrtc.a b/ap/lib/libps/220A1_vehicle_dc/drv/webrtc.a
index c86f9b5..123cbbb 100755
--- a/ap/lib/libps/220A1_vehicle_dc/drv/webrtc.a
+++ b/ap/lib/libps/220A1_vehicle_dc/drv/webrtc.a
Binary files differ
diff --git a/ap/lib/libvoice/Makefile b/ap/lib/libvoice/Makefile
index 7d677fb..48061f2 100755
--- a/ap/lib/libvoice/Makefile
+++ b/ap/lib/libvoice/Makefile
@@ -25,11 +25,14 @@
 LIB_STATIC = libvoice.a

 ifeq ($(USE_VOICE_ALSA),yes)

 OBJS = voice.o alsa_call.o voice_api.o voiceipc.o

-else ifeq ($(USE_VOICE_BUFFER_IN_AP),yes)

-OBJS = voice.o voice_buffer.o

+

 else

 OBJS = voice.o

 endif

+

+ifeq ($(USE_VOICE_BUFFER_IN_AP),yes)

+OBJS += voice_buffer.o

+endif

  

 CFLAGS += -g

 LDFLAGS += -lpthread

diff --git a/ap/lib/libvoice/include/voice_lib.h b/ap/lib/libvoice/include/voice_lib.h
index 4023dc3..2238b6b 100755
--- a/ap/lib/libvoice/include/voice_lib.h
+++ b/ap/lib/libvoice/include/voice_lib.h
@@ -55,6 +55,10 @@
  int voice_Vploop(int *path);
  int zDrvVolte_PreOpen(T_ZDrvVolte_Cfg *cfgParam);
  void zDrvVolte_PreClose(void);	
+ int voice_SetVoiceProcess(int *vp);
+ int voice_GetVoiceProcess(void);
+
+
  
 #ifdef _VBUFF_IN_SINGLE_CORE	
    int vbuffer_stream_start(void);
diff --git a/ap/lib/libvoice/voice.c b/ap/lib/libvoice/voice.c
index 61b9c1e..6af0fa6 100755
--- a/ap/lib/libvoice/voice.c
+++ b/ap/lib/libvoice/voice.c
@@ -167,7 +167,7 @@
 	}

 	ret = ioctl(fd, VOICE_IOCTL_VPLOOP, path);

 	if (ret) {

-		printf("voice_Vploop:  ret=%d,path=%p.\n", ret, path);

+		printf("voice_Vploop:  ret=%d,path=%d.\n", ret, *path);

 		close(fd);

 		return  -1;

 	}

@@ -224,18 +224,20 @@
 		}

 	}

 #if defined(_VBUFF_IN_SINGLE_CORE) || defined(_VBUFF_IN_MULTI_CORE)

-	printf("%s: use voice buffer,return!\n",__func__); 

+	printf("%s: ap use voice buffer,return!\n",__func__); 

 	return 0;

 

 #endif	

 #if defined(_ALSA_CODEC_IN_CAP) && defined(_USE_ALSA_AT_INTF)

+	   printf("%s:_ALSA_CODEC_IN_CAP and at intf!\n",__func__);

 

    

-	   printf("%s: i2s and codec not need config,return!\n",__func__); 

+	   printf("%s:ap i2s and codec not need config,return!\n",__func__); 

 	   return 0;

 

 #elif defined(_ALSA_CODEC_IN_CAP)

 

+	   printf("%s:_ALSA_CODEC_IN_CAP!\n",__func__);

 

 	   if(cfgParam->clock_rate == 8000){

 

@@ -261,6 +263,7 @@
     

 #endif

 

+	printf("%s:ap do mixer and pcm opt!\n",__func__); 

 

 	//open mixer dev for codec control

 	voice_mixer = mixer_open(0);

@@ -390,6 +393,93 @@
 }

 

 

+int voice_SetVoiceProcess(int *vp)

+{

+	int ret = 0;

+	int fd = -1;

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

+	fd = open(VOICE_DEV_NAME, O_RDONLY);

+	if (fd < 0) {

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

+		return  -1;

+	}

+	ret = ioctl(fd, VOICE_IOCTL_SET_VP, vp);

+	if (ret) {

+		printf("%s:  ret=%d,vp=%d.\n",__func__, ret, *vp);

+		close(fd);

+		return  -1;

+	}

+	close(fd);

+	return 0;

+

+}

+int voice_GetVoiceProcess(void)

+{

+	int ret = 0;

+	int fd = -1;

+	int vp = 0;

+	fd = open(VOICE_DEV_NAME, O_RDONLY);

+	if (fd < 0) {

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

+		return  -1;

+	}

+	ret = ioctl(fd, VOICE_IOCTL_GET_VP, &vp);

+	if (ret) {

+		printf("%s:  ret=%d,vp=%d.\n",__func__, ret, vp);

+		close(fd);

+		return  -1;

+	}

+	close(fd);

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

+	

+	return vp;

+

+}

 

 

 

+

+int voice_SetVoiceBuffer(T_VoiceBuf_Para *vb)

+{

+	int ret = 0;

+	int fd = -1;

+	printf("%s:   start enable=%d,type=%d!\n",__func__,vb->enable,vb->type);

+	fd = open(VOICE_DEV_NAME, O_RDONLY);

+	if (fd < 0) {

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

+		return  -1;

+	}

+	ret = ioctl(fd, VOICE_IOCTL_SET_VBUF, vb);

+	if (ret) {

+		printf("%s:  ret=%d.\n",__func__, ret);

+		close(fd);

+		return  -1;

+	}

+	close(fd);

+	return 0;

+

+}

+

+int voice_GetVoiceBuffer(T_VoiceBuf_Para *vb)

+{

+	int ret = 0;

+	int fd = -1;

+	fd = open(VOICE_DEV_NAME, O_RDONLY);

+	if (fd < 0) {

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

+		return  -1;

+	}

+	ret = ioctl(fd, VOICE_IOCTL_GET_VBUF, vb);

+	if (ret) {

+		printf("%s: ret=%d.\n",__func__, ret);

+		close(fd);

+		return  -1;

+	}

+	close(fd);

+	printf("%s:   start fs=%d enable=%d,type=%d!\n",__func__,vb->fs,vb->enable,vb->type);

+	

+	

+	return ret;

+

+}

+

diff --git a/ap/os/linux/linux-3.4.x/drivers/cpko/cpko_main.c b/ap/os/linux/linux-3.4.x/drivers/cpko/cpko_main.c
index e77e5fe..78abbea 100755
--- a/ap/os/linux/linux-3.4.x/drivers/cpko/cpko_main.c
+++ b/ap/os/linux/linux-3.4.x/drivers/cpko/cpko_main.c
@@ -80,36 +80,39 @@
 zDrvVp_AudioDataOpen(UINT32 audioType,UINT32 sampleRate);extern SINT32 
 zDrvVp_AudioDataClose(void);extern SINT32 zDrvVp_GetVpLoop_Wrap(VOID);extern 
 VOID zDrvVp_Status(UINT32*sample_rate,UINT32*voice_status);extern VOID 
-zDrvVp_UpdateVoiceNv(UINT8*voice_nv_update);typedef struct cpko_section{unsigned
+zDrvVp_UpdateVoiceNv(UINT8*voice_nv_update);extern int zDrvVp_SetVoiceProc_Wrap(
+int val);extern int zDrvVp_GetVoiceProc_Wrap(void);extern int 
+zDrvVp_SetVoiceBuffer_Wrap(int en,int type);extern void 
+zDrvVp_GetVoiceBuffer_Wrap(int*en,int*type);typedef struct cpko_section{unsigned
  int cpko_text_start;unsigned int cpko_rodata_start;unsigned int 
 __utran_modem_text_start;unsigned int __lte_modem_text_start;unsigned int 
 __comm_modem_text_start;unsigned int modem_text_end;unsigned int cpko_data_start
 ;unsigned int cpko_bss_start;unsigned int cpko_text_offset;}cpko_section_layout;
 cpko_section_layout cpko_ps_section;int raise(int signo){return
-(0x9e6+3955-0x1959);}extern unsigned int SysEntry(void);static int 
+(0x1293+3341-0x1fa0);}extern unsigned int SysEntry(void);static int 
 ko_Main_Thread(void*data){struct sched_param param={.sched_priority=
-MAX_USER_RT_PRIO/(0x19ec+1080-0x1e22)-(0x1448+357-0x15aa)};int ret=
-(0x20f+6386-0x1b01);sched_setscheduler(current,SCHED_FIFO,&param);ret=SysEntry()
-;if(ret!=(0x381+2774-0xe57))panic("Main_Thread\n");param.sched_priority=
-MAX_USER_RT_PRIO-(0x839+7013-0x2370);sched_setscheduler(kthreadd_task,SCHED_FIFO
-,&param);return(0xef+5068-0x14bb);}int zte_modem_ko_start(void){kthread_run(
+MAX_USER_RT_PRIO/(0x212a+283-0x2243)-(0xf96+4078-0x1f81)};int ret=
+(0x556+3365-0x127b);sched_setscheduler(current,SCHED_FIFO,&param);ret=SysEntry()
+;if(ret!=(0x762+3053-0x134f))panic("Main_Thread\n");param.sched_priority=
+MAX_USER_RT_PRIO-(0x20f+9342-0x265f);sched_setscheduler(kthreadd_task,SCHED_FIFO
+,&param);return(0xb1d+2770-0x15ef);}int zte_modem_ko_start(void){kthread_run(
 ko_Main_Thread,NULL,"\x5a\x54\x45\x4d\x61\x69\x6e\x54\x68\x72\x65\x61\x64");
-return(0x12ac+2426-0x1c26);}static void cpko_sectioninfo_set(void){int ret;
-struct file*fp;mm_segment_t old_fs;loff_t cpko_pos=(0x8bd+6473-0x2206);struct 
+return(0xda9+1225-0x1272);}static void cpko_sectioninfo_set(void){int ret;struct
+ file*fp;mm_segment_t old_fs;loff_t cpko_pos=(0xd79+4186-0x1dd3);struct 
 cpps_globalModem globalVar;fp=filp_open(
 "\x2f\x6c\x69\x62\x2f\x63\x70\x6b\x6f\x2f\x63\x70\x6b\x6f\x5f\x73\x65\x63\x69\x6e\x66\x6f\x2e\x62\x69\x6e"
-,(0x81a+3218-0x14ac),(0x1263+2589-0x1c80));if(IS_ERR(fp)||fp==NULL)panic(
+,(0xd6f+4364-0x1e7b),(0x1e3a+1192-0x22e2));if(IS_ERR(fp)||fp==NULL)panic(
 "\x6f\x70\x65\x6e\x20\x66\x69\x6c\x65\x20\x65\x72\x72\x6f\x72" "\n");old_fs=
 get_fs();set_fs(KERNEL_DS);ret=vfs_read(fp,(char*)&cpko_ps_section,sizeof(
-cpko_section_layout),&cpko_pos);if(ret<=(0xa02+7211-0x262d))panic(
+cpko_section_layout),&cpko_pos);if(ret<=(0x1438+2416-0x1da8))panic(
 "\x72\x65\x61\x64\x20\x66\x69\x6c\x65\x20\x65\x72\x72\x6f\x72" "\n");filp_close(
 fp,NULL);
 #ifdef CONFIG_MODEM_CODE_IS_MAPPING
 fp=filp_open(
 "\x2f\x6c\x69\x62\x2f\x63\x70\x6b\x6f\x2f\x63\x70\x6b\x6f\x2e\x6b\x6f",
-(0xaf4+502-0xcea),(0xe41+3977-0x1dca));if(IS_ERR(fp)||fp==NULL)panic(
+(0xaf7+4826-0x1dd1),(0x16a0+1762-0x1d82));if(IS_ERR(fp)||fp==NULL)panic(
 "\x6f\x70\x65\x6e\x20\x66\x69\x6c\x65\x20\x65\x72\x72\x6f\x72" "\n");fp->f_ra.
-ra_pages=(0x370+4606-0x156e);
+ra_pages=(0x16f1+3892-0x2625);
 #endif
 if(cpko_ps_section.cpko_text_start){globalVar.cpko_text_start=(unsigned long)
 cpko_ps_section.cpko_text_start;globalVar.cpko_rodata_start=(unsigned long)
@@ -129,7 +132,7 @@
 vfree_modem_section(globalVar.cpko_text_start,globalVar.modem_text_end);
 #endif
 }else panic("\x66\x69\x6c\x65\x20\x65\x72\x72\x6f\x72" "\n");}static int 
-cpko_start(void){struct cpps_callbacks callback={(0xef6+2228-0x17aa)};callback.
+cpko_start(void){struct cpps_callbacks callback={(0x386+531-0x599)};callback.
 zOss_ResetNVFactory=zOss_ResetNVFactory;callback.zOss_NvramFlush=zOss_NvramFlush
 ;callback.zOss_NvItemWrite=zOss_NvItemWrite;callback.zOss_NvItemWriteFactory=
 zOss_NvItemWriteFactory;callback.zOss_NvItemRead=zOss_NvItemRead;callback.
@@ -184,7 +187,11 @@
 zDrvVp_SetPath_Wrap=zDrvVp_SetPath_Wrap;callback.zDrvVp_GetPath_Wrap=
 zDrvVp_GetPath_Wrap;callback.halVoice_Open3G=halVoice_Open3G;callback.
 halVoice_Close3G=halVoice_Close3G;callback.zDrvVp_GetSlicFlag=zDrvVp_GetSlicFlag
-;callback.zDrvVp_SetEchoDelay_Wrap=zDrvVp_SetEchoDelay_Wrap;callback.
+;callback.zDrvVp_SetVoiceProc_Wrap=zDrvVp_SetVoiceProc_Wrap;callback.
+zDrvVp_GetVoiceProc_Wrap=zDrvVp_GetVoiceProc_Wrap;callback.
+zDrvVp_SetVoiceBuffer_Wrap=zDrvVp_SetVoiceBuffer_Wrap;callback.
+zDrvVp_GetVoiceBuffer_Wrap=zDrvVp_GetVoiceBuffer_Wrap;callback.
+zDrvVp_SetEchoDelay_Wrap=zDrvVp_SetEchoDelay_Wrap;callback.
 zDrvVp_GetEchoDelay_Wrap=zDrvVp_GetEchoDelay_Wrap;callback.
 zDrvVp_SetTxNsMode_Wrap=zDrvVp_SetTxNsMode_Wrap;callback.zDrvVp_GetTxNsMode_Wrap
 =zDrvVp_GetTxNsMode_Wrap;callback.zDrvVp_SetRxNsMode_Wrap=
@@ -205,5 +212,5 @@
 psm_GetModemSleepFlagStatus=psm_GetModemSleepFlagStatus;
 #endif
 cpps_callbacks_register(&callback);cpko_sectioninfo_set();zte_modem_ko_start();
-return(0x562+5820-0x1c1e);}static int cpko_stop(void){return(0x4bc+6970-0x1ff6);
-}module_init(cpko_start);module_exit(cpko_stop);
+return(0xa8b+6811-0x2526);}static int cpko_stop(void){return(0x6d2+1995-0xe9d);}
+module_init(cpko_start);module_exit(cpko_stop);
diff --git a/ap/os/linux/linux-3.4.x/drivers/staging/Makefile b/ap/os/linux/linux-3.4.x/drivers/staging/Makefile
index a935c69..a02bedb 100755
--- a/ap/os/linux/linux-3.4.x/drivers/staging/Makefile
+++ b/ap/os/linux/linux-3.4.x/drivers/staging/Makefile
@@ -62,6 +62,6 @@
 obj-$(CONFIG_CAMERA_DRV)	    += camera/
 obj-$(CONFIG_AMR_DRV)		+= amrdrv/
 obj-$(CONFIG_VOICE_DRV)		+= voicedrv/
-obj-$(CONFIG_VOICE_BUFFER_DRV)		+= voicebufferdrv/
+obj-y		+= voicebufferdrv/
 obj-$(CONFIG_AUDIOMIX_DRV)		    += audiomixdrv/
 obj-$(CONFIG_PLAT_TEST)         += plat_test/
diff --git a/ap/os/linux/linux-3.4.x/drivers/staging/voicebufferdrv/Makefile b/ap/os/linux/linux-3.4.x/drivers/staging/voicebufferdrv/Makefile
index 7c8c2fd..597480a 100755
--- a/ap/os/linux/linux-3.4.x/drivers/staging/voicebufferdrv/Makefile
+++ b/ap/os/linux/linux-3.4.x/drivers/staging/voicebufferdrv/Makefile
@@ -1,5 +1,5 @@
 #
 # voice buffer driver. 
 #
-obj-$(CONFIG_VOICE_BUFFER_DRV)	+= voice_buffer_drv.o
-voice_buffer_drv-$(CONFIG_VOICE_BUFFER_DRV) := voice_buffer_dev.o
+obj-y	+= voice_buffer_drv.o
+voice_buffer_drv-y := voice_buffer_dev.o
diff --git a/ap/os/linux/linux-3.4.x/drivers/staging/voicedrv/voice.c b/ap/os/linux/linux-3.4.x/drivers/staging/voicedrv/voice.c
index a47acf0..ef8d187 100755
--- a/ap/os/linux/linux-3.4.x/drivers/staging/voicedrv/voice.c
+++ b/ap/os/linux/linux-3.4.x/drivers/staging/voicedrv/voice.c
@@ -30,6 +30,7 @@
 extern int halVoice_SetVolOut(T_HalVoice_Block* pVoiceBlock);
 extern int halVoice_Enable(void);
 extern int halVoice_Disable(void);
+extern int zDrvVp_Loop(int);
 
 #ifdef _USE_VEHICLE_DC
 extern int zDrvVp_GetVol_Wrap(void);
@@ -39,6 +40,9 @@
 extern int zDrvVp_SetMute_Wrap(bool enable);
 extern bool zDrvVp_GetMute_Wrap(void);
 #endif
+extern void zDrvVp_UpdateVoiceNv(unsigned char *voice_nv_update);
+extern unsigned int zOss_NvItemWrite(unsigned int NvItemID, unsigned char *NvItemData, unsigned int NvItemLen);
+
 static int voice_open(struct inode *ip, struct file *fp);
 static int voice_release(struct inode *ip, struct file *fp);
 static long voice_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
@@ -163,6 +167,29 @@
 
 #endif
 
+
+
+static int voice_SetVp(int vp)
+{
+	int ret = 0;
+	ret = CPPS_FUNC(cpps_callbacks, zDrvVp_SetVoiceProc_Wrap)(vp);
+	if(ret < 0)
+	{
+		  printk(KERN_ERR "vp_SetVp fail = %d\n",vp);
+		  return ret;
+	}
+	return 0;
+}
+
+static int voice_GetVp(void)
+{      
+   	int vp; 
+    vp = CPPS_FUNC(cpps_callbacks, zDrvVp_GetVoiceProc_Wrap)();
+    return vp;
+}
+
+
+
 /* file operations for volte device /dev/volte_device */
 static const struct file_operations voice_fops = {
 	.owner = THIS_MODULE,
@@ -406,7 +433,7 @@
 		bool para;
 
 		if (copy_from_user(&para, argp, sizeof(para))) {
-			print_audio("voice_ioctl  set vol copy_to_user err!\n");
+			print_audio("voice_ioctl  set mute copy_to_user err!\n");
 			return -EFAULT;
 		}
 		ret = voice_SetMute(para);
@@ -501,6 +528,69 @@
 
 		break;
 	}
+	case VOICE_IOCTL_SET_VP: {
+		pr_info("voice set voice process! \n");
+		int para;
+
+		if (copy_from_user(&para, argp, sizeof(para))) {
+			print_audio("voice_ioctl  set vp copy_to_user err!\n");
+			return -EFAULT;
+		}
+		ret = voice_SetVp(para);
+		break;
+	}
+
+	case VOICE_IOCTL_GET_VP: {
+		pr_info("voice get voice process! \n");
+		int vp;
+
+		vp = voice_GetVp();
+
+		if (copy_to_user(argp, &vp, sizeof(vp))) {
+			pr_err("voice_ioctl  get vp copy_to_user err!\n");
+			return -EFAULT;
+		}
+		break;
+	}
+
+	case VOICE_IOCTL_GET_VBUF: {
+		int fs = 0;
+		int en = 0;
+	    int type = 0;
+		T_VoiceBuf_Para vb;
+		CPPS_FUNC(cpps_callbacks, zDrvVp_Status)(&fs, NULL);
+		pr_info("voice_ioctl  zDrvVp_Status fs=%d!\n", fs);
+		CPPS_FUNC(cpps_callbacks, zDrvVp_GetVoiceBuffer_Wrap)(&en,&type);	
+		vb.fs = fs;
+		vb.enable = en;
+		vb.type = type;
+		pr_info("voice_ioctl GET_VBUF,enable=%d type=%d!\n",vb.enable,vb.type);
+		
+		if (copy_to_user(argp, &vb, sizeof(vb))) {
+			pr_err("voice_ioctl	GET_VBUF copy_to_user err!\n");
+			return -EFAULT;
+		}
+	
+		break;
+	}
+
+	case VOICE_IOCTL_SET_VBUF: {
+		T_VoiceBuf_Para vb;
+
+		if (copy_from_user(&vb, argp, sizeof(vb))) {
+			print_audio("voice_ioctl  SET_VBUF copy_to_user err!\n");
+			return -EFAULT;
+		}
+
+		CPPS_FUNC(cpps_callbacks, zDrvVp_SetVoiceBuffer_Wrap)(vb.enable,vb.type);	
+		pr_info("voice_ioctl  SET_VBUF,enable=%d type=%d!\n",vb.enable,vb.type);
+	
+
+	
+		break;
+	}
+
+	
 	default: {
 		pr_info("voice_ioctl  invalid cmd!\n");
 		break;
diff --git a/ap/os/linux/linux-3.4.x/drivers/staging/voltedrv/volte.c b/ap/os/linux/linux-3.4.x/drivers/staging/voltedrv/volte.c
index 2341465..262868f 100644
--- a/ap/os/linux/linux-3.4.x/drivers/staging/voltedrv/volte.c
+++ b/ap/os/linux/linux-3.4.x/drivers/staging/voltedrv/volte.c
@@ -39,6 +39,7 @@
  extern int32_t zDrvVoice_WriteStop(void);
  extern int32_t zDrvVoice_ReadOneFrame(uint8_t *pBuf);
  extern int32_t zDrvVoice_WriteOneFrame(uint8_t *pBuf);
+ extern int  zDrvVp_GetSlicFlag(void);
 
 
 
diff --git a/ap/os/linux/linux-3.4.x/include/linux/module.h b/ap/os/linux/linux-3.4.x/include/linux/module.h
index 2c82c91..4424555 100755
--- a/ap/os/linux/linux-3.4.x/include/linux/module.h
+++ b/ap/os/linux/linux-3.4.x/include/linux/module.h
@@ -21,6 +21,9 @@
 #include <linux/percpu.h>
 #include <asm/module.h>
 #include <linux/amr_drv.h>
+
+#include <linux/volte_drv.h>
+
 /* Not Yet Implemented */
 #define MODULE_SUPPORTED_DEVICE(name)
 
@@ -743,6 +746,11 @@
     void (*zDrvDtmf_Detect_RegCallbacks)(T_DrvDtmf_Detect_Opt);
 	int (*zDrvVp_SetPath_Wrap)(int);
 	int (*zDrvVp_GetSlicFlag)(void);
+    int (*zDrvVp_SetVoiceProc_Wrap)(int);
+    int (*zDrvVp_GetVoiceProc_Wrap)(void);
+	int (*zDrvVp_SetVoiceBuffer_Wrap)(int ,int );
+	void (*zDrvVp_GetVoiceBuffer_Wrap)(int *,int *);
+	
 	int (*zDrvVp_SetEchoDelay_Wrap)(int);
 	int (*zDrvVp_GetEchoDelay_Wrap)(void);
 	int (*zDrvVp_SetTxNsMode_Wrap)(int);
diff --git a/ap/os/linux/linux-3.4.x/include/linux/volte_drv.h b/ap/os/linux/linux-3.4.x/include/linux/volte_drv.h
index 47a6c01..d281d7d 100755
--- a/ap/os/linux/linux-3.4.x/include/linux/volte_drv.h
+++ b/ap/os/linux/linux-3.4.x/include/linux/volte_drv.h
@@ -73,6 +73,15 @@
 
 } T_Voice_Para;
 
+typedef struct {
+	uint32_t fs;  //8000;16000 
+	uint32_t enable; //// 0 disable;1 enable
+	uint32_t type;//0 single core;1 mult core
+
+
+} T_VoiceBuf_Para;
+
+
 #ifdef __KERNEL__
 struct voice_dev {
 	T_Voice_Para param;
@@ -97,6 +106,14 @@
 #define VOICE_IOCTL_GET_FS	_IOR('v', 20, int)
 #define VOICE_IOCTL_SET_VOICE_NVRW	_IOW('v', 21, int)
 
+#define VOICE_IOCTL_SET_VP	_IOW('v', 22, int)
+#define VOICE_IOCTL_GET_VP	_IOR('v', 23, int) 
+
+#define VOICE_IOCTL_SET_VBUF	_IOW('v', 24, T_VoiceBuf_Para)
+#define VOICE_IOCTL_GET_VBUF	_IOR('v', 25, T_VoiceBuf_Para) 
+
+
+
 #ifdef __KERNEL__
 #define  print_audio(fmt, ...)  \
 		printk(fmt, ##__VA_ARGS__)
diff --git a/ap/project/zx297520v3/prj_vehicle_dc_ref/build/config.mk b/ap/project/zx297520v3/prj_vehicle_dc_ref/build/config.mk
index 4f38694..24f8ce3 100755
--- a/ap/project/zx297520v3/prj_vehicle_dc_ref/build/config.mk
+++ b/ap/project/zx297520v3/prj_vehicle_dc_ref/build/config.mk
@@ -62,6 +62,9 @@
 #else

 #CUSTOM_MACRO += -D_CPE_AUDIO_PRJ

 endif

+ifeq ($(USE_VOICE_AT),yes)

+CUSTOM_MACRO += -D_USE_VOICE_AT

+endif

 ifeq ($(USE_VOICE_ALSA),yes)

 CUSTOM_MACRO += -D_USE_VOICE_ALSA

 endif

diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
index c15e093..b86c379 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
@@ -85,7 +85,7 @@
 #DISTRO_FEATURES += "MMI_LCD"
 #语音控制
 DISTRO_FEATURES += "voice_alsa"
-#DISTRO_FEATURES += "use_voice_buffer"
+DISTRO_FEATURES += "use_voice_buffer"
 
 #cap_oem.img
 DISTRO_FEATURES += " oemfs "
@@ -140,6 +140,7 @@
 CUSTOM_MACRO += "${@bb.utils.contains('DISTRO_FEATURES', 'use_voice_buffer', '-D_USE_VOICE_BUFFER', '', d)}"
 #CONFIG_VB_TRANSMIT_INTF = "RTP"
 #CONFIG_VB_TRANSMIT_INTF = "USB"
+CONFIG_VB_TRANSMIT_INTF = "NULL"
 CUSTOM_MACRO += "${@bb.utils.contains('CONFIG_VB_TRANSMIT_INTF', 'RTP', '-D_VB_TRANSMIT_INTF_RTP', '', d)}"
 CUSTOM_MACRO += "${@bb.utils.contains('CONFIG_VB_TRANSMIT_INTF', 'USB', '-D_VB_TRANSMIT_INTF_USB', '', d)}"
 #wifi 配置
@@ -316,11 +317,13 @@
         lynq-wifi-demo \
         lynq-adc-demo \
         lynq-at-test \
+        lynq-vb-demo \
         lynq-monitor-demo \
         "
 
 zxic_app_open += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'rild', '', d)}"
 zxic_app_open += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'BL', 'tel-svr', '', d)}"
+zxic_app_open += "${@bb.utils.contains('CONFIG_VB_TRANSMIT_INTF', 'NULL', 'vb-demo', '', d)}"
 
 #开源应用及库	
 meta_app_open += "\
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-voice-demo/files/lynq-qser-voice-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-voice-demo/files/lynq-qser-voice-demo.cpp
index 41c5c97..c3187a8 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-voice-demo/files/lynq-qser-voice-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-voice-demo/files/lynq-qser-voice-demo.cpp
@@ -29,6 +29,8 @@
     {7,   "qser_voice_set_test_num"},

     {8,   "qser_voice_fast_ecall"},

 #endif

+    {9,   "qser_voice_set_audio_mode"},

+    {10,  "qser_voice_get_audio_mode"},

     {-1,    NULL}

 };

 

@@ -51,6 +53,9 @@
 int (*qser_voice_set_speech_volume)(const int volume);

 int (*qser_voice_get_speech_volume)(int *volume);

 int (*qser_voice_set_dtmf)(const char callnum);

+int (*qser_voice_set_audio_mode)(const int audio_mode);

+int (*qser_voice_get_audio_mode)(int* audio_mode);

+

 

 #ifdef ECALL_SUPPORT

 int (*qser_voice_set_test_num)(voice_client_handle_type*       h_voice,E_QSER_VOICE_ECALL_SET_TYPE_T type, const char *test_num, int test_num_length);

@@ -119,6 +124,7 @@
     int ret    = 0;

     int  voice_call_id = 0;

     voice_client_handle_type    h_voice     = 0;

+    int audio_mode = 0;

     

     const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";

     dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);

@@ -230,7 +236,23 @@
             printf("qser_voice_add_ecall_indhandler not defined or exported in %s\n", lynqLibPath_Call);

             return -1;

     }

-#endif

+#endif    

+

+    qser_voice_set_audio_mode = (int(*)(const int audio_mode))dlsym(dlHandle_call, "qser_voice_set_audio_mode");

+    if(qser_voice_set_audio_mode == NULL) 

+    {

+        printf("qser_voice_set_audio_mode not defined or exported in %s\n", lynqLibPath_Call);

+        return -1;

+    }

+

+    

+    qser_voice_get_audio_mode = (int(*)(int* audio_mode))dlsym(dlHandle_call, "qser_voice_get_audio_mode");

+    if(qser_voice_get_audio_mode == NULL) 

+    {

+        printf("qser_voice_get_audio_mode not defined or exported in %s\n", lynqLibPath_Call);

+        return -1;

+    }

+    

     

     ret = qser_voice_call_client_init(&h_voice);

     if(ret != 0 )

@@ -378,6 +400,22 @@
                 break;

             }            

 #endif

+            case 9:

+            {   

+                

+                printf("please input voice audio mode: 0 codec, 1 rtp\n");

+                scanf("%d", &audio_mode);

+                ret = qser_voice_set_audio_mode(audio_mode);

+                printf("qser_voice_set_audio_mode ret = %d, audio_mode is %d\n", ret, audio_mode);

+                break;

+            }            

+            case 10:

+            {  

+                ret = qser_voice_get_audio_mode(&audio_mode);

+                printf("qser_voice_get_audio_mode ret = %d, audio_mode is %d\n", ret, audio_mode);

+                break;

+            }            

+

             default:

                 print_help();

                 break;

diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/files/lynq_vb_demo.c b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/files/lynq_vb_demo.c
new file mode 100755
index 0000000..6fde401
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/files/lynq_vb_demo.c
@@ -0,0 +1,778 @@
+#include <stdio.h>

+#include <unistd.h>

+#include <string.h>

+#include <stdlib.h>

+#include <stdint.h>

+#include <sys/ioctl.h>

+#include <fcntl.h>

+//#include "voice_ipc.h"

+

+#define _USE_VOICE_BUFFER

+#include "voice_lib.h"

+#include <fcntl.h>

+#include <signal.h>

+#include <semaphore.h>

+#include <sys/types.h>

+#include <pthread.h>

+

+/*command max len*/

+#define VOICE_CMD_MAX_LEN 64

+

+#define EXIT_CMD_STOP	"stop\n"

+#define EXIT_CMD_Q	"q\n"

+#define EXIT_CMD_EXIT   "exit\n"

+

+#define REQ_VOICE_BUFFER_TEST_START        "voice_buffer_test_start"

+#define REQ_VOICE_BUFFER_TEST_STOP         "voice_buffer_test_stop"

+#define REQ_VOICE_BUFFER_LOOP_TEST_START        "voice_buffer_loop_test_start"

+#define REQ_VOICE_BUFFER_LOOP_TEST_STOP         "voice_buffer_loop_test_stop"

+#define REQ_VOICE_BUFFER_RTP_TEST_START        "voice_buffer_rtp_test_start"

+#define REQ_VOICE_BUFFER_RTP_TEST_STOP         "voice_buffer_rtp_test_stop"

+

+

+  

+#define VBUFFER_TX_FILE_NAME "/mnt/userdata/tx.pcm"

+#define VBUFFER_RX_FILE_NAME "/mnt/userdata/rx.pcm"

+#define VBUFFER_TX16_FILE_NAME "/mnt/userdata/tx16.pcm"

+#define VBUFFER_RX16_FILE_NAME "/mnt/userdata/rx16.pcm"

+

+

+

+#define VB_MAX_INT	     0x7fffffff

+#define VB_MIN_INT        0 

+#define VB_INT_OVERFLOW(x) if((x < VB_MIN_INT)||(x > VB_MAX_INT))  x = 0;

+ 

+#define RX_FILE_LEN_MAX 0x100000  

+

+

+

+typedef int (vb_thread_proc)(void*);

+struct vbuf_info_t

+{

+	int fd;

+    pthread_t	    rx_test_thread;	

+    pthread_t	    tx_test_thread;

+	pthread_t	    loop_test_thread;

+	int quit;

+	char        	*tx_buf;

+    char        	*rx_buf;

+	int buf_size;

+	char *tx_filename;

+	char *rx_filename;

+    FILE *tx_file;

+	FILE *rx_file;

+    int tx_filesize;

+	int rx_filesize;		

+	int fs;	 	

+};

+

+static struct vbuf_info_t vbuf_rec;

+

+static void printUsage(const char *Opt)

+{

+    printf("Usage: %s\n", Opt);

+     

+    printf("voice_buffer_test_start                      value: 8000,16000\n");

+    printf("voice_buffer_test_stop                       no value input\n");

+	printf("voice_buffer_loop_test_start                      value: 8000,16000\n");

+    printf("voice_buffer_loop_test_stop                       no value input\n");

+    printf("\n");

+}

+

+static int vbuffer_start_flag = 0;

+static int tx_optcount = 0;

+static int rx_optcount = 0;	

+static int first_rderr_flag = 0;

+static int first_wrerr_flag = 0;

+

+

+

+//whole rx path

+static int vb_rx_test_thread_func(void *arg)

+{

+    int ret;

+

+    char* buf = vbuf_rec.rx_buf;

+    int size = vbuf_rec.buf_size;

+    int bytes_read = 0;

+    int r_size;

+

+ 

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

+    memset (buf,0, size);

+    

+    while (!vbuf_rec.quit) 

+    {

+		rx_optcount ++;	

+		VB_INT_OVERFLOW(rx_optcount);

+		if((rx_optcount%1000) == 0){

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

+

+		}

+		else if(rx_optcount == 1000000){

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

+			rx_optcount = 0;

+			

+		}

+

+        //read form ps

+		r_size = voice_buffer_read(vbuf_rec.fd, buf, size);

+        if(r_size <= 0) 

+        {

+            first_rderr_flag++;			

+			VB_INT_OVERFLOW(first_rderr_flag);			

+            continue ;

+        }

+		else{

+			first_rderr_flag = 0;

+

+		}

+		

+        if(vbuf_rec.rx_file != NULL) 

+        {

+			r_size = fwrite(buf, 1,size, vbuf_rec.rx_file);

+

+		    if (r_size != size) {

+		        //printf("Error fwrite size not eq,r_size=%d,size=%d\n",r_size,size);

+		    }

+			else{

+			

+		        bytes_read += size;

+				if(bytes_read >= vbuf_rec.rx_filesize){

+					fseek(vbuf_rec.rx_file, 0, SEEK_SET);

+					bytes_read = 0;

+					printf("fwrite over write maxsize(%d)!!!\n",vbuf_rec.rx_filesize);

+				

+				}

+			}

+        }

+		

+		

+    }

+    

+    return 0;

+}

+

+static int vb_tx_test_thread_func(void *arg)

+{

+    int ret;

+    int num_read;

+

+	

+    char* buf = vbuf_rec.tx_buf;

+	

+    int size = vbuf_rec.buf_size;

+     int w_size;

+

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

+ 

+	

+    memset(buf, 0,size);    

+    while (!vbuf_rec.quit) 

+    {

+

+	    if(vbuf_rec.tx_file != NULL) 

+	    {

+

+	        num_read = fread(buf,1,size, vbuf_rec.tx_file);

+			

+	        if (num_read != size) {

+		        //printf("Error fread size not eq,num_read=%d,size=%d\n",num_read,size);

+			}

+	        if (num_read <= 0) {

+		        printf("Error fread size not eq,num_read=%d,size=%d\n",num_read,size); 

+				fseek(vbuf_rec.tx_file, 0, SEEK_SET);

+			}

+	    }			

+		tx_optcount ++;

+		VB_INT_OVERFLOW(tx_optcount);

+		

+		w_size = voice_buffer_write(vbuf_rec.fd, buf, size);

+        if(w_size <= 0) 

+        {

+        	first_wrerr_flag++;

+			

+			VB_INT_OVERFLOW(first_wrerr_flag);

+			

+            continue;

+        }

+		else{

+			first_wrerr_flag = 0;

+

+		}

+

+    }

+    return 0;

+}

+

+

+static int vb_thread_create( const char *name,pthread_t	*thread_t, vb_thread_proc *proc, 

+								int stack_size, unsigned priority,void *arg )

+{

+    pthread_attr_t thread_attr;

+    int ret;

+	int default_size;

+    

+    struct sched_param    param;

+    int  policy = SCHED_FIFO;

+    

+    printf("%s: start! \n",__func__);

+    

+    /* Init thread attributes */

+    pthread_attr_init(&thread_attr);    

+    /* Create the thread. */

+

+    ret = pthread_create( thread_t, &thread_attr,proc, arg);

+    if (ret != 0) 

+    {

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

+    

+    	pthread_attr_destroy(&thread_attr);

+        return ret;

+    }

+	

+    pthread_attr_getstacksize(&thread_attr, &default_size);

+    printf("%s: pthread_attr_getstacksize(%d)! \n",__func__,default_size);

+    

+    pthread_attr_destroy(&thread_attr);

+	

+    printf("%s: end \n",__func__);

+    return 0;

+}

+

+

+int voice_buffer_stream_test_start(int fs)

+{

+    int ret = 0;

+    int buf_size = 320;

+	tx_optcount = 0;

+	rx_optcount = 0;	

+    int* buf_int;

+

+	int i;

+

+	if(vbuffer_start_flag == 1){ 

+		printf(" VB already start,return \n");

+

+		return 0;

+	}

+

+	vbuffer_start_flag = 1;

+

+

+

+	if((vbuf_rec.fd != -1)&&(vbuf_rec.fd != 0)){

+		printf(" VB fd already get, vbuf_rec.fd=%d return \n",vbuf_rec.fd);

+	}

+

+	if(fs == 8000){

+

+		buf_size = 320;

+	}

+	else if(fs == 16000){

+

+		buf_size = 640;

+	}	

+	else

+	{

+		buf_size = 320;

+	}

+ 	printf("Starting vb stream fs=%d buf_size=%d \n",fs,buf_size);

+

+ 	printf("%s:open tx and rx file \n",__func__);

+	if(fs == 8000){

+

+   		vbuf_rec.tx_filename = VBUFFER_TX_FILE_NAME;//"/cache/tx.pcm";

+    	vbuf_rec.rx_filename = VBUFFER_RX_FILE_NAME;//"/cache/rx.pcm";

+

+	}

+	else if(fs == 16000){

+

+    	vbuf_rec.tx_filename = VBUFFER_TX16_FILE_NAME;//"/cache/tx16.pcm";

+    	vbuf_rec.rx_filename = VBUFFER_RX16_FILE_NAME;//"/cache/rx16.pcm";

+

+	}	

+	else

+	{

+		vbuf_rec.tx_filename = VBUFFER_TX_FILE_NAME;//"/cache/tx.pcm";

+		vbuf_rec.rx_filename = VBUFFER_RX_FILE_NAME;//"/cache/rx.pcm";

+

+	}

+

+

+

+	

+    vbuf_rec.tx_file = fopen(vbuf_rec.tx_filename , "rb");

+    if (!vbuf_rec.tx_file) {

+        printf("Unable to open file '%s'\n", vbuf_rec.tx_filename);

+        //return -1;

+    }

+

+

+    vbuf_rec.rx_file = fopen(vbuf_rec.rx_filename, "wb");

+    if (!vbuf_rec.rx_file) {

+        printf(stderr, "Unable to create file '%s'\n", vbuf_rec.rx_filename);

+		//fclose(vbuf_rec.tx_file);

+ 

+        //return -1;

+    }

+	vbuf_rec.rx_filesize = RX_FILE_LEN_MAX;	

+	printf("%s : vbuf_rec.rx_filesize(%d) \n",__func__,vbuf_rec.rx_filesize);

+

+    vbuf_rec.rx_buf = (char*) malloc(buf_size);

+	if(!vbuf_rec.rx_buf) {

+		printf("%s : malloc buf fail,return \n",__func__);

+		goto err;

+	}	

+    vbuf_rec.tx_buf = (char*) malloc(buf_size);  

+	if(!vbuf_rec.tx_buf) {

+		free(vbuf_rec.rx_buf);

+		printf("%s : malloc buf fail,return \n",__func__);

+	    vbuf_rec.rx_buf = NULL;

+		goto err;

+	}	

+	vbuf_rec.buf_size = buf_size;

+	

+    vbuf_rec.quit = 0;

+	

+	printf("%s : vb open start \n",__func__);

+

+	

+    vbuf_rec.fd = voice_buffer_open();

+	if(vbuf_rec.fd <= 0){

+		printf("%s : vb open fail fd=%d,return \n",__func__,vbuf_rec.fd);

+		ret = -1;

+		goto err;

+		

+	}

+	printf("%s :voice_buffer_open end \n",__func__);

+	

+	printf("%s :rx tx vb_thread_create start \n",__func__);

+    ret = vb_thread_create ("vb_playback_test",&vbuf_rec.rx_test_thread, vb_rx_test_thread_func, 

+    							4*1024,35,NULL);

+    if (ret != 0)

+    {

+		printf("%s :rx vb_thread_create fail ret=%d,return \n",__func__,ret);    

+		goto err;

+    }

+

+	printf("%s :rx vb_thread_create end \n",__func__);

+

+    ret = vb_thread_create ( "vbuf_record_test", &vbuf_rec.tx_test_thread, vb_tx_test_thread_func,

+    							4*1024,35,NULL);

+    if (ret != 0) 

+    {

+    

+		printf("%s :tx vb_thread_create fail ret=%d,return \n",__func__,ret);

+        vbuf_rec.quit = 1;

+        pthread_join(vbuf_rec.rx_test_thread,NULL);

+        vbuf_rec.rx_test_thread = NULL;

+		goto err;

+    }

+	printf("%s :tx vb_thread_create end \n",__func__);

+

+     return 0;

+

+err:

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+	

+	fclose(vbuf_rec.tx_file);

+	vbuf_rec.tx_file = NULL;

+	fclose(vbuf_rec.rx_file);

+	vbuf_rec.rx_file = NULL;

+	

+    return ret;

+}

+

+

+//Stop stream

+int voice_buffer_stream_test_stop(void)

+{

+    int ret = 0;

+	printf("%s:rx tx thread exit start \n",__func__);

+	if(vbuf_rec.quit == 1) {

+		printf("%s,already stop ,return\n",__func__);

+

+	}

+    

+    vbuf_rec.quit = 1;

+	voice_buffer_stop(vbuf_rec.fd);

+    if (vbuf_rec.tx_test_thread) 

+    {

+        pthread_join (vbuf_rec.tx_test_thread,NULL);

+        vbuf_rec.tx_test_thread = NULL;

+		

+    }

+    

+    if (vbuf_rec.rx_test_thread) 

+    {	

+        pthread_join (vbuf_rec.rx_test_thread,NULL);

+        vbuf_rec.rx_test_thread = NULL;

+    }

+	

+    printf("voice_buffer_close start \n");

+    ret = voice_buffer_close(vbuf_rec.fd); 

+    if(ret != 0) 

+    {

+		printf("%s : vb close fail \n",__func__);

+    }

+	vbuf_rec.fd = -1;

+	

+	if(vbuf_rec.tx_file != NULL) 

+	{

+		fclose(vbuf_rec.tx_file);

+		printf("%s : vb close ,close tx file \n",__func__);

+		vbuf_rec.tx_file = NULL;

+	}

+		

+	if(vbuf_rec.rx_file != NULL) 

+	{

+

+		fclose(vbuf_rec.rx_file);

+		printf("%s : vb close ,close rx file \n",__func__);

+		vbuf_rec.rx_file = NULL;

+		

+	}

+

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+

+

+	vbuffer_start_flag = 0;	

+    printf("Stopping vb stream end\n");

+    return 0;

+}

+

+

+static int vb_loop_test_thread_func(void *arg)

+{

+    int ret;

+

+    char* buf = vbuf_rec.rx_buf;

+    int size = vbuf_rec.buf_size;

+

+	//char* buf = vbuf_rec.tx_buf;

+	

+    //int size = vbuf_rec.buf_size;

+    int w_size;

+    int r_size;

+

+ 

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

+    memset (buf,0, size);

+    

+    while (!vbuf_rec.quit) 

+    {

+		rx_optcount ++;	

+		VB_INT_OVERFLOW(rx_optcount);

+		if((rx_optcount%1000) == 0){

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

+

+		}

+		else if(rx_optcount == 1000000){

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

+			rx_optcount = 0;

+			

+		}

+

+        //read form ps

+		r_size = voice_buffer_read(vbuf_rec.fd, vbuf_rec.rx_buf, size);

+        if(r_size <= 0) 

+        {

+            first_rderr_flag++;			

+			VB_INT_OVERFLOW(first_rderr_flag);			

+            continue ;

+        }

+		else{

+			first_rderr_flag = 0;

+		}

+        memcpy(vbuf_rec.tx_buf,vbuf_rec.rx_buf,size);

+		w_size = voice_buffer_write(vbuf_rec.fd, vbuf_rec.tx_buf, size);

+        if(w_size <= 0) 

+        {

+        	first_wrerr_flag++;

+			

+			VB_INT_OVERFLOW(first_wrerr_flag);

+			

+            continue;

+        }

+		else{

+			first_wrerr_flag = 0;

+		}

+		

+    }

+    

+    return 0;

+}

+

+

+int voice_buffer_stream_loop_test_start(int fs)

+{

+    int ret = 0;

+    int buf_size = 320;

+	tx_optcount = 0;

+	rx_optcount = 0;	

+    int* buf_int;

+

+	int i;

+

+	if(vbuffer_start_flag == 1){ 

+		printf(" VB already start,return \n");

+

+		return 0;

+	}

+

+	if((vbuf_rec.fd != -1)&&(vbuf_rec.fd != 0)){

+		printf(" VB fd already get, vbuf_rec.fd=%d return \n",vbuf_rec.fd);

+	}

+

+	vbuffer_start_flag = 1;

+

+	if(fs == 8000){

+

+		buf_size = 320;

+	}

+	else if(fs == 16000){

+

+		buf_size = 640;

+	}	

+	else

+	{

+		buf_size = 320;

+	}

+ 	printf("Starting vb stream fs=%d buf_size=%d \n",fs,buf_size);

+

+    vbuf_rec.rx_buf = (char*) malloc(buf_size);

+	if(!vbuf_rec.rx_buf) {

+		printf("%s : malloc buf fail,return \n",__func__);

+		return -1;

+	}	

+    vbuf_rec.tx_buf = (char*) malloc(buf_size);  

+	if(!vbuf_rec.tx_buf) {

+		free(vbuf_rec.rx_buf);

+		printf("%s : malloc buf fail,return \n",__func__);

+	    vbuf_rec.rx_buf = NULL;

+		return -1;

+	}	

+	vbuf_rec.buf_size = buf_size;

+	

+    vbuf_rec.quit = 0;

+	

+	printf("%s : vb open start \n",__func__);

+

+	

+    vbuf_rec.fd = voice_buffer_open();

+	if(vbuf_rec.fd <= 0){

+		printf("%s : vb open fail fd=%d,return \n",__func__,vbuf_rec.fd);

+		ret = -1;

+		goto err;

+		

+	}	

+	printf("%s :loop vb_thread_create start \n",__func__);

+    ret = vb_thread_create ("vb_playback_test",&vbuf_rec.loop_test_thread, vb_loop_test_thread_func, 

+    							4*1024,35,NULL);

+    if (ret != 0)

+    {

+		printf("%s :rx vb_thread_create fail ret=%d,return \n",__func__,ret);    

+		goto err;

+    }

+

+	printf("%s :rx vb_thread_create end \n",__func__);

+

+     return 0;

+

+err:

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+	

+    return ret;

+}

+

+int voice_buffer_stream_loop_test_stop(void)

+{

+    int ret = 0;

+	printf("%s:loop thread exit start \n",__func__);

+	if(vbuf_rec.quit == 1) {

+		printf("%s,already stop ,return\n",__func__);

+

+	}

+    

+    vbuf_rec.quit = 1;

+	voice_buffer_stop(vbuf_rec.fd);

+    if (vbuf_rec.loop_test_thread) 

+    {

+        pthread_join (vbuf_rec.loop_test_thread,NULL);

+        vbuf_rec.tx_test_thread = NULL;

+		

+    }

+    	

+    printf("voice_buffer_close start \n");

+    ret = voice_buffer_close(vbuf_rec.fd); 

+    if(ret != 0) 

+    {

+		printf("%s : vb close fail \n",__func__);

+    }

+	vbuf_rec.fd = -1;

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+

+

+	vbuffer_start_flag = 0;	

+    printf("Stopping vb stream end\n");

+    return 0;

+}

+

+int voice_buffer_rtp_test_start(int fs)

+{   

+    return voice_buffer_stream_test_start(fs);

+}

+

+

+

+int voice_buffer_rtp_test_stop(void)

+{   

+    return voice_buffer_stream_test_stop();

+}

+

+void voice_buffer_cmd_proc(char *cmdstr)

+{

+    int ret = 0;

+	char data[VOICE_CMD_MAX_LEN];

+	int cmdstr_len = strlen(cmdstr) -1; //-strlen("\r")

+    int value = 0;

+    int *p_value = &value;

+    

+    cmdstr[cmdstr_len] = '\0'; //+strlen("\0")

+

+	ret = sscanf(cmdstr, "%s", data);

+    if(1 != ret){

+        printf("data sscanf failed!(%d)\n", ret);

+        return;

+    }

+	if(0 == strncmp(data, REQ_VOICE_BUFFER_TEST_START, strlen(REQ_VOICE_BUFFER_TEST_START))){

+

+		ret = sscanf(cmdstr, "%*s %d", &value);

+        if(1 != ret){

+            printf("%s,value sscanf failed!(%d)\n",data, ret);

+            return;

+        }

+		

+        printf("%s set value %d\n", data, value);

+		ret = voice_buffer_stream_test_start(value);

+

+		printf("%s return ret=%d\n", data, ret);

+		

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_TEST_STOP, strlen(REQ_VOICE_BUFFER_TEST_STOP))){

+		ret = voice_buffer_stream_test_stop();

+		printf("%s return %d\n", data, ret);

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_LOOP_TEST_START, strlen(REQ_VOICE_BUFFER_LOOP_TEST_START))){

+

+		ret = sscanf(cmdstr, "%*s %d", &value);

+        if(1 != ret){

+            printf("%s,value sscanf failed!(%d)\n",data, ret);

+            return;

+        }

+		

+        printf("%s set value %d\n", data, value);

+		ret = voice_buffer_stream_loop_test_start(value);

+

+		printf("%s return ret=%d\n", data, ret);

+		

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_LOOP_TEST_STOP, strlen(REQ_VOICE_BUFFER_LOOP_TEST_STOP))){

+		printf("voice_buffer_stream_loop_test_stop \n");

+		ret = voice_buffer_stream_loop_test_stop();

+		printf("%s return %d\n", data, ret);

+	}

+    if(0 == strncmp(data, REQ_VOICE_BUFFER_RTP_TEST_START, strlen(REQ_VOICE_BUFFER_RTP_TEST_START))){

+

+		ret = sscanf(cmdstr, "%*s %d", &value);

+        if(1 != ret){

+            printf("%s,value sscanf failed!(%d)\n",data, ret);

+            return;

+        }

+		

+        printf("%s set value %d\n", data, value);

+		ret = voice_buffer_rtp_test_start(value);

+

+		printf("%s return ret=%d\n", data, ret);

+		

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_RTP_TEST_STOP, strlen(REQ_VOICE_BUFFER_RTP_TEST_STOP))){

+		ret = voice_buffer_rtp_test_stop();

+		printf("%s return %d\n", data, ret);

+	}	

+    else{

+		printf("Request unknow.\n");

+        printUsage(cmdstr);

+	}

+}

+

+void signal_handle_func(int sig)

+{

+	printf("sig(%d) signal_handle_func exit ",sig);

+	exit(0);

+}

+

+void signal_handle_func_term(int sig)

+{

+	printf("sig(%d) signal_handle_func exit ",sig);

+    voice_buffer_stream_loop_test_stop();

+    voice_buffer_stream_test_stop();

+    voice_buffer_rtp_test_stop();

+	exit(0);

+}

+

+

+int main(int argc, char **argv)

+{

+    char cmdstr[VOICE_CMD_MAX_LEN];

+    printf("voice_demo start\n");

+	

+	signal(SIGINT, signal_handle_func);

+	signal(SIGQUIT, signal_handle_func);

+	signal(SIGTERM, signal_handle_func_term);

+	signal(SIGPIPE, signal_handle_func);

+

+    memset(&vbuf_rec,0,sizeof(vbuf_rec));

+

+    while(1){

+        memset(cmdstr, 0, VOICE_CMD_MAX_LEN);

+

+        printf("Please input an voice_demo command:\n");

+

+        if(NULL != fgets(cmdstr, VOICE_CMD_MAX_LEN - 1, stdin)){

+            if(0 == strcmp(EXIT_CMD_STOP, cmdstr) || 

+                0 == strcmp(EXIT_CMD_Q, cmdstr) || 

+                0 == strcmp(EXIT_CMD_EXIT, cmdstr)){

+				break;

+			}

+            

+            printf("len:%d, cmdstr:%s\n", strlen(cmdstr), cmdstr);

+            

+            if(1 >= strlen(cmdstr)){

+				continue;

+			}

+

+            voice_buffer_cmd_proc(cmdstr);

+        }

+    }

+

+    printf("voice_demo end\n");

+    

+    return 0;

+}

+

diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/files/makefile b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/files/makefile
new file mode 100755
index 0000000..6a6f960
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/files/makefile
@@ -0,0 +1,47 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -g -Os \
+                -flto \
+                -fpermissive \
+                -fPIC \
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0
+endif
+
+LOCAL_CFLAGS += -Werror=implicit-function-declaration
+
+$(warning ################# rock ROOT: $(ROOT),includedir:$(includedir),)
+
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(ROOT)$(includedir)/ \
+
+
+
+LOCAL_LIBS := \
+    -L. \
+    -ldl \
+    -lpthread \
+    -lvoice \
+
+SOURCES = $(wildcard *.c)
+
+EXECUTABLE = lynq_vb_demo
+
+OBJECTS=$(SOURCES:.c=.o)
+all: $(EXECUTABLE)
+
+$(EXECUTABLE): $(OBJECTS)
+	$(CC) $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.c
+	$(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/lynq-vb-demo.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/lynq-vb-demo.bb
new file mode 100755
index 0000000..b01d3b0
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-vb-demo/lynq-vb-demo.bb
@@ -0,0 +1,29 @@
+#inherit externalsrc package
+
+DESCRIPTION = "lynq-vb-demo"
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=b1e07e8d88e26263e71d3a9e2aa9a2ff"
+DEPENDS += "libvoice"
+SRC_URI = "file://lynq_vb_demo.c \
+           file://makefile \
+"
+
+SRC-DIR = "${S}/../lynq-vb-demo"
+FILES_${PN} += "${bindir}/"
+TARGET_CC_ARCH += "${LDFLAGS}"
+
+S = "${WORKDIR}"
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+	if test "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" || test "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4"; then
+		oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -mhard-float"
+	else
+		oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST}"
+	fi
+}
+
+do_install() {
+	install -d ${D}${bindir}/
+	install -m 0755 ${S}/lynq_vb_demo ${D}${bindir}/
+}
diff --git a/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo.bb b/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo.bb
new file mode 100755
index 0000000..68f2fd2
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo.bb
@@ -0,0 +1,64 @@
+DESCRIPTION = "vb_demo"
+DEPENDS     = "libvoice"
+SECTION     = "app"
+LICENSE     = "zte"
+PV = "1.0.0"
+PR = "r0"
+
+CLASS_COM = " \
+    ${@bb.utils.contains('DISTRO_FEATURES', 'procd', 'openwrt openwrt-services', '', d)} \
+    ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'systemd', '', d)} \
+"
+inherit ${CLASS_COM}
+
+#配置code路径信息。
+FILESEXTRAPATHS_prepend :="${APP-OPEN-PATH}:"
+SRC_URI = " \
+          file://test/vb_demo \		  
+		  ${@bb.utils.contains("DISTRO_FEATURES", "procd", "file://vb_demo.init","", d)} \
+		  ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "file://vb_demo.service","", d)} \
+          "
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/zte;md5=c075689d1d1e06d4ab5bbe53623a6808"
+S = "${WORKDIR}"
+S_SRC_PATH = "${S}/test/vb_demo"
+#引用公用头文件和编译选项。
+include ${BSPDIR}/sources/meta-zxic/conf/app_com.inc
+
+#inherit autotools pkgconfig systemd
+
+do_compile() {
+	make -C ${S_SRC_PATH}
+}
+
+do_install () {
+	install -d ${D}${bindir}/
+	install -m 0755 ${S_SRC_PATH}/vb_demo ${D}${bindir}/
+	
+	if ${@bb.utils.contains('DISTRO_FEATURES','procd','true','false',d)}; then
+		install -Dm 0755 ${WORKDIR}/vb_demo.init ${D}${sysconfdir}/init.d/vb_demo
+	fi
+
+	if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+		install -d ${D}${systemd_unitdir}/system
+		install -m 0644 ${WORKDIR}/vb_demo.service ${D}${systemd_unitdir}/system
+	fi
+	
+	#install elfs
+	install -d ${ELFS-PATH}/
+	install -m 0755 ${S_SRC_PATH}/vb_demo ${ELFS-PATH}/	
+}
+
+do_cleanlibs () {
+	rm -fr ${ELFS-PATH}/vb_demo
+}
+
+addtask  cleanlibs after do_clean  before do_cleansstate
+
+FILES_${PN} = "\
+    ${bindir}/ \
+    ${@bb.utils.contains("DISTRO_FEATURES", "procd", "${sysconfdir}/init.d/vb_demo","", d)} \
+    "
+SYSTEMD_SERVICE_${PN}     = "vb_demo.service"
+SYSTEMD_AUTO_ENABLE_${PN} = "disable"
+
+RDEPENDS_${PN} = " libvoice"
diff --git a/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo/vb_demo.init b/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo/vb_demo.init
new file mode 100755
index 0000000..e05899f
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo/vb_demo.init
@@ -0,0 +1,21 @@
+#!/bin/sh /etc/rc.common
+
+START=18
+STOP=85
+USE_PROCD=1
+
+logger -t vb_demo
+
+start_service() {
+	procd_open_instance
+	procd_set_param command /usr/bin/vb_demo
+	procd_set_param stdout 1  # forward stdout of the command to logd
+	procd_set_param stderr 1  # same for stderr
+	procd_set_param respawn
+	procd_close_instance
+}
+
+stop_service() 
+{
+	echo "add clean code"
+}
diff --git a/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo/vb_demo.service b/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo/vb_demo.service
new file mode 100755
index 0000000..d519809
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic/recipes-app/vb-demo/vb-demo/vb_demo.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=The vb_demo service
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/vb_demo
+Restart=always
+
+[Install]
+WantedBy=basic.target
+
diff --git a/cap/zx297520v3/sources/meta-zxic/recipes-kernel/linux/files/zx297520v3/linux-5_10-vehicle_dc_ref-normal-defconfig b/cap/zx297520v3/sources/meta-zxic/recipes-kernel/linux/files/zx297520v3/linux-5_10-vehicle_dc_ref-normal-defconfig
index ef22244..5681c94 100755
--- a/cap/zx297520v3/sources/meta-zxic/recipes-kernel/linux/files/zx297520v3/linux-5_10-vehicle_dc_ref-normal-defconfig
+++ b/cap/zx297520v3/sources/meta-zxic/recipes-kernel/linux/files/zx297520v3/linux-5_10-vehicle_dc_ref-normal-defconfig
@@ -2232,12 +2232,12 @@
 # end of Microsoft Hyper-V guest support
 
 # CONFIG_GREYBUS is not set
-# CONFIG_STAGING is not set
+CONFIG_STAGING=y
 #
 # ZX297520 voice buffer driver
 #
-# CONFIG_VOICE_BUFFER_DRV is not set
-# CONFIG_VBUFF_IN_MULTI_CORE is not set
+CONFIG_VOICE_BUFFER_DRV=y
+CONFIG_VBUFF_IN_MULTI_CORE=y
 # CONFIG_GOLDFISH is not set
 # CONFIG_CHROME_PLATFORMS is not set
 # CONFIG_MELLANOX_PLATFORM is not set
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/cc.cpp b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/cc.cpp
index 213c61a..46ee24a 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/cc.cpp
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/cc.cpp
@@ -47,6 +47,7 @@
 /*Warren add for t800 ril servie 2021/12/23 start*/
 #include "lynq_interface.h"
 #include <binder/Parcel.h>
+#include "call_rtp.h"
 #ifdef LED_SUPPORT
 #include "led.h"
 #endif
@@ -187,16 +188,17 @@
 }
 int mixer_set(int value )
 {
-    RLOGD("lynq this is function:%s,line%d",__FUNCTION__,__LINE__);
-    #if LYNQ_CC_SUPPORT
-    int ret;
 
      //set mixer ctl to om:1 or off:0
     if(value){
-        ret = set_mixer_ctrl_value_int(isEcallAudioPath() ? g_mixer_name_ecall: g_mixer_name, value);
-        RLOGD("mixer_set(%s) = %d, ret: %d", (isEcallAudioPath() ? g_mixer_name_ecall: g_mixer_name), value, ret);
-    } else {
-        //setEcallAudioPathOn(false);
+        //ret = set_mixer_ctrl_value_int(isEcallAudioPath() ? g_mixer_name_ecall: g_mixer_name, value);
+      
+        exe_set_voice_audio_mode(exe_get_voice_audio_mode());
+        
+     // RLOGD("mixer_set(%s) = %d, ret: %d", (isEcallAudioPath() ? g_mixer_name_ecall: g_mixer_name), value, ret);
+    } else {   
+        exe_set_voice_audio_mode(AUDIO_MODE_ALL_CLOSE);
+/*        
         ret = get_mixer_ctrl_value_int(g_mixer_name);
         RLOGD("mixer_set(get_mixer_ctrl_value_int: %s) = %d", g_mixer_name, ret);
         if(ret > 0) {
@@ -206,11 +208,9 @@
             ret = set_mixer_ctrl_value_int(g_mixer_name_ecall, value);
             RLOGD("mixer_set(%s) = %d", g_mixer_name_ecall, ret);
         }
+*/
     }
 
-
-    return ret;
-    #endif //LYNQ_CC_SUPPORT
     return 0;//LYNQ_CC_SUPPORT
 }
 int mixer_reset_set(int value )
@@ -459,7 +459,7 @@
     }
     }
     p.setDataPosition(pos);
-    setEcallAudioPathOn(false);
+//  setEcallAudioPathOn(false);
     pRI->pCI->dispatchFunction(p, pRI);
     inCallstatus = CALL_ON;
     return 0;
@@ -763,7 +763,7 @@
     writeStringToParcel(p, (const char *)argv[3+ParticipantsNumber]);//clir
 
     p.setDataPosition(pos);
-    setEcallAudioPathOn(false);
+//  setEcallAudioPathOn(false);
     pRI->pCI->dispatchFunction(p, pRI);
     return 0;
 }
@@ -787,7 +787,7 @@
 #endif
 
     p.setDataPosition(pos);
-    setEcallAudioPathOn(false);
+//  setEcallAudioPathOn(false);
     pRI->pCI->dispatchFunction(p, pRI);
     return 0;
 }
@@ -1143,7 +1143,7 @@
     }
   }
   p.setDataPosition(pos);
-  setEcallAudioPathOn(false);
+//setEcallAudioPathOn(false);
   pRI->pCI->dispatchFunction(p, pRI);
   return 0;
 }
@@ -1537,25 +1537,15 @@
 //void callStateChange(void)
 void speechonoff(int callnum)
 {
-    RLOGD("lynq this is function:%s,line%d",__FUNCTION__,__LINE__);
-    #if LYNQ_CC_SUPPORT
     static int callIndex = 0;
     RLOGD("callnum = %d, Call State Change then judge speech on/off!", callnum);
     callIndex = callnum;
-#ifdef GSW_RIL_CFG
-    if( callIndex >= 1 && speechStatus == SPEECH_OFF) {  //speech on
+    lock_rtp_audio_mtx(); 	
+    if( callIndex > 0 && speechStatus == SPEECH_OFF) {  //speech on
         //RLOGD("DemoAPP Call shell command (pactl set-card-profile 0 phonecall)");
         //system("pactl set-card-profile 0 phonecall");
         //RLOGD("DemoAPP Call shell command end");
-        set_codec(1); //hqing add for Geely demand on 11/07/2022, init cs call, open codec
-#endif
-
-#ifdef MOBILETEK_RIL_CFG
-    if( callIndex == 1 && speechStatus == SPEECH_OFF) {  //speech on
-        //RLOGD("DemoAPP Call shell command (pactl set-card-profile 0 phonecall)");
-        //system("pactl set-card-profile 0 phonecall");
-        //RLOGD("DemoAPP Call shell command end");
-#endif
+//        set_codec(LYNQ_CALL, CODEC_OPEN); //hqing add for Geely demand on 11/07/2022, init cs call, open codec
         if (get_audio_path() == 0) {
             mixer_set(1);
             speechStatus = NORMAL_SPEECH_ON;
@@ -1564,6 +1554,7 @@
             speechStatus = BT_SPEECH_ON;
         }
         inCallstatus = CALL_ON;
+        unlock_rtp_audio_mtx();
         RLOGD("[speech]: set on");
         sendCallMsg(true); //for Power Manager test
     } else if (callIndex == 0
@@ -1571,8 +1562,8 @@
                    || speechStatus == BT_SPEECH_ON)) { //speech off
         StopRecord();
         sendCallMsg(false); // for Power Manager test.
-        dtmf_stop(dtmf_handle);
-        dtmf_handle = NULL;
+//      dtmf_stop(dtmf_handle);
+//      dtmf_handle = NULL;
         if (speechStatus == NORMAL_SPEECH_ON) {
             mixer_set(0);
         } else {
@@ -1584,17 +1575,15 @@
         speechStatus = SPEECH_OFF;
         inCallstatus = CALL_OFF;
         resetMute();
-#ifdef GSW_RIL_CFG
-        set_codec(0); //hqing add for Geely demand on 11/07/2022, after cs call, close codec for power Manager
-#endif
+        unlock_rtp_audio_mtx();
+//      set_codec(LYNQ_CALL, CODEC_CLOSE); //hqing add for Geely demand on 11/07/2022, after cs call, close codec for power Manager
         RLOGD("[speech]: set off");
     } else {
+        unlock_rtp_audio_mtx();
         RLOGD("callIndex is %d, speechStatus is %d.",callIndex, speechStatus);
     }
 
     return;
-#endif //LYNQ_CC_SUPPORT
-return;//LYNQ_CC_SUPPORT
 }
 
 //RIL_REQUEST_SET_MUTE
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h
index 168d776..8e74197 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h
@@ -240,6 +240,11 @@
     {"RIL_REQUEST_DEMO_LOCAL_SET_GOST_DEFAULT",gostTransmitDefaultSet,"Set gost ecall default",-1},
     #endif /*ECALL_SUPPORT*/
 
+	//rtp
+    {"LYNQ_REQUEST_SET_VOICE_AUDIO_MODE",set_voice_audio_mode,"set voice audio mode",LYNQ_REQUEST_SET_VOICE_AUDIO_MODE},
+
+    {"LYNQ_REQUEST_GET_VOICE_AUDIO_MODE",get_voice_audio_mode,"get voice audio mode",LYNQ_REQUEST_GET_VOICE_AUDIO_MODE},
+ 
 #ifdef MODE_DSDS
     {"SET_DEFAULT_SIM_ALL",set_default_sim_all, "set default sim_all", -1},
     {"GET_DEFAULT_SIM_ALL",get_default_sim_all, "get default sim_all", -1},
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.cpp b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.cpp
index dd0b7ff..5951ee3 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.cpp
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.cpp
@@ -70,7 +70,6 @@
 static ECALL_TYPE ecall_type = ECALL_TYPE::EN16454_ECALL;
 static bool inNeedRegister = false;
 static bool gostFastEcallFlg = false;
-static bool is_ecall_audio_path = false;
 
 int gost_sms_argc = 0;
 std::vector<std::string> gost_sms_argv;
@@ -158,11 +157,6 @@
 static int g_ecall_test=0;
 static int g_reset_timer =6;
 
-bool isEcallAudioPath() {
-    RLOGD("%s , is_ecall_audio_path: %d", __FUNCTION__, is_ecall_audio_path);
-    return is_ecall_audio_path;
-}
-
 bool isEcallAutoanswerTimerFinish() {
     struct itimerspec timespec;
     if(timer_gettime(sAutoAnsTimer, &timespec) == -1) {
@@ -185,21 +179,7 @@
     }
     return false;
 }
-
-void setEcallAudioPathOn(bool on) {
-    RLOGD("%s() , is_ecall_audio_path: %d, on: %d", __FUNCTION__, is_ecall_audio_path, on);
-
-    if((is_ecall_audio_path != on) && (isEcallAutoanswerTimerFinish())) {
-        is_ecall_audio_path = on;
-    }
-    RLOGD("%s() , is_ecall_audio_path: %d", __FUNCTION__, is_ecall_audio_path);
-}
-
 void autoAnswerEcall(bool on) {
-    RLOGD("%s() , is_ecall_audio_path: %d, on: %d", __FUNCTION__, is_ecall_audio_path, on);
-    if(is_ecall_audio_path != on) {
-        is_ecall_audio_path = on;
-    }
     if(on) {
         char* argv[2] = {"", "1"};
         autoAnswerCall(2, argv, RIL_SOCKET_ID(0), NULL); //unused socket id;
@@ -424,8 +404,7 @@
     }
     else if(sig.sival_int == redial_sig_value) {
         redial_tag = REDIAL_EXPIRES;
-        RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_RESET_IVS, UDP,RIL_SOCKET_ID(fast_ecall_socket_id));
-        resetIVS(0, NULL, RIL_SOCKET_ID(fast_ecall_socket_id), pRI);
+        resetEcallIVSandAudio(UDP, RIL_SOCKET_ID(fast_ecall_socket_id));      
         fast_argc = 0;
         fast_argv.clear();
      
@@ -632,7 +611,7 @@
         stop_ecall_timer(sRedialTimer, redial_sig_value);
 		
         redial_tag = REDIAL_SUCCESS;
-        resetEcallIVSandAudio(RSPD, soc_id);
+        resetEcallIVSandAudio(RSPD, RIL_SOCKET_ID(fast_ecall_socket_id));
         saveEcallRecord(p_cur->ind);
 
         act_fecall_socid = soc_id;
@@ -724,8 +703,7 @@
             stop_ecall_timer(sT6,sT6_sig_value);
             stop_ecall_timer(sT7,sT7_sig_value);
             ecall_test_sub_recover();
-            RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_RESET_IVS, UDP, soc_id);
-            resetIVS(0, NULL, soc_id, pRI);
+            resetEcallIVSandAudio(UDP, soc_id);                 
             redialFastEcall(soc_id);
         }
         else {   /* redial_tag == REDIAL_SUCCESS || redial_tag == REDIAL_EXPIRES */
@@ -1012,7 +990,7 @@
 //RIL_REQUEST_ECALL_RESET_IVS
 int resetIVS(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
   android::Parcel p;
-
+/*
   if (getSpeechStatus() == SPEECH_OFF) {
     if (get_audio_path() == 0) {
       setSpeechAndStatus(1);
@@ -1020,7 +998,7 @@
       setSpeechAndStatus(2);
     }
   }
-
+*/
   //paramter none
   pRI->pCI->dispatchFunction(p, pRI);
   return 0;
@@ -1096,7 +1074,7 @@
   p.writeInt32(1);
   p.writeInt32(type);
   p.setDataPosition(pos);
-  setEcallAudioPathOn(true);
+//  setEcallAudioPathOn(true);
   pRI->pCI->dispatchFunction(p, pRI);
   return 0;
 }
@@ -1169,7 +1147,7 @@
 
     p.setDataPosition(pos);
     normal_ecall_tag = true;
-    setEcallAudioPathOn(true);
+//  setEcallAudioPathOn(true);
     act_fecall_socid = -1;
     act_feCall_Id = -1;
     pRI->pCI->dispatchFunction(p, pRI);
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.h
index 7c5e668..8439cc4 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ecall/eCall.h
@@ -95,8 +95,6 @@
 int gostEcallResendMsd(bool flg);
 void gostSetInNeedRegister(bool flags);
 void gostFastEcallFlgSet(bool flags);
-bool isEcallAudioPath();
-void setEcallAudioPathOn(bool on);
 void init_redial_flag();
 #endif /*ECALL_SUPPORT*/
 #endif
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h
index 95a50ce..db8e782 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h
@@ -24,6 +24,9 @@
 #define LYNQ_REQUEST_CHANGE_SCREEN_STATE (LYNQ_REQUEST_VENDOR_BASE + 14)/*jb.qi add for two sim suspend 2022/9/19*/
 #define LYNQ_REQUEST_CHANGE_RADIO (LYNQ_REQUEST_VENDOR_BASE + 15)
 #define LYNQ_REQUEST_CHANGE_SLEEP_STATE (LYNQ_REQUEST_VENDOR_BASE + 16)/*jb.qi change for suspend 2024/2/23 start*/
+#define LYNQ_REQUEST_SET_VOICE_AUDIO_MODE (LYNQ_REQUEST_VENDOR_BASE + 28)
+#define LYNQ_REQUEST_GET_VOICE_AUDIO_MODE (LYNQ_REQUEST_VENDOR_BASE + 21)
+
 
 #ifdef ECALL_SUPPORT
 #define RIL_UNSOL_ECALL_T2_TIMER_OUT  9000
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/makefile b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/makefile
index 70aac91..848b70a 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/makefile
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/makefile
@@ -105,6 +105,7 @@
   -I$(LOCAL_PATH)/factory \
   -I$(LOCAL_PATH)/temp \
   -I$(LOCAL_PATH)/led/include \
+  -I$(LOCAL_PATH)/rtp \
   -I$(ROOT)$(includedir)/logger \
   -I$(ROOT)$(includedir)/liblog \
   -I$(ROOT)$(includedir)/liblynq-thermal \
@@ -157,7 +158,7 @@
 endif
 
 
-SOURCES = $(wildcard util/*.cpp *.cpp ecall/*.cpp ecall/gost/*.cpp ecall/gost/utils/*.cpp ecall/gost/sslp/*.cpp ecall/gost/sslp/auth/*.cpp ecall/gost/sslp/firmware/*.cpp ecall/gost/sslp/commands/*.cpp ecall/gost/sslp/ecall/*.cpp ecall/gost/sslp/teledata/*.cpp data/*.cpp sms/*.cpp sms/gsm/*.cpp sms/cdma/*.cpp atci/*.cpp stateManager/*.cpp sms/lynqSmsManager/*.cpp led/*.cpp)
+SOURCES = $(wildcard util/*.cpp *.cpp ecall/*.cpp ecall/gost/*.cpp ecall/gost/utils/*.cpp ecall/gost/sslp/*.cpp ecall/gost/sslp/auth/*.cpp ecall/gost/sslp/firmware/*.cpp ecall/gost/sslp/commands/*.cpp ecall/gost/sslp/ecall/*.cpp ecall/gost/sslp/teledata/*.cpp data/*.cpp sms/*.cpp sms/gsm/*.cpp sms/cdma/*.cpp atci/*.cpp stateManager/*.cpp sms/lynqSmsManager/*.cpp led/*.cpp rtp/*.cpp)
 
 EXECUTABLE = lynq-ril-service
 
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp
index 71bce71..19b2854 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp
@@ -99,6 +99,7 @@
 #include <include/lynq_uci.h>
 #endif
 #include "lynq_shm.h"
+#include "call_rtp.h"
 
 #define LOG_TAG "DEMO_RIL"
 #define WAIT_TIME_FOR_SIM_SWITCH 30
@@ -5331,6 +5332,8 @@
         case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
         case LYNQ_REQUEST_CHANGE_SCREEN_STATE:return "LYNQ_REQUEST_CHANGE_SCREEN_STATE";/*jb.qi add for two sim sleep 2022/9/19*/
         case LYNQ_REQUEST_CHANGE_RADIO:return "LYNQ_REQUEST_CHANGE_RADIO";/*lei add for factory test of sleep 2022/9/19*/
+        case LYNQ_REQUEST_SET_VOICE_AUDIO_MODE:return "LYNQ_REQUEST_SET_VOICE_AUDIO_MODE";
+        case LYNQ_REQUEST_GET_VOICE_AUDIO_MODE:return "LYNQ_REQUEST_GET_VOICE_AUDIO_MODE";
         case RIL_REQUEST_GET_MSISDN:return "RIL_REQUEST_GET_MSISDN";
         case RIL_REQUEST_RESET_SIMCARD:return "RIL_REQUEST_RESET_SIMCARD";
         case LYNQ_REQUEST_CHANGE_SLEEP_STATE: return "LYNQ_REQUEST_CHANGE_SLEEP_STATE";/*jb.qi change for suspend 2024/2/23 */
@@ -5800,6 +5803,8 @@
     mbtk_netled_init();
 #endif
     mixer_init();
+    lynq_init_rtp();
+
     if(utils::is_support_dsds()) {
         for(int i = 0; i < 2 ; i++) {
             init(i);
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp.cpp b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp.cpp
new file mode 100755
index 0000000..981292e
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp.cpp
@@ -0,0 +1,794 @@
+

+#include <stdio.h>

+#include <sys/types.h>

+#include <sys/socket.h>

+#include <arpa/inet.h>

+#include <fcntl.h>

+#include <string.h>

+#include <stdlib.h>

+#include <unistd.h>

+#include <binder/Parcel.h>

+#include <log/log.h>

+#include <cutils/jstring.h>

+#include <pthread.h>

+#include "liblog/lynq_deflog.h"

+#include <sys/time.h>

+#include <string.h>

+//#include "lynq_call.h"

+//#include "lynq_module_common.h"

+//#include "lynq_call_common.h"

+#include "common.h"

+#include "call_rtp.h"

+#include "call_rtp_inner.h"

+#include "lynq_interface.h"

+#include "ecall/eCall.h"

+#include "cc.h"

+#include "lynq_at.h"

+

+#undef LOG_TAG

+#define LOG_TAG "ECALL_RTP"

+

+#if 0

+static lynq_rtp_client_info g_rtp_client_info;

+static lynq_rtp_server_info g_rtp_server_info;

+

+static pthread_t g_rtp_thread[RTP_MODE_MAX];

+static bool g_rtp_thread_valid[RTP_MODE_MAX]={0};

+#endif

+

+static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;

+

+static LYNQ_Audio_Mode s_current_audio_mode=AUDIO_MODE_CODEC;

+

+int lock_rtp_audio_mtx()

+{

+    return pthread_mutex_lock(&mtx);

+}

+

+int unlock_rtp_audio_mtx()

+{

+    return pthread_mutex_unlock(&mtx);

+}

+

+

+int set_voice_audio_mode(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{    

+    android::Parcel p;
+    int setValue = 0;
+

+    if(argc < 2) {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_VOICE_AUDIO_MODE,0,2);

+        android::LYNQ_RIL_respSocket_sp(p,pRI);
+        free(pRI);
+        RLOGW("%s fail! argc is %d",__FUNCTION__,argc);

+        return -1;
+    }
+
+    setValue = atoi(argv[1]);

+    RLOGD("%s %d start",__FUNCTION__,setValue);

+    if(setValue < AUDIO_MODE_CODEC || setValue > AUDIO_MODE_ALL_CLOSE ) {

+        RLOGW("Warning: parameter %d is over-range!",setValue);

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_VOICE_AUDIO_MODE,0,3);

+        android::LYNQ_RIL_respSocket_sp(p,pRI);

+        free(pRI);

+        return -1;

+    }

+

+    int s = lock_rtp_audio_mtx();

+    if(s != 0) {
+        RLOGE("%s lock_rtp_audio_mtx fail",__FUNCTION__);

+    }

+

+    LYNQ_Audio_Mode old_audio_mode;

+    old_audio_mode=s_current_audio_mode;

+    s_current_audio_mode=(LYNQ_Audio_Mode) setValue; 

+#if 0

+    if((get_call_status() == CALL_ON) && getSpeechStatus() == NORMAL_SPEECH_ON)        

+    {

+	

+        if(s_current_audio_mode!=old_audio_mode)

+        {

+            RLOGD("%s, change mode in real time",__FUNCTION__);

+            if(exe_set_voice_audio_mode(s_current_audio_mode)

+            {

+                s_current_audio_mode=old_audio_mode;                

+                s = unlock_rtp_audio_mtx();

+                if(s != 0) {

+                    RLOGE("%s, unlock_rtp_audio_mtx fail",__FUNCTION__);

+                }

+                

+                android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_VOICE_AUDIO_MODE,0,5);

+                android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+                free(pRI);

+                return RESULT_ERROR; 

+            }

+        }        

+    }    

+#endif

+    s = unlock_rtp_audio_mtx();

+    if(s != 0) {

+        RLOGE("%s, unlock_rtp_audio_mtx fail",__FUNCTION__);

+    }

+

+    android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_VOICE_AUDIO_MODE,0,0);

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+    free(pRI);

+    RLOGD("%s %d finish",__FUNCTION__,setValue);

+    return RESULT_OK; 

+}

+

+#if 0

+int set_remote_rtp_ip(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    RLOGD("%s start!",__FUNCTION__);

+    android::Parcel p;

+

+    if(argc < 2) {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_REMOTE_RTP_IP,0,2);

+        android::LYNQ_RIL_respSocket_sp(p,pRI);
+        free(pRI);
+        RLOGW("Warning: no %s!",__FUNCTION__);

+        return -1;
+    } 

+

+    if(exe_set_remote_rtp_ip(argv[1],strlen(argv[1])+1)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_REMOTE_RTP_IP,0,0);

+        RLOGD(">>>>%s<<<< success value is %s!\n", __FUNCTION__, argv[1]);

+    }

+    else

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_REMOTE_RTP_IP,0,4);

+        RLOGD(">>>>%s <<<< failure value is %s!\n",__FUNCTION__, argv[1]);

+    }       

+

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+    free(pRI);
+    return RESULT_OK; 

+}

+int set_vlan_info(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    RLOGD("%s start!",__FUNCTION__);

+    android::Parcel p;

+    const char* vlan_info="";   

+        

+    if(argc >1) 

+    {

+        vlan_info=argv[1];      

+    } 

+

+    if(exe_set_vlan_info(vlan_info,strlen(vlan_info)+1)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_VLAN_INFO,0,0);

+        RLOGD(">>>>%s<<<< success value is %s!\n", __FUNCTION__, vlan_info);

+    }

+    else

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_VLAN_INFO,0,4);

+        RLOGE(">>>>%s <<<< failure value is %s!\n",__FUNCTION__, vlan_info);

+    }       

+

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+    free(pRI);
+    return RESULT_OK; 

+}

+

+int set_rtp_port(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    RLOGD("%s start!",__FUNCTION__);

+    android::Parcel p;

+

+    if(argc < 3) 

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PORT,0,2);

+        android::LYNQ_RIL_respSocket_sp(p,pRI);
+        free(pRI);
+        RLOGW("Warning: no %s!",__FUNCTION__);

+        return -1;
+    } 

+

+    if(exe_set_rtp_port((LYNQ_Rtp_Mode)(atoi(argv[1])),atoi(argv[2]))==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PORT,0,0);

+        RLOGD(">>>>%s<<<< success value is %s %s!\n", __FUNCTION__, argv[1],argv[2]);

+    }

+    else

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PORT,0,4);

+        RLOGE(">>>>%s <<<< failure value is %s %s!\n",__FUNCTION__, argv[1],argv[2]);

+    }

+

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+    free(pRI);

+ 

+    return RESULT_OK; 

+}

+    

+

+int set_rtp_param(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    RLOGD("%s start!",__FUNCTION__);

+    android::Parcel p;

+

+    if(argc < 4) {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PARAM,0,2);

+        android::LYNQ_RIL_respSocket_sp(p,pRI);
+        free(pRI);
+        RLOGW("Warning: no %s!",__FUNCTION__);

+        return -1;
+    } 

+

+    if(exe_set_rtp_param(atoi(argv[1]),atoi(argv[2]),atoi(argv[3]))==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PARAM,0,0);

+        RLOGD(">>>>%s<<<< success value is %s %s %s!\n", __FUNCTION__, argv[1],argv[2],argv[3]);

+    }

+    else

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PARAM,0,4);   

+        RLOGE(">>>>%s <<<< failure value is %s %s %s!\n",__FUNCTION__, argv[1],argv[2],argv[3]);

+    } 

+    

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+    free(pRI);

+

+    return RESULT_OK; 

+}

+

+int set_call_rtp_ssrc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    RLOGD("%s start!",__FUNCTION__);

+    android::Parcel p;

+

+    if(argc < 3) {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_CALL_RTP_SSRC,0,2);

+        android::LYNQ_RIL_respSocket_sp(p,pRI);
+        free(pRI);
+        RLOGW("Warning: no %s!",__FUNCTION__);

+        return -1;
+    } 

+

+    if(exe_set_call_rtp_ssrc(atoi(argv[1]),strtoul(argv[2],0,0))==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_CALL_RTP_SSRC,0,0);

+        RLOGD(">>>>%s<<<< success value is %s %s!\n", __FUNCTION__, argv[1],argv[2]);

+    }

+    else

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_CALL_RTP_SSRC,0,4);

+        RLOGE(">>>>%s <<<< failure value is %s %s!\n",__FUNCTION__, argv[1],argv[2]);

+    } 

+    

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);  

+    free(pRI);

+

+    return RESULT_OK; 

+}

+#endif

+

+int get_voice_audio_mode(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    android::Parcel p;

+    int mode = exe_get_voice_audio_mode();

+ 

+    android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_VOICE_AUDIO_MODE,0,0);

+

+    #ifdef MOBILETEK_TARGET_PLATFORM_T106        

+    p.writeInt32(1);

+    #endif

+

+    p.writeInt32(mode);

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);
+    free(pRI);

+    return RESULT_OK;

+}

+

+#if 0

+int get_remote_rtp_ip(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    char rtp_ip[MAX_IP_LENGTH]={0};

+

+    android::Parcel p;

+    if(exe_get_remote_rtp_ip(rtp_ip,MAX_IP_LENGTH)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_REMOTE_RTP_IP,0,0);

+        p.writeInt32(1);

+        android::writeStringToParcel(p,rtp_ip);        

+    }

+    else 

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_REMOTE_RTP_IP,0,2);

+    } 

+   

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);
+    free(pRI);

+    return RESULT_OK;

+}

+

+int get_vlan_info(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    char vlan_info[MAX_VLAN_INFO_LENGTH]={0};

+

+    android::Parcel p;

+    if(exe_get_vlan_info(vlan_info,MAX_VLAN_INFO_LENGTH)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_VLAN_INFO,0,0);

+        p.writeInt32(1);

+        android::writeStringToParcel(p,vlan_info);        

+    }

+    else 

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_VLAN_INFO,0,2);

+    } 

+   

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);
+    free(pRI);

+    return RESULT_OK;

+}

+

+int get_rtp_port(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    int rtp_port;

+    android::Parcel p;

+

+    

+    if(argc < 2) {

+           android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_RTP_PORT,0,2);

+           android::LYNQ_RIL_respSocket_sp(p,pRI);

+           free(pRI);

+           RLOGW("Warning: no %s!",__FUNCTION__);

+           return RESULT_ERROR;

+    } 

+    if(exe_get_rtp_port((LYNQ_Rtp_Mode) (atoi(argv[1])),&rtp_port)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_VLAN_INFO,0,0);

+        p.writeInt32(rtp_port);        

+    }

+    else 

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_VLAN_INFO,0,3);

+    } 

+   

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);
+    free(pRI);

+    return RESULT_OK;

+}

+

+int get_rtp_param(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    int clock_rate, channels, latency;

+    android::Parcel p;

+    

+    if(exe_get_rtp_param(&clock_rate, &channels, &latency)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_RTP_PARAM,0,0);

+        p.writeInt32(clock_rate);    

+        p.writeInt32(channels);    

+        p.writeInt32(latency);    

+    }

+    else 

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_RTP_PARAM,0,2);

+    } 

+   

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);
+    free(pRI);

+    return RESULT_OK;

+}

+

+int get_call_rtp_ssrc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)

+{

+    android::Parcel p;

+

+    int ssrc_mode;

+    unsigned int ssrc;

+    

+    if(exe_get_call_rtp_ssrc(&ssrc_mode, &ssrc)==RESULT_OK)

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_CALL_RTP_SSRC,0,0);

+        p.writeInt32(ssrc_mode);    

+        p.writeUint32(ssrc);            

+    }

+    else 

+    {

+        android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_CALL_RTP_SSRC,0,2);

+    } 

+   

+    android::LYNQ_RIL_respSocket(p,(void *)pRI);
+    free(pRI);

+    return RESULT_OK;

+}

+#endif

+

+void lynq_init_rtp()

+{       

+    exe_set_voice_audio_mode(AUDIO_MODE_INIT);

+    

+    RLOGD("lynq init rtp success!!!");

+    return;

+}

+

+/*Audio Path setting begin*/

+/*sub function*/

+#if 0

+void exe_set_rtp_mixer_ctrl(int audio_mode)

+{

+    char cmd[256];

+    RLOGD("set_rtp_mixer_ctrl, audio mode is %d", audio_mode);

+    if(audio_mode==AUDIO_MODE_RTP)

+    {

+        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on_ecall\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 1);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 1);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 1);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 1);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 1);

+        system(cmd);    

+    }

+    else if(audio_mode==AUDIO_MODE_CODEC)

+    {        

+        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 0);

+        system(cmd);    

+        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on_ecall\" %d", 1);

+        system(cmd);

+    }    

+    else 

+    {

+        if(audio_mode==AUDIO_MODE_INIT)

+        {

+            sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 0);

+            system(cmd);

+        }

+        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on_ecall\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 0);

+        system(cmd);

+        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 0);

+        system(cmd);    

+    }

+}

+

+static int record_count=0;

+void* exe_start_rtp_cmd(void *arg)

+{

+    int* rtp_mode= (int*) arg;

+    char cmd[384];

+    char vlan_para_string[sizeof(RTP_VLAN_INFO_FORMAT)+MAX_VLAN_INFO_LENGTH-2/*sizeof "%s"*/]={0};

+    char ssrc_para_string[sizeof(RTP_SSRC_INFO_FORMAT)+MAX_SSRC_INFO_LENGTH-2/*sizeof "%u"*/]={0};

+    RLOGD("exe_start_rtp_cmd: rtp_mode is %d",(*rtp_mode));    

+    if ((*rtp_mode) == RTP_CLIENT)

+    {

+         if(g_ril_test==RIL_STUB_TEST_SWTICH_RTP_RECORD)

+         {

+             system("sleep 30");

+         }

+         else             

+         {

+              sprintf(cmd,RTP_FROM_CMD, \

+                    g_rtp_client_info.port,g_rtp_client_info.clockrate,g_rtp_client_info.channels, \

+                    g_rtp_client_info.latency);            

+              RLOGD("start from rtp play: cmd is %s",cmd);    

+              system(cmd);

+           }

+    }

+    else if ((*rtp_mode) == RTP_SERVER)

+    {

+        if(g_ril_test==RIL_STUB_TEST_SWTICH_RTP_RECORD)

+        {

+            const char* record_fmt="arecord -D hw:0,6 -c 2 -d 10 -r 32000 -f S16_LE --period-size=1280    --buffer-size=5120 /tmp/record_%d.wav";

+            sprintf(cmd,record_fmt,record_count);     

+            RLOGD("start to rtp play: cmd is %s",cmd);

+            record_count++;

+            system(cmd);        

+        }

+        else

+        {        

+            if(strlen(g_rtp_server_info.vlan_info)>0)

+            {

+               sprintf(vlan_para_string,RTP_VLAN_INFO_FORMAT,g_rtp_server_info.vlan_info);

+            }

+    

+            if(g_rtp_server_info.ssrc_mode == Rtp_Ssrc_specific)

+            {

+               sprintf(ssrc_para_string,RTP_SSRC_INFO_FORMAT,g_rtp_server_info.ssrc);

+            }

+            sprintf(cmd,RTP_TO_CMD,   \

+            g_rtp_client_info.channels, g_rtp_client_info.clockrate, ssrc_para_string, g_rtp_server_info.ip,vlan_para_string,g_rtp_server_info.port);       

+            

+            RLOGD("start to rtp play: cmd is %s",cmd);

+            system(cmd);    

+        }

+        

+    }

+    return NULL;

+}

+

+int exe_start_rtp_thread(int rtp_mode)

+{

+    int ret;

+    pthread_attr_t attr;

+    static int start_mode[RTP_MODE_MAX]={0,1};  

+

+    pthread_attr_init(&attr);

+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

+    ret = pthread_create(&(g_rtp_thread[rtp_mode]),&attr,exe_start_rtp_cmd,&(start_mode[rtp_mode]));

+    if(ret != 0)

+    {

+        g_rtp_thread_valid[rtp_mode]=0;

+        RLOGE("rtp create %d pthread error, ret is %d",rtp_mode, ret);

+        return ret;

+    }

+    g_rtp_thread_valid[rtp_mode]=1;

+    return RESULT_OK;  

+}

+#endif 

+

+/*set*/

+int exe_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)

+{

+    int ret;

+    int i;

+

+    char* cmd1="AT+VOICE_BUFFER=1,1";

+    char* cmd2="AT+VOICE_PROCESS=0";

+    char* cmd3="AT+VOICE_BUFFER=0,0";

+    char* cmd4="AT+VOICE_PROCESS=1";

+    char* argv[2]={0};

+

+    char cmd[256];

+    

+

+    RLOGD("%s %d",__FUNCTION__,audio_mode);

+    if(audio_mode==AUDIO_MODE_RTP)

+    {  

+	    sprintf(cmd, "%s", "killall lynq_vb_demo");

+        system(cmd);

+        argv[1] = cmd1;

+        lynqSendAt(2,argv,1011);       

+   	    argv[1] = cmd4;

+        lynqSendAt(2,argv,1012);     

+        sprintf(cmd, "echo voice_buffer_rtp_test_start %d | lynq_vb_demo &", 16000);

+        system(cmd);

+    }

+#ifdef MOBILETEK_TARGET_PLATFORM_T106 

+    else if(audio_mode==AUDIO_MODE_FILE)

+    {  

+  	    sprintf(cmd, "%s", "killall lynq_vb_demo");

+        system(cmd);

+        argv[1] = cmd1;

+        lynqSendAt(2,argv,1011);

+        argv[1] = cmd4;

+        lynqSendAt(2,argv,1012);

+        sprintf(cmd, "echo voice_buffer_test_start %d | lynq_vb_demo &", 16000);

+        system(cmd);

+    }

+    else if(audio_mode==AUDIO_MODE_LOOP_BACK)

+    {  

+	    sprintf(cmd, "%s", "killall lynq_vb_demo");

+        system(cmd);

+        argv[1] = cmd1;

+        lynqSendAt(2,argv,1011);

+        argv[1] = cmd2;

+        lynqSendAt(2,argv,1012);

+        sprintf(cmd, "echo voice_buffer_loop_test_start %d | lynq_vb_demo &", 16000);

+        system(cmd);

+    }

+#endif

+#if 0	

+    else if(audio_mode==AUDIO_MODE_CODEC)

+    {

+        

+        for(i=0;i<RTP_MODE_MAX;i++)

+        {

+            if(g_rtp_thread_valid[i]) 

+            {

+                 ret = pthread_cancel(g_rtp_thread[i]);

+                 RLOGD("pthread cancel rtp %d ret = %d",i,ret);

+                 ret = pthread_join(g_rtp_thread[i],NULL);

+                 RLOGD("pthread join rtp %d ret = %d",i,ret);

+                 g_rtp_thread_valid[i] = 0;

+            }

+            else 

+            {

+                RLOGD("rtp thread %d needn't stop",i);

+            }

+        }          

+        exe_set_rtp_mixer_ctrl(audio_mode);        

+

+    }

+#endif 

+    else // audio_mode==AUDIO_MODE_ALL_CLOSE /AUDIO_MODE_INIT/AUDIO_MODE_CODEC

+    {   

+        sprintf(cmd, "%s", "killall lynq_vb_demo");

+        system(cmd);

+        argv[1] = cmd4;

+        lynqSendAt(2,argv,1013);

+        argv[1] = cmd3;

+        lynqSendAt(2,argv,1014);

+        

+/*

+        for(i=0;i<RTP_MODE_MAX;i++)

+        {

+            if(g_rtp_thread_valid[i]) 

+            {

+                 ret = pthread_cancel(g_rtp_thread[i]);

+                 RLOGD("pthread cancel rtp %d ret = %d",i,ret);

+                 ret = pthread_join(g_rtp_thread[i],NULL);

+                 RLOGD("pthread join rtp %d ret = %d",i,ret);

+                 g_rtp_thread_valid[i] = 0;

+            }

+            else 

+            {

+                RLOGD("rtp thread %d needn't stop",i);

+            }

+        }    

+        exe_set_rtp_mixer_ctrl(audio_mode);          

+*/ 

+    }

+    RLOGD("%s %d suc",__FUNCTION__,audio_mode);

+    return RESULT_OK;    

+

+}

+

+#if 0

+int exe_set_remote_rtp_ip(const char* ip, const int ip_length)

+{

+    if (NULL == ip)

+    {

+        RLOGE("ip is NULL!!!");

+        return LYNQ_E_PARAMETER_ANONALY;

+    }

+    if ((ip_length < strlen(ip)+1) || (ip_length > MAX_IP_LENGTH))

+    {

+        RLOGE("incoming ip length error %d", ip_length);

+        return LYNQ_E_PARAMETER_ANONALY;

+    }    

+

+    bzero(g_rtp_server_info.ip,MAX_IP_LENGTH);

+    strcpy(g_rtp_server_info.ip,ip);

+    

+    RLOGD("exe_set_remote_rtp_ip suc: ip is %s, length is %d", ip,ip_length);

+    

+    return RESULT_OK;  

+}

+int exe_set_vlan_info(const char* vlan_info, const int vlan_info_length)

+{

+    if (NULL == vlan_info)

+    {

+        RLOGE("vlan_info is NULL!!!");

+        return LYNQ_E_PARAMETER_ANONALY;

+    }

+    

+    if ((vlan_info_length < strlen(vlan_info)+1) || (vlan_info_length > MAX_VLAN_INFO_LENGTH))

+    {

+        RLOGE("incoming vlan_info error, vlan info length %d", vlan_info_length);

+        return LYNQ_E_PARAMETER_ANONALY;

+    }    

+

+    

+    bzero(g_rtp_server_info.vlan_info,MAX_VLAN_INFO_LENGTH);

+    strcpy(g_rtp_server_info.vlan_info,vlan_info);

+   

+    RLOGD("exe_set_vlan_info suc: vlan is %s, length is %d", vlan_info,vlan_info_length);

+    

+    return RESULT_OK;  

+}

+int exe_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port)

+{  

+    if (port < 0)

+    {

+        RLOGE("invalid port number %d", port);

+        return LYNQ_E_PARAMETER_ANONALY;

+    }

+    if (rtp_mode == 0)

+    {

+        g_rtp_client_info.port = port;

+    }

+    else if (rtp_mode == 1)

+    {

+        g_rtp_server_info.port = port;

+    }

+    RLOGD("exe_set_rtp_port suc: LYNQ_Rtp_Mode is %d, port is %d", rtp_mode, port);

+    return RESULT_OK;  

+}

+int exe_set_rtp_param(const int clock_rate,const int channels,const int latency) 

+{

+    g_rtp_client_info.clockrate = clock_rate;

+    g_rtp_client_info.channels = channels;

+    g_rtp_client_info.latency = latency;

+    RLOGD("exe_set_rtp_param suc: clockrate is %d, channels is %d, latency is %d", clock_rate, channels, latency);

+    return RESULT_OK;  

+}

+int exe_set_call_rtp_ssrc(const int ssrc_mode,const unsigned int ssrc)

+{

+    if(ssrc_mode < Rtp_Ssrc_random || ssrc_mode > Rtp_Ssrc_specific)

+    {

+        return LYNQ_E_PARAMETER_ANONALY;

+    }

+    g_rtp_server_info.ssrc_mode = ssrc_mode;

+    g_rtp_server_info.ssrc = ssrc ;

+    RLOGD("%s suc: param is %d %u", __func__, ssrc_mode, ssrc);

+    return RESULT_OK;

+}

+#endif

+

+/*get*/

+LYNQ_Audio_Mode exe_get_voice_audio_mode()

+{

+    return s_current_audio_mode;

+}

+

+#if 0

+int exe_get_remote_rtp_ip(char* ip, const int ip_length)

+{

+    if(ip_length < strlen(g_rtp_server_info.ip)+1)

+    {

+        RLOGE("ip length %d is shorter than saved ip length %d",ip_length,strlen(g_rtp_server_info.ip)+1);

+        return LYNQ_E_PARAMETER_ANONALY;

+    }

+    

+    bzero(ip,ip_length);

+    strcpy(ip,g_rtp_server_info.ip);

+    

+    return RESULT_OK;  

+}

+int exe_get_vlan_info(char* vlan_info, const int vlan_info_length)

+{

+    if(vlan_info_length < strlen(g_rtp_server_info.vlan_info)+1)

+    {

+        RLOGE("vlan info length %d is shorter than saved vlan info length %d",vlan_info_length,strlen(g_rtp_server_info.vlan_info)+1);

+        return LYNQ_E_PARAMETER_ANONALY;

+    }

+   

+    bzero(vlan_info,vlan_info_length);

+    strcpy(vlan_info,g_rtp_server_info.vlan_info);        

+   

+    return RESULT_OK;  

+}

+int exe_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)

+{    

+    if (rtp_mode == 0)

+    {

+        *port = g_rtp_client_info.port;

+    }

+    else if (rtp_mode == 1)

+    {

+        *port = g_rtp_server_info.port;

+    }

+    return RESULT_OK;  

+}

+int exe_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode

+{

+    *clock_rate = g_rtp_client_info.clockrate;

+    *channels = g_rtp_client_info.channels ;

+    *latency = g_rtp_client_info.latency;

+

+    return RESULT_OK;  

+}

+int exe_get_call_rtp_ssrc(int* ssrc_mode, unsigned int* ssrc)

+{   

+    *ssrc_mode = g_rtp_server_info.ssrc_mode;

+    *ssrc = g_rtp_server_info.ssrc ;   

+    

+    return RESULT_OK;

+}

+#endif

diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp.h
new file mode 100755
index 0000000..784c765
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp.h
@@ -0,0 +1,36 @@
+#ifndef CALL_RTP_H

+#define CALL_RTP 1

+

+void lynq_init_rtp();

+int set_voice_audio_mode(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int set_remote_rtp_ip(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int set_vlan_info(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int set_rtp_port(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int set_rtp_param(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int set_call_rtp_ssrc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int get_voice_audio_mode(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int get_remote_rtp_ip(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int get_vlan_info(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int get_rtp_port(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int get_rtp_param(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+int get_call_rtp_ssrc(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);

+

+

+typedef enum{

+    AUDIO_MODE_CODEC = 0,     /* Codec */

+    AUDIO_MODE_RTP,      /* RTP */   

+#ifdef MOBILETEK_TARGET_PLATFORM_T106        

+    AUDIO_MODE_FILE,

+    AUDIO_MODE_LOOP_BACK,

+#endif    

+    AUDIO_MODE_INIT,

+    AUDIO_MODE_ALL_CLOSE,

+}LYNQ_Audio_Mode;

+int exe_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode);

+LYNQ_Audio_Mode exe_get_voice_audio_mode();

+

+

+int lock_rtp_audio_mtx();

+int unlock_rtp_audio_mtx();

+

+#endif

diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp_inner.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp_inner.h
new file mode 100755
index 0000000..11b51a3
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/rtp/call_rtp_inner.h
@@ -0,0 +1,68 @@
+#ifndef CALL_RTP_INNER_H

+#define CALL_RTP_INNER_H 1

+

+#ifdef __cplusplus

+extern "C" {

+#endif

+

+#define MAX_IP_LENGTH 128

+#define MAX_VLAN_INFO_LENGTH 32

+#define MAX_SSRC_INFO_LENGTH 10   /*2^32=4294967296, 10 digit*/

+

+typedef enum{

+    RTP_CLIENT = 0,     

+    RTP_SERVER =1,

+    RTP_MODE_MAX

+}LYNQ_Rtp_Mode;

+

+#define RTP_FROM_CMD "gst-launch-1.0 -v udpsrc port=%d caps=\'application/x-rtp, media=(string)audio, clock-rate=(int)%d, channels=(int)%d\' ! rtpjitterbuffer latency=%d ! rtpL16depay ! audioconvert ! alsasink device=\'hw:0,2\'"

+#define RTP_TO_CMD   "gst-launch-1.0 -v alsasrc device=\'hw:0,6\' ! audioconvert ! audio/x-raw,format=S16BE, channels=%d ! audioresample  ! audio/x-raw, rate=%d ! rtpL16pay ! %s udpsink host=%s %s auto-multicast=true port=%d"                        

+#define RTP_VLAN_INFO_FORMAT "multicast-iface=\"%s\""

+#define RTP_SSRC_INFO_FORMAT " rtpmux name=mux ssrc=%u !"

+

+#define USER_LOG_TAG "LYNQ_CALL"

+

+#define RESULT_OK (0)

+#define RESULT_ERROR (-1)

+#define LYNQ_E_PARAMETER_ANONALY 7000

+

+typedef enum{

+    Rtp_Ssrc_random = 0,     

+    Rtp_Ssrc_specific =1,   

+}LYNQ_Rtp_Ssrc_Mode;

+

+typedef struct

+{   

+    char ip[MAX_IP_LENGTH];

+    int port;   

+    int ssrc_mode;

+    unsigned int ssrc;

+    char vlan_info[MAX_VLAN_INFO_LENGTH];

+}lynq_rtp_server_info;

+

+typedef struct

+{       

+    int port;

+    int clockrate;  

+    int latency;

+    int channels;

+}lynq_rtp_client_info;

+

+/*set*/

+int exe_set_remote_rtp_ip(const char* ip, const int ip_length);

+int exe_set_vlan_info(const char* vlan_info, const int vlan_info_length);

+int exe_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port);

+int exe_set_rtp_param(const int clock_rate,const int channels,const int latency); //only for client

+int exe_set_call_rtp_ssrc(const int ssrc_mode, const unsigned int ssrc);

+/*get*/

+int exe_get_remote_rtp_ip(char* ip, const int ip_length);

+int exe_get_vlan_info(char* vlan_info, const int vlan_info_length);

+int exe_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port);

+int exe_get_rtp_param(int* clock_rate,int* channels, int* latency);//only for client

+int exe_get_call_rtp_ssrc(int* ssrc_mod, unsigned int* ssrc);

+/*Audio Path setting end*/

+

+#ifdef __cplusplus

+}

+#endif

+#endif

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h
index 01df12e..fd50c3c 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h
@@ -167,7 +167,7 @@
 int lynq_set_call_rtp_ssrc(const LYNQ_Rtp_Ssrc_Mode ssrc_mode, const unsigned int ssrc);

 

 /*get*/

-LYNQ_Audio_Mode lynq_get_voice_audio_mode();

+int lynq_get_voice_audio_mode(LYNQ_Audio_Mode* voice_audio_mode);

 int lynq_get_remote_rtp_ip(char* ip, const int ip_length);

 int lynq_get_vlan_info(char* vlan_info, const int vlan_info_length);

 int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port);

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp
index 05550f1..3540ac0 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp
@@ -811,7 +811,7 @@
         return LYNQ_E_INNER_ERROR;

     }      

 

-    lynq_init_rtp();

+

 

     g_module_init_flag = MODULE_RUNNING;

     return 0;

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h
index 21077df..e65f243 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h
@@ -19,5 +19,5 @@
 void urc_ecall_msg_process(Parcel *p);

 #endif

 

-void lynq_init_rtp();

+int lynq_get_common_request(int request_id, int* status);

 #endif

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp
index 4d6c1b3..d532c14 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp
@@ -17,375 +17,50 @@
 #include "lynq_call.h"

 #include "lynq_module_common.h"

 #include "lynq_call_common.h"

-

-#define RTP_FROM_CMD "gst-launch-1.0 -v udpsrc port=%d caps=\'application/x-rtp, media=(string)audio, clock-rate=(int)%d, channels=(int)%d\' ! rtpjitterbuffer latency=%d ! rtppcmadepay ! alawdec ! audioresample ! audioconvert ! alsasink device=\'hw:0,2\'"

-#define RTP_TO_CMD   "gst-launch-1.0 -v alsasrc device=\'hw:0,6\' ! audioconvert ! audioresample ! alawenc ! rtppcmapay ! %s udpsink host=%s %s auto-multicast=true port=%d"

-#define RTP_VLAN_INFO_FORMAT "multicast-iface=\"%s\""

-#define RTP_SSRC_INFO_FORMAT " rtpmux name=mux ssrc=%u !"

+#include "lynq_module_socket.h"

 

 #define USER_LOG_TAG "LYNQ_CALL"

 

-typedef struct

-{   

-    char ip[MAX_IP_LENGTH];

-    int port;   

-    int ssrc_mode;

-    unsigned int ssrc;

-    char vlan_info[MAX_VLAN_INFO_LENGTH];

-}lynq_rtp_server_info;

-

-typedef struct

-{       

-    int port;

-    int clockrate;  

-    int latency;

-    int channels;

-}lynq_rtp_client_info;

-

-static lynq_rtp_client_info g_rtp_client_info;

-static lynq_rtp_server_info g_rtp_server_info;

-

-static pthread_t g_rtp_thread[RTP_MODE_MAX];

-static bool g_rtp_thread_valid[RTP_MODE_MAX];

-

-void lynq_init_rtp()

-{   

-    memset(&g_rtp_client_info,0,sizeof(g_rtp_client_info));

-    memset(&g_rtp_server_info,0,sizeof(g_rtp_server_info));    

-  

-

-    lynq_set_rtp_param(8000,1,400);

-

-    for(int i=0;i<RTP_MODE_MAX;i++)

-    {

-        lynq_set_rtp_port(i,6666);

-        g_rtp_thread_valid[i] = 0;

-    }          

-    

-    LYDBGLOG("lynq init rtp success!!!");

-    return;

-}

-

-/*Audio Path setting begin*/

-/*sub function*/

-void lynq_set_rtp_mixer_ctrl(int enable_rtp)

-{

-    char cmd[256];

-    LYINFLOG("set_rtp_mixer_ctrl %d", enable_rtp);

-    if(enable_rtp)

-    {

-        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 0);

-        system(cmd);

-        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 1);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 1);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 1);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 1);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 1);

-        system(cmd);    

-    }

-    else 

-    {        

-        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 0);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 0);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 0);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 0);

-        system(cmd);

-        sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 0);

-        system(cmd);    

-        sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 1);

-        system(cmd);

-    }    

-}

-

-void* lynq_start_rtp_cmd(void *arg)

-{

-    int* rtp_mode= (int*) arg;

-    char cmd[384];

-    char vlan_para_string[sizeof(RTP_VLAN_INFO_FORMAT)+MAX_VLAN_INFO_LENGTH-2/*sizeof "%s"*/]={0};

-    char ssrc_para_string[sizeof(RTP_SSRC_INFO_FORMAT)+MAX_SSRC_INFO_LENGTH-2/*sizeof "%u"*/]={0};

-    LYINFLOG("lynq_start_rtp_cmd: rtp_mode is %d",(*rtp_mode));    

-    if ((*rtp_mode) == RTP_CLIENT)

-    {

-        sprintf(cmd,RTP_FROM_CMD, \

-            g_rtp_client_info.port,g_rtp_client_info.clockrate,g_rtp_client_info.channels, \

-            g_rtp_client_info.latency);            

-    //  LYINFLOG("start from rtp play: cmd is %s",cmd);    

-        system(cmd);

-    }

-    else if ((*rtp_mode) == RTP_SERVER)

-    {

-        if(strlen(g_rtp_server_info.vlan_info)>0)

-        {

-           sprintf(vlan_para_string,RTP_VLAN_INFO_FORMAT,g_rtp_server_info.vlan_info);

-        }

-

-        if(g_rtp_server_info.ssrc_mode == Rtp_Ssrc_specific)

-        {

-           sprintf(ssrc_para_string,RTP_SSRC_INFO_FORMAT,g_rtp_server_info.ssrc);

-        }

-        sprintf(cmd,RTP_TO_CMD,   \

-        ssrc_para_string, g_rtp_server_info.ip,vlan_para_string,g_rtp_server_info.port);       

-        

-        LYINFLOG("start to rtp play: cmd is %s",cmd);

-        system(cmd);    

-    }

-    return NULL;

-}

-

-int lynq_start_rtp_thread(int rtp_mode)

-{

-    int ret;

-    pthread_attr_t attr;

-    static int start_mode[RTP_MODE_MAX]={0,1};  

-

-    pthread_attr_init(&attr);

-    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

-    ret = pthread_create(&(g_rtp_thread[rtp_mode]),&attr,lynq_start_rtp_cmd,&(start_mode[rtp_mode]));

-    if(ret != 0)

-    {

-        g_rtp_thread_valid[rtp_mode]=0;

-        LYERRLOG("rtp create %d pthread error, ret is %d",rtp_mode, ret);

-        return ret;

-    }

-    g_rtp_thread_valid[rtp_mode]=1;

-    return RESULT_OK;  

-}

-

 /*set*/

 int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)

 {

-    int ret;

-    int i;

-    

-    if(audio_mode==AUDIO_MODE_RTP)

+    if(g_module_init_flag != MODULE_RUNNING)

     {

-        lynq_set_rtp_mixer_ctrl(1);

-        for(i=0;i<RTP_MODE_MAX;i++)

-        {

-            if(!g_rtp_thread_valid[i])

-            {

-                if(lynq_start_rtp_thread(i)!= 0)

-                {

-                    LYERRLOG("start rtp %d fail",i);

-                    break;

-                }

-                else 

-                {

-                    LYINFLOG("start rtp %d suc",i);        

-                }

-            }

-            else 

-            {

-                LYERRLOG("rtp %d needn't start",i); 

-            }

-        }

-        if(i!= RTP_MODE_MAX)            

-        {

-            LYERRLOG("start rtp whole fail");

-            lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);

-            return RESULT_ERROR;

-        }

-        LYINFLOG("start rtp whole suc");          

-        return RESULT_OK;  

+        LYERRLOG("%s module state %d error",__func__,g_module_init_flag);

+        return LYNQ_E_CONFLICT;

     }

-    else if(audio_mode==AUDIO_MODE_CODEC)

+    if(audio_mode < AUDIO_MODE_CODEC)

     {

-         for(i=0;i<RTP_MODE_MAX;i++)

-        {

-            if(g_rtp_thread_valid[i]) 

-            {

-                 ret = pthread_cancel(g_rtp_thread[i]);

-                 LYINFLOG("pthread cancel rtp %d ret = %d",i,ret);

-                 ret = pthread_join(g_rtp_thread[i],NULL);

-                 LYINFLOG("pthread join rtp %d ret = %d",i,ret);

-                 g_rtp_thread_valid[i] = 0;

-            }

-            else 

-            {

-                LYINFLOG("rtp %d needn't stop",i);

-            }

-        }

-        lynq_set_rtp_mixer_ctrl(0);     

-        LYINFLOG("stop rtp suc");

-    }

-    return RESULT_OK;    

-}

-int lynq_set_remote_rtp_ip(const char* ip, const int ip_length)

-{

-    if (NULL == ip)

-    {

-        LYERRLOG("ip is NULL!!!");

         return LYNQ_E_PARAMETER_ANONALY;

     }

-    if ((ip_length < strlen(ip)+1) || (ip_length > MAX_IP_LENGTH))

-    {

-        LYERRLOG("incoming ip length error %d", ip_length);

-        return LYNQ_E_PARAMETER_ANONALY;

-    }    

 

-    bzero(g_rtp_server_info.ip,MAX_IP_LENGTH);

-    strcpy(g_rtp_server_info.ip,ip);

-    

-    LYINFLOG("lynq_set_remote_rtp_ip suc: ip is %s, length is %d", ip,ip_length);

-    

-    return RESULT_OK;  

-}

-int lynq_set_vlan_info(const char* vlan_info, const int vlan_info_length)

-{

-    if (NULL == vlan_info)

+    Parcel* p=NULL;

+    int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_VOICE_AUDIO_MODE,1,"%d",audio_mode);

+    if(ret==RESULT_OK)

     {

-        LYERRLOG("vlan_info is NULL!!!");

-        return LYNQ_E_PARAMETER_ANONALY;

+        delete p;        

     }

-    

-    if ((vlan_info_length < strlen(vlan_info)+1) || (vlan_info_length > MAX_VLAN_INFO_LENGTH))

-    {

-        LYERRLOG("incoming vlan_info error, vlan info length %d", vlan_info_length);

-        return LYNQ_E_PARAMETER_ANONALY;

-    }    

-

-    

-    bzero(g_rtp_server_info.vlan_info,MAX_VLAN_INFO_LENGTH);

-    strcpy(g_rtp_server_info.vlan_info,vlan_info);

-   

-    LYINFLOG("lynq_set_vlan_info suc: vlan is %s, length is %d", vlan_info,vlan_info_length);

-    

-    return RESULT_OK;  

-}

-int lynq_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port)

-{  

-    if (port < 0)

-    {

-        LYERRLOG("invalid port number %d", port);

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

-    if (rtp_mode == 0)

-    {

-        g_rtp_client_info.port = port;

-    }

-    else if (rtp_mode == 1)

-    {

-        g_rtp_server_info.port = port;

-    }

-    LYINFLOG("lynq_set_rtp_port suc: LYNQ_Rtp_Mode is %d, port is %d", rtp_mode, port);

-    return RESULT_OK;  

-}

-int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency) //only for client mode

-{

-    g_rtp_client_info.clockrate = clock_rate;

-    g_rtp_client_info.channels = channels;

-    g_rtp_client_info.latency = latency;

-    LYINFLOG("lynq_set_rtp_param suc: clockrate is %d, channels is %d, latency is %d", clock_rate, channels, latency);

-    return RESULT_OK;  

-}

-int lynq_set_call_rtp_ssrc(const LYNQ_Rtp_Ssrc_Mode ssrc_mode,const unsigned int ssrc)

-{

-    if(ssrc_mode < Rtp_Ssrc_random || ssrc_mode > Rtp_Ssrc_specific)

-    {

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

-    g_rtp_server_info.ssrc_mode = ssrc_mode;

-    g_rtp_server_info.ssrc = ssrc ;

-    LYINFLOG("%s suc: param is %d %d", __func__, ssrc_mode, ssrc);

-    return RESULT_OK;

+    return ret;

 }

 /*get*/

-LYNQ_Audio_Mode lynq_get_voice_audio_mode()

+int lynq_get_voice_audio_mode(LYNQ_Audio_Mode* voice_audio_mode)

 {

-    if(g_rtp_thread_valid[0])

+    if(g_module_init_flag != MODULE_RUNNING)

     {

-        return AUDIO_MODE_RTP;

+        LYERRLOG("%s module state %d error",__func__,g_module_init_flag);

+        return LYNQ_E_CONFLICT;

     }

-    else 

+

+    if(voice_audio_mode==NULL)

     {

-        return AUDIO_MODE_CODEC;

-    }

-}

-int lynq_get_remote_rtp_ip(char* ip, const int ip_length)

-{

-    if(ip==NULL)

-    {

-        LYERRLOG("ip is NULL");

+        LYERRLOG("parameter is NULL");

         return LYNQ_E_PARAMETER_ANONALY;

     }    

 

-    if(ip_length < strlen(g_rtp_server_info.ip)+1)

-    {

-        LYERRLOG("ip length %d is shorter than saved ip length %d",ip_length,strlen(g_rtp_server_info.ip)+1);

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

-    

-    bzero(ip,ip_length);

-    strcpy(ip,g_rtp_server_info.ip);

-    

-    return RESULT_OK;  

-}

-int lynq_get_vlan_info(char* vlan_info, const int vlan_info_length)

-{

-    if(vlan_info==NULL) 

-    {

-        LYERRLOG("vlan info is NULL");

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

+    int local_mode;

 

-    if(vlan_info_length < strlen(g_rtp_server_info.vlan_info)+1)

-    {

-        LYERRLOG("vlan info length %d is shorter than saved vlan info length %d",vlan_info_length,strlen(g_rtp_server_info.vlan_info)+1);

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

-   

-    bzero(vlan_info,vlan_info_length);

-    strcpy(vlan_info,g_rtp_server_info.vlan_info);        

-   

-    return RESULT_OK;  

-}

-int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)

-{

-    if(port==NULL)

-    {

-        return LYNQ_E_PARAMETER_ANONALY;

-    }   

-    if (rtp_mode == 0)

-    {

-        *port = g_rtp_client_info.port;

-    }

-    else if (rtp_mode == 1)

-    {

-        *port = g_rtp_server_info.port;

-    }

-    return RESULT_OK;  

-}

-int lynq_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode

-{

-    if(clock_rate == NULL || channels ==NULL || latency ==NULL)

-    {

-        LYERRLOG("input parameter is NULL");

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

+    int ret=lynq_get_common_request(LYNQ_REQUEST_GET_VOICE_AUDIO_MODE,&local_mode);

 

-    *clock_rate = g_rtp_client_info.clockrate;

-    *channels = g_rtp_client_info.channels ;

-    *latency = g_rtp_client_info.latency;

-

-    return RESULT_OK;  

-}

-int lynq_get_call_rtp_ssrc(int* ssrc_mode, unsigned int* ssrc)

-{

-    if(ssrc_mode == NULL || ssrc ==NULL)

-    {

-        LYERRLOG("input parameter is NULL");

-        return LYNQ_E_PARAMETER_ANONALY;

-    }

-    

-    *ssrc_mode = g_rtp_server_info.ssrc_mode;

-    *ssrc = g_rtp_server_info.ssrc ;   

-    

-    return RESULT_OK;

+    *voice_audio_mode = (LYNQ_Audio_Mode) local_mode;

+    return ret;

 }

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h
index 590971a..47b7eab 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h
@@ -30,6 +30,8 @@
 #define LYNQ_REQUEST_OOS_DEEP_SLEEP_RECOVER_TIMER_INTERVAL (LYNQ_REQUEST_VENDOR_BASE +13)

 #define LYNQ_REQUEST_CHANGE_SCREEN_STATE (LYNQ_REQUEST_VENDOR_BASE + 14)/*jb.qi add for two sim suspend 2022/9/19*/

 #define LYNQ_REQUEST_CHANGE_RADIO (LYNQ_REQUEST_VENDOR_BASE + 15)

+#define LYNQ_REQUEST_SET_VOICE_AUDIO_MODE (LYNQ_REQUEST_VENDOR_BASE + 28)

+#define LYNQ_REQUEST_GET_VOICE_AUDIO_MODE (LYNQ_REQUEST_VENDOR_BASE + 21)

 /*the same with lynq_interface.h end*/

 

 typedef enum{

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/include/lynq-qser-voice.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/include/lynq-qser-voice.h
index 8de497a..1c4c586 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/include/lynq-qser-voice.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/include/lynq-qser-voice.h
@@ -58,6 +58,13 @@
     void                    *contextPtr
 );
 
+typedef enum 
+{
+    E_QSER_VOICE_AUDIO_MODE_CODEC       = 0, /**<  Voice call audio mode codec*/
+    E_QSER_VOICE_AUDIO_MODE_RTP         = 1, /**<  Voice call audio mode rtp. */
+}E_QSER_VOICE_CALL_AUDIO_MODE_T;
+
+
 /* Init voice module and return h_voice, this should be called before any other APIs */
 int qser_voice_call_client_init(voice_client_handle_type  *ph_voice);
 
@@ -96,6 +103,11 @@
 
 int qser_voice_set_dtmf(const char callnum);
 
+int qser_voice_set_audio_mode(const E_QSER_VOICE_CALL_AUDIO_MODE_T audio_mode);
+
+int qser_voice_get_audio_mode(E_QSER_VOICE_CALL_AUDIO_MODE_T* audio_mode);
+
+
 
 /*
 Usage 1 (register callback and wait for new call in, then answer): 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp
index 657d8c0..537272a 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-voice/lynq-qser-voice.cpp
@@ -258,6 +258,18 @@
 
 }
 
+int qser_voice_set_audio_mode(const E_QSER_VOICE_CALL_AUDIO_MODE_T audio_mode)
+{
+   return lynq_set_voice_audio_mode((LYNQ_Audio_Mode) audio_mode);
+}
+
+int qser_voice_get_audio_mode(E_QSER_VOICE_CALL_AUDIO_MODE_T* audio_mode)
+{   
+   return lynq_get_voice_audio_mode((LYNQ_Audio_Mode*) audio_mode );
+}
+
+
+
 #ifdef ECALL_SUPPORT
 int qser_voice_fast_ecall(voice_client_handle_type*       h_voice,
                         int                         *call_id,
diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/Makefile b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/Makefile
index 07cf19a..701804e 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/Makefile
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/Makefile
@@ -31,6 +31,12 @@
 else

 OBJS = voice.o alsa_call.o voice_ipc.o

 endif

+

+ifeq ($(CONFIG_VB_TRANSMIT_INTF), NULL)

+OBJS += voice_buffer.o

+endif

+

+

 CFLAGS += -g

 #LDFLAGS += -lpthread 

 

diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/include/voice_lib.h b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/include/voice_lib.h
index 14ac0cc..f43a1a2 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/include/voice_lib.h
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/include/voice_lib.h
@@ -81,7 +81,12 @@
 	int vbuffer_client_stream_stop(void); 
 
 	#endif
-	
+	int voice_buffer_open(void);
+	int voice_buffer_close(int fd);
+	int voice_buffer_write(int fd, unsigned char *pdata, unsigned int len);
+	int voice_buffer_read(int fd, unsigned char *pdata, unsigned int len);
+	int voice_buffer_ioctl(int fd, unsigned int cmd, void *pvalue);
+	int voice_buffer_stop(int fd);
 #endif
 
 
diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice.c
index 01267be..b8f0364 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice.c
@@ -217,10 +217,13 @@
 		slic_flag = voice_GetSlicFlag();

 		printf(" voice  slic flag  get, slic_flag=%d!\n", slic_flag);

 		if (slic_flag == 1) {

+			

+			printf("%s:cap slic_flag set,return!\n",__func__); 

 			return 0;

 		}

 	}

 

+	printf("%s:cap do mixer and pcm opt!\n",__func__); 

 

 	//open mixer dev for codec control

 	voice_mixer = mixer_open(0);

diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice_buffer.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice_buffer.c
index e236432..d4e48e2 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice_buffer.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/platform/libvoice/voice_buffer.c
@@ -133,10 +133,6 @@
     FILE *rtp_tx_pcm_file;

 	int rtp_tx_pcm_filesize;

 

-	

-#endif

-	int fs;	

-

 	int sockfd;

 	int af;

 	struct sockaddr_in src;	

@@ -146,6 +142,11 @@
 	char *rtp_from_net_filename;

     FILE *rtp_from_net_file;

 	int rtp_from_net_filesize;	

+		

+#endif

+	int fs;	

+

+

 #ifdef _USE_VOICE_ALSA	

     struct mixer *mixer_handle;

     struct pcm   *p_pcm_handle;

@@ -264,8 +265,12 @@
 	

 	fd = open(VBUFFER_DEV_NAME, VBUFFER_DEV_FLAGS);

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

+    if(fd<0)

+    {        

+        return -1;

+    }

+        

 

-	signal(SIGIO,vb_signal_back_func);

 	fcntl(fd,F_SETOWN,getpid());

 	oflags = fcntl(fd,F_GETFL);	

 	fcntl(fd,F_SETFL,oflags|FASYNC);

@@ -368,6 +373,25 @@
 }

 

 

+int voice_buffer_stop(int fd)

+{

+	int ret;

+	if (fd > 0) {

+		sem_post(&vb_rec.read_sem);

+		sem_post(&vb_rec.write_sem);	

+	}

+	else{

+		printf("%s: fd invalid,return!\n",__func__);		

+		return -ENOENT;

+

+	}	

+	return ret;

+}

+

+

+#ifdef _VB_TRANSMIT_INTF_RTP

+

+

 

 //#define BINDING_DEVICE_NAME	"eth0" 

 //#define DEST_IP_ADDR	"192.168.0.100" 

@@ -556,6 +580,8 @@
 	

 	return s_size;

 }

+

+#endif

 static int vb_thread_create( const char *name,pthread_t	*thread_t, vb_thread_proc *proc, 

 								int stack_size, unsigned priority,void *arg )

 {

@@ -1072,6 +1098,7 @@
 

 

 

+#ifdef _VB_TRANSMIT_INTF_RTP

 

 //640+12

 char rtp_in_buf[652]={0};

@@ -1615,6 +1642,7 @@
     return 0;

 }

 

+#endif

 static int vb_rx_thread_func(void *arg)

 {

     int ret;

diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/27aa26d_2.patch b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/27aa26d_2.patch
new file mode 100755
index 0000000..062dea0
--- /dev/null
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/27aa26d_2.patch
@@ -0,0 +1,2746 @@
+From 27aa26d8b7757c6208f80f13ff2f0dade0307383 Mon Sep 17 00:00:00 2001
+From: 徐新强0318000513 <xu.xinqiang@sanechips.com.cn>
+Date: Tue, 16 Jul 2024 12:56:20 +0800
+Subject: [PATCH] 用户故事:voicebuffer和voice代码共存实现 故障单号:ZX297520V3-525028   合入内容:voicebuffer和voice代码共存,通过变量控制流程 cp 引入来源: 需求ZX297520V3-525218 case:0240520CBA2FB95 波及分析:通话功能 测试建议:进行通话测试,声音是否正常;voicebuffer功能是否正常。 组件标签:NA 是否自测:是 自测台位:研发自己的板子 自测用例:NA
+
+Change-Id: I8f9057f6be80ead6417ffd63c75add87fce24ab9
+---
+
+
+--- a/ps/driver/inc/misc/drvs_voiceprocess.h
++++ b/ps/driver/inc/misc/drvs_voiceprocess.h
+@@ -283,6 +283,10 @@
+ 	BOOL firstRegZCATFlag; //25

+ 	T_Hal_EcallData	ecallData;//26

+     UINT8 voice_nv_update;//27

++	UINT8 useVoiceBuffer; // 0 not use,1 use

++	UINT8 voiceBufferType; //0 single core, 1 dual core

++

++	

+ } T_zDrvVoice_GbVar; //T_zDrvVoice_GbVar

+ 

+ typedef struct

+
+--- a/ps/driver/src/chipsets/src/audio_base/audio_config/audioRef_cfg.c
++++ b/ps/driver/src/chipsets/src/audio_base/audio_config/audioRef_cfg.c
+@@ -25,6 +25,7 @@
+ #include "drvs_general.h"

+ #include "drvs_i2s.h"

+ #include "drvs_voiceprocess.h"

++#include "hal_voiceprocess.h"

+ #include "drvs_voice_config.h"

+ #include "drvs_i2c.h"

+ #include "NvParam_drv.h"

+@@ -132,7 +133,7 @@
+ 

+ //#define AUDIO_USE_FIXED_ADDRESS

+ 

+-#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

++//#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

+ #define VP_INOUT_NOBAK_BUFSIZE  640

+ 

+ /**************************************************************************

+@@ -595,7 +596,8 @@
+ 	//ret = zDrvNand_Read(OS_FLASH_VOICE_DRV_RW_NONFAC_BASE_ADDR,  sizeof(audionvflag), ((UINT8 *)(&audionvflag)));

+ 	ret = zOss_NvItemRead(OS_FLASH_VOICE_DRV_RW_NONFAC_BASE_ADDR, ((UINT8 *)(&audionvflag)),  sizeof(audionvflag));

+ 

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " zDrvVoiceConfig_Init zOss_NvItemRead isVpParamInNv=%d,isUseSlicCodec=%d!\n", audionvflag.isVpParamInNv, audionvflag.isUseSlicCodec);

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " zDrvVoiceConfig_Init zOss_NvItemRead isVpParamInNv=%d,isUseSlicCodec=%d,isUseVoiceProc=%d,isUseTdm=%d,isUseEcall=%d!\n", audionvflag.isVpParamInNv, audionvflag.isUseSlicCodec,audionvflag.isUseVoiceProc,audionvflag.isUseTdm,audionvflag.isUseEcall);

+ 	//hal_TestTopI2sConfig();

+ 

+ 	if (ret != DRV_SUCCESS)

+
+
+--- a/ps/driver/src/chipsets/src/audio_base/audiointf/hal_audextintf.c
++++ b/ps/driver/src/chipsets/src/audio_base/audiointf/hal_audextintf.c
+@@ -193,6 +193,40 @@
+ {

+ 	return g_voiceVar.muteEn;

+ }

++

++int zDrvVp_SetVoiceProc_Wrap(int val)

++{

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: val=%d !\n",__func__,val);

++

++	g_voiceVar.audio_ctrlFlag.isUseVoiceProc = val;

++	return DRV_SUCCESS;

++}

++

++int zDrvVp_GetVoiceProc_Wrap(void)

++{

++	return g_voiceVar.audio_ctrlFlag.isUseVoiceProc;

++}

++

++int zDrvVp_SetVoiceBuffer_Wrap(int en,int type)

++{

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: en=%d,type=%d !\n",__func__,en,type);

++

++	g_voiceVar.useVoiceBuffer = en;

++	g_voiceVar.voiceBufferType = type;

++	return DRV_SUCCESS;

++}

++

++void zDrvVp_GetVoiceBuffer_Wrap(int *en,int *type)

++{

++    if((en!=NULL)&&(type!=NULL)){

++		*en = g_voiceVar.useVoiceBuffer;

++		*type = g_voiceVar.voiceBufferType;

++		

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: en=%d,type=%d !\n",__func__,*type,*en);

++    }

++}

++

++

+ SINT32 zDrvVp_SetRxMute_Wrap(int enable)

+ {

+ 	return zDrvVp_SetRxMute(enable, VOICE_DOWNLINK);

+
+
+--- a/ps/driver/src/chipsets/src/audio_base/audiointf/voice_procintf.c
++++ b/ps/driver/src/chipsets/src/audio_base/audiointf/voice_procintf.c
+@@ -15,6 +15,10 @@
+ * 	                                           Include files
+ ****************************************************************************/
+ #include "drvs_general.h"
++
++#include "drvs_volte.h"
++#include "drvs_voiceprocess.h"
++
+ #include "drvs_ramlog.h"
+ #include <oss_clib.h>
+ #include <oss_kernel.h>
+@@ -73,8 +77,12 @@
+ 
+ 	g_voiceVar.isUseSlicCodec = g_voiceVar.audio_ctrlFlag.isUseSlicCodec;
+ 	g_voiceVar.g_isUseTdm = g_voiceVar.audio_ctrlFlag.isUseTdm;
++	
++	g_voiceVar.useVoiceBuffer = g_voiceVar.audio_ctrlFlag.isUseVoiceBuffer; // 0 not use,1 use
++	g_voiceVar.voiceBufferType = g_voiceVar.audio_ctrlFlag.selVoiceBufferType;//0 single core, 1 dual core
+ 
+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " VoiceProc_InitNvParam isUseVoiceProc=%d,isUseSlicCodec=%d,isUseTdm=%d!\n", g_voiceVar.audio_ctrlFlag.isUseVoiceProc, g_voiceVar.isUseSlicCodec, g_voiceVar.audio_ctrlFlag.isUseTdm);
++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " VoiceProc_InitNvParam isUseVoiceProc=%d,isUseSlicCodec=%d,isUseTdm=%d,useVoiceBuffer=%d,voiceBufferType=%d!\n", g_voiceVar.audio_ctrlFlag.isUseVoiceProc, \
++		                                  g_voiceVar.isUseSlicCodec, g_voiceVar.audio_ctrlFlag.isUseTdm,g_voiceVar.useVoiceBuffer,g_voiceVar.voiceBufferType);
+ 	if (g_voiceVar.audio_ctrlFlag.isUseVoiceProc == 1)
+ 	{
+ #ifdef _USE_NXP_AUD
+
+
+--- a/ps/driver/src/chipsets/src/audio_base/i2s/hal_i2s.c
++++ b/ps/driver/src/chipsets/src/audio_base/i2s/hal_i2s.c
+@@ -4322,6 +4322,37 @@
+ */

+ VOID vp_SetTopI2sConfig(VOID)

+ {

++	

++

++UINT32 AmrRegBit = 0;

++

++if (g_voiceVar.useVoiceBuffer == 1){ 

++

++

++

++	/* inter loop */

++	AmrRegBit = ARM_I2S_LOOP_CFG;

++

++	AmrRegBit &= 0xfffffe07;

++	AmrRegBit |= 0x000000a8; /* 0x000000a8 loop dsp afe(loop i2s1)--arm i2s2(loop i2s2) 0x00000150 loop dsp arm(loop i2s1)--afe i2s2(loop i2s2)*/

++

++	ARM_I2S_LOOP_CFG = AmrRegBit;

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_SetTopI2sConfig ARM_I2S_LOOP_CFG=0x%x\n", ARM_I2S_LOOP_CFG);

++}

++#ifdef CONFIG_VOICE_BUFFER_DRV  

++	/* inter loop */

++	AmrRegBit = ARM_I2S_LOOP_CFG;

++

++	AmrRegBit &= 0xfffffe07;

++	AmrRegBit |= 0x000000a8; /* 0x000000a8 loop dsp afe(loop i2s1)--arm i2s2(loop i2s2) 0x00000150 loop dsp arm(loop i2s1)--afe i2s2(loop i2s2)*/

++

++	ARM_I2S_LOOP_CFG = AmrRegBit;

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_SetTopI2sConfig ARM_I2S_LOOP_CFG=0x%x\n", ARM_I2S_LOOP_CFG);

++

++#endif

++

+ #if 0

+ 	UINT32 AmrRegBit = 0;

+ 	int ret;

+diff --git a/ps/driver/src/chipsets/src/audio_base/include/hal_voicebuffer.h b/ps/driver/src/chipsets/src/audio_base/include/hal_voicebuffer.h
+new file mode 100755
+index 0000000..a9fbd34
+--- /dev/null
++++ b/ps/driver/src/chipsets/src/audio_base/include/hal_voicebuffer.h
+@@ -0,0 +1,107 @@
++/*******************************************************************************

++ * Copyright (C) 2007, ZTE Corporation.

++ *

++ * File Name:    hal_voicebuffer.h

++ * File Mark:    

++* Description:  Provide voicebuffer hal function prototype declaration and type declaration.

++ * Others:        

++ * Version:       V0.5

++ * Author:        xxq

++ * Date:          2024-07-11

++ * History 1:      

++ *     Date: 

++ *     Version:

++ *     Author: 

++ *     Modification:  add mute/read/write/loopback.

++ * History 2: 

++  ********************************************************************************/

++

++#ifndef _HAL_VOICEBUFFER_H

++#define _HAL_VOICEBUFFER_H

++

++

++/****************************************************************************

++*                                             Include files

++****************************************************************************/

++

++

++/****************************************************************************

++*                                             Macros

++****************************************************************************/

++#define VP_BUF_LENGTH  0x7FF80 //0xFFD80   //0x7FE40  //0x4df80// (0.5M  0x80000)

++#define VP_FRAME_BUFFER_SIZE 320 //20ms 800KHZ

++#define VP_I2S_BUFFER_SIZE 320

++#define VOICE_SYNC_TIMEOUT_TIME 100

++	

++	//#define VP_INOUT_BAK_BUFFER_SIZE 0x30000	// 0x60000

++#define VP_INOUT_NOBAK_BUFSIZE  640

++#define VB_MAX_INT	     0x7fffffff

++#define VB_MIN_INT        0 //(0-2<<31)//0x80000000

++	

++#define VB_INT_OVERFLOW(x) if((x < VB_MIN_INT)||(x > VB_MAX_INT))  x = 0;

++

++#define RPMSG_CAP_ID 1

++

++#define MAX_BUF_SIZE	     640

++#define MAX_BUF_NUM        3

++

++/****************************************************************************

++*                                             Types

++****************************************************************************/

++

++

++

++enum{

++	UP_LINK,

++	DOWN_LINK	

++};

++

++struct voice_ring_buffer {

++	volatile uint read_pos;

++	volatile uint write_pos;

++	volatile char data[];

++

++};

++

++

++/****************************************************************************

++*                                             Constants

++****************************************************************************/

++

++/****************************************************************************

++*                                             Global  Variables

++****************************************************************************/

++

++/****************************************************************************

++*                                             Function Prototypes

++****************************************************************************/

++

++SINT32 vp_Open_Vbuffer(void);

++

++SINT32 vp_Close_Vbuffer(void);

++

++SINT32 vp_VoiceI2sStart_Vbuffer(VOID);

++

++VOID vp_VoiceI2sStop_Vbuffer(VOID);

++

++SINT32 zDrvVp_VoiceWorkStop_Vbuffer(VOID);

++

++SINT32 vp_VolteReadStart_Vbuffer(VOID);

++//whole replace 

++SINT32 vp_VolteReadStop_Vbuffer(VOID);

++

++SINT32 vp_VolteWriteStart_Vbuffer(VOID);

++//whole replace

++SINT32 vp_VolteWriteStop_Vbuffer(VOID);

++

++SINT32 vp_WriteDataToCodec_Vbuffer(UINT8 *pBuf, UINT32 count);

++

++SINT32 vp_ReadDataFromCodec_Vbuffer(UINT8 *pBuf, UINT32 count);

++

++SINT32 vp_CreateThreadSemaph_Vbuffer(VOID);

++

++

++

++

++#endif/*_HAL_VOICEBUFFER_H*/

++

+diff --git a/ps/driver/src/chipsets/src/audio_base/include/hal_voiceprocess.h b/ps/driver/src/chipsets/src/audio_base/include/hal_voiceprocess.h
+old mode 100644
+new mode 100755
+index 371297d..810e12c
+--- a/ps/driver/src/chipsets/src/audio_base/include/hal_voiceprocess.h
++++ b/ps/driver/src/chipsets/src/audio_base/include/hal_voiceprocess.h
+@@ -23,14 +23,42 @@
+  *                                                 Include files                                	    *

+  **************************************************************************/

+ 

++

++/****************************************************************************

++* 	                                           Local Types

++****************************************************************************/

++

++typedef enum

++{

++	VBUF_SEM = 0,//voice buffer

++	ECALL_SEM,		

++	SEM_MAX

++} T_Sem_Owner;

++

++typedef enum

++{

++	DIR_RX,

++	DIR_TX, 	

++	DIR_ALL,

++	DIR_MAX

++} T_Data_Dir_Type;

++

++

+ /**************************************************************************

+  *                                                 Macro                                    	            *

+  **************************************************************************/

++#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

++

++//#define TEST_WHITE_NOISE

++

++//#define  VB_DATA_LOSS_TEST

++

++

+ #if 0

+ #define VOICE_TONE_MIXER_FUNCTION 

+ //#define TEST_WHITE_NOISE

+ 

+-

++#endif

+ 

+ /****************************************************************************

+ * 	                                        Global Constants                                        *

+@@ -47,6 +75,7 @@
+ /****************************************************************************

+ * 	                                         Function Prototypes                                    *

+ ****************************************************************************/

++#if 0

+ typedef enum

+ {

+     VP_I2S_IDLE = 0,

+@@ -60,6 +89,13 @@
+ /**************************************************************************

+  *                              Function Prototypes                                    *

+  **************************************************************************/

++#ifdef ECALL_SUPPORT

++

++

++SINT32 update_ecall_state(T_Data_Dir_Type dir);

++

++

++#endif

+ 

+ 

+ 

+diff --git a/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c b/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c
+old mode 100644
+new mode 100755
+index 322aea4..50e28da
+--- a/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c
++++ b/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c
+@@ -54,6 +54,7 @@
+ #define TDM_DRIVER_VERSION          1

+ 

+ //#define ARM_TDM_LOOP_SET	*((volatile unsigned int *)(ZX_SOC_SYS_BASE + 0x60))

++#define ARM_TDM_LOOP_CFG	*((volatile UINT32 *)(SOC_SYS_REG_BASE+0x60))

+ 

+ /* version register */

+ #define TDM_VERSION     				0x0104	/*TDM Version V1.4*/

+@@ -2415,7 +2416,12 @@
+ 	memset(temp, 0, sizeof(temp));

+ 	tdmDmaState[TDM_RX].channel = DMA_CH_TDM_RX0;

+ 	tdmDmaState[TDM_RX].ch = dma_request_channel(mask, zx29_dma_filter_fn, (void*)(tdmDmaState[TDM_RX].channel));

+-	

++	if(!tdmDmaState[TDM_RX].ch){

++		

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: dma_request_channel fail,  dma_id(%d).\n",__func__,tdmDmaState[TDM_RX].channel);

++		return DRV_ERR_BUSY;

++

++	}	

+ 	for (i = 0; i < TDM_OUT_BUF_NUM; i++) {

+ 		temp[i].dest_addr 	= tdmDmaState[TDM_RX].dma_phyaddr  + (tdmStream->rxLen) * i;

+ 		temp[i].src_addr	= ZX29_TDM_PHYS + 0x24;

+@@ -2484,6 +2490,12 @@
+ 	memset(temp, 0, sizeof(temp));

+ 	tdmDmaState[TDM_TX].channel = DMA_CH_TDM_TX0;	

+ 	tdmDmaState[TDM_TX].ch = dma_request_channel(mask, zx29_dma_filter_fn, (void*)(tdmDmaState[TDM_TX].channel));

++	if(!tdmDmaState[TDM_TX].ch){

++		

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: dma_request_channel fail,  dma_id(%d).\n",__func__,tdmDmaState[TDM_TX].channel);

++		return DRV_ERR_BUSY;

++

++	}

+ 	

+ 	for (i = 0; i < TDM_OUT_BUF_NUM; i++) {

+ 		temp[i].src_addr 	= tdmDmaState[TDM_TX].dma_phyaddr + (txStream->txLen) * i;

+@@ -2840,6 +2852,7 @@
+ 	SINT32 ret = DRV_SUCCESS;

+ 

+ 	ret = tdm_Reset();

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvTDM_Reset , ret=%d",ret);

+ 	

+ 	return ret;

+ }

+@@ -3751,6 +3764,21 @@
+ 

+ VOID vp_SetTopTdmConfig(VOID)

+ {

++    UINT32 AmrRegBit = 0;

++

++	/* inter loop */

++	AmrRegBit = ARM_TDM_LOOP_CFG;

++	

++	AmrRegBit &= 0xfffffe07;

++	AmrRegBit |= 0x000000a8; /* 0x000000a8 loop dsp afe(loop i2s1)--arm i2s2(loop i2s2) 0x00000150 loop dsp arm(loop i2s1)--afe i2s2(loop i2s2)*/

++

++	ARM_TDM_LOOP_CFG = AmrRegBit;

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_SetTopTDMConfig ARM_TDM_LOOP_CFG=0x%x\n", ARM_TDM_LOOP_CFG);

++	

++

++

++

+ #if 0

+     UINT32 AmrRegBit = 0;

+ 	int ret = 0;

+diff --git a/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voicebuffer.c b/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voicebuffer.c
+new file mode 100755
+index 0000000..8f9f5f5
+--- /dev/null
++++ b/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voicebuffer.c
+@@ -0,0 +1,1000 @@
++/*******************************************************************************

++ * Copyright (C) 2007, ZTE Corporation.

++ *

++ * File Name:hal_voicebuffer.c

++ * File Mark:

++ * Description: voice buffer function.

++ * Others:

++ * Version:

++ * Author:        xxq

++ * Date:          2024-07-03

++ * History 1:

++ *     Date: 

++ *     Version:

++ *     Author:

++ *     Modification: edit for union version

++ * History 2:

++  ********************************************************************************/

++

++/****************************************************************************

++* 	                                           Include files

++****************************************************************************/

++#include "drvs_general.h"

++#include "drvs_volte.h"

++#include "drvs_i2s.h"

++#include "drvs_voiceprocess.h"

++#include "hal_voiceprocess.h"

++#include "drvs_voice_config.h"

++//#include "hal_pcmmixer.h"

++#include "NvParam_drv.h"

++#include "drvs_io_voice.h"

++#include "hal_ringdata.h"

++#include "drvs_tdm.h"

++#include "hal_dtmf_detect.h"

++#include "hal_audio_data.h"

++//#define TEST_WHITE_NOISE

++

++//#define  VB_DATA_LOSS_TEST

++#ifdef TEST_WHITE_NOISE

++#include "Fs8000_WhiteNoise_Mon.h"

++//#include "Fs8000_Sine_440Hz_Mon.h"

++#endif

++

++#include "drvs_icp.h"

++#include "drvs_rpmsg.h"

++//#include <linux/completion.h>

++#include "hal_voicebuffer.h"

++

++/****************************************************************************

++* 	                                           Local Macros

++****************************************************************************/

++//#define USE_AUDIO_RING

++//#define VP_GET_TX_ALL_DATA

++

++

++/****************************************************************************

++* 	                                           Local Types

++****************************************************************************/

++

++

++/****************************************************************************

++* 	                                           Local Constants

++****************************************************************************/

++

++/****************************************************************************

++* 	                                           Local Function Prototypes

++****************************************************************************/

++

++/****************************************************************************

++* 	                                          Global Constants

++****************************************************************************/

++

++

++/****************************************************************************

++* 	                                          Global Variables

++****************************************************************************/

++//static T_zDrvVp_SpeechState *s_pSpeechState = NULL;

++extern T_zDrvVp_SpeechState s_speechState;  //104 bytes

++extern T_zDrvVoice_GbVar g_voiceVar;

++extern T_zDrvVp_State s_vpState;

++

++

++#ifdef ECALL_SUPPORT

++extern int eWrErr;

++extern UINT8 e_reg_flag;

++

++#endif

++

++//for test whiteNoise

++#ifdef TEST_WHITE_NOISE

++extern UINT32 tempCount;

++extern UINT8 *pVoiceTempBuf;

++#endif

++

++

++extern T_ZDrv_VpInOutBuffer vpInOutBuffer;

++

++extern T_HalMixerToneInfo mixerToneInfo;

++

++static int vbuffer_init_flag = 0;

++

++/****************************************************************************

++* 	                                          Global Function Prototypes

++****************************************************************************/

++//aduvoice config code

++

++

++

++

++

++

++extern SINT32 voice_ToneMixerData(UINT8 *pvdata, UINT32 size, UINT8 *pmixdata);//xiu gai chu sheng ming

++extern SINT32 zDrvI2S_Read_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);//xiu gai chu sheng ming

++extern SINT32 zDrvI2S_Write_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);//xiu gai chu sheng ming

++

++

++

++/****************************************************************************

++* 	                                          Function Definitions

++****************************************************************************/

++ZOSS_TIMER_ID s_voiceTimerId ;

++ZOSS_SEMAPHORE_ID s_voiceRdSema;

++ZOSS_SEMAPHORE_ID s_voiceWrSema;

++

++//#ifdef CONFIG_VOICE_BUFFER_DRV  

++//#ifdef _VBUFF_IN_MULTI_CORE

++//voice buffer use in multi core 

++//#define RPMSG_CAP_ID 1

++

++

++

++int timer_cb_count = 0;

++int first_full_flag = 0;

++int first_empty_flag = 0;

++

++int vb_read_count = 0;

++int vb_write_count = 0;

++

++

++static void voiceTimerCallBack_Mt(SINT32 para)

++{

++	T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

++	

++	UINT8 s = 1;

++	icp_pMsg.actorID = RPMSG_CAP_ID;

++

++	icp_pMsg.chID = channel_41;

++	icp_pMsg.flag |= RPMSG_WRITE_INT;

++	icp_pMsg.buf = (void *)&s;

++	icp_pMsg.len = 1;

++

++

++	zOss_PutSemaphore(s_voiceWrSema);

++	zOss_PutSemaphore(s_voiceRdSema);

++	//zDrvRpMsg_Write(&icp_pMsg); 

++	zDrvRpMsg_Write_Cap(&icp_pMsg); 

++	timer_cb_count++;

++	VB_INT_OVERFLOW(timer_cb_count);

++#ifdef VB_DATA_LOSS_TEST

++

++	if((timer_cb_count%1000 ) == 0){

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s:timer_cb_count(%d)\n",__FUNCTION__,timer_cb_count);

++		if(timer_cb_count> 10000000) 

++			timer_cb_count=0;

++	}

++

++#endif

++	

++//	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voiceTimerCallBack timer=%u\n", cpu_clock(0)>>10);

++}

++

++struct voice_ring_buffer *voice_buff[2] = {NULL,NULL};

++

++

++

++static bool voice_buff_is_full(int read_pos, int write_pos)

++{

++

++

++	if ((write_pos - read_pos) >= 20000000) {

++		write_pos = write_pos - 20000000;

++		//voice_buff[UP_LINK]->write_pos = write_pos;

++		voice_buff[DOWN_LINK]->write_pos = write_pos;

++	}

++	return ((write_pos - read_pos) == MAX_BUF_NUM);

++}

++static bool voice_buff_is_empty(int read_pos, int write_pos)

++{

++	

++	return (write_pos == read_pos);

++}

++static int voice_buffer_write( char *buf, int count)

++{

++	int read_pos, write_pos;	

++

++

++	read_pos = voice_buff[DOWN_LINK]->read_pos;

++	write_pos = voice_buff[DOWN_LINK]->write_pos;	

++	if(vb_write_count == 0){

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: first read_pos=%d write_pos=%d \n",__FUNCTION__,read_pos,write_pos);

++	}

++

++	

++	if(voice_buff_is_full(read_pos, write_pos)){

++		//zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice_buffer_read readbuffer is full \n");

++   		 first_full_flag++;

++		VB_INT_OVERFLOW(first_full_flag);

++		if(first_full_flag == 1)

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: writebuffer is full  read_pos %d,write_pos %d,vb_write_count %d,count %d\n",__FUNCTION__,read_pos,write_pos,vb_write_count,count);

++		return DRV_ERROR_FULL;

++	}

++	else {

++		vb_write_count++;	

++		

++		VB_INT_OVERFLOW(vb_write_count);

++		first_full_flag = 0;

++		zOss_Memcpy(&(voice_buff[DOWN_LINK]->data[(write_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]), buf, count);

++	

++		write_pos++;

++

++		voice_buff[DOWN_LINK]->write_pos = write_pos;

++

++	}

++	

++	return DRV_SUCCESS;

++}

++static int voice_buffer_read(char *buf, size_t count)

++{

++	int read_pos, write_pos;

++	int* buf_int;

++	int i;

++	

++	read_pos = voice_buff[UP_LINK]->read_pos;

++	write_pos = voice_buff[UP_LINK]->write_pos;

++	if(vb_read_count == 0){

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: first read_pos=%d write_pos=%d \n",__FUNCTION__,read_pos,write_pos);

++	}

++

++	if ((count > 0) && (count <= MAX_BUF_SIZE))  {

++		if(voice_buff_is_empty(read_pos, write_pos)){

++			first_empty_flag++;

++			VB_INT_OVERFLOW(first_empty_flag);

++			if(first_empty_flag ==1)

++				zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: readbuffer is empty,read_pos %d,write_pos %d,vb_read_count %d,count %d\n",__FUNCTION__,read_pos,write_pos,vb_read_count,count);

++			//add memset,del return . edit for  far end hear near end repreat voice pcm, FROM MBB TEST

++			

++		#ifndef  VB_DATA_LOSS_TEST

++			zOss_Memset(&(voice_buff[UP_LINK]->data[(read_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]),0, count);

++			zOss_Memset(buf,0, count);

++		#endif			

++			//return DRV_ERROR_EMPTY;

++			

++

++		}

++		else {

++			

++		    vb_read_count++; 			

++			VB_INT_OVERFLOW(vb_read_count);		

++			first_empty_flag = 0;

++			

++			zOss_Memcpy(buf, &(voice_buff[UP_LINK]->data[(read_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]), count);

++			//zOss_Memset(&(voice_buff[UP_LINK]->data[(read_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]),0, count);

++

++#ifdef VB_DATA_LOSS_TEST

++

++			

++			if(vb_read_count < 5){

++				pr_info("ps :count=%d vb_read_count=%d,read_pos=%d,write_pos=%d\n",count,vb_read_count,read_pos,write_pos);

++

++			

++				buf_int =( int*) &voice_buff[UP_LINK]->data[(write_pos%MAX_BUF_NUM)*MAX_BUF_SIZE];

++				

++				for(i=0;i<(count/4);i++){

++				   //*(buf_int+i) = i;

++				   //buf_int[i] = i;

++				 if(i>0x1f)  

++					zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"ps: *(buf_int+%d)=%d\n",i,*(buf_int+i));

++				}

++			

++			}

++#endif

++			read_pos++;

++			if(read_pos == 20000000)

++				read_pos = 0;

++			voice_buff[UP_LINK]->read_pos = read_pos;

++		}

++

++

++	}

++		

++	

++	return DRV_SUCCESS;

++}

++

++

++//voice buffer use in single core 

++extern int voicebuffer_ulqueue_read(void *buf, unsigned int size);

++extern int voicebuffer_dlqueue_write(void  *buf, unsigned int  size);

++extern void voice_inform_to_app(void);

++//static DECLARE_COMPLETION(s_voice_completion);

++//ZOSS_TIMER_ID s_voiceTimerId ;

++//ZOSS_SEMAPHORE_ID s_voiceRdSema;

++//ZOSS_SEMAPHORE_ID s_voiceWrSema;

++static void voiceTimerCallBack(SINT32 para)

++{

++//	complete_all(&s_voice_completion);

++	zOss_PutSemaphore(s_voiceWrSema);

++	zOss_PutSemaphore(s_voiceRdSema);

++	voice_inform_to_app();

++//	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voiceTimerCallBack timer=%u\n", cpu_clock(0)>>10);

++}

++

++

++

++

++

++static SINT32 vp_rxsem_count_Init(void)

++{

++	UINT32 i = 0;

++	UINT32 semCount = 0;

++	SINT32 Count = 0;

++

++	semCount = zOss_GetSemaphoreCount(s_voiceRdSema);

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_rxsem_count_Init rxSem count=%d\n",  semCount);

++

++	Count = semCount;

++	if(Count > 0)  {

++		for(i = 0; i < Count; i++) {

++			zOss_GetSemaphore(s_voiceRdSema, ZOSS_NO_WAIT);

++		}

++	}

++

++	return DRV_SUCCESS;

++}

++

++static SINT32 vp_txsem_count_Init(void)

++{

++	UINT32 i = 0;

++	UINT32 semCount = 0;

++	SINT32 Count = 0;

++

++	semCount = zOss_GetSemaphoreCount(s_voiceWrSema);

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_txsem_count_Init txSem count=%d \n",  semCount);

++

++	Count = 3 - semCount;

++	if(Count > 0) {

++		for(i = 0; i < Count; i++) {

++			zOss_PutSemaphore(s_voiceWrSema);

++		}

++	} else if(Count < 0) {

++		Count = 0 - Count;

++		for(i = 0; i < Count; i++) {

++			zOss_GetSemaphore(s_voiceWrSema, ZOSS_NO_WAIT);

++		}

++	}

++	

++	return DRV_SUCCESS;

++}

++

++

++

++

++

++SINT32 vp_Open_Vbuffer(void)

++{

++	SINT32 ret = DRV_SUCCESS;

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s:  start \n", __func__);

++	if (g_voiceVar.voiceBufferType == 1)//multi core

++	{

++		vp_rxsem_count_Init();

++		vp_txsem_count_Init();

++		voice_buff[UP_LINK]->read_pos = 0;

++		voice_buff[UP_LINK]->write_pos = 0; 

++		voice_buff[DOWN_LINK]->read_pos = 0;

++		voice_buff[DOWN_LINK]->write_pos = 0; 

++		zOss_Memset(&(voice_buff[DOWN_LINK]->data[0]),0, MAX_BUF_NUM*MAX_BUF_SIZE);

++		zOss_Memset(&(voice_buff[UP_LINK]->data[0]),0, MAX_BUF_NUM*MAX_BUF_SIZE);

++		//for debug

++		timer_cb_count = 0;

++		first_full_flag = 0;

++		first_empty_flag = 0;

++

++		vb_read_count = 0;

++		vb_write_count = 0;	

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open_Vbuffer  init voice buffer val!\n");

++

++		

++	}else{

++

++	//	INIT_COMPLETION(s_voice_copletion);

++		vp_rxsem_count_Init();

++		vp_txsem_count_Init();

++	}

++

++	return DRV_SUCCESS;

++

++}

++

++

++SINT32 vp_Close_Vbuffer(void)

++{

++	SINT32 ret = DRV_SUCCESS;

++    

++	if (g_voiceVar.voiceBufferType == 1)//multi core

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: timer_cb_count %d,first_full_flag %d,first_empty_flag %d,vb_read_count %d,vb_write_count %d!\n",__FUNCTION__,timer_cb_count,first_full_flag,first_empty_flag,vb_read_count,vb_write_count);

++	}

++

++	return DRV_SUCCESS;

++}

++

++SINT32 vp_VoiceI2sStart_Vbuffer(VOID)

++{

++	SINT32 ret = DRV_SUCCESS;

++

++	UINT8 *read_buf = NULL;

++	UINT8 *write_buf = NULL;

++	UINT32 read_len = 0;

++	UINT32 write_len = 0;

++

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: start.\n",__func__);

++

++

++	ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

++	if (ret != DRV_SUCCESS)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer failed ret is %d .\n", ret);

++		return DRV_ERROR;

++	}

++	if (g_voiceVar.voiceBufferType == 1)//multi core

++	{	

++		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack_Mt, 0);

++	}

++	else{

++		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

++

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer VB zOss_StartTimer\n");

++

++	ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

++

++	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

++	if (ret != DRV_SUCCESS)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

++		return DRV_ERROR;

++	}

++	zOss_Memset(write_buf, 0, write_len);

++	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

++	if (ret != DRV_SUCCESS)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error12:zDrvI2S_Write I2S_2 ret=%d", ret);

++	}

++	

++	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

++	if (ret != DRV_SUCCESS)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error13:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

++		return DRV_ERROR;

++	}

++	zOss_Memset(write_buf, 0, write_len);

++	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

++	if (ret != DRV_SUCCESS)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error14:zDrvI2S_Write I2S_2 ret=%d", ret);

++	}

++    

++	if (g_voiceVar.voiceBufferType == 1)//multi core

++	{

++

++		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++

++	}else{

++		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++	}

++	

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: end.\n",__func__);

++	return ret;

++}

++VOID vp_VoiceI2sStop_Vbuffer(VOID)

++{

++	SINT32 ret = DRV_SUCCESS;

++    return ret;

++}

++

++

++

++SINT32 zDrvVp_VoiceWorkStop_Vbuffer(VOID)

++{

++	SINT32  ret = DRV_SUCCESS;

++

++	//complete_all(&s_voice_completion);

++	zOss_PutSemaphore(s_voiceRdSema);

++	zOss_PutSemaphore(s_voiceWrSema);

++	zOss_StopTimer(s_voiceTimerId);

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: zOss_StopTimer\n",__func__);

++

++

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: success",__func__);

++	return DRV_SUCCESS;

++}

++

++

++SINT32 vp_VolteReadStart_Vbuffer(VOID)

++{

++	SINT32 ret = DRV_SUCCESS;

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart_Vbuffer start\n");

++    

++	if (g_voiceVar.voiceBufferType == 1)//multi core

++	{

++		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack_Mt, 0);

++	}

++	else

++	{

++		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

++

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart_Vbuffer zOss_StartTimer start\n");

++

++	return DRV_SUCCESS;

++}

++//whole replace 

++SINT32 vp_VolteReadStop_Vbuffer(VOID)

++{

++	SINT32  ret = DRV_SUCCESS;

++

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		zOss_PutSemaphore(s_voiceRdSema);

++	

++	}

++	else

++	{

++

++#ifdef  CONFIG_VOICE_BUFFER_DRV  

++		zOss_PutSemaphore(s_voiceRdSema);

++#else

++

++		//zDrvI2s_RxRlsSemaBeforeStop(I2S_1);

++		zDrvExtAudio_RxRlsSemaBeforeStop();

++

++#if 0//move to close lvwenhua 20150910

++		ret = zDrvExtAudio_Read_Stop();

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVolte_ReadStop I2S1 Stop wrong  ret=%d", ret);

++		}

++#endif

++#endif

++

++	}

++

++	if (s_speechState.volteVpCfgEnFlag == 1)

++	{

++		ret = halVpCfg_Disable();

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: halVpCfg_Enable err ret=%x !\n",__func__, ret);

++		}

++		else

++		{

++			s_speechState.volteVpCfgEnFlag = 0;

++		}

++	}

++

++	s_speechState.volteVpReadStopFlag = 1;//together control vp s_speechState

++	if ((s_speechState.volteVpWriteStopFlag == 1) && (s_speechState.volteVpReadStopFlag == 1))

++	{

++		g_voiceVar.vpI2sStatus = VP_I2S_OPEN;

++		

++		if (g_voiceVar.useVoiceBuffer == 1)

++		{

++			zOss_StopTimer(s_voiceTimerId);

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: zOss_StopTimer\n",__func__);

++		

++		}

++		else

++		{

++#ifdef  CONFIG_VOICE_BUFFER_DRV  	

++			zOss_StopTimer(s_voiceTimerId);

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStop_Vbuffer zOss_StopTimer\n");

++#endif

++	}

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: end\n",__func__);

++	return ret;

++}

++

++SINT32 vp_VolteWriteStart_Vbuffer(VOID)

++{

++	SINT32 ret = DRV_SUCCESS;

++

++	//???? for check

++	if (g_voiceVar.voiceBufferType == 1)//multi core

++	{

++		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++	}

++	else

++	{

++		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "%s:end \n",__func__);

++

++	return ret;

++}

++//whole replace

++SINT32 vp_VolteWriteStop_Vbuffer(VOID)

++{

++	SINT32  ret = DRV_SUCCESS;

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		zOss_PutSemaphore(s_voiceWrSema);

++	

++	}

++	else

++	{

++

++#ifdef  CONFIG_VOICE_BUFFER_DRV  

++		//complete_all(&s_voice_completion);

++		zOss_PutSemaphore(s_voiceWrSema);

++#else

++		//zDrvI2s_TxRlsSemaBeforeStop(I2S_1);

++		zDrvExtAudio_TxRlsSemaBeforeStop();

++#endif

++	}

++#if 0//move to close lvwenhua 20150910

++	//wait for write drain semaphore

++#ifdef VOICE_TONE_MIXER_FUNCTION

++	voice_ToneMixerStop();

++#endif

++

++	ret = zDrvExtAudio_Write_Stop();

++	if (ret != DRV_SUCCESS)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVolte_WriteStop I2S1 Stop wrong  ret=%d", ret);

++	}

++

++	//s_VolteWriteSema = 0;

++#endif

++

++	if (s_speechState.volteVpCfgEnFlag == 1)

++	{

++		ret = halVpCfg_Disable();

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStop_Vbuffer halVpCfg_Enable err ret=%x !\n", ret);

++		}

++		else

++		{

++			s_speechState.volteVpCfgEnFlag = 0;

++		}

++	}

++

++	s_speechState.volteVpWriteStopFlag = 1;//together control vp s_speechState

++	if ((s_speechState.volteVpWriteStopFlag == 1) && (s_speechState.volteVpReadStopFlag == 1))

++	{

++		g_voiceVar.vpI2sStatus = VP_I2S_OPEN;

++		

++		if (g_voiceVar.useVoiceBuffer == 1)

++		{

++			zOss_StopTimer(s_voiceTimerId);

++		

++		}

++		else

++		{

++			

++#ifdef  CONFIG_VOICE_BUFFER_DRV 

++			zOss_StopTimer(s_voiceTimerId);

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStop_Vbuffer zOss_StopTimer\n");

++#endif

++		}

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStop_Vbuffer \n");

++	return ret;

++}

++

++

++/*******************************************************************************

++ * For union version

++ * Others:

++ ********************************************************************************/

++SINT32 vp_WriteDataToCodec_Vbuffer(UINT8 *pBuf, UINT32 count)

++{

++	SINT32  ret = DRV_SUCCESS;

++	SINT32  e_ret = DRV_SUCCESS;	

++	UINT8 *write_buf = NULL;

++	UINT32 write_len = 0;

++	UINT8 *e_write_buf = NULL;

++	UINT32 e_write_len = 0;

++	UINT32 i = 0, j = 0;

++#ifdef TEST_WHITE_NOISE

++	// UINT32 tempCount = 0;

++	//zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "test the white noise");

++	//UINT8 *pVoiceTempBuf = s_voiceTempBuffer;

++#endif

++

++

++

++	if (pBuf == NULL)

++	{

++		return DRV_ERR_INVALID_PARAM;

++	}

++

++	if (count != s_speechState.i2sWriteParam.buffersize)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_WriteDataToCodec_Vbuffer write data length err,count=%d,writebuffersize=%d \n", count, s_speechState.i2sWriteParam.buffersize);

++		return DRV_ERR_INVALID_PARAM;

++	}

++	#ifdef ECALL_SUPPORT	

++

++	if(e_reg_flag == 1)

++	{		

++		e_ret = update_ecall_state(DIR_RX); 

++		if (e_ret == DRV_ERR_NOT_SUPPORTED)

++		{

++			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "vp_WriteDataToCodec_Vbuffer get__ecall_state fun not register or invalid para,e_ret=%d !\n",e_ret);

++	

++		}	

++	}	

++	#endif

++

++

++

++	#ifdef TEST_WHITE_NOISE

++

++	zOss_Memcpy(s_speechState.pVpTempRxInBuffer, pVoiceTempBuf, s_speechState.totalFrameBufSize);

++

++	pVoiceTempBuf += s_speechState.totalFrameBufSize;

++	tempCount += s_speechState.totalFrameBufSize;

++	if (tempCount >= 0x4df80)   //307200

++		//if(tempCount >= 0x4e200)   //320000

++	{

++		pVoiceTempBuf = s_voiceTempBuffer;

++		tempCount = 0;

++	}

++	#endif

++

++	#ifdef VOICE_TONE_MIXER_FUNCTION

++

++	if (mixerToneInfo.StartMixer == TRUE) 

++	{

++		//voice_ToneMixerData( s_speechState.pVpTempRxInBuffer);

++		if ((g_voiceVar.voiceInVolteMode == 1) && (g_voiceVar.volteIsWb == 1)) 

++		{

++			voice_ToneMixerData(s_speechState.pVpTempRxInBuffer, 640,  s_speechState.pVpTempRxInBuffer);

++		} 

++		else 

++		{

++			voice_ToneMixerData(s_speechState.pVpTempRxInBuffer, 320,  s_speechState.pVpTempRxInBuffer);

++		}

++

++	}

++

++	#endif

++	if (pBuf !=  s_speechState.pVpTempRxInBuffer)

++	{

++		zOss_Memcpy(s_speechState.pVpTempRxInBuffer, pBuf, s_speechState.totalFrameBufSize);

++	}

++    

++	if (g_voiceVar.vProcIsNormal == TRUE)

++	{

++		VoiceProc_RxProcess(& s_speechState.pVpTempRxInBuffer, & s_speechState.pVpTempRxOutPutBuffer, s_speechState.frameCount);

++	}

++	else

++	{

++		zOss_Memcpy((VOID *)(s_speechState.pVpTempRxOutPutBuffer), (VOID *) s_speechState.pVpTempRxInBuffer, s_speechState.totalFrameBufSize);

++	}

++	//wait_for_completion_timeout(&s_voice_completion, 60);

++	zOss_GetSemaphore(s_voiceWrSema,  60);

++	//#ifdef _VBUFF_IN_MULTI_CORE

++	if (g_voiceVar.voiceBufferType == 1)

++	{

++		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++	}

++	else

++	{			

++		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++	}

++	if (g_voiceVar.voiceInVolteMode == 1)

++	{

++		s_speechState.rxSaveLen += s_speechState.totalFrameBufSize;

++		if (s_speechState.rxSaveLen >= s_speechState.inOutBufUseSize)

++		{

++			s_speechState.rxSaveLen = 0;

++		}

++		s_speechState.pVpTempRxInBuffer = s_vpState.pVpRxInBuffer + s_speechState.rxSaveLen;

++		#ifdef _USE_VP_OUTPUT_RXOUT_DATA

++        s_speechState.pVpTempRxOutPutBuffer = s_vpState.pVpRxOutPutBuffer + s_speechState.rxSaveLen;

++		#else

++		s_speechState.pVpTempRxOutPutBuffer = s_vpState.pVpRxOutPutBuffer;

++		#endif

++	}

++

++	

++	if (s_speechState.firstWriteDataFlag == FALSE)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_WriteDataToCodec_Vbuffer first write ret=%d,tick=%d.\n", ret, zOss_GetTickCount());

++		s_speechState.firstWriteDataFlag = TRUE;

++	}

++

++	return ret;

++}

++

++

++

++SINT32 vp_ReadDataFromCodec_Vbuffer(UINT8 *pBuf, UINT32 count)

++{

++	SINT32  ret = DRV_SUCCESS;

++	UINT8 *read_buf = NULL;

++	UINT32 read_len = 0;

++

++	UINT32 i = 0, j = 0;

++#ifdef CONFIG_ARCH_ZX297520V3_CPE_SWITCH

++	UINT8 temp8bit = 0;

++	UINT8 *ptemp8bit = NULL;

++#endif

++

++	if (pBuf == NULL)

++	{

++		return DRV_ERR_INVALID_PARAM;

++	}

++

++	if (count != s_speechState.i2sReadParam.buffersize)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: read data length err,count=%d,readbuffersize=%d \n",__func__, count, s_speechState.i2sReadParam.buffersize);

++		return DRV_ERR_INVALID_PARAM;

++	}

++#ifdef ECALL_SUPPORT

++

++	if(e_reg_flag == 1)

++	{		

++		ret = update_ecall_state(DIR_TX); 

++		if (ret == DRV_ERR_NOT_SUPPORTED)

++		{

++			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "vp_ReadDataFromCodecvp_ReadDataFromCodec get__ecall_state fun not register,ret=%d !\n",ret);

++	

++		}	

++	}	

++#endif

++	

++

++//	wait_for_completion_timeout(&s_voice_completion, 60);

++	zOss_GetSemaphore(s_voiceRdSema,  60);

++	if (g_voiceVar.voiceBufferType == 1)

++	{

++		voice_buffer_read(s_speechState.pVpTempTxInBuffer,  s_speechState.totalFrameBufSize);

++

++	}

++	else

++	{

++		voicebuffer_ulqueue_read(s_speechState.pVpTempTxInBuffer,  s_speechState.totalFrameBufSize);

++	}

++	if (g_voiceVar.vProcIsNormal == TRUE)

++	{

++		VoiceProc_TxProcess(&s_speechState.pVpTempTxInBuffer, NULL, &s_speechState.pVpTempTxOutPutBuffer, s_speechState.frameCount);	

++	}

++	else

++	{

++		zOss_Memcpy((VOID *)(s_speechState.pVpTempTxOutPutBuffer), (VOID *) s_speechState.pVpTempTxInBuffer, s_speechState.totalFrameBufSize);

++	}

++

++	if (pBuf !=  s_speechState.pVpTempTxOutPutBuffer)

++	{

++		zOss_Memcpy(pBuf, s_speechState.pVpTempTxOutPutBuffer, s_speechState.totalFrameBufSize);

++	}

++	

++	if (g_voiceVar.voiceInVolteMode == 1)

++	{

++		// s_speechState.txSaveLen += VP_FRAME_BUFFER_SIZE;

++		s_speechState.txSaveLen += s_speechState.totalFrameBufSize;

++		if (s_speechState.txSaveLen >= s_speechState.inOutBufUseSize)

++		{

++			s_speechState.txSaveLen = 0;

++		}

++		s_speechState.pVpTempTxInBuffer = s_vpState.pVpTxInBuffer + s_speechState.txSaveLen;

++		s_speechState.pVpTempTxOutPutBuffer = s_vpState.pVpTxOutPutBuffer + s_speechState.txSaveLen;

++	}

++	

++	

++	if (s_speechState.firstReadDataFlag == FALSE)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_ReadDataFromCodec first read tick=%d.\n", zOss_GetTickCount());

++		s_speechState.firstReadDataFlag = TRUE;

++	}

++

++	return ret;

++}

++

++

++

++SINT32 vp_CreateThreadSemaph_Vbuffer(VOID)

++{

++	

++//#ifdef CONFIG_VOICE_BUFFER_DRV  	

++//	init_completion(&s_voice_completion);

++	if(vbuffer_init_flag == 1){

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vbuffer already init,return! \n");

++		return DRV_SUCCESS;

++

++	}

++	s_voiceRdSema = zOss_CreateSemaphore("voice_rx_sem", 0);

++	if(NULL == s_voiceRdSema) {

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create voice_rx_sem err \n");

++		return DRV_ERROR;

++	}

++

++	s_voiceWrSema  = zOss_CreateSemaphore("voice_tx_sem", 0);

++	if(NULL == s_voiceWrSema) {

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create voice_tx_sem err \n");

++		return DRV_ERROR;

++	}

++	if (g_voiceVar.voiceBufferType == 1)

++	{	

++	 	s_voiceTimerId  = zOss_CreateTimer("voice_frameTimer", voiceTimerCallBack_Mt, 0, TRUE);

++	}

++	else

++	{

++		s_voiceTimerId	= zOss_CreateTimer("voice_frameTimer", voiceTimerCallBack, 0, TRUE);

++

++	}

++	 

++	 zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "s_voiceTimerId=%p\n", s_voiceTimerId);

++	if(!s_voiceTimerId)

++	{

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice_frameTimer  failed\n");

++		return DRV_ERROR;

++	}

++//#ifdef _VBUFF_IN_MULTI_CORE

++	//if (g_voiceVar.voiceBufferType == 1)//multi core

++	{

++

++		SINT32 ret = 0;

++

++		//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

++		ret = zDrvRpMsg_CreateChannel_Cap(RPMSG_CAP_ID,channel_41,0x10);

++

++		if(DRV_SUCCESS != ret) {

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create rpmsg err(%d) \n",ret);

++			return DRV_ERROR;

++		}

++		

++		volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

++		volatile unsigned int rpMsgBuf[2] = {0,0}; 

++		//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

++		icp_pMsg.actorID = RPMSG_CAP_ID;

++		icp_pMsg.chID = channel_41;

++		icp_pMsg.flag &= ~RPMSG_READ_POLL;

++		icp_pMsg.buf = rpMsgBuf;

++		icp_pMsg.len = 8;

++		ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

++		if(ret <= 0){

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

++			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

++			

++

++		}

++		else{

++			#if 0

++

++			voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

++			voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

++			#else

++

++			voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

++			voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

++			#endif

++	

++			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

++			,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

++				,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

++		}

++		

++	}

++//#endif

++	vbuffer_init_flag = 1;

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_CreateThreadSemaph success. \r\n");

++	return DRV_SUCCESS;

++}

++

++

++

++

++

++

++

++

++

++

++

++

++

++

++

++

++

++

++

+diff --git a/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c b/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c
+index f34d0b7..3296dad 100755
+--- a/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c
++++ b/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c
+@@ -34,9 +34,7 @@
+ #include "drvs_tdm.h"

+ #include "hal_dtmf_detect.h"

+ #include "hal_audio_data.h"

+-//#define TEST_WHITE_NOISE

+ 

+-//#define  VB_DATA_LOSS_TEST

+ #ifdef TEST_WHITE_NOISE

+ #include "Fs8000_WhiteNoise_Mon.h"

+ //#include "Fs8000_Sine_440Hz_Mon.h"

+@@ -45,40 +43,19 @@
+ #include "drvs_icp.h"

+ #include "drvs_rpmsg.h"

+ //#include <linux/completion.h>

++

++#include "hal_voicebuffer.h"

++

+ /****************************************************************************

+ * 	                                           Local Macros

+ ****************************************************************************/

+ //#define USE_AUDIO_RING

+ //#define VP_GET_TX_ALL_DATA

+ 

+-#define VP_BUF_LENGTH  0x7FF80 //0xFFD80   //0x7FE40  //0x4df80// (0.5M  0x80000)

+-#define VP_FRAME_BUFFER_SIZE 320 //20ms 800KHZ

+-#define VP_I2S_BUFFER_SIZE 320

+-#define VOICE_SYNC_TIMEOUT_TIME 100

+-

+-#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

+-#define VP_INOUT_NOBAK_BUFSIZE  640

+-#define VB_MAX_INT	     0x7fffffff

+-#define VB_MIN_INT        0 //(0-2<<31)//0x80000000

+-

+-#define VB_INT_OVERFLOW(x) if((x < VB_MIN_INT)||(x > VB_MAX_INT))  x = 0;

+ /****************************************************************************

+ * 	                                           Local Types

+ ****************************************************************************/

+-	typedef enum

+-	{

+-		VBUF_SEM = 0,//voice buffer

+-		ECALL_SEM,		

+-		SEM_MAX

+-	} T_Sem_Owner;

+ 

+-	typedef enum

+-	{

+-		DIR_RX,

+-		DIR_TX, 	

+-		DIR_ALL,

+-		DIR_MAX

+-	} T_Data_Dir_Type;

+ 

+ /****************************************************************************

+ * 	                                           Local Constants

+@@ -104,7 +81,46 @@
+ * 	                                          Global Variables

+ ****************************************************************************/

+ //static T_zDrvVp_SpeechState *s_pSpeechState = NULL;

++#if 0

+ static T_zDrvVp_SpeechState s_speechState = {0};  //104 bytes

++#else

++T_zDrvVp_SpeechState s_speechState = {

++		//use for vp data process

++	.pVpTempRxInBuffer = NULL,	

++	.pVpTempTxInBuffer = NULL,	

++	.pVpTempRxOutPutBuffer = NULL,	

++	.pVpTempTxOutPutBuffer = NULL,	

++		

++	.pVpI2sCfg = NULL,	

++		

++	.vpCfgParam = {0},

++		

++	.i2sWriteParam = {0},

++	.i2sReadParam = {0},

++		

++	.frameCount = 0,

++	.totalFrameBufSize = 0,

++	.inOutBufUseSize = 0,

++	.rxSaveLen = 0,

++	.txSaveLen = 0,

++	.saveLen = 0,

++		

++	.pcmSlotNum = 0,

++	.pcmWbSecDataPosition = 0,

++		

++	.volteVpWriteStopFlag = 0,

++	.volteVpReadStopFlag = 0,

++	. volteVpCfgEnFlag = 0,

++	.firstWriteDataFlag = FALSE,

++	.firstReadDataFlag = FALSE,

++	.i2sIsRstFlag = FALSE,

++

++};

++

++

++#endif

++

++#if 0

+ 

+ T_zDrvVoice_GbVar g_voiceVar =

+ {

+@@ -138,32 +154,104 @@
+ #endif

+     0 //27 voice_nv_update

+ };

++#else

++T_zDrvVoice_GbVar g_voiceVar =

++{

++	.volteIsWb = 0,					//volteIsWb

++	.isUseSlicCodec = 0,					//isUseSlicCodec

++	.g_isUseTdm = 0,					//g_isUseTdm

++	.voiceInGsmTdMode = 0,					//voiceInGsmTdMode

++	.voiceInVolteMode = 0,					//voiceInVolteMode

++	.innerI2sIsMaster = FALSE,				//innerI2sIsMaster

++	.innerI2sIsI2sMode = TRUE,				//innerI2sIsI2sMode

++	.vpLoopRuning = FALSE,				//vpLoopRunning

++	.muteEn = FALSE,				//muteEn

++	.vProcIsNormal = FALSE,				//vProcIsNormal

++	.vpI2sStatus = VP_I2S_IDLE,		//vpI2sStatus

++	.vpPath = VP_PATH_HANDSET,	//vpPath

++	.vpLoopPath = VP_PATH_HANDSET,	//vpLoopPath

++	.vpVol = VP_VOL_3,			//vpVol

++	.voiceMode = MAX_VOICE_MODE,		//voiceMode

++	.vpInitGain = -1,					//vpInitGain

++	.audio_ctrlFlag = {0},				//audio_ctrlFlag

++	

++    .dtmfDirSel = DTMF_IDLE,			//dtmfDirSel

++    .sample_rate = 0,					//sample_rate

++    .useDtmfLoop = 0,					//useDtmfLoop

++    .muteCount = 0,					//muteCount

++    .vpLoopBkRunning = FALSE,				//vpLoopBkRunning

++	.rxMuteEn = FALSE,              //rxMuteEn

++	.firstRegZCATFlag = FALSE,

++#ifdef ECALL_SUPPORT	

++    .ecallData = {0},			    //ecallData

++#endif

++	.voice_nv_update = 0, // voice_nv_update

++	.useVoiceBuffer = 0,// 0 not use,1 use

++	.voiceBufferType = 0, //0 single core, 1 dual core

++	

++};

++

++#endif

++

++#if 0

++

+ 

+ static T_zDrvVp_State s_vpState =

+ {

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	0,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	{0},

+-	{0},

+-	0,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL,

+-	NULL

++	NULL,//1 pVpRxInBuffer

++	NULL,//2 pVpTxInBuffer

++	NULL,//3 pVpRxOutPutBuffer

++	NULL,//4 pVpTxOutPutBuffer

++	0,//5 inOutBufSize

++	NULL,//6 pVpInnerI2sCfg

++	NULL,//7 pVpExtI2sCfg

++	NULL,//8 pVpExtI2sWbCfg

++	NULL,//9 s_pVpTdmCfg

++	NULL,//10 s_pVpTdmWbCfg

++	NULL,//11 pVpTdmCfg

++	{0},//12 pMsg

++	{0},//13 pMsgBuf[2]

++	//0,//14

++	NULL,//15 vpThread

++	NULL,//16 rcvDtmfThread

++	NULL,//17 vpSemaphore

++	NULL,//18 vpThreadQuitSema

++	NULL,//19 vpLoopThread

++	NULL,//20 vpLoopSemaphore

++	NULL//21 vpState

+ //	{0}

+ };

++#else

++T_zDrvVp_State s_vpState =

++{

++	.pVpRxInBuffer = NULL,//1

++	.pVpTxInBuffer = NULL,//2

++	.pVpRxOutPutBuffer = NULL,//3

++	.pVpTxOutPutBuffer = NULL,//4

++	.inOutBufSize = 0,//5

++	.pVpInnerI2sCfg = NULL,//6

++	.pVpExtI2sCfg = NULL,//7

++	.pVpExtI2sWbCfg = NULL,//8

++	.s_pVpTdmCfg = NULL,//9

++	.s_pVpTdmWbCfg = NULL,//10

++	.pVpTdmCfg = NULL,//11

++	.pMsg = {0},//12

++	.pMsgBuf = {0},//13

++	.vpThread = NULL,//14

++	.rcvDtmfThread = NULL,//15

++	.vpSemaphore = NULL,//16

++	.vpThreadQuitSema = NULL,//17

++	.vpLoopThread = NULL,//18

++	.vpLoopSemaphore = NULL,//19

++

++	.vpState = NULL,//

++//	{0}

++};

++

++

++#endif

++

++

+ 

+ //for test whiteNoise

+ #ifdef TEST_WHITE_NOISE

+@@ -271,8 +359,8 @@
+ ****************************************************************************/

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #ifdef _VBUFF_IN_MULTI_CORE

+-#define RPMSG_CAP_ID 1

+-

++//#define RPMSG_CAP_ID 1

++#if 0

+ ZOSS_TIMER_ID s_voiceTimerId ;

+ ZOSS_SEMAPHORE_ID s_voiceRdSema;

+ ZOSS_SEMAPHORE_ID s_voiceWrSema;

+@@ -283,9 +371,22 @@
+ 

+ int vb_read_count = 0;

+ int vb_write_count = 0;

++#else

++//define in hal_voicebuffer.c

++extern ZOSS_TIMER_ID s_voiceTimerId ;

++extern ZOSS_SEMAPHORE_ID s_voiceRdSema;

++extern ZOSS_SEMAPHORE_ID s_voiceWrSema;

+ 

++extern int timer_cb_count;

++extern int first_full_flag;

++extern int first_empty_flag;

+ 

+-void voiceTimerCallBack(SINT32 para)

++extern int vb_read_count;

++extern int vb_write_count;

++

++#endif

++

++static void voiceTimerCallBack(SINT32 para)

+ {

+ 	T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

+ 	

+@@ -316,22 +417,8 @@
+ 	

+ //	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voiceTimerCallBack timer=%u\n", cpu_clock(0)>>10);

+ }

+-#define MAX_BUF_SIZE	     640

+-#define MAX_BUF_NUM        3

+ 

+-

+-enum{

+-	UP_LINK,

+-	DOWN_LINK	

+-};

+-

+-struct voice_ring_buffer {

+-	volatile uint read_pos;

+-	volatile uint write_pos;

+-	volatile char data[];

+-

+-};

+-struct voice_ring_buffer *voice_buff[2] = {NULL,NULL};

++extern struct voice_ring_buffer *voice_buff[2];

+ 

+ 

+ 

+@@ -460,10 +547,10 @@
+ extern int  voicebuffer_dlqueue_write(void  *buf, unsigned int  size);

+ extern void voice_inform_to_app(void);

+ //static DECLARE_COMPLETION(s_voice_completion);

+-ZOSS_TIMER_ID s_voiceTimerId ;

+-ZOSS_SEMAPHORE_ID s_voiceRdSema;

+-ZOSS_SEMAPHORE_ID s_voiceWrSema;

+-void voiceTimerCallBack(SINT32 para)

++extern ZOSS_TIMER_ID s_voiceTimerId ;

++extern ZOSS_SEMAPHORE_ID s_voiceRdSema;

++extern ZOSS_SEMAPHORE_ID s_voiceWrSema;

++static void voiceTimerCallBack(SINT32 para)

+ {

+ //	complete_all(&s_voice_completion);

+ 	zOss_PutSemaphore(s_voiceWrSema);

+@@ -476,7 +563,7 @@
+ 

+ #endif

+ 

+-SINT32 vp_rxsem_count_Init(void)

++static SINT32 vp_rxsem_count_Init(void)

+ {

+ 	UINT32 i = 0;

+ 	UINT32 semCount = 0;

+@@ -495,7 +582,7 @@
+ 	return DRV_SUCCESS;

+ }

+ 

+-SINT32 vp_txsem_count_Init(void)

++static SINT32 vp_txsem_count_Init(void)

+ {

+ 	UINT32 i = 0;

+ 	UINT32 semCount = 0;

+@@ -522,6 +609,7 @@
+ #endif

+ 

+ 

++

+ #ifdef ECALL_SUPPORT

+ int eWrErr = 0;

+ UINT8 e_reg_flag = 0;

+@@ -532,6 +620,7 @@
+ UINT32 e_rdCount = 0;

+ T_Ecall_State preEcallRxSta = 0;

+ T_Ecall_State preEcallTxSta = 0;	

++

+ 

+ //tx

+ SINT32 rdsem_count_Init(T_Sem_Owner owner)

+@@ -706,7 +795,7 @@
+ 

+ 	e_startCount = 0;

+     e_stopCount = 0;

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Open  end!\n");

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Open bufsize=%d end!\n",bufsize);

+ 

+ 	return DRV_SUCCESS;

+ 

+@@ -758,7 +847,7 @@
+ {

+ 	SINT32 ret = DRV_SUCCESS;

+ 

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s start e_startCount=%d \n",__FUNCTION__,e_startCount);

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: start e_startCount=%d \n",__FUNCTION__,e_startCount);

+ 	if(g_voiceVar.ecallData.ecallSta == ECALL_ST_START)

+ 	{

+ 		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Start repeat ecallSta=%d\n",g_voiceVar.ecallData.ecallSta);

+@@ -785,7 +874,7 @@
+ SINT32 ecall_Stop(VOID)

+ {

+ 	SINT32  ret = DRV_SUCCESS;

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s start e_stopCount=%d \n",__FUNCTION__,e_stopCount);

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: start e_stopCount=%d \n",__FUNCTION__,e_stopCount);

+ 	

+ 	if((g_voiceVar.ecallData.ecallSta == ECALL_ST_STOP)||(g_voiceVar.ecallData.ecallSta == ECALL_ST_CLOSE))

+ 	{

+@@ -833,7 +922,7 @@
+ 	{						

+ 		if(dir == DIR_RX)

+ 		{

+-			

++

+ 			preEcallRxSta = g_voiceVar.ecallData.ecallRxSta;

+ 			g_voiceVar.ecallData.ecallRxSta = ECALL_ST_RX_INUSE;

+ 			//zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "update_ecall_state rx state change to ecallRxSta = %d\n", g_voiceVar.ecallData.ecallRxSta);

+@@ -964,9 +1053,15 @@
+ 	return DRV_SUCCESS;

+ }

+ 

++

+ SINT32 zDrvExtAudio_Open(T_ZDrvI2s_TransMode i2sTransMode)

+ {

++

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}

++	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -984,6 +1079,9 @@
+ SINT32 zDrvExtAudio_Reset()

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1000,6 +1098,9 @@
+ SINT32 zDrvExtAudio_Close()

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1017,6 +1118,9 @@
+ SINT32 zDrvExtAudio_Write_Prepare(T_ZDrvI2S_Cfg *i2sCfg, T_ZDrvTdm_Cfg *tdmCfg)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1035,6 +1139,9 @@
+                                 T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1052,6 +1159,9 @@
+                                    T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1068,6 +1178,9 @@
+ SINT32 zDrvExtAudio_Read_Prepare(T_ZDrvI2S_Cfg *i2sCfg, T_ZDrvTdm_Cfg *tdmCfg)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1086,6 +1199,9 @@
+                                T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1103,6 +1219,9 @@
+                                   T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1119,6 +1238,9 @@
+ SINT32 zDrvExtAudio_Write(const UINT8 *pBuf, UINT32 uiLen)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1136,6 +1258,9 @@
+ SINT32 zDrvExtAudio_Read(const UINT8 **pBuf, UINT32 *uiLen)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  	

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1195,9 +1320,13 @@
+ 	return ret;

+ }

+ #endif

++

+ SINT32 zDrvExtAudio_Write_Stop()

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1215,6 +1344,9 @@
+ SINT32 zDrvExtAudio_Read_Stop()

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else	

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1232,6 +1364,9 @@
+ SINT32 zDrvExtAudio_GetBuf(UINT8 **pBuf, UINT32 *uiLen)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  	

+ #else

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1263,6 +1398,9 @@
+ SINT32 zDrvExtAudio_FreeBuf(UINT8 *pBuf)

+ {

+ 	int ret = 0;

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return ret;

++	}	

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else		

+ 	if (g_voiceVar.g_isUseTdm != 1)

+@@ -1279,6 +1417,10 @@
+ 

+ void zDrvExtAudio_RlsAllSemaBeforeStop(void)

+ {

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return;

++	}

++

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else		

+ 	if (g_voiceVar.g_isUseTdm == 1)

+@@ -1296,6 +1438,10 @@
+ 

+ void zDrvExtAudio_RxRlsSemaBeforeStop(void)

+ {

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return;

++	}

++

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else		

+ 	if (g_voiceVar.g_isUseTdm == 1)

+@@ -1311,6 +1457,10 @@
+ 

+ void zDrvExtAudio_TxRlsSemaBeforeStop(void)

+ {

++	if (g_voiceVar.useVoiceBuffer == 1){ 

++		return;

++	}

++

+ #ifdef CONFIG_VOICE_BUFFER_DRV  

+ #else		

+ 	if (g_voiceVar.g_isUseTdm == 1)

+@@ -1595,7 +1745,19 @@
+ 

+ 	ext_aRdCount = 0;

+ 	ext_aRdFBufCount = 0;

++	

++	

+ 

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_Open_Vbuffer();		

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open_Vbuffer ret=%d!\n",ret);

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open_Vbuffer useVoiceBuffer=%d voiceBufferType=%d!\n",g_voiceVar.useVoiceBuffer,g_voiceVar.voiceBufferType);

++

++	

++

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open  end!\n");

+ 

+ 	return DRV_SUCCESS;

+ 

+@@ -2282,7 +2444,7 @@
+ 		ret = ecall_Close();

+ 		if (ret != DRV_SUCCESS)

+ 		{

+-		   zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Open error,ret=%d", ret);

++		   zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s:ecall_Close error,ret=%d",__func__,ret);

+ 		}	

+ 		e_reg_flag = 0;

+ 	}

+@@ -2305,6 +2467,12 @@
+ 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: timer_cb_count %d,first_full_flag %d,first_empty_flag %d,vb_read_count %d,vb_write_count %d!\n",__FUNCTION__,timer_cb_count,first_full_flag,first_empty_flag,vb_read_count,vb_write_count);

+ #endif

+ 

++	if(g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_Close_Vbuffer();

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Close_Vbuffer ret=%d!\n",ret);

++	

++	}

+ 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: ext_aRdCount %d,ext_aRdFBufCount %d!\n",__FUNCTION__,ext_aRdCount,ext_aRdFBufCount);

+ 

+ 

+@@ -2337,176 +2505,185 @@
+ //	{

+ //		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "is the i2s loopback mode");

+ //	}

++	

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_VoiceI2sStart_Vbuffer();

++	}

++	else

++	{

++

+ #ifdef  CONFIG_VOICE_BUFFER_DRV  	

+-	ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

+-		return DRV_ERROR;

+-	}

+-	

+-	zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart VB zOss_StartTimer\n");

++		ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

++			return DRV_ERROR;

++		}

++		

++		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart VB zOss_StartTimer\n");

+ 

+-	ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

++		ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

+ 

+-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

+-	}

+-	

+-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error13:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error14:zDrvI2S_Write I2S_2 ret=%d", ret);

+-	}

++		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

++		}

++		

++		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error13:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error14:zDrvI2S_Write I2S_2 ret=%d", ret);

++		}

+ #ifdef _VBUFF_IN_MULTI_CORE

+-	voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+ 

+ #else

+-	voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+ #endif

+ #else	

+-	if (g_voiceVar.isUseSlicCodec == 1)

+-	{

+-

+-		if (s_speechState.i2sIsRstFlag == FALSE)

++		if (g_voiceVar.isUseSlicCodec == 1)

+ 		{

+-			ret = zDrvExtAudio_Reset();

+-			if (ret != DRV_SUCCESS)

++

++			if (s_speechState.i2sIsRstFlag == FALSE)

+ 			{

+-				zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvExtAudio_Reset() err ret=%d ", ret);

+-				return DRV_ERROR;

++				ret = zDrvExtAudio_Reset();

++				if (ret != DRV_SUCCESS)

++				{

++					zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvExtAudio_Reset() err ret=%d ", ret);

++					return DRV_ERROR;

++				}

++				s_speechState.i2sIsRstFlag = TRUE;

+ 			}

+-			s_speechState.i2sIsRstFlag = TRUE;

++

+ 		}

+ 

+-	}

++		ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

++			return DRV_ERROR;

++		}

+ 

+-	ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

+-		return DRV_ERROR;

+-	}

++		ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

+ 

+-	ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S1_Read_Start failed ret is %d .\n", ret);

++			zDrvI2S_Read_Stop(I2S_2);

++			return DRV_ERROR;

++		}

+ 

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S1_Read_Start failed ret is %d .\n", ret);

+-		zDrvI2S_Read_Stop(I2S_2);

+-		return DRV_ERROR;

+-	}

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read_Start  ret=%d", ret);

+ 

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read_Start  ret=%d", ret);

++		ret = zDrvI2S_Read(I2S_2, &read_buf, &read_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read I2S_2 ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_2 ret=%d", ret);

+ 

+-	ret = zDrvI2S_Read(I2S_2, &read_buf, &read_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read I2S_2 ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_2 ret=%d", ret);

++		ret = zDrvExtAudio_Read(&read_buf, &read_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_1 ret=%d", ret);

+ 

+-	ret = zDrvExtAudio_Read(&read_buf, &read_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_1 ret=%d", ret);

++		ret += zDrvExtAudio_Read_Stop();

++		ret += zDrvI2S_Read_Stop(I2S_2);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

++			return DRV_ERROR;

++		}

+ 

+-	ret += zDrvExtAudio_Read_Stop();

+-	ret += zDrvI2S_Read_Stop(I2S_2);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart first read/write stop ret=%d", ret);

+ 

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart first read/write stop ret=%d", ret);

++		ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

+ 

+-	ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

++		ret += zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+ 

+-	ret += zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

++		ret += zDrvExtAudio_Write_Start(&s_speechState.i2sWriteParam, s_speechState.pVpI2sCfg, &s_VpTdmWriteParam, s_vpState.pVpTdmCfg);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error4:zDrvI2S_Write_Start  ret=%d", ret);

++			return DRV_ERROR;

++		}

++		ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error5:zDrvI2S_GetBuf  ret=%d", ret);

++			return DRV_ERROR;

++		}

+ 

+-	ret += zDrvExtAudio_Write_Start(&s_speechState.i2sWriteParam, s_speechState.pVpI2sCfg, &s_VpTdmWriteParam, s_vpState.pVpTdmCfg);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error4:zDrvI2S_Write_Start  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error5:zDrvI2S_GetBuf  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret += zDrvExtAudio_Write(write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error6:zDrvI2S_Write  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

+-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error8:zDrvI2S_Write I2S_2 ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error9:zDrvI2S_GetBuf  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret += zDrvExtAudio_Write(write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error10:zDrvI2S_Write  ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error11:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

+-	}

++		zOss_Memset(write_buf, 0, write_len);

++		ret += zDrvExtAudio_Write(write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error6:zDrvI2S_Write  ret=%d", ret);

++			return DRV_ERROR;

++		}

++		ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

++		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error8:zDrvI2S_Write I2S_2 ret=%d", ret);

++			return DRV_ERROR;

++		}

++		ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error9:zDrvI2S_GetBuf  ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret += zDrvExtAudio_Write(write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error10:zDrvI2S_Write  ret=%d", ret);

++			return DRV_ERROR;

++		}

++		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error11:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

++		}

+ 

+ #endif

++	}

+ #ifdef ECALL_SUPPORT

+ 	if((g_voiceVar.audio_ctrlFlag.isUseEcall == 1)&&(e_reg_flag == 1))

+ 	{

+@@ -2657,18 +2834,27 @@
+ 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVp_VoiceWorkStop call voice_ToneMixerStop !\n");

+ 

+ 	g_voiceVar.vpI2sStatus = VP_I2S_OPEN;

+-#ifdef  CONFIG_VOICE_BUFFER_DRV 

+-	//complete_all(&s_voice_completion);

+-	zOss_PutSemaphore(s_voiceRdSema);

+-	zOss_PutSemaphore(s_voiceWrSema);

+-	zOss_StopTimer(s_voiceTimerId);

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVp_VoiceWorkStop zOss_StopTimer\n");

+-#else

+-	//zDrvI2s_RxRlsSemaBeforeStop(I2S_1);

+-	//zDrvI2s_TxRlsSemaBeforeStop(I2S_1);

+-	zDrvExtAudio_RlsAllSemaBeforeStop();

+-#endif

++

+ 	

++

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = zDrvVp_VoiceWorkStop_Vbuffer();

++	}

++	else

++	{	

++#ifdef  CONFIG_VOICE_BUFFER_DRV 

++		//complete_all(&s_voice_completion);

++		zOss_PutSemaphore(s_voiceRdSema);

++		zOss_PutSemaphore(s_voiceWrSema);

++		zOss_StopTimer(s_voiceTimerId);

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVp_VoiceWorkStop zOss_StopTimer\n");

++#else

++		//zDrvI2s_RxRlsSemaBeforeStop(I2S_1);

++		//zDrvI2s_TxRlsSemaBeforeStop(I2S_1);

++		zDrvExtAudio_RlsAllSemaBeforeStop();

++#endif

++	}	

+ 	zDrvI2s_RxRlsSemaBeforeStop(I2S_2);

+ 	zDrvI2s_TxRlsSemaBeforeStop(I2S_2);

+ 

+@@ -2736,10 +2922,19 @@
+ 	}

+ 

+ 	g_voiceVar.vpI2sStatus = VP_I2S_INUSE;

++	

++	

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_VolteReadStart_Vbuffer();

++	}

++	else

++	{	

+ #ifdef  CONFIG_VOICE_BUFFER_DRV

+-	zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart zOss_StartTimer start\n");

+-#endif	

++		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart zOss_StartTimer start\n");

++#endif

++	}

+ 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "vp_VolteReadStart \n");

+ 

+ 	return DRV_SUCCESS;

+@@ -2748,6 +2943,15 @@
+ SINT32 vp_VolteReadStop(VOID)

+ {

+ 	SINT32  ret = DRV_SUCCESS;

++

++	

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_VolteReadStop_Vbuffer();

++	    return ret;

++	}

++

++	

+ #ifdef  CONFIG_VOICE_BUFFER_DRV  

+ 	zOss_PutSemaphore(s_voiceRdSema);

+ #else

+@@ -2844,46 +3048,54 @@
+ 	}

+ 

+ 	g_voiceVar.vpI2sStatus = VP_I2S_INUSE;

++	

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		vp_VolteWriteStart_Vbuffer();	

++	}

++	else

++	{

+ #ifdef  CONFIG_VOICE_BUFFER_DRV  

+ #ifdef _VBUFF_IN_MULTI_CORE

+-	voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+ 

+ #else

+-	voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

++		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+ #endif

+ #else

+-	ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error1:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

+-		zDrvExtAudio_Write_Stop();

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret = zDrvExtAudio_Write(write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error2:zDrvI2S_Write I2S_1 ret=%d", ret);

+-		zDrvExtAudio_Write_Stop();

+-		return DRV_ERROR;

+-	}

+-	ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error3:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

+-		zDrvExtAudio_Write_Stop();

+-		return DRV_ERROR;

+-	}

+-	zOss_Memset(write_buf, 0, write_len);

+-	ret = zDrvExtAudio_Write(write_buf, write_len);

+-	if (ret != DRV_SUCCESS)

+-	{

+-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error4:zDrvI2S_Write I2S_1 ret=%d", ret);

+-		zDrvExtAudio_Write_Stop();

+-		return DRV_ERROR;

+-	}

++		ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error1:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

++			zDrvExtAudio_Write_Stop();

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret = zDrvExtAudio_Write(write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error2:zDrvI2S_Write I2S_1 ret=%d", ret);

++			zDrvExtAudio_Write_Stop();

++			return DRV_ERROR;

++		}

++		ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error3:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

++			zDrvExtAudio_Write_Stop();

++			return DRV_ERROR;

++		}

++		zOss_Memset(write_buf, 0, write_len);

++		ret = zDrvExtAudio_Write(write_buf, write_len);

++		if (ret != DRV_SUCCESS)

++		{

++			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error4:zDrvI2S_Write I2S_1 ret=%d", ret);

++			zDrvExtAudio_Write_Stop();

++			return DRV_ERROR;

++		}

+ #endif

+-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "vp_VolteWriteStart \n");

++	}

++	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "vp_VolteWriteStart end\n");

+ 

+ 	return DRV_SUCCESS;

+ }

+@@ -2891,6 +3103,13 @@
+ SINT32 vp_VolteWriteStop(VOID)

+ {

+ 	SINT32  ret = DRV_SUCCESS;

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_VolteWriteStop_Vbuffer();

++	    return ret;

++	}

++

++

+ 

+ #ifdef  CONFIG_VOICE_BUFFER_DRV  

+ 	//complete_all(&s_voice_completion);

+@@ -2961,6 +3180,11 @@
+ 	//UINT8 *pVoiceTempBuf = s_voiceTempBuffer;

+ #endif

+ 

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_WriteDataToCodec_Vbuffer(pBuf, count);

++	    return ret;

++	}

+ 

+ 

+ 	if (pBuf == NULL)

+@@ -3285,6 +3509,14 @@
+ 	UINT8 *ptemp8bit = NULL;

+ #endif

+ 

++	if (g_voiceVar.useVoiceBuffer == 1)

++	{

++		ret = vp_ReadDataFromCodec_Vbuffer(pBuf, count);

++	    return ret;

++	}

++

++

++

+ 	if (pBuf == NULL)

+ 	{

+ 		return DRV_ERR_INVALID_PARAM;

+@@ -3313,6 +3545,8 @@
+ //	wait_for_completion_timeout(&s_voice_completion, 60);

+ 	zOss_GetSemaphore(s_voiceRdSema,  60);

+ 	#ifdef _VBUFF_IN_MULTI_CORE

++

++	

+ 	voice_buffer_read(s_speechState.pVpTempTxInBuffer,  s_speechState.totalFrameBufSize);

+ 

+ 	#else

+@@ -3911,11 +4145,14 @@
+ 

+ SINT32 vp_CreateThreadSemaph(VOID)

+ {

++	SINT32 ret = 0;

++

+ 	s_vpState.vpSemaphore = zOss_CreateSemaphore("VpI2sReadWriteSemaphore", 0);

+ #ifdef _USE_WEBRTC_AUD

+ 	s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 8192, 15, 0, 1);

+ #else

+-	s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 1024, 15, 0, 1);

++	//s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 1024, 15, 0, 1);

++	s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 8192, 15, 0, 1);	

+ #endif

+ 

+ #ifdef  _OS_TOS

+@@ -3937,6 +4174,9 @@
+ 		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create vp Thread sem err s_vpState.vpThread=%p,s_vpState.vpSemaphore=%p !\r\n", s_vpState.vpThread, s_vpState.vpSemaphore);

+ 		return DRV_ERROR;

+ 	}

++

++

++

+ #ifdef CONFIG_VOICE_BUFFER_DRV  	

+ //	init_completion(&s_voice_completion);

+ 	s_voiceRdSema = zOss_CreateSemaphore("voice_rx_sem", 0);

+@@ -3959,50 +4199,57 @@
+ 		return DRV_ERROR;

+ 	}

+ #ifdef _VBUFF_IN_MULTI_CORE

+-		SINT32 ret = 0;

++	//SINT32 ret = 0;

+ 

+-		//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

+-		ret = zDrvRpMsg_CreateChannel_Cap(RPMSG_CAP_ID,channel_41,0x10);

++	//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

++	ret = zDrvRpMsg_CreateChannel_Cap(RPMSG_CAP_ID,channel_41,0x10);

+ 

+-		if(DRV_SUCCESS != ret) {

+-			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create rpmsg err(%d) \n",ret);

+-			return DRV_ERROR;

+-		}

++	if(DRV_SUCCESS != ret) {

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create rpmsg err(%d) \n",ret);

++		return DRV_ERROR;

++	}

++	

++	volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

++	volatile unsigned int rpMsgBuf[2] = {0,0}; 

++	//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

++	icp_pMsg.actorID = RPMSG_CAP_ID;

++	icp_pMsg.chID = channel_41;

++	icp_pMsg.flag &= ~RPMSG_READ_POLL;

++	icp_pMsg.buf = rpMsgBuf;

++	icp_pMsg.len = 8;

++	ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

++	if(ret <= 0){

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

++		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+ 		

+-		volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

+-		volatile unsigned int rpMsgBuf[2] = {0,0}; 

+-		//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

+-		icp_pMsg.actorID = RPMSG_CAP_ID;

+-		icp_pMsg.chID = channel_41;

+-		icp_pMsg.flag &= ~RPMSG_READ_POLL;

+-		icp_pMsg.buf = rpMsgBuf;

+-		icp_pMsg.len = 8;

+-		ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

+-		if(ret <= 0){

+-			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+-			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+-			

+ 

+-		}

+-		else{

+-			#if 0

++	}

++	else{

++		#if 0

+ 

+-			voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

+-			voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

+-			#else

++		voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

++		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

++		#else

+ 

+-			voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+-			voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

+-			#endif

+-	

+-			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

++		voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

++		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

++		#endif

++

++		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

++		,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

++		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+ 			,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+-			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+-				,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+-		}

++	}

+ #endif

++

++#else

++    //flag ctrl voicebuffer func

++	vp_CreateThreadSemaph_Vbuffer();

++

++

+ #endif

+-	

++

++

+ 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_CreateThreadSemaph success. \r\n");

+ 	return DRV_SUCCESS;

+ }

+diff --git a/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/makefile b/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/makefile
+old mode 100644
+new mode 100755
+index 67080f1..b775a15
+--- a/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/makefile
++++ b/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/makefile
+@@ -32,6 +32,7 @@
+  			-I$(CHIP_SRC_PATH)/audio_base/webrtc/signal_processing/include \

+  			-I$(CHIP_SRC_PATH)/audio_base/webrtc/aecm/interface \

+  			-I$(CHIP_SRC_PATH)/audio_base/webrtc/ns \

++ 			-I$(CHIP_SRC_PATH)/audio_base/webrtc/ns/interface \

+  			-I$(CHIP_SRC_PATH)/audio_base/webrtc/agc/interface \

+  			-I$(DRV_PATH)/src/chipsets/inc \

+ 			-I$(CHIP_SRC_PATH)/audio_base/include \

+diff --git a/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/webrtc_refintf.c b/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/webrtc_refintf.c
+index ea41162..da7b26a 100755
+--- a/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/webrtc_refintf.c
++++ b/ps/driver/src/chipsets/src/audio_base/webrtc/webrtc_ref/webrtc_refintf.c
+@@ -26,8 +26,10 @@
+ #include "NvParam_drv.h"
+ #include "RWNvConfig.h"
+ #ifdef USE_WEBRTC_NSX
++#include "noise_suppression_x.h"
+ #include "nsx_core.h"
+ #else
++#include "noise_suppression.h"
+ #include "ns_core.h"
+ #endif
+ /****************************************************************************
+@@ -356,7 +358,11 @@
+ 		if (ret != 0)
+ 		{
+ 			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "WebRtcNs_Init ret=%d !\r\n", ret);
++#ifdef USE_WEBRTC_NSX
++			WebRtcNsx_Free(*nsInst);
++#else
+ 			WebRtcNs_Free(*nsInst);
++#endif			
+ 			*nsInst = NULL;
+ 			return DRV_ERROR;
+ 		}
diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/Makefile b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/Makefile
new file mode 100755
index 0000000..0f14425
--- /dev/null
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/Makefile
@@ -0,0 +1,32 @@
+include $(COMMON_MK)
+
+EXEC = vb_demo
+OBJS = vb_demo.o
+
+CFLAGS += -I.
+CFLAGS += -I./inc
+CFLAGS += -I$(APP_DIR)/include
+
+
+CFLAGS += -g
+CFLAGS += -g -Werror=implicit-function-declaration
+
+LDLIBS += -lpthread
+LDLIBS += -lvoice -L$(LIB_DIR)/libvoice
+
+all: $(EXEC)
+$(EXEC)all: $(EXEC)
+
+$(EXEC): $(OBJS)
+	$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) -Wl,--end-group
+	@cp $@ $@.elf
+
+romfs:
+	$(ROMFSINST) -e  /sbin/$(EXEC)
+	
+clean:
+	-rm -f $(EXEC) *.elf *.gdb *.o
+
+	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS$(LDLIBS_$@))
+
+
diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/vb_demo.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/vb_demo.c
new file mode 100755
index 0000000..4b5b9bb
--- /dev/null
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/vb_demo/vb_demo.c
@@ -0,0 +1,778 @@
+#ifdef USE_CAP_SUPPORT

+#include <stdio.h>

+#include <unistd.h>

+#include <string.h>

+#include <stdlib.h>

+#include <stdint.h>

+#include <sys/ioctl.h>

+#include <fcntl.h>

+//#include "voice_ipc.h"

+#include "voice_lib.h"

+#include <fcntl.h>

+#include <signal.h>

+#include <semaphore.h>

+#include <sys/types.h>

+#include <pthread.h>

+

+/*command max len*/

+#define VOICE_CMD_MAX_LEN 64

+

+#define EXIT_CMD_STOP	"stop\n"

+#define EXIT_CMD_Q	"q\n"

+#define EXIT_CMD_EXIT   "exit\n"

+

+#define REQ_VOICE_BUFFER_TEST_START        "voice_buffer_test_start"

+#define REQ_VOICE_BUFFER_TEST_STOP         "voice_buffer_test_stop"

+#define REQ_VOICE_BUFFER_LOOP_TEST_START        "voice_buffer_loop_test_start"

+#define REQ_VOICE_BUFFER_LOOP_TEST_STOP         "voice_buffer_loop_test_stop"

+#define REQ_VOICE_BUFFER_RTP_TEST_START        "voice_buffer_rtp_test_start"

+#define REQ_VOICE_BUFFER_RTP_TEST_STOP         "voice_buffer_rtp_test_stop"

+

+

+  

+#define VBUFFER_TX_FILE_NAME "/mnt/userdata/tx.pcm"

+#define VBUFFER_RX_FILE_NAME "/mnt/userdata/rx.pcm"

+#define VBUFFER_TX16_FILE_NAME "/mnt/userdata/tx16.pcm"

+#define VBUFFER_RX16_FILE_NAME "/mnt/userdata/rx16.pcm"

+

+

+#define VB_MAX_INT	     0x7fffffff

+#define VB_MIN_INT        0 

+#define VB_INT_OVERFLOW(x) if((x < VB_MIN_INT)||(x > VB_MAX_INT))  x = 0;

+ 

+#define RX_FILE_LEN_MAX 0x100000  

+

+

+

+typedef int (vb_thread_proc)(void*);

+struct vbuf_info_t

+{

+	int fd;

+    pthread_t	    rx_test_thread;	

+    pthread_t	    tx_test_thread;

+	pthread_t	    loop_test_thread;

+	int quit;

+	char        	*tx_buf;

+    char        	*rx_buf;

+	int buf_size;

+	char *tx_filename;

+	char *rx_filename;

+    FILE *tx_file;

+	FILE *rx_file;

+    int tx_filesize;

+	int rx_filesize;		

+	int fs;	 	

+};

+

+static struct vbuf_info_t vbuf_rec;

+

+static void printUsage(const char *Opt)

+{

+    printf("Usage: %s\n", Opt);

+     

+    printf("voice_buffer_test_start                      value: 8000,16000\n");

+    printf("voice_buffer_test_stop                       no value input\n");

+	printf("voice_buffer_loop_test_start                      value: 8000,16000\n");

+    printf("voice_buffer_loop_test_stop                       no value input\n");

+    printf("\n");

+}

+

+static int vbuffer_start_flag = 0;

+static int tx_optcount = 0;

+static int rx_optcount = 0;	

+static int first_rderr_flag = 0;

+static int first_wrerr_flag = 0;

+

+

+

+//whole rx path

+static int vb_rx_test_thread_func(void *arg)

+{

+    int ret;

+

+    char* buf = vbuf_rec.rx_buf;

+    int size = vbuf_rec.buf_size;

+    int bytes_read = 0;

+    int r_size;

+

+ 

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

+    memset (buf,0, size);

+    

+    while (!vbuf_rec.quit) 

+    {

+		rx_optcount ++;	

+		VB_INT_OVERFLOW(rx_optcount);

+		if((rx_optcount%1000) == 0){

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

+

+		}

+		else if(rx_optcount == 1000000){

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

+			rx_optcount = 0;

+			

+		}

+

+        //read form ps

+		r_size = voice_buffer_read(vbuf_rec.fd, buf, size);

+        if(r_size <= 0) 

+        {

+            first_rderr_flag++;			

+			VB_INT_OVERFLOW(first_rderr_flag);			

+            continue ;

+        }

+		else{

+			first_rderr_flag = 0;

+

+		}

+		

+        if(vbuf_rec.rx_file != NULL) 

+        {

+			r_size = fwrite(buf, 1,size, vbuf_rec.rx_file);

+

+		    if (r_size != size) {

+		        //printf("Error fwrite size not eq,r_size=%d,size=%d\n",r_size,size);

+		    }

+			else{

+			

+		        bytes_read += size;

+				if(bytes_read >= vbuf_rec.rx_filesize){

+					fseek(vbuf_rec.rx_file, 0, SEEK_SET);

+					bytes_read = 0;

+					printf("fwrite over write maxsize(%d)!!!\n",vbuf_rec.rx_filesize);

+				

+				}

+			}

+        }

+		

+		

+    }

+    

+    return 0;

+}

+

+static int vb_tx_test_thread_func(void *arg)

+{

+    int ret;

+    int num_read;

+

+	

+    char* buf = vbuf_rec.tx_buf;

+	

+    int size = vbuf_rec.buf_size;

+     int w_size;

+

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

+ 

+	

+    memset(buf, 0,size);    

+    while (!vbuf_rec.quit) 

+    {

+

+	    if(vbuf_rec.tx_file != NULL) 

+	    {

+

+	        num_read = fread(buf,1,size, vbuf_rec.tx_file);

+			

+	        if (num_read != size) {

+		        //printf("Error fread size not eq,num_read=%d,size=%d\n",num_read,size);

+			}

+	        if (num_read <= 0) {

+		        printf("Error fread size not eq,num_read=%d,size=%d\n",num_read,size); 

+				fseek(vbuf_rec.tx_file, 0, SEEK_SET);

+			}

+	    }			

+		tx_optcount ++;

+		VB_INT_OVERFLOW(tx_optcount);

+		

+		w_size = voice_buffer_write(vbuf_rec.fd, buf, size);

+        if(w_size <= 0) 

+        {

+        	first_wrerr_flag++;

+			

+			VB_INT_OVERFLOW(first_wrerr_flag);

+			

+            continue;

+        }

+		else{

+			first_wrerr_flag = 0;

+

+		}

+

+    }

+    return 0;

+}

+

+

+static int vb_thread_create( const char *name,pthread_t	*thread_t, vb_thread_proc *proc, 

+								int stack_size, unsigned priority,void *arg )

+{

+    pthread_attr_t thread_attr;

+    int ret;

+	int default_size;

+    

+    struct sched_param    param;

+    int  policy = SCHED_FIFO;

+    

+    printf("%s: start! \n",__func__);

+    

+    /* Init thread attributes */

+    pthread_attr_init(&thread_attr);    

+    /* Create the thread. */

+

+    ret = pthread_create( thread_t, &thread_attr,proc, arg);

+    if (ret != 0) 

+    {

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

+    

+    	pthread_attr_destroy(&thread_attr);

+        return ret;

+    }

+	

+    pthread_attr_getstacksize(&thread_attr, &default_size);

+    printf("%s: pthread_attr_getstacksize(%d)! \n",__func__,default_size);

+    

+    pthread_attr_destroy(&thread_attr);

+	

+    printf("%s: end \n",__func__);

+    return 0;

+}

+

+

+int voice_buffer_stream_test_start(int fs)

+{

+    int ret = 0;

+    int buf_size = 320;

+	tx_optcount = 0;

+	rx_optcount = 0;	

+    int* buf_int;

+

+	int i;

+

+	if(vbuffer_start_flag == 1){ 

+		printf(" VB already start,return \n");

+

+		return 0;

+	}

+

+	vbuffer_start_flag = 1;

+

+

+

+	if((vbuf_rec.fd != -1)&&(vbuf_rec.fd != 0)){

+		printf(" VB fd already get, vbuf_rec.fd=%d return \n",vbuf_rec.fd);

+	}

+

+	if(fs == 8000){

+

+		buf_size = 320;

+	}

+	else if(fs == 16000){

+

+		buf_size = 640;

+	}	

+	else

+	{

+		buf_size = 320;

+	}

+ 	printf("Starting vb stream fs=%d buf_size=%d \n",fs,buf_size);

+

+ 	printf("%s:open tx and rx file \n",__func__);

+	if(fs == 8000){

+

+   		vbuf_rec.tx_filename = VBUFFER_TX_FILE_NAME;//"/cache/tx.pcm";

+    	vbuf_rec.rx_filename = VBUFFER_RX_FILE_NAME;//"/cache/rx.pcm";

+

+	}

+	else if(fs == 16000){

+

+    	vbuf_rec.tx_filename = VBUFFER_TX16_FILE_NAME;//"/cache/tx16.pcm";

+    	vbuf_rec.rx_filename = VBUFFER_RX16_FILE_NAME;//"/cache/rx16.pcm";

+

+	}	

+	else

+	{

+		vbuf_rec.tx_filename = VBUFFER_TX_FILE_NAME;//"/cache/tx.pcm";

+		vbuf_rec.rx_filename = VBUFFER_RX_FILE_NAME;//"/cache/rx.pcm";

+

+	}

+

+

+

+	

+    vbuf_rec.tx_file = fopen(vbuf_rec.tx_filename , "rb");

+    if (!vbuf_rec.tx_file) {

+        printf("Unable to open file '%s'\n", vbuf_rec.tx_filename);

+        //return -1;

+    }

+

+

+    vbuf_rec.rx_file = fopen(vbuf_rec.rx_filename, "wb");

+    if (!vbuf_rec.rx_file) {

+        printf(stderr, "Unable to create file '%s'\n", vbuf_rec.rx_filename);

+		//fclose(vbuf_rec.tx_file);

+ 

+        //return -1;

+    }

+	vbuf_rec.rx_filesize = RX_FILE_LEN_MAX;	

+	printf("%s : vbuf_rec.rx_filesize(%d) \n",__func__,vbuf_rec.rx_filesize);

+

+    vbuf_rec.rx_buf = (char*) malloc(buf_size);

+	if(!vbuf_rec.rx_buf) {

+		printf("%s : malloc buf fail,return \n",__func__);

+		goto err;

+	}	

+    vbuf_rec.tx_buf = (char*) malloc(buf_size);  

+	if(!vbuf_rec.tx_buf) {

+		free(vbuf_rec.rx_buf);

+		printf("%s : malloc buf fail,return \n",__func__);

+	    vbuf_rec.rx_buf = NULL;

+		goto err;

+	}	

+	vbuf_rec.buf_size = buf_size;

+	

+    vbuf_rec.quit = 0;

+	

+	printf("%s : vb open start \n",__func__);

+

+	

+    vbuf_rec.fd = voice_buffer_open();

+	if(vbuf_rec.fd <= 0){

+		printf("%s : vb open fail fd=%d,return \n",__func__,vbuf_rec.fd);

+		ret = -1;

+		goto err;

+		

+	}

+	printf("%s :voice_buffer_open end \n",__func__);

+	

+	printf("%s :rx tx vb_thread_create start \n",__func__);

+    ret = vb_thread_create ("vb_playback_test",&vbuf_rec.rx_test_thread, vb_rx_test_thread_func, 

+    							4*1024,35,NULL);

+    if (ret != 0)

+    {

+		printf("%s :rx vb_thread_create fail ret=%d,return \n",__func__,ret);    

+		goto err;

+    }

+

+	printf("%s :rx vb_thread_create end \n",__func__);

+

+    ret = vb_thread_create ( "vbuf_record_test", &vbuf_rec.tx_test_thread, vb_tx_test_thread_func,

+    							4*1024,35,NULL);

+    if (ret != 0) 

+    {

+    

+		printf("%s :tx vb_thread_create fail ret=%d,return \n",__func__,ret);

+        vbuf_rec.quit = 1;

+        pthread_join(vbuf_rec.rx_test_thread,NULL);

+        vbuf_rec.rx_test_thread = NULL;

+		goto err;

+    }

+	printf("%s :tx vb_thread_create end \n",__func__);

+

+     return 0;

+

+err:

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+	

+	fclose(vbuf_rec.tx_file);

+	vbuf_rec.tx_file = NULL;

+	fclose(vbuf_rec.rx_file);

+	vbuf_rec.rx_file = NULL;

+	

+    return ret;

+}

+

+

+//Stop stream

+int voice_buffer_stream_test_stop(void)

+{

+    int ret = 0;

+	printf("%s:rx tx thread exit start \n",__func__);

+	if(vbuf_rec.quit == 1) {

+		printf("%s,already stop ,return\n",__func__);

+

+	}

+    

+    vbuf_rec.quit = 1;

+	voice_buffer_stop(vbuf_rec.fd);

+    if (vbuf_rec.tx_test_thread) 

+    {

+        pthread_join (vbuf_rec.tx_test_thread,NULL);

+        vbuf_rec.tx_test_thread = NULL;

+		

+    }

+    

+    if (vbuf_rec.rx_test_thread) 

+    {	

+        pthread_join (vbuf_rec.rx_test_thread,NULL);

+        vbuf_rec.rx_test_thread = NULL;

+    }

+	

+    printf("voice_buffer_close start \n");

+    ret = voice_buffer_close(vbuf_rec.fd); 

+    if(ret != 0) 

+    {

+		printf("%s : vb close fail \n",__func__);

+    }

+	vbuf_rec.fd = -1;

+	

+	if(vbuf_rec.tx_file != NULL) 

+	{

+		fclose(vbuf_rec.tx_file);

+		printf("%s : vb close ,close tx file \n",__func__);

+		vbuf_rec.tx_file = NULL;

+	}

+		

+	if(vbuf_rec.rx_file != NULL) 

+	{

+

+		fclose(vbuf_rec.rx_file);

+		printf("%s : vb close ,close rx file \n",__func__);

+		vbuf_rec.rx_file = NULL;

+		

+	}

+

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+

+

+	vbuffer_start_flag = 0;	

+    printf("Stopping vb stream end\n");

+    return 0;

+}

+

+

+static int vb_loop_test_thread_func(void *arg)

+{

+    int ret;

+

+    char* buf = vbuf_rec.rx_buf;

+    int size = vbuf_rec.buf_size;

+

+	//char* buf = vbuf_rec.tx_buf;

+	

+    //int size = vbuf_rec.buf_size;

+    int w_size;

+    int r_size;

+

+ 

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

+    memset (buf,0, size);

+    

+    while (!vbuf_rec.quit) 

+    {

+		rx_optcount ++;	

+		VB_INT_OVERFLOW(rx_optcount);

+		if((rx_optcount%1000) == 0){

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

+

+		}

+		else if(rx_optcount == 1000000){

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

+			rx_optcount = 0;

+			

+		}

+

+        //read form ps

+		r_size = voice_buffer_read(vbuf_rec.fd, vbuf_rec.rx_buf, size);

+        if(r_size <= 0) 

+        {

+            first_rderr_flag++;			

+			VB_INT_OVERFLOW(first_rderr_flag);			

+            continue ;

+        }

+		else{

+			first_rderr_flag = 0;

+		}

+        memcpy(vbuf_rec.tx_buf,vbuf_rec.rx_buf,size);

+		w_size = voice_buffer_write(vbuf_rec.fd, vbuf_rec.tx_buf, size);

+        if(w_size <= 0) 

+        {

+        	first_wrerr_flag++;

+			

+			VB_INT_OVERFLOW(first_wrerr_flag);

+			

+            continue;

+        }

+		else{

+			first_wrerr_flag = 0;

+		}

+		

+    }

+    

+    return 0;

+}

+

+

+int voice_buffer_stream_loop_test_start(int fs)

+{

+    int ret = 0;

+    int buf_size = 320;

+	tx_optcount = 0;

+	rx_optcount = 0;	

+    int* buf_int;

+

+	int i;

+

+	if(vbuffer_start_flag == 1){ 

+		printf(" VB already start,return \n");

+

+		return 0;

+	}

+

+	if((vbuf_rec.fd != -1)&&(vbuf_rec.fd != 0)){

+		printf(" VB fd already get, vbuf_rec.fd=%d return \n",vbuf_rec.fd);

+	}

+

+	vbuffer_start_flag = 1;

+

+	if(fs == 8000){

+

+		buf_size = 320;

+	}

+	else if(fs == 16000){

+

+		buf_size = 640;

+	}	

+	else

+	{

+		buf_size = 320;

+	}

+ 	printf("Starting vb stream fs=%d buf_size=%d \n",fs,buf_size);

+

+    vbuf_rec.rx_buf = (char*) malloc(buf_size);

+	if(!vbuf_rec.rx_buf) {

+		printf("%s : malloc buf fail,return \n",__func__);

+		return -1;

+	}	

+    vbuf_rec.tx_buf = (char*) malloc(buf_size);  

+	if(!vbuf_rec.tx_buf) {

+		free(vbuf_rec.rx_buf);

+		printf("%s : malloc buf fail,return \n",__func__);

+	    vbuf_rec.rx_buf = NULL;

+		return -1;

+	}	

+	vbuf_rec.buf_size = buf_size;

+	

+    vbuf_rec.quit = 0;

+	

+	printf("%s : vb open start \n",__func__);

+

+	

+    vbuf_rec.fd = voice_buffer_open();

+	if(vbuf_rec.fd <= 0){

+		printf("%s : vb open fail fd=%d,return \n",__func__,vbuf_rec.fd);

+		ret = -1;

+		goto err;

+		

+	}	

+	printf("%s :loop vb_thread_create start \n",__func__);

+    ret = vb_thread_create ("vb_playback_test",&vbuf_rec.loop_test_thread, vb_loop_test_thread_func, 

+    							4*1024,35,NULL);

+    if (ret != 0)

+    {

+		printf("%s :rx vb_thread_create fail ret=%d,return \n",__func__,ret);    

+		goto err;

+    }

+

+	printf("%s :rx vb_thread_create end \n",__func__);

+

+     return 0;

+

+err:

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+	

+    return ret;

+}

+

+int voice_buffer_stream_loop_test_stop(void)

+{

+    int ret = 0;

+	printf("%s:loop thread exit start \n",__func__);

+	if(vbuf_rec.quit == 1) {

+		printf("%s,already stop ,return\n",__func__);

+

+	}

+    

+    vbuf_rec.quit = 1;

+	voice_buffer_stop(vbuf_rec.fd);

+    if (vbuf_rec.loop_test_thread) 

+    {

+        pthread_join (vbuf_rec.loop_test_thread,NULL);

+        vbuf_rec.tx_test_thread = NULL;

+		

+    }

+    	

+    printf("voice_buffer_close start \n");

+    ret = voice_buffer_close(vbuf_rec.fd); 

+    if(ret != 0) 

+    {

+		printf("%s : vb close fail \n",__func__);

+    }

+	vbuf_rec.fd = -1;

+	free(vbuf_rec.rx_buf);

+	vbuf_rec.rx_buf = NULL;

+

+	free(vbuf_rec.tx_buf);

+	vbuf_rec.tx_buf = NULL;

+

+

+	vbuffer_start_flag = 0;	

+    printf("Stopping vb stream end\n");

+    return 0;

+}

+

+int voice_buffer_rtp_test_start(int fs)

+{   

+    return voice_buffer_stream_test_start(fs);

+}

+

+

+

+int voice_buffer_rtp_test_stop(void)

+{   

+    return voice_buffer_stream_test_stop();

+}

+

+void voice_buffer_cmd_proc(char *cmdstr)

+{

+    int ret = 0;

+	char data[VOICE_CMD_MAX_LEN];

+	int cmdstr_len = strlen(cmdstr) -1; //-strlen("\r")

+    int value = 0;

+    int *p_value = &value;

+    

+    cmdstr[cmdstr_len] = '\0'; //+strlen("\0")

+

+	ret = sscanf(cmdstr, "%s", data);

+    if(1 != ret){

+        printf("data sscanf failed!(%d)\n", ret);

+        return;

+    }

+	if(0 == strncmp(data, REQ_VOICE_BUFFER_TEST_START, strlen(REQ_VOICE_BUFFER_TEST_START))){

+

+		ret = sscanf(cmdstr, "%*s %d", &value);

+        if(1 != ret){

+            printf("%s,value sscanf failed!(%d)\n",data, ret);

+            return;

+        }

+		

+        printf("%s set value %d\n", data, value);

+		ret = voice_buffer_stream_test_start(value);

+

+		printf("%s return ret=%d\n", data, ret);

+		

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_TEST_STOP, strlen(REQ_VOICE_BUFFER_TEST_STOP))){

+		ret = voice_buffer_stream_test_stop();

+		printf("%s return %d\n", data, ret);

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_LOOP_TEST_START, strlen(REQ_VOICE_BUFFER_LOOP_TEST_START))){

+

+		ret = sscanf(cmdstr, "%*s %d", &value);

+        if(1 != ret){

+            printf("%s,value sscanf failed!(%d)\n",data, ret);

+            return;

+        }

+		

+        printf("%s set value %d\n", data, value);

+		ret = voice_buffer_stream_loop_test_start(value);

+

+		printf("%s return ret=%d\n", data, ret);

+		

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_LOOP_TEST_STOP, strlen(REQ_VOICE_BUFFER_LOOP_TEST_STOP))){

+		printf("voice_buffer_stream_loop_test_stop \n");

+		ret = voice_buffer_stream_loop_test_stop();

+		printf("%s return %d\n", data, ret);

+	}

+    if(0 == strncmp(data, REQ_VOICE_BUFFER_RTP_TEST_START, strlen(REQ_VOICE_BUFFER_RTP_TEST_START))){

+

+		ret = sscanf(cmdstr, "%*s %d", &value);

+        if(1 != ret){

+            printf("%s,value sscanf failed!(%d)\n",data, ret);

+            return;

+        }

+		

+        printf("%s set value %d\n", data, value);

+		ret = voice_buffer_rtp_test_start(value);

+

+		printf("%s return ret=%d\n", data, ret);

+		

+	}

+	else if(0 == strncmp(data, REQ_VOICE_BUFFER_RTP_TEST_STOP, strlen(REQ_VOICE_BUFFER_RTP_TEST_STOP))){

+		ret = voice_buffer_rtp_test_stop();

+		printf("%s return %d\n", data, ret);

+	}	

+    else{

+		printf("Request unknow.\n");

+        printUsage(cmdstr);

+	}

+}

+

+void signal_handle_func(int sig)

+{

+	printf("sig(%d) signal_handle_func exit ",sig);

+	exit(0);

+}

+

+void signal_handle_func_term(int sig)

+{

+	printf("sig(%d) signal_handle_func exit ",sig);

+    voice_buffer_stream_loop_test_stop();

+    voice_buffer_stream_test_stop();

+    voice_buffer_rtp_test_stop();

+	exit(0);

+}

+

+

+int main(int argc, char **argv)

+{

+    char cmdstr[VOICE_CMD_MAX_LEN];

+    printf("voice_demo start\n");

+	

+	signal(SIGINT, signal_handle_func);

+	signal(SIGQUIT, signal_handle_func);

+	signal(SIGTERM, signal_handle_func_term);

+	signal(SIGPIPE, signal_handle_func);

+

+    memset(&vbuf_rec,0,sizeof(vbuf_rec));

+

+    while(1){

+        memset(cmdstr, 0, VOICE_CMD_MAX_LEN);

+

+        printf("Please input an voice_demo command:\n");

+

+        if(NULL != fgets(cmdstr, VOICE_CMD_MAX_LEN - 1, stdin)){

+            if(0 == strcmp(EXIT_CMD_STOP, cmdstr) || 

+                0 == strcmp(EXIT_CMD_Q, cmdstr) || 

+                0 == strcmp(EXIT_CMD_EXIT, cmdstr)){

+				break;

+			}

+            

+            printf("len:%d, cmdstr:%s\n", strlen(cmdstr), cmdstr);

+            

+            if(1 >= strlen(cmdstr)){

+				continue;

+			}

+

+            voice_buffer_cmd_proc(cmdstr);

+        }

+    }

+

+    printf("voice_demo end\n");

+    

+    return 0;

+}

+

+#endif

+

diff --git a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/voice_demo/voice_demo.c b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/voice_demo/voice_demo.c
index 3c0895d..c544c48 100755
--- a/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/voice_demo/voice_demo.c
+++ b/cap/zx297520v3/zxic_code/zxic_source/zxic_app_open/test/voice_demo/voice_demo.c
@@ -318,6 +318,7 @@
 		ret = vbuffer_stream_test_stop();

 		printf("%s return %d\n", data, ret);

 	}

+	#ifdef _VB_TRANSMIT_INTF_RTP

 	else if(0 == strncmp(data, REQ_VOICE_BUFFER_RTP_TEST_START, strlen(REQ_VOICE_BUFFER_RTP_TEST_START))){

 

 		ret = sscanf(cmdstr, "%*s %d", &value);

@@ -339,6 +340,7 @@
 		ret = vbuffer_rtp_test_stop();

 		printf("%s return %d\n", data, ret);

 	}

+#endif

 	else if(0 == strncmp(data, REQ_VOICE_BUFFER_START, strlen(REQ_VOICE_BUFFER_START))){

 

 		ret = sscanf(cmdstr, "%*s %d", &value);

diff --git a/cp/ps/driver/inc/misc/drvs_voiceprocess.h b/cp/ps/driver/inc/misc/drvs_voiceprocess.h
index 67cc84d..acceb20 100755
--- a/cp/ps/driver/inc/misc/drvs_voiceprocess.h
+++ b/cp/ps/driver/inc/misc/drvs_voiceprocess.h
@@ -283,6 +283,10 @@
 	BOOL firstRegZCATFlag; //25

 	T_Hal_EcallData	ecallData;//26

     UINT8 voice_nv_update;//27

+	UINT8 useVoiceBuffer; // 0 not use,1 use

+	UINT8 voiceBufferType; //0 single core, 1 dual core

+

+	

 } T_zDrvVoice_GbVar; //T_zDrvVoice_GbVar

 

 typedef struct

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/audio_config/audioRef_cfg.c b/cp/ps/driver/src/chipsets/src/audio_base/audio_config/audioRef_cfg.c
index 7489d52..20c1ddc 100755
--- a/cp/ps/driver/src/chipsets/src/audio_base/audio_config/audioRef_cfg.c
+++ b/cp/ps/driver/src/chipsets/src/audio_base/audio_config/audioRef_cfg.c
@@ -25,6 +25,7 @@
 #include "drvs_general.h"

 #include "drvs_i2s.h"

 #include "drvs_voiceprocess.h"

+#include "hal_voiceprocess.h"

 #include "drvs_voice_config.h"

 #include "drvs_i2c.h"

 #include "NvParam_drv.h"

@@ -132,7 +133,7 @@
 

 //#define AUDIO_USE_FIXED_ADDRESS

 

-#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

+//#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

 #define VP_INOUT_NOBAK_BUFSIZE  640

 

 /**************************************************************************

@@ -595,7 +596,8 @@
 	//ret = zDrvNand_Read(OS_FLASH_VOICE_DRV_RW_NONFAC_BASE_ADDR,  sizeof(audionvflag), ((UINT8 *)(&audionvflag)));

 	ret = zOss_NvItemRead(OS_FLASH_VOICE_DRV_RW_NONFAC_BASE_ADDR, ((UINT8 *)(&audionvflag)),  sizeof(audionvflag));

 

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " zDrvVoiceConfig_Init zOss_NvItemRead isVpParamInNv=%d,isUseSlicCodec=%d!\n", audionvflag.isVpParamInNv, audionvflag.isUseSlicCodec);

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " zDrvVoiceConfig_Init zOss_NvItemRead isVpParamInNv=%d,isUseSlicCodec=%d,isUseVoiceProc=%d,isUseTdm=%d,isUseEcall=%d!\n", audionvflag.isVpParamInNv, audionvflag.isUseSlicCodec,audionvflag.isUseVoiceProc,audionvflag.isUseTdm,audionvflag.isUseEcall);

 	//hal_TestTopI2sConfig();

 

 	if (ret != DRV_SUCCESS)

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/audiointf/hal_audextintf.c b/cp/ps/driver/src/chipsets/src/audio_base/audiointf/hal_audextintf.c
index dff7364..db57346 100755
--- a/cp/ps/driver/src/chipsets/src/audio_base/audiointf/hal_audextintf.c
+++ b/cp/ps/driver/src/chipsets/src/audio_base/audiointf/hal_audextintf.c
@@ -193,6 +193,40 @@
 {

 	return g_voiceVar.muteEn;

 }

+

+int zDrvVp_SetVoiceProc_Wrap(int val)

+{

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: val=%d !\n",__func__,val);

+

+	g_voiceVar.audio_ctrlFlag.isUseVoiceProc = val;

+	return DRV_SUCCESS;

+}

+

+int zDrvVp_GetVoiceProc_Wrap(void)

+{

+	return g_voiceVar.audio_ctrlFlag.isUseVoiceProc;

+}

+

+int zDrvVp_SetVoiceBuffer_Wrap(int en,int type)

+{

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: en=%d,type=%d !\n",__func__,en,type);

+

+	g_voiceVar.useVoiceBuffer = en;

+	g_voiceVar.voiceBufferType = type;

+	return DRV_SUCCESS;

+}

+

+void zDrvVp_GetVoiceBuffer_Wrap(int *en,int *type)

+{

+    if((en!=NULL)&&(type!=NULL)){

+		*en = g_voiceVar.useVoiceBuffer;

+		*type = g_voiceVar.voiceBufferType;

+		

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: en=%d,type=%d !\n",__func__,*type,*en);

+    }

+}

+

+

 SINT32 zDrvVp_SetRxMute_Wrap(int enable)

 {

 	return zDrvVp_SetRxMute(enable, VOICE_DOWNLINK);

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/audiointf/voice_procintf.c b/cp/ps/driver/src/chipsets/src/audio_base/audiointf/voice_procintf.c
index 2f0e803..5146753 100644
--- a/cp/ps/driver/src/chipsets/src/audio_base/audiointf/voice_procintf.c
+++ b/cp/ps/driver/src/chipsets/src/audio_base/audiointf/voice_procintf.c
@@ -15,6 +15,10 @@
 * 	                                           Include files
 ****************************************************************************/
 #include "drvs_general.h"
+
+#include "drvs_volte.h"
+#include "drvs_voiceprocess.h"
+
 #include "drvs_ramlog.h"
 #include <oss_clib.h>
 #include <oss_kernel.h>
@@ -73,8 +77,12 @@
 
 	g_voiceVar.isUseSlicCodec = g_voiceVar.audio_ctrlFlag.isUseSlicCodec;
 	g_voiceVar.g_isUseTdm = g_voiceVar.audio_ctrlFlag.isUseTdm;
+	
+	g_voiceVar.useVoiceBuffer = g_voiceVar.audio_ctrlFlag.isUseVoiceBuffer; // 0 not use,1 use
+	g_voiceVar.voiceBufferType = g_voiceVar.audio_ctrlFlag.selVoiceBufferType;//0 single core, 1 dual core
 
-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " VoiceProc_InitNvParam isUseVoiceProc=%d,isUseSlicCodec=%d,isUseTdm=%d!\n", g_voiceVar.audio_ctrlFlag.isUseVoiceProc, g_voiceVar.isUseSlicCodec, g_voiceVar.audio_ctrlFlag.isUseTdm);
+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, " VoiceProc_InitNvParam isUseVoiceProc=%d,isUseSlicCodec=%d,isUseTdm=%d,useVoiceBuffer=%d,voiceBufferType=%d!\n", g_voiceVar.audio_ctrlFlag.isUseVoiceProc, \
+		                                  g_voiceVar.isUseSlicCodec, g_voiceVar.audio_ctrlFlag.isUseTdm,g_voiceVar.useVoiceBuffer,g_voiceVar.voiceBufferType);
 	if (g_voiceVar.audio_ctrlFlag.isUseVoiceProc == 1)
 	{
 #ifdef _USE_NXP_AUD
diff --git a/cp/ps/driver/src/chipsets/src/audio_base/i2s/hal_i2s.c b/cp/ps/driver/src/chipsets/src/audio_base/i2s/hal_i2s.c
index 983a92a..5ea7c1d 100755
--- a/cp/ps/driver/src/chipsets/src/audio_base/i2s/hal_i2s.c
+++ b/cp/ps/driver/src/chipsets/src/audio_base/i2s/hal_i2s.c
@@ -4322,6 +4322,37 @@
 */

 VOID vp_SetTopI2sConfig(VOID)

 {

+	

+

+UINT32 AmrRegBit = 0;

+

+if (g_voiceVar.useVoiceBuffer == 1){ 

+

+

+

+	/* inter loop */

+	AmrRegBit = ARM_I2S_LOOP_CFG;

+

+	AmrRegBit &= 0xfffffe07;

+	AmrRegBit |= 0x000000a8; /* 0x000000a8 loop dsp afe(loop i2s1)--arm i2s2(loop i2s2) 0x00000150 loop dsp arm(loop i2s1)--afe i2s2(loop i2s2)*/

+

+	ARM_I2S_LOOP_CFG = AmrRegBit;

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_SetTopI2sConfig ARM_I2S_LOOP_CFG=0x%x\n", ARM_I2S_LOOP_CFG);

+}

+#ifdef CONFIG_VOICE_BUFFER_DRV  

+	/* inter loop */

+	AmrRegBit = ARM_I2S_LOOP_CFG;

+

+	AmrRegBit &= 0xfffffe07;

+	AmrRegBit |= 0x000000a8; /* 0x000000a8 loop dsp afe(loop i2s1)--arm i2s2(loop i2s2) 0x00000150 loop dsp arm(loop i2s1)--afe i2s2(loop i2s2)*/

+

+	ARM_I2S_LOOP_CFG = AmrRegBit;

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_SetTopI2sConfig ARM_I2S_LOOP_CFG=0x%x\n", ARM_I2S_LOOP_CFG);

+

+#endif

+

 #if 0

 	UINT32 AmrRegBit = 0;

 	int ret;

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/include/hal_voicebuffer.h b/cp/ps/driver/src/chipsets/src/audio_base/include/hal_voicebuffer.h
new file mode 100755
index 0000000..a9fbd34
--- /dev/null
+++ b/cp/ps/driver/src/chipsets/src/audio_base/include/hal_voicebuffer.h
@@ -0,0 +1,107 @@
+/*******************************************************************************

+ * Copyright (C) 2007, ZTE Corporation.

+ *

+ * File Name:    hal_voicebuffer.h

+ * File Mark:    

+* Description:  Provide voicebuffer hal function prototype declaration and type declaration.

+ * Others:        

+ * Version:       V0.5

+ * Author:        xxq

+ * Date:          2024-07-11

+ * History 1:      

+ *     Date: 

+ *     Version:

+ *     Author: 

+ *     Modification:  add mute/read/write/loopback.

+ * History 2: 

+  ********************************************************************************/

+

+#ifndef _HAL_VOICEBUFFER_H

+#define _HAL_VOICEBUFFER_H

+

+

+/****************************************************************************

+*                                             Include files

+****************************************************************************/

+

+

+/****************************************************************************

+*                                             Macros

+****************************************************************************/

+#define VP_BUF_LENGTH  0x7FF80 //0xFFD80   //0x7FE40  //0x4df80// (0.5M  0x80000)

+#define VP_FRAME_BUFFER_SIZE 320 //20ms 800KHZ

+#define VP_I2S_BUFFER_SIZE 320

+#define VOICE_SYNC_TIMEOUT_TIME 100

+	

+	//#define VP_INOUT_BAK_BUFFER_SIZE 0x30000	// 0x60000

+#define VP_INOUT_NOBAK_BUFSIZE  640

+#define VB_MAX_INT	     0x7fffffff

+#define VB_MIN_INT        0 //(0-2<<31)//0x80000000

+	

+#define VB_INT_OVERFLOW(x) if((x < VB_MIN_INT)||(x > VB_MAX_INT))  x = 0;

+

+#define RPMSG_CAP_ID 1

+

+#define MAX_BUF_SIZE	     640

+#define MAX_BUF_NUM        3

+

+/****************************************************************************

+*                                             Types

+****************************************************************************/

+

+

+

+enum{

+	UP_LINK,

+	DOWN_LINK	

+};

+

+struct voice_ring_buffer {

+	volatile uint read_pos;

+	volatile uint write_pos;

+	volatile char data[];

+

+};

+

+

+/****************************************************************************

+*                                             Constants

+****************************************************************************/

+

+/****************************************************************************

+*                                             Global  Variables

+****************************************************************************/

+

+/****************************************************************************

+*                                             Function Prototypes

+****************************************************************************/

+

+SINT32 vp_Open_Vbuffer(void);

+

+SINT32 vp_Close_Vbuffer(void);

+

+SINT32 vp_VoiceI2sStart_Vbuffer(VOID);

+

+VOID vp_VoiceI2sStop_Vbuffer(VOID);

+

+SINT32 zDrvVp_VoiceWorkStop_Vbuffer(VOID);

+

+SINT32 vp_VolteReadStart_Vbuffer(VOID);

+//whole replace 

+SINT32 vp_VolteReadStop_Vbuffer(VOID);

+

+SINT32 vp_VolteWriteStart_Vbuffer(VOID);

+//whole replace

+SINT32 vp_VolteWriteStop_Vbuffer(VOID);

+

+SINT32 vp_WriteDataToCodec_Vbuffer(UINT8 *pBuf, UINT32 count);

+

+SINT32 vp_ReadDataFromCodec_Vbuffer(UINT8 *pBuf, UINT32 count);

+

+SINT32 vp_CreateThreadSemaph_Vbuffer(VOID);

+

+

+

+

+#endif/*_HAL_VOICEBUFFER_H*/

+

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c b/cp/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c
index 322aea4..50e28da 100644
--- a/cp/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c
+++ b/cp/ps/driver/src/chipsets/src/audio_base/tdm/hal_tdm.c
@@ -54,6 +54,7 @@
 #define TDM_DRIVER_VERSION          1

 

 //#define ARM_TDM_LOOP_SET	*((volatile unsigned int *)(ZX_SOC_SYS_BASE + 0x60))

+#define ARM_TDM_LOOP_CFG	*((volatile UINT32 *)(SOC_SYS_REG_BASE+0x60))

 

 /* version register */

 #define TDM_VERSION     				0x0104	/*TDM Version V1.4*/

@@ -2415,7 +2416,12 @@
 	memset(temp, 0, sizeof(temp));

 	tdmDmaState[TDM_RX].channel = DMA_CH_TDM_RX0;

 	tdmDmaState[TDM_RX].ch = dma_request_channel(mask, zx29_dma_filter_fn, (void*)(tdmDmaState[TDM_RX].channel));

-	

+	if(!tdmDmaState[TDM_RX].ch){

+		

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: dma_request_channel fail,  dma_id(%d).\n",__func__,tdmDmaState[TDM_RX].channel);

+		return DRV_ERR_BUSY;

+

+	}	

 	for (i = 0; i < TDM_OUT_BUF_NUM; i++) {

 		temp[i].dest_addr 	= tdmDmaState[TDM_RX].dma_phyaddr  + (tdmStream->rxLen) * i;

 		temp[i].src_addr	= ZX29_TDM_PHYS + 0x24;

@@ -2484,6 +2490,12 @@
 	memset(temp, 0, sizeof(temp));

 	tdmDmaState[TDM_TX].channel = DMA_CH_TDM_TX0;	

 	tdmDmaState[TDM_TX].ch = dma_request_channel(mask, zx29_dma_filter_fn, (void*)(tdmDmaState[TDM_TX].channel));

+	if(!tdmDmaState[TDM_TX].ch){

+		

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: dma_request_channel fail,  dma_id(%d).\n",__func__,tdmDmaState[TDM_TX].channel);

+		return DRV_ERR_BUSY;

+

+	}

 	

 	for (i = 0; i < TDM_OUT_BUF_NUM; i++) {

 		temp[i].src_addr 	= tdmDmaState[TDM_TX].dma_phyaddr + (txStream->txLen) * i;

@@ -2840,6 +2852,7 @@
 	SINT32 ret = DRV_SUCCESS;

 

 	ret = tdm_Reset();

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvTDM_Reset , ret=%d",ret);

 	

 	return ret;

 }

@@ -3751,6 +3764,21 @@
 

 VOID vp_SetTopTdmConfig(VOID)

 {

+    UINT32 AmrRegBit = 0;

+

+	/* inter loop */

+	AmrRegBit = ARM_TDM_LOOP_CFG;

+	

+	AmrRegBit &= 0xfffffe07;

+	AmrRegBit |= 0x000000a8; /* 0x000000a8 loop dsp afe(loop i2s1)--arm i2s2(loop i2s2) 0x00000150 loop dsp arm(loop i2s1)--afe i2s2(loop i2s2)*/

+

+	ARM_TDM_LOOP_CFG = AmrRegBit;

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_SetTopTDMConfig ARM_TDM_LOOP_CFG=0x%x\n", ARM_TDM_LOOP_CFG);

+	

+

+

+

 #if 0

     UINT32 AmrRegBit = 0;

 	int ret = 0;

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voicebuffer.c b/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voicebuffer.c
new file mode 100755
index 0000000..8d0e5f7
--- /dev/null
+++ b/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voicebuffer.c
@@ -0,0 +1,1065 @@
+/*******************************************************************************

+ * Copyright (C) 2007, ZTE Corporation.

+ *

+ * File Name:hal_voicebuffer.c

+ * File Mark:

+ * Description: voice buffer function.

+ * Others:

+ * Version:

+ * Author:        xxq

+ * Date:          2024-07-03

+ * History 1:

+ *     Date: 

+ *     Version:

+ *     Author:

+ *     Modification: edit for union version

+ * History 2:

+  ********************************************************************************/

+

+/****************************************************************************

+* 	                                           Include files

+****************************************************************************/

+#include "drvs_general.h"

+#include "drvs_volte.h"

+#include "drvs_i2s.h"

+#include "drvs_voiceprocess.h"

+#include "hal_voiceprocess.h"

+#include "drvs_voice_config.h"

+//#include "hal_pcmmixer.h"

+#include "NvParam_drv.h"

+#include "drvs_io_voice.h"

+#include "hal_ringdata.h"

+#include "drvs_tdm.h"

+#include "hal_dtmf_detect.h"

+#include "hal_audio_data.h"

+//#define TEST_WHITE_NOISE

+

+//#define  VB_DATA_LOSS_TEST

+#ifdef TEST_WHITE_NOISE

+#include "Fs8000_WhiteNoise_Mon.h"

+//#include "Fs8000_Sine_440Hz_Mon.h"

+#endif

+

+#include "drvs_icp.h"

+#include "drvs_rpmsg.h"

+//#include <linux/completion.h>

+#include "hal_voicebuffer.h"

+

+/****************************************************************************

+* 	                                           Local Macros

+****************************************************************************/

+//#define USE_AUDIO_RING

+//#define VP_GET_TX_ALL_DATA

+

+

+/****************************************************************************

+* 	                                           Local Types

+****************************************************************************/

+

+

+/****************************************************************************

+* 	                                           Local Constants

+****************************************************************************/

+static SINT32 vp_Get_Add_RpMsg_Vbuffer(VOID);

+

+/****************************************************************************

+* 	                                           Local Function Prototypes

+****************************************************************************/

+

+/****************************************************************************

+* 	                                          Global Constants

+****************************************************************************/

+

+

+/****************************************************************************

+* 	                                          Global Variables

+****************************************************************************/

+//static T_zDrvVp_SpeechState *s_pSpeechState = NULL;

+extern T_zDrvVp_SpeechState s_speechState;  //104 bytes

+extern T_zDrvVoice_GbVar g_voiceVar;

+extern T_zDrvVp_State s_vpState;

+

+

+#ifdef ECALL_SUPPORT

+extern int eWrErr;

+extern UINT8 e_reg_flag;

+

+#endif

+

+//for test whiteNoise

+#ifdef TEST_WHITE_NOISE

+extern UINT32 tempCount;

+extern UINT8 *pVoiceTempBuf;

+#endif

+

+

+extern T_ZDrv_VpInOutBuffer vpInOutBuffer;

+

+extern T_HalMixerToneInfo mixerToneInfo;

+

+static int vbuffer_init_flag = 0;

+

+/****************************************************************************

+* 	                                          Global Function Prototypes

+****************************************************************************/

+//aduvoice config code

+

+

+

+

+

+

+extern SINT32 voice_ToneMixerData(UINT8 *pvdata, UINT32 size, UINT8 *pmixdata);//xiu gai chu sheng ming

+extern SINT32 zDrvI2S_Read_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);//xiu gai chu sheng ming

+extern SINT32 zDrvI2S_Write_Start(T_ZDrvI2S_Id tId, T_ZDrvI2s_Params *params, T_ZDrvI2S_Cfg *ptCfg);//xiu gai chu sheng ming

+

+

+

+/****************************************************************************

+* 	                                          Function Definitions

+****************************************************************************/

+ZOSS_TIMER_ID s_voiceTimerId ;

+ZOSS_SEMAPHORE_ID s_voiceRdSema;

+ZOSS_SEMAPHORE_ID s_voiceWrSema;

+

+//#ifdef CONFIG_VOICE_BUFFER_DRV  

+//#ifdef _VBUFF_IN_MULTI_CORE

+//voice buffer use in multi core 

+//#define RPMSG_CAP_ID 1

+

+

+

+int timer_cb_count = 0;

+int first_full_flag = 0;

+int first_empty_flag = 0;

+

+int vb_read_count = 0;

+int vb_write_count = 0;

+

+

+

+struct voice_ring_buffer *voice_buff[2] = {NULL,NULL};

+

+

+

+static bool voice_buff_is_full(int read_pos, int write_pos)

+{

+

+

+	if ((write_pos - read_pos) >= 20000000) {

+		write_pos = write_pos - 20000000;

+		//voice_buff[UP_LINK]->write_pos = write_pos;

+		voice_buff[DOWN_LINK]->write_pos = write_pos;

+	}

+	return ((write_pos - read_pos) == MAX_BUF_NUM);

+}

+static bool voice_buff_is_empty(int read_pos, int write_pos)

+{

+	

+	return (write_pos == read_pos);

+}

+static int voice_buffer_write( char *buf, int count)

+{

+	int read_pos, write_pos;	

+

+

+	read_pos = voice_buff[DOWN_LINK]->read_pos;

+	write_pos = voice_buff[DOWN_LINK]->write_pos;	

+	if(vb_write_count == 0){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: first read_pos=%d write_pos=%d \n",__FUNCTION__,read_pos,write_pos);

+	}

+

+	

+	if(voice_buff_is_full(read_pos, write_pos)){

+		//zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice_buffer_read readbuffer is full \n");

+   		 first_full_flag++;

+		VB_INT_OVERFLOW(first_full_flag);

+		if(first_full_flag == 1)

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: writebuffer is full  read_pos %d,write_pos %d,vb_write_count %d,count %d\n",__FUNCTION__,read_pos,write_pos,vb_write_count,count);

+		return DRV_ERROR_FULL;

+	}

+	else {

+		vb_write_count++;	

+		

+		VB_INT_OVERFLOW(vb_write_count);

+		first_full_flag = 0;

+		zOss_Memcpy(&(voice_buff[DOWN_LINK]->data[(write_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]), buf, count);

+	

+		write_pos++;

+

+		voice_buff[DOWN_LINK]->write_pos = write_pos;

+

+	}

+	

+	return DRV_SUCCESS;

+}

+static int voice_buffer_read(char *buf, size_t count)

+{

+	int read_pos, write_pos;

+	int* buf_int;

+	int i;

+	

+	read_pos = voice_buff[UP_LINK]->read_pos;

+	write_pos = voice_buff[UP_LINK]->write_pos;

+	if(vb_read_count == 0){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: first read_pos=%d write_pos=%d \n",__FUNCTION__,read_pos,write_pos);

+	}

+

+	if ((count > 0) && (count <= MAX_BUF_SIZE))  {

+		if(voice_buff_is_empty(read_pos, write_pos)){

+			first_empty_flag++;

+			VB_INT_OVERFLOW(first_empty_flag);

+			if(first_empty_flag ==1)

+				zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"%s: readbuffer is empty,read_pos %d,write_pos %d,vb_read_count %d,count %d\n",__FUNCTION__,read_pos,write_pos,vb_read_count,count);

+			//add memset,del return . edit for  far end hear near end repreat voice pcm, FROM MBB TEST

+			

+		#ifndef  VB_DATA_LOSS_TEST

+			zOss_Memset(&(voice_buff[UP_LINK]->data[(read_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]),0, count);

+			zOss_Memset(buf,0, count);

+		#endif			

+			//return DRV_ERROR_EMPTY;

+			

+

+		}

+		else {

+			

+		    vb_read_count++; 			

+			VB_INT_OVERFLOW(vb_read_count);		

+			first_empty_flag = 0;

+			

+			zOss_Memcpy(buf, &(voice_buff[UP_LINK]->data[(read_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]), count);

+			//zOss_Memset(&(voice_buff[UP_LINK]->data[(read_pos%MAX_BUF_NUM)*MAX_BUF_SIZE]),0, count);

+

+#ifdef VB_DATA_LOSS_TEST

+

+			

+			if(vb_read_count < 5){

+				pr_info("ps :count=%d vb_read_count=%d,read_pos=%d,write_pos=%d\n",count,vb_read_count,read_pos,write_pos);

+

+			

+				buf_int =( int*) &voice_buff[UP_LINK]->data[(write_pos%MAX_BUF_NUM)*MAX_BUF_SIZE];

+				

+				for(i=0;i<(count/4);i++){

+				   //*(buf_int+i) = i;

+				   //buf_int[i] = i;

+				 if(i>0x1f)  

+					zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,"ps: *(buf_int+%d)=%d\n",i,*(buf_int+i));

+				}

+			

+			}

+#endif

+			read_pos++;

+			if(read_pos == 20000000)

+				read_pos = 0;

+			voice_buff[UP_LINK]->read_pos = read_pos;

+		}

+

+

+	}

+		

+	

+	return DRV_SUCCESS;

+}

+

+

+//voice buffer use in single core 

+extern int voicebuffer_ulqueue_read(void *buf, unsigned int size);

+extern int voicebuffer_dlqueue_write(void  *buf, unsigned int  size);

+extern void voice_inform_to_app(void);

+//static DECLARE_COMPLETION(s_voice_completion);

+//ZOSS_TIMER_ID s_voiceTimerId ;

+//ZOSS_SEMAPHORE_ID s_voiceRdSema;

+//ZOSS_SEMAPHORE_ID s_voiceWrSema;

+static void voiceTimerCallBack(SINT32 para)

+{

+

+

+	if (g_voiceVar.voiceBufferType == 1)//multi core

+	{	

+

+

+		T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

+		

+		UINT8 s = 1;

+		icp_pMsg.actorID = RPMSG_CAP_ID;

+

+		icp_pMsg.chID = channel_41;

+		icp_pMsg.flag |= RPMSG_WRITE_INT;

+		icp_pMsg.buf = (void *)&s;

+		icp_pMsg.len = 1;

+

+

+		zOss_PutSemaphore(s_voiceWrSema);

+		zOss_PutSemaphore(s_voiceRdSema);

+		//zDrvRpMsg_Write(&icp_pMsg); 

+#ifdef _USE_VEHICLE_DC	

+		zDrvRpMsg_Write_Cap(&icp_pMsg);

+#endif

+		timer_cb_count++;

+		VB_INT_OVERFLOW(timer_cb_count);

+#ifdef VB_DATA_LOSS_TEST

+

+		if((timer_cb_count%1000 ) == 0){

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s:timer_cb_count(%d)\n",__FUNCTION__,timer_cb_count);

+			if(timer_cb_count> 10000000) 

+				timer_cb_count=0;

+		}

+

+#endif

+	

+

+	}

+	else{

+

+

+

+	//	complete_all(&s_voice_completion);

+		zOss_PutSemaphore(s_voiceWrSema);

+		zOss_PutSemaphore(s_voiceRdSema);

+		voice_inform_to_app();

+	//	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voiceTimerCallBack timer=%u\n", cpu_clock(0)>>10);

+	}

+

+

+}

+

+

+

+

+

+static SINT32 vp_rxsem_count_Init(void)

+{

+	UINT32 i = 0;

+	UINT32 semCount = 0;

+	SINT32 Count = 0;

+

+	semCount = zOss_GetSemaphoreCount(s_voiceRdSema);

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_rxsem_count_Init rxSem count=%d\n",  semCount);

+

+	Count = semCount;

+	if(Count > 0)  {

+		for(i = 0; i < Count; i++) {

+			zOss_GetSemaphore(s_voiceRdSema, ZOSS_NO_WAIT);

+		}

+	}

+

+	return DRV_SUCCESS;

+}

+

+static SINT32 vp_txsem_count_Init(void)

+{

+	UINT32 i = 0;

+	UINT32 semCount = 0;

+	SINT32 Count = 0;

+

+	semCount = zOss_GetSemaphoreCount(s_voiceWrSema);

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_txsem_count_Init txSem count=%d \n",  semCount);

+

+	Count = 3 - semCount;

+	if(Count > 0) {

+		for(i = 0; i < Count; i++) {

+			zOss_PutSemaphore(s_voiceWrSema);

+		}

+	} else if(Count < 0) {

+		Count = 0 - Count;

+		for(i = 0; i < Count; i++) {

+			zOss_GetSemaphore(s_voiceWrSema, ZOSS_NO_WAIT);

+		}

+	}

+	

+	return DRV_SUCCESS;

+}

+

+

+

+

+

+SINT32 vp_Open_Vbuffer(void)

+{

+	SINT32 ret = DRV_SUCCESS;

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s:  start \n", __func__);

+	if (g_voiceVar.voiceBufferType == 1)//multi core

+	{

+ 		vp_Get_Add_RpMsg_Vbuffer();	

+		

+		vp_rxsem_count_Init();

+		vp_txsem_count_Init();

+		voice_buff[UP_LINK]->read_pos = 0;

+		voice_buff[UP_LINK]->write_pos = 0; 

+		voice_buff[DOWN_LINK]->read_pos = 0;

+		voice_buff[DOWN_LINK]->write_pos = 0; 

+		zOss_Memset(&(voice_buff[DOWN_LINK]->data[0]),0, MAX_BUF_NUM*MAX_BUF_SIZE);

+		zOss_Memset(&(voice_buff[UP_LINK]->data[0]),0, MAX_BUF_NUM*MAX_BUF_SIZE);

+		//for debug

+		timer_cb_count = 0;

+		first_full_flag = 0;

+		first_empty_flag = 0;

+

+		vb_read_count = 0;

+		vb_write_count = 0;	

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open_Vbuffer  init voice buffer val!\n");

+

+		

+	}else{

+

+	//	INIT_COMPLETION(s_voice_copletion);

+		vp_rxsem_count_Init();

+		vp_txsem_count_Init();

+	}

+

+	return DRV_SUCCESS;

+

+}

+

+

+SINT32 vp_Close_Vbuffer(void)

+{

+	SINT32 ret = DRV_SUCCESS;

+    

+	if (g_voiceVar.voiceBufferType == 1)//multi core

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: timer_cb_count %d,first_full_flag %d,first_empty_flag %d,vb_read_count %d,vb_write_count %d!\n",__FUNCTION__,timer_cb_count,first_full_flag,first_empty_flag,vb_read_count,vb_write_count);

+	}

+

+	return DRV_SUCCESS;

+}

+

+SINT32 vp_VoiceI2sStart_Vbuffer(VOID)

+{

+	SINT32 ret = DRV_SUCCESS;

+

+	UINT8 *read_buf = NULL;

+	UINT8 *write_buf = NULL;

+	UINT32 read_len = 0;

+	UINT32 write_len = 0;

+

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: start.\n",__func__);

+

+

+	ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+	if (ret != DRV_SUCCESS)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer failed ret is %d .\n", ret);

+		return DRV_ERROR;

+	}

+

+	zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

+

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer VB zOss_StartTimer\n");

+

+	ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

+

+	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+	if (ret != DRV_SUCCESS)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+		return DRV_ERROR;

+	}

+	zOss_Memset(write_buf, 0, write_len);

+	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+	if (ret != DRV_SUCCESS)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error12:zDrvI2S_Write I2S_2 ret=%d", ret);

+	}

+	

+	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+	if (ret != DRV_SUCCESS)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error13:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+		return DRV_ERROR;

+	}

+	zOss_Memset(write_buf, 0, write_len);

+	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+	if (ret != DRV_SUCCESS)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart_Vbuffer error14:zDrvI2S_Write I2S_2 ret=%d", ret);

+	}

+    

+	if (g_voiceVar.voiceBufferType == 1)//multi core

+	{

+

+		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+

+	}else{

+		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+	}

+	

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: end.\n",__func__);

+	return ret;

+}

+VOID vp_VoiceI2sStop_Vbuffer(VOID)

+{

+	SINT32 ret = DRV_SUCCESS;

+    return ret;

+}

+

+

+

+SINT32 zDrvVp_VoiceWorkStop_Vbuffer(VOID)

+{

+	SINT32  ret = DRV_SUCCESS;

+

+	//complete_all(&s_voice_completion);

+	zOss_PutSemaphore(s_voiceRdSema);

+	zOss_PutSemaphore(s_voiceWrSema);

+	zOss_StopTimer(s_voiceTimerId);

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: zOss_StopTimer\n",__func__);

+

+

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: success",__func__);

+	return DRV_SUCCESS;

+}

+

+

+SINT32 vp_VolteReadStart_Vbuffer(VOID)

+{

+	SINT32 ret = DRV_SUCCESS;

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart_Vbuffer start\n");

+    

+	zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart_Vbuffer zOss_StartTimer start\n");

+

+	return DRV_SUCCESS;

+}

+//whole replace 

+SINT32 vp_VolteReadStop_Vbuffer(VOID)

+{

+	SINT32  ret = DRV_SUCCESS;

+

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		zOss_PutSemaphore(s_voiceRdSema);

+	

+	}

+	else

+	{

+

+#ifdef  CONFIG_VOICE_BUFFER_DRV  

+		zOss_PutSemaphore(s_voiceRdSema);

+#else

+

+		//zDrvI2s_RxRlsSemaBeforeStop(I2S_1);

+		zDrvExtAudio_RxRlsSemaBeforeStop();

+

+#if 0//move to close lvwenhua 20150910

+		ret = zDrvExtAudio_Read_Stop();

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVolte_ReadStop I2S1 Stop wrong  ret=%d", ret);

+		}

+#endif

+#endif

+

+	}

+

+	if (s_speechState.volteVpCfgEnFlag == 1)

+	{

+		ret = halVpCfg_Disable();

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: halVpCfg_Enable err ret=%x !\n",__func__, ret);

+		}

+		else

+		{

+			s_speechState.volteVpCfgEnFlag = 0;

+		}

+	}

+

+	s_speechState.volteVpReadStopFlag = 1;//together control vp s_speechState

+	if ((s_speechState.volteVpWriteStopFlag == 1) && (s_speechState.volteVpReadStopFlag == 1))

+	{

+		g_voiceVar.vpI2sStatus = VP_I2S_OPEN;

+		

+		if (g_voiceVar.useVoiceBuffer == 1)

+		{

+			zOss_StopTimer(s_voiceTimerId);

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: zOss_StopTimer\n",__func__);

+		

+		}

+		else

+		{

+#ifdef  CONFIG_VOICE_BUFFER_DRV  	

+			zOss_StopTimer(s_voiceTimerId);

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStop_Vbuffer zOss_StopTimer\n");

+#endif

+	}

+	}

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: end\n",__func__);

+	return ret;

+}

+

+SINT32 vp_VolteWriteStart_Vbuffer(VOID)

+{

+	SINT32 ret = DRV_SUCCESS;

+

+	//???? for check

+	if (g_voiceVar.voiceBufferType == 1)//multi core

+	{

+		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+	}

+	else

+	{

+		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+	}

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "%s:end \n",__func__);

+

+	return ret;

+}

+//whole replace

+SINT32 vp_VolteWriteStop_Vbuffer(VOID)

+{

+	SINT32  ret = DRV_SUCCESS;

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		zOss_PutSemaphore(s_voiceWrSema);

+	

+	}

+	else

+	{

+

+#ifdef  CONFIG_VOICE_BUFFER_DRV  

+		//complete_all(&s_voice_completion);

+		zOss_PutSemaphore(s_voiceWrSema);

+#else

+		//zDrvI2s_TxRlsSemaBeforeStop(I2S_1);

+		zDrvExtAudio_TxRlsSemaBeforeStop();

+#endif

+	}

+#if 0//move to close lvwenhua 20150910

+	//wait for write drain semaphore

+#ifdef VOICE_TONE_MIXER_FUNCTION

+	voice_ToneMixerStop();

+#endif

+

+	ret = zDrvExtAudio_Write_Stop();

+	if (ret != DRV_SUCCESS)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVolte_WriteStop I2S1 Stop wrong  ret=%d", ret);

+	}

+

+	//s_VolteWriteSema = 0;

+#endif

+

+	if (s_speechState.volteVpCfgEnFlag == 1)

+	{

+		ret = halVpCfg_Disable();

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStop_Vbuffer halVpCfg_Enable err ret=%x !\n", ret);

+		}

+		else

+		{

+			s_speechState.volteVpCfgEnFlag = 0;

+		}

+	}

+

+	s_speechState.volteVpWriteStopFlag = 1;//together control vp s_speechState

+	if ((s_speechState.volteVpWriteStopFlag == 1) && (s_speechState.volteVpReadStopFlag == 1))

+	{

+		g_voiceVar.vpI2sStatus = VP_I2S_OPEN;

+		

+		if (g_voiceVar.useVoiceBuffer == 1)

+		{

+

+			zOss_StopTimer(s_voiceTimerId);

+				

+		}

+		else

+		{

+			

+#ifdef  CONFIG_VOICE_BUFFER_DRV 

+			zOss_StopTimer(s_voiceTimerId);

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStop_Vbuffer zOss_StopTimer\n");

+#endif

+		}

+	}

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStop_Vbuffer \n");

+	return ret;

+}

+

+

+/*******************************************************************************

+ * For union version

+ * Others:

+ ********************************************************************************/

+SINT32 vp_WriteDataToCodec_Vbuffer(UINT8 *pBuf, UINT32 count)

+{

+	SINT32  ret = DRV_SUCCESS;

+	SINT32  e_ret = DRV_SUCCESS;	

+	UINT8 *write_buf = NULL;

+	UINT32 write_len = 0;

+	UINT8 *e_write_buf = NULL;

+	UINT32 e_write_len = 0;

+	UINT32 i = 0, j = 0;

+#ifdef TEST_WHITE_NOISE

+	// UINT32 tempCount = 0;

+	//zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "test the white noise");

+	//UINT8 *pVoiceTempBuf = s_voiceTempBuffer;

+#endif

+

+

+

+	if (pBuf == NULL)

+	{

+		return DRV_ERR_INVALID_PARAM;

+	}

+

+	if (count != s_speechState.i2sWriteParam.buffersize)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_WriteDataToCodec_Vbuffer write data length err,count=%d,writebuffersize=%d \n", count, s_speechState.i2sWriteParam.buffersize);

+		return DRV_ERR_INVALID_PARAM;

+	}

+	#ifdef ECALL_SUPPORT	

+

+	if(e_reg_flag == 1)

+	{		

+		e_ret = update_ecall_state(DIR_RX); 

+		if (e_ret == DRV_ERR_NOT_SUPPORTED)

+		{

+			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "vp_WriteDataToCodec_Vbuffer get__ecall_state fun not register or invalid para,e_ret=%d !\n",e_ret);

+	

+		}	

+	}	

+	#endif

+

+

+

+	#ifdef TEST_WHITE_NOISE

+

+	zOss_Memcpy(s_speechState.pVpTempRxInBuffer, pVoiceTempBuf, s_speechState.totalFrameBufSize);

+

+	pVoiceTempBuf += s_speechState.totalFrameBufSize;

+	tempCount += s_speechState.totalFrameBufSize;

+	if (tempCount >= 0x4df80)   //307200

+		//if(tempCount >= 0x4e200)   //320000

+	{

+		pVoiceTempBuf = s_voiceTempBuffer;

+		tempCount = 0;

+	}

+	#endif

+

+	#ifdef VOICE_TONE_MIXER_FUNCTION

+

+	if (mixerToneInfo.StartMixer == TRUE) 

+	{

+		//voice_ToneMixerData( s_speechState.pVpTempRxInBuffer);

+		if ((g_voiceVar.voiceInVolteMode == 1) && (g_voiceVar.volteIsWb == 1)) 

+		{

+			voice_ToneMixerData(s_speechState.pVpTempRxInBuffer, 640,  s_speechState.pVpTempRxInBuffer);

+		} 

+		else 

+		{

+			voice_ToneMixerData(s_speechState.pVpTempRxInBuffer, 320,  s_speechState.pVpTempRxInBuffer);

+		}

+

+	}

+

+	#endif

+	if (pBuf !=  s_speechState.pVpTempRxInBuffer)

+	{

+		zOss_Memcpy(s_speechState.pVpTempRxInBuffer, pBuf, s_speechState.totalFrameBufSize);

+	}

+    

+	if (g_voiceVar.vProcIsNormal == TRUE)

+	{

+		VoiceProc_RxProcess(& s_speechState.pVpTempRxInBuffer, & s_speechState.pVpTempRxOutPutBuffer, s_speechState.frameCount);

+	}

+	else

+	{

+		zOss_Memcpy((VOID *)(s_speechState.pVpTempRxOutPutBuffer), (VOID *) s_speechState.pVpTempRxInBuffer, s_speechState.totalFrameBufSize);

+	}

+	//wait_for_completion_timeout(&s_voice_completion, 60);

+	zOss_GetSemaphore(s_voiceWrSema,  60);

+	//#ifdef _VBUFF_IN_MULTI_CORE

+	if (g_voiceVar.voiceBufferType == 1)

+	{

+		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+	}

+	else

+	{			

+		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+	}

+	if (g_voiceVar.voiceInVolteMode == 1)

+	{

+		s_speechState.rxSaveLen += s_speechState.totalFrameBufSize;

+		if (s_speechState.rxSaveLen >= s_speechState.inOutBufUseSize)

+		{

+			s_speechState.rxSaveLen = 0;

+		}

+		s_speechState.pVpTempRxInBuffer = s_vpState.pVpRxInBuffer + s_speechState.rxSaveLen;

+		#ifdef _USE_VP_OUTPUT_RXOUT_DATA

+        s_speechState.pVpTempRxOutPutBuffer = s_vpState.pVpRxOutPutBuffer + s_speechState.rxSaveLen;

+		#else

+		s_speechState.pVpTempRxOutPutBuffer = s_vpState.pVpRxOutPutBuffer;

+		#endif

+	}

+

+	

+	if (s_speechState.firstWriteDataFlag == FALSE)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_WriteDataToCodec_Vbuffer first write ret=%d,tick=%d.\n", ret, zOss_GetTickCount());

+		s_speechState.firstWriteDataFlag = TRUE;

+	}

+

+	return ret;

+}

+

+

+

+SINT32 vp_ReadDataFromCodec_Vbuffer(UINT8 *pBuf, UINT32 count)

+{

+	SINT32  ret = DRV_SUCCESS;

+	UINT8 *read_buf = NULL;

+	UINT32 read_len = 0;

+

+	UINT32 i = 0, j = 0;

+#ifdef CONFIG_ARCH_ZX297520V3_CPE_SWITCH

+	UINT8 temp8bit = 0;

+	UINT8 *ptemp8bit = NULL;

+#endif

+

+	if (pBuf == NULL)

+	{

+		return DRV_ERR_INVALID_PARAM;

+	}

+

+	if (count != s_speechState.i2sReadParam.buffersize)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: read data length err,count=%d,readbuffersize=%d \n",__func__, count, s_speechState.i2sReadParam.buffersize);

+		return DRV_ERR_INVALID_PARAM;

+	}

+#ifdef ECALL_SUPPORT

+

+	if(e_reg_flag == 1)

+	{		

+		ret = update_ecall_state(DIR_TX); 

+		if (ret == DRV_ERR_NOT_SUPPORTED)

+		{

+			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "vp_ReadDataFromCodecvp_ReadDataFromCodec get__ecall_state fun not register,ret=%d !\n",ret);

+	

+		}	

+	}	

+#endif

+	

+

+//	wait_for_completion_timeout(&s_voice_completion, 60);

+	zOss_GetSemaphore(s_voiceRdSema,  60);

+	if (g_voiceVar.voiceBufferType == 1)

+	{

+		voice_buffer_read(s_speechState.pVpTempTxInBuffer,  s_speechState.totalFrameBufSize);

+

+	}

+	else

+	{

+		voicebuffer_ulqueue_read(s_speechState.pVpTempTxInBuffer,  s_speechState.totalFrameBufSize);

+	}

+	if (g_voiceVar.vProcIsNormal == TRUE)

+	{

+		VoiceProc_TxProcess(&s_speechState.pVpTempTxInBuffer, NULL, &s_speechState.pVpTempTxOutPutBuffer, s_speechState.frameCount);	

+	}

+	else

+	{

+		zOss_Memcpy((VOID *)(s_speechState.pVpTempTxOutPutBuffer), (VOID *) s_speechState.pVpTempTxInBuffer, s_speechState.totalFrameBufSize);

+	}

+

+	if (pBuf !=  s_speechState.pVpTempTxOutPutBuffer)

+	{

+		zOss_Memcpy(pBuf, s_speechState.pVpTempTxOutPutBuffer, s_speechState.totalFrameBufSize);

+	}

+	

+	if (g_voiceVar.voiceInVolteMode == 1)

+	{

+		// s_speechState.txSaveLen += VP_FRAME_BUFFER_SIZE;

+		s_speechState.txSaveLen += s_speechState.totalFrameBufSize;

+		if (s_speechState.txSaveLen >= s_speechState.inOutBufUseSize)

+		{

+			s_speechState.txSaveLen = 0;

+		}

+		s_speechState.pVpTempTxInBuffer = s_vpState.pVpTxInBuffer + s_speechState.txSaveLen;

+		s_speechState.pVpTempTxOutPutBuffer = s_vpState.pVpTxOutPutBuffer + s_speechState.txSaveLen;

+	}

+	

+	

+	if (s_speechState.firstReadDataFlag == FALSE)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_ReadDataFromCodec first read tick=%d.\n", zOss_GetTickCount());

+		s_speechState.firstReadDataFlag = TRUE;

+	}

+

+	return ret;

+}

+

+

+

+

+SINT32 vp_CreateThreadSemaph_Vbuffer(VOID)

+{

+	SINT32 ret = 0;

+//#ifdef CONFIG_VOICE_BUFFER_DRV  	

+//	init_completion(&s_voice_completion);

+    /*

+	if(vbuffer_init_flag == 1){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vbuffer already init,return! \n");

+		return DRV_SUCCESS;

+

+	}

+	*/

+	s_voiceRdSema = zOss_CreateSemaphore("voice_rx_sem", 0);

+	if(NULL == s_voiceRdSema) {

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create voice_rx_sem err \n");

+		return DRV_ERROR;

+	}

+

+	s_voiceWrSema  = zOss_CreateSemaphore("voice_tx_sem", 0);

+	if(NULL == s_voiceWrSema) {

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create voice_tx_sem err \n");

+		return DRV_ERROR;

+	}

+

+	

+ 

+	s_voiceTimerId	= zOss_CreateTimer("voice_frameTimer", voiceTimerCallBack, 0, TRUE);	 

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "s_voiceTimerId=%p\n", s_voiceTimerId);

+	if(!s_voiceTimerId)

+	{

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice_frameTimer  failed\n");

+		return DRV_ERROR;

+	}

+

+

+

+

+	//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

+#ifdef _USE_VEHICLE_DC		

+	ret = zDrvRpMsg_CreateChannel_Cap(RPMSG_CAP_ID,channel_41,0x10);

+

+	if(DRV_SUCCESS != ret) {

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create rpmsg err(%d) \n",ret);

+		return DRV_ERROR;

+	}

+/*	

+	volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

+	volatile unsigned int rpMsgBuf[2] = {0,0}; 

+	//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

+	icp_pMsg.actorID = RPMSG_CAP_ID;

+	icp_pMsg.chID = channel_41;

+	icp_pMsg.flag &= ~RPMSG_READ_POLL;

+	icp_pMsg.buf = rpMsgBuf;

+	icp_pMsg.len = 8;

+

+	

+	ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

+	if(ret <= 0){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+		

+

+	}

+	else{

+		#if 0

+

+		voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

+		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

+		#else

+

+		voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

+		#endif

+

+		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+		,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+			,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+	}

+*/	

+

+	

+#endif

+	//vbuffer_init_flag = 1;

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_CreateThreadSemaph success. \r\n");

+	return DRV_SUCCESS;

+}

+

+

+

+

+static SINT32 vp_Get_Add_RpMsg_Vbuffer(VOID)

+{

+	SINT32 ret = 0;

+//#ifdef CONFIG_VOICE_BUFFER_DRV  	

+//	init_completion(&s_voice_completion);

+    

+	if(vbuffer_init_flag == 1){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vbuffer already init,return! \n");

+		return DRV_SUCCESS;

+

+	}

+

+	//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

+#ifdef _USE_VEHICLE_DC		

+

+	volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

+	volatile unsigned int rpMsgBuf[2] = {0,0}; 

+	//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

+	icp_pMsg.actorID = RPMSG_CAP_ID;

+	icp_pMsg.chID = channel_41;

+	icp_pMsg.flag &= ~RPMSG_READ_POLL;

+	icp_pMsg.buf = rpMsgBuf;

+	icp_pMsg.len = 8;

+

+	

+	ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

+	if(ret <= 0){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+		

+

+	}

+	else{

+		#if 0

+

+		voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

+		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

+		#else

+

+		voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

+		#endif

+

+		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+		,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+			,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+

+		vbuffer_init_flag = 1;

+

+	}

+	

+

+	

+#endif

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: success. \r\n",__func__);

+	return DRV_SUCCESS;

+}

+

+

+

+

+

+

+

+

+

+

+

+

+

+

+

diff --git a/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c b/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c
index f34d0b7..3296dad 100755
--- a/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c
+++ b/cp/ps/driver/src/chipsets/src/audio_base/voiceprocess/hal_voiceprocess.c
@@ -34,9 +34,7 @@
 #include "drvs_tdm.h"

 #include "hal_dtmf_detect.h"

 #include "hal_audio_data.h"

-//#define TEST_WHITE_NOISE

 

-//#define  VB_DATA_LOSS_TEST

 #ifdef TEST_WHITE_NOISE

 #include "Fs8000_WhiteNoise_Mon.h"

 //#include "Fs8000_Sine_440Hz_Mon.h"

@@ -45,40 +43,19 @@
 #include "drvs_icp.h"

 #include "drvs_rpmsg.h"

 //#include <linux/completion.h>

+

+#include "hal_voicebuffer.h"

+

 /****************************************************************************

 * 	                                           Local Macros

 ****************************************************************************/

 //#define USE_AUDIO_RING

 //#define VP_GET_TX_ALL_DATA

 

-#define VP_BUF_LENGTH  0x7FF80 //0xFFD80   //0x7FE40  //0x4df80// (0.5M  0x80000)

-#define VP_FRAME_BUFFER_SIZE 320 //20ms 800KHZ

-#define VP_I2S_BUFFER_SIZE 320

-#define VOICE_SYNC_TIMEOUT_TIME 100

-

-#define VP_INOUT_BAK_BUFFER_SIZE 0x30000  // 0x60000

-#define VP_INOUT_NOBAK_BUFSIZE  640

-#define VB_MAX_INT	     0x7fffffff

-#define VB_MIN_INT        0 //(0-2<<31)//0x80000000

-

-#define VB_INT_OVERFLOW(x) if((x < VB_MIN_INT)||(x > VB_MAX_INT))  x = 0;

 /****************************************************************************

 * 	                                           Local Types

 ****************************************************************************/

-	typedef enum

-	{

-		VBUF_SEM = 0,//voice buffer

-		ECALL_SEM,		

-		SEM_MAX

-	} T_Sem_Owner;

 

-	typedef enum

-	{

-		DIR_RX,

-		DIR_TX, 	

-		DIR_ALL,

-		DIR_MAX

-	} T_Data_Dir_Type;

 

 /****************************************************************************

 * 	                                           Local Constants

@@ -104,7 +81,46 @@
 * 	                                          Global Variables

 ****************************************************************************/

 //static T_zDrvVp_SpeechState *s_pSpeechState = NULL;

+#if 0

 static T_zDrvVp_SpeechState s_speechState = {0};  //104 bytes

+#else

+T_zDrvVp_SpeechState s_speechState = {

+		//use for vp data process

+	.pVpTempRxInBuffer = NULL,	

+	.pVpTempTxInBuffer = NULL,	

+	.pVpTempRxOutPutBuffer = NULL,	

+	.pVpTempTxOutPutBuffer = NULL,	

+		

+	.pVpI2sCfg = NULL,	

+		

+	.vpCfgParam = {0},

+		

+	.i2sWriteParam = {0},

+	.i2sReadParam = {0},

+		

+	.frameCount = 0,

+	.totalFrameBufSize = 0,

+	.inOutBufUseSize = 0,

+	.rxSaveLen = 0,

+	.txSaveLen = 0,

+	.saveLen = 0,

+		

+	.pcmSlotNum = 0,

+	.pcmWbSecDataPosition = 0,

+		

+	.volteVpWriteStopFlag = 0,

+	.volteVpReadStopFlag = 0,

+	. volteVpCfgEnFlag = 0,

+	.firstWriteDataFlag = FALSE,

+	.firstReadDataFlag = FALSE,

+	.i2sIsRstFlag = FALSE,

+

+};

+

+

+#endif

+

+#if 0

 

 T_zDrvVoice_GbVar g_voiceVar =

 {

@@ -138,32 +154,104 @@
 #endif

     0 //27 voice_nv_update

 };

+#else

+T_zDrvVoice_GbVar g_voiceVar =

+{

+	.volteIsWb = 0,					//volteIsWb

+	.isUseSlicCodec = 0,					//isUseSlicCodec

+	.g_isUseTdm = 0,					//g_isUseTdm

+	.voiceInGsmTdMode = 0,					//voiceInGsmTdMode

+	.voiceInVolteMode = 0,					//voiceInVolteMode

+	.innerI2sIsMaster = FALSE,				//innerI2sIsMaster

+	.innerI2sIsI2sMode = TRUE,				//innerI2sIsI2sMode

+	.vpLoopRuning = FALSE,				//vpLoopRunning

+	.muteEn = FALSE,				//muteEn

+	.vProcIsNormal = FALSE,				//vProcIsNormal

+	.vpI2sStatus = VP_I2S_IDLE,		//vpI2sStatus

+	.vpPath = VP_PATH_HANDSET,	//vpPath

+	.vpLoopPath = VP_PATH_HANDSET,	//vpLoopPath

+	.vpVol = VP_VOL_3,			//vpVol

+	.voiceMode = MAX_VOICE_MODE,		//voiceMode

+	.vpInitGain = -1,					//vpInitGain

+	.audio_ctrlFlag = {0},				//audio_ctrlFlag

+	

+    .dtmfDirSel = DTMF_IDLE,			//dtmfDirSel

+    .sample_rate = 0,					//sample_rate

+    .useDtmfLoop = 0,					//useDtmfLoop

+    .muteCount = 0,					//muteCount

+    .vpLoopBkRunning = FALSE,				//vpLoopBkRunning

+	.rxMuteEn = FALSE,              //rxMuteEn

+	.firstRegZCATFlag = FALSE,

+#ifdef ECALL_SUPPORT	

+    .ecallData = {0},			    //ecallData

+#endif

+	.voice_nv_update = 0, // voice_nv_update

+	.useVoiceBuffer = 0,// 0 not use,1 use

+	.voiceBufferType = 0, //0 single core, 1 dual core

+	

+};

+

+#endif

+

+#if 0

+

 

 static T_zDrvVp_State s_vpState =

 {

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	0,

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	{0},

-	{0},

-	0,

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	NULL,

-	NULL

+	NULL,//1 pVpRxInBuffer

+	NULL,//2 pVpTxInBuffer

+	NULL,//3 pVpRxOutPutBuffer

+	NULL,//4 pVpTxOutPutBuffer

+	0,//5 inOutBufSize

+	NULL,//6 pVpInnerI2sCfg

+	NULL,//7 pVpExtI2sCfg

+	NULL,//8 pVpExtI2sWbCfg

+	NULL,//9 s_pVpTdmCfg

+	NULL,//10 s_pVpTdmWbCfg

+	NULL,//11 pVpTdmCfg

+	{0},//12 pMsg

+	{0},//13 pMsgBuf[2]

+	//0,//14

+	NULL,//15 vpThread

+	NULL,//16 rcvDtmfThread

+	NULL,//17 vpSemaphore

+	NULL,//18 vpThreadQuitSema

+	NULL,//19 vpLoopThread

+	NULL,//20 vpLoopSemaphore

+	NULL//21 vpState

 //	{0}

 };

+#else

+T_zDrvVp_State s_vpState =

+{

+	.pVpRxInBuffer = NULL,//1

+	.pVpTxInBuffer = NULL,//2

+	.pVpRxOutPutBuffer = NULL,//3

+	.pVpTxOutPutBuffer = NULL,//4

+	.inOutBufSize = 0,//5

+	.pVpInnerI2sCfg = NULL,//6

+	.pVpExtI2sCfg = NULL,//7

+	.pVpExtI2sWbCfg = NULL,//8

+	.s_pVpTdmCfg = NULL,//9

+	.s_pVpTdmWbCfg = NULL,//10

+	.pVpTdmCfg = NULL,//11

+	.pMsg = {0},//12

+	.pMsgBuf = {0},//13

+	.vpThread = NULL,//14

+	.rcvDtmfThread = NULL,//15

+	.vpSemaphore = NULL,//16

+	.vpThreadQuitSema = NULL,//17

+	.vpLoopThread = NULL,//18

+	.vpLoopSemaphore = NULL,//19

+

+	.vpState = NULL,//

+//	{0}

+};

+

+

+#endif

+

+

 

 //for test whiteNoise

 #ifdef TEST_WHITE_NOISE

@@ -271,8 +359,8 @@
 ****************************************************************************/

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #ifdef _VBUFF_IN_MULTI_CORE

-#define RPMSG_CAP_ID 1

-

+//#define RPMSG_CAP_ID 1

+#if 0

 ZOSS_TIMER_ID s_voiceTimerId ;

 ZOSS_SEMAPHORE_ID s_voiceRdSema;

 ZOSS_SEMAPHORE_ID s_voiceWrSema;

@@ -283,9 +371,22 @@
 

 int vb_read_count = 0;

 int vb_write_count = 0;

+#else

+//define in hal_voicebuffer.c

+extern ZOSS_TIMER_ID s_voiceTimerId ;

+extern ZOSS_SEMAPHORE_ID s_voiceRdSema;

+extern ZOSS_SEMAPHORE_ID s_voiceWrSema;

 

+extern int timer_cb_count;

+extern int first_full_flag;

+extern int first_empty_flag;

 

-void voiceTimerCallBack(SINT32 para)

+extern int vb_read_count;

+extern int vb_write_count;

+

+#endif

+

+static void voiceTimerCallBack(SINT32 para)

 {

 	T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

 	

@@ -316,22 +417,8 @@
 	

 //	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voiceTimerCallBack timer=%u\n", cpu_clock(0)>>10);

 }

-#define MAX_BUF_SIZE	     640

-#define MAX_BUF_NUM        3

 

-

-enum{

-	UP_LINK,

-	DOWN_LINK	

-};

-

-struct voice_ring_buffer {

-	volatile uint read_pos;

-	volatile uint write_pos;

-	volatile char data[];

-

-};

-struct voice_ring_buffer *voice_buff[2] = {NULL,NULL};

+extern struct voice_ring_buffer *voice_buff[2];

 

 

 

@@ -460,10 +547,10 @@
 extern int  voicebuffer_dlqueue_write(void  *buf, unsigned int  size);

 extern void voice_inform_to_app(void);

 //static DECLARE_COMPLETION(s_voice_completion);

-ZOSS_TIMER_ID s_voiceTimerId ;

-ZOSS_SEMAPHORE_ID s_voiceRdSema;

-ZOSS_SEMAPHORE_ID s_voiceWrSema;

-void voiceTimerCallBack(SINT32 para)

+extern ZOSS_TIMER_ID s_voiceTimerId ;

+extern ZOSS_SEMAPHORE_ID s_voiceRdSema;

+extern ZOSS_SEMAPHORE_ID s_voiceWrSema;

+static void voiceTimerCallBack(SINT32 para)

 {

 //	complete_all(&s_voice_completion);

 	zOss_PutSemaphore(s_voiceWrSema);

@@ -476,7 +563,7 @@
 

 #endif

 

-SINT32 vp_rxsem_count_Init(void)

+static SINT32 vp_rxsem_count_Init(void)

 {

 	UINT32 i = 0;

 	UINT32 semCount = 0;

@@ -495,7 +582,7 @@
 	return DRV_SUCCESS;

 }

 

-SINT32 vp_txsem_count_Init(void)

+static SINT32 vp_txsem_count_Init(void)

 {

 	UINT32 i = 0;

 	UINT32 semCount = 0;

@@ -522,6 +609,7 @@
 #endif

 

 

+

 #ifdef ECALL_SUPPORT

 int eWrErr = 0;

 UINT8 e_reg_flag = 0;

@@ -533,6 +621,7 @@
 T_Ecall_State preEcallRxSta = 0;

 T_Ecall_State preEcallTxSta = 0;	

 

+

 //tx

 SINT32 rdsem_count_Init(T_Sem_Owner owner)

 {

@@ -706,7 +795,7 @@
 

 	e_startCount = 0;

     e_stopCount = 0;

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Open  end!\n");

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Open bufsize=%d end!\n",bufsize);

 

 	return DRV_SUCCESS;

 

@@ -758,7 +847,7 @@
 {

 	SINT32 ret = DRV_SUCCESS;

 

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s start e_startCount=%d \n",__FUNCTION__,e_startCount);

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: start e_startCount=%d \n",__FUNCTION__,e_startCount);

 	if(g_voiceVar.ecallData.ecallSta == ECALL_ST_START)

 	{

 		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Start repeat ecallSta=%d\n",g_voiceVar.ecallData.ecallSta);

@@ -785,7 +874,7 @@
 SINT32 ecall_Stop(VOID)

 {

 	SINT32  ret = DRV_SUCCESS;

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s start e_stopCount=%d \n",__FUNCTION__,e_stopCount);

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: start e_stopCount=%d \n",__FUNCTION__,e_stopCount);

 	

 	if((g_voiceVar.ecallData.ecallSta == ECALL_ST_STOP)||(g_voiceVar.ecallData.ecallSta == ECALL_ST_CLOSE))

 	{

@@ -833,7 +922,7 @@
 	{						

 		if(dir == DIR_RX)

 		{

-			

+

 			preEcallRxSta = g_voiceVar.ecallData.ecallRxSta;

 			g_voiceVar.ecallData.ecallRxSta = ECALL_ST_RX_INUSE;

 			//zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "update_ecall_state rx state change to ecallRxSta = %d\n", g_voiceVar.ecallData.ecallRxSta);

@@ -964,9 +1053,15 @@
 	return DRV_SUCCESS;

 }

 

+

 SINT32 zDrvExtAudio_Open(T_ZDrvI2s_TransMode i2sTransMode)

 {

+

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}

+	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -984,6 +1079,9 @@
 SINT32 zDrvExtAudio_Reset()

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1000,6 +1098,9 @@
 SINT32 zDrvExtAudio_Close()

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1017,6 +1118,9 @@
 SINT32 zDrvExtAudio_Write_Prepare(T_ZDrvI2S_Cfg *i2sCfg, T_ZDrvTdm_Cfg *tdmCfg)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1035,6 +1139,9 @@
                                 T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1052,6 +1159,9 @@
                                    T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1068,6 +1178,9 @@
 SINT32 zDrvExtAudio_Read_Prepare(T_ZDrvI2S_Cfg *i2sCfg, T_ZDrvTdm_Cfg *tdmCfg)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1086,6 +1199,9 @@
                                T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1103,6 +1219,9 @@
                                   T_ZDrvTdm_Params *tdmParams, T_ZDrvTdm_Cfg *tdmCfg)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1119,6 +1238,9 @@
 SINT32 zDrvExtAudio_Write(const UINT8 *pBuf, UINT32 uiLen)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1136,6 +1258,9 @@
 SINT32 zDrvExtAudio_Read(const UINT8 **pBuf, UINT32 *uiLen)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  	

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1195,9 +1320,13 @@
 	return ret;

 }

 #endif

+

 SINT32 zDrvExtAudio_Write_Stop()

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1215,6 +1344,9 @@
 SINT32 zDrvExtAudio_Read_Stop()

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else	

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1232,6 +1364,9 @@
 SINT32 zDrvExtAudio_GetBuf(UINT8 **pBuf, UINT32 *uiLen)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  	

 #else

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1263,6 +1398,9 @@
 SINT32 zDrvExtAudio_FreeBuf(UINT8 *pBuf)

 {

 	int ret = 0;

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return ret;

+	}	

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else		

 	if (g_voiceVar.g_isUseTdm != 1)

@@ -1279,6 +1417,10 @@
 

 void zDrvExtAudio_RlsAllSemaBeforeStop(void)

 {

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return;

+	}

+

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else		

 	if (g_voiceVar.g_isUseTdm == 1)

@@ -1296,6 +1438,10 @@
 

 void zDrvExtAudio_RxRlsSemaBeforeStop(void)

 {

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return;

+	}

+

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else		

 	if (g_voiceVar.g_isUseTdm == 1)

@@ -1311,6 +1457,10 @@
 

 void zDrvExtAudio_TxRlsSemaBeforeStop(void)

 {

+	if (g_voiceVar.useVoiceBuffer == 1){ 

+		return;

+	}

+

 #ifdef CONFIG_VOICE_BUFFER_DRV  

 #else		

 	if (g_voiceVar.g_isUseTdm == 1)

@@ -1595,7 +1745,19 @@
 

 	ext_aRdCount = 0;

 	ext_aRdFBufCount = 0;

+	

+	

 

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_Open_Vbuffer();		

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open_Vbuffer ret=%d!\n",ret);

+	}

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open_Vbuffer useVoiceBuffer=%d voiceBufferType=%d!\n",g_voiceVar.useVoiceBuffer,g_voiceVar.voiceBufferType);

+

+	

+

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Open  end!\n");

 

 	return DRV_SUCCESS;

 

@@ -2282,7 +2444,7 @@
 		ret = ecall_Close();

 		if (ret != DRV_SUCCESS)

 		{

-		   zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "ecall_Open error,ret=%d", ret);

+		   zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s:ecall_Close error,ret=%d",__func__,ret);

 		}	

 		e_reg_flag = 0;

 	}

@@ -2305,6 +2467,12 @@
 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: timer_cb_count %d,first_full_flag %d,first_empty_flag %d,vb_read_count %d,vb_write_count %d!\n",__FUNCTION__,timer_cb_count,first_full_flag,first_empty_flag,vb_read_count,vb_write_count);

 #endif

 

+	if(g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_Close_Vbuffer();

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_Close_Vbuffer ret=%d!\n",ret);

+	

+	}

 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "%s: ext_aRdCount %d,ext_aRdFBufCount %d!\n",__FUNCTION__,ext_aRdCount,ext_aRdFBufCount);

 

 

@@ -2337,176 +2505,185 @@
 //	{

 //		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "is the i2s loopback mode");

 //	}

+	

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_VoiceI2sStart_Vbuffer();

+	}

+	else

+	{

+

 #ifdef  CONFIG_VOICE_BUFFER_DRV  	

-	ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

-		return DRV_ERROR;

-	}

-	

-	zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart VB zOss_StartTimer\n");

+		ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

+			return DRV_ERROR;

+		}

+		

+		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart VB zOss_StartTimer\n");

 

-	ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

+		ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

 

-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

-	}

-	

-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error13:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error14:zDrvI2S_Write I2S_2 ret=%d", ret);

-	}

+		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

+		}

+		

+		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error13:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error14:zDrvI2S_Write I2S_2 ret=%d", ret);

+		}

 #ifdef _VBUFF_IN_MULTI_CORE

-	voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

 

 #else

-	voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

 #endif

 #else	

-	if (g_voiceVar.isUseSlicCodec == 1)

-	{

-

-		if (s_speechState.i2sIsRstFlag == FALSE)

+		if (g_voiceVar.isUseSlicCodec == 1)

 		{

-			ret = zDrvExtAudio_Reset();

-			if (ret != DRV_SUCCESS)

+

+			if (s_speechState.i2sIsRstFlag == FALSE)

 			{

-				zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvExtAudio_Reset() err ret=%d ", ret);

-				return DRV_ERROR;

+				ret = zDrvExtAudio_Reset();

+				if (ret != DRV_SUCCESS)

+				{

+					zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvExtAudio_Reset() err ret=%d ", ret);

+					return DRV_ERROR;

+				}

+				s_speechState.i2sIsRstFlag = TRUE;

 			}

-			s_speechState.i2sIsRstFlag = TRUE;

+

 		}

 

-	}

+		ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

+			return DRV_ERROR;

+		}

 

-	ret = zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S2_Read_Start failed ret is %d .\n", ret);

-		return DRV_ERROR;

-	}

+		ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

 

-	ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S1_Read_Start failed ret is %d .\n", ret);

+			zDrvI2S_Read_Stop(I2S_2);

+			return DRV_ERROR;

+		}

 

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvI2S1_Read_Start failed ret is %d .\n", ret);

-		zDrvI2S_Read_Stop(I2S_2);

-		return DRV_ERROR;

-	}

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read_Start  ret=%d", ret);

 

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read_Start  ret=%d", ret);

+		ret = zDrvI2S_Read(I2S_2, &read_buf, &read_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read I2S_2 ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_2 ret=%d", ret);

 

-	ret = zDrvI2S_Read(I2S_2, &read_buf, &read_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read I2S_2 ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_2 ret=%d", ret);

+		ret = zDrvExtAudio_Read(&read_buf, &read_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_1 ret=%d", ret);

 

-	ret = zDrvExtAudio_Read(&read_buf, &read_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart zDrvI2S_Read I2S_1 ret=%d", ret);

+		ret += zDrvExtAudio_Read_Stop();

+		ret += zDrvI2S_Read_Stop(I2S_2);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

+			return DRV_ERROR;

+		}

 

-	ret += zDrvExtAudio_Read_Stop();

-	ret += zDrvI2S_Read_Stop(I2S_2);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error:zDrvI2S_Read  ret=%d", ret);

-		return DRV_ERROR;

-	}

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart first read/write stop ret=%d", ret);

 

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart first read/write stop ret=%d", ret);

+		ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

 

-	ret += zDrvExtAudio_Read_Start(&s_speechState.i2sReadParam, s_speechState.pVpI2sCfg, &s_vpTdmReadParam, s_vpState.pVpTdmCfg);

+		ret += zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

 

-	ret += zDrvI2S_Read_Start(I2S_2, &s_speechState.i2sReadParam, s_vpState.pVpInnerI2sCfg);

+		ret += zDrvExtAudio_Write_Start(&s_speechState.i2sWriteParam, s_speechState.pVpI2sCfg, &s_VpTdmWriteParam, s_vpState.pVpTdmCfg);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error4:zDrvI2S_Write_Start  ret=%d", ret);

+			return DRV_ERROR;

+		}

+		ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error5:zDrvI2S_GetBuf  ret=%d", ret);

+			return DRV_ERROR;

+		}

 

-	ret += zDrvExtAudio_Write_Start(&s_speechState.i2sWriteParam, s_speechState.pVpI2sCfg, &s_VpTdmWriteParam, s_vpState.pVpTdmCfg);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error4:zDrvI2S_Write_Start  ret=%d", ret);

-		return DRV_ERROR;

-	}

-	ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error5:zDrvI2S_GetBuf  ret=%d", ret);

-		return DRV_ERROR;

-	}

-

-	zOss_Memset(write_buf, 0, write_len);

-	ret += zDrvExtAudio_Write(write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error6:zDrvI2S_Write  ret=%d", ret);

-		return DRV_ERROR;

-	}

-	ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error8:zDrvI2S_Write I2S_2 ret=%d", ret);

-		return DRV_ERROR;

-	}

-	ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error9:zDrvI2S_GetBuf  ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret += zDrvExtAudio_Write(write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error10:zDrvI2S_Write  ret=%d", ret);

-		return DRV_ERROR;

-	}

-	ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error11:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

-	}

+		zOss_Memset(write_buf, 0, write_len);

+		ret += zDrvExtAudio_Write(write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error6:zDrvI2S_Write  ret=%d", ret);

+			return DRV_ERROR;

+		}

+		ret = zDrvI2S_Write_Start(I2S_2, &s_speechState.i2sWriteParam, s_vpState.pVpInnerI2sCfg);

+		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error7:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error8:zDrvI2S_Write I2S_2 ret=%d", ret);

+			return DRV_ERROR;

+		}

+		ret += zDrvExtAudio_GetBuf(&write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error9:zDrvI2S_GetBuf  ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret += zDrvExtAudio_Write(write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error10:zDrvI2S_Write  ret=%d", ret);

+			return DRV_ERROR;

+		}

+		ret += zDrvI2S_GetBuf(I2S_2, &write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error11:zDrvI2S_GetBuf I2S_2 ret=%d", ret);

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret = zDrvI2S_Write(I2S_2, write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VoiceI2sStart error12:zDrvI2S_Write I2S_2 ret=%d", ret);

+		}

 

 #endif

+	}

 #ifdef ECALL_SUPPORT

 	if((g_voiceVar.audio_ctrlFlag.isUseEcall == 1)&&(e_reg_flag == 1))

 	{

@@ -2657,18 +2834,27 @@
 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVp_VoiceWorkStop call voice_ToneMixerStop !\n");

 

 	g_voiceVar.vpI2sStatus = VP_I2S_OPEN;

-#ifdef  CONFIG_VOICE_BUFFER_DRV 

-	//complete_all(&s_voice_completion);

-	zOss_PutSemaphore(s_voiceRdSema);

-	zOss_PutSemaphore(s_voiceWrSema);

-	zOss_StopTimer(s_voiceTimerId);

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVp_VoiceWorkStop zOss_StopTimer\n");

-#else

-	//zDrvI2s_RxRlsSemaBeforeStop(I2S_1);

-	//zDrvI2s_TxRlsSemaBeforeStop(I2S_1);

-	zDrvExtAudio_RlsAllSemaBeforeStop();

-#endif

+

 	

+

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = zDrvVp_VoiceWorkStop_Vbuffer();

+	}

+	else

+	{	

+#ifdef  CONFIG_VOICE_BUFFER_DRV 

+		//complete_all(&s_voice_completion);

+		zOss_PutSemaphore(s_voiceRdSema);

+		zOss_PutSemaphore(s_voiceWrSema);

+		zOss_StopTimer(s_voiceTimerId);

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "zDrvVp_VoiceWorkStop zOss_StopTimer\n");

+#else

+		//zDrvI2s_RxRlsSemaBeforeStop(I2S_1);

+		//zDrvI2s_TxRlsSemaBeforeStop(I2S_1);

+		zDrvExtAudio_RlsAllSemaBeforeStop();

+#endif

+	}	

 	zDrvI2s_RxRlsSemaBeforeStop(I2S_2);

 	zDrvI2s_TxRlsSemaBeforeStop(I2S_2);

 

@@ -2736,10 +2922,19 @@
 	}

 

 	g_voiceVar.vpI2sStatus = VP_I2S_INUSE;

+	

+	

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_VolteReadStart_Vbuffer();

+	}

+	else

+	{	

 #ifdef  CONFIG_VOICE_BUFFER_DRV

-	zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart zOss_StartTimer start\n");

-#endif	

+		zOss_StartTimer(s_voiceTimerId, 20, voiceTimerCallBack, 0);

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteReadStart zOss_StartTimer start\n");

+#endif

+	}

 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "vp_VolteReadStart \n");

 

 	return DRV_SUCCESS;

@@ -2748,6 +2943,15 @@
 SINT32 vp_VolteReadStop(VOID)

 {

 	SINT32  ret = DRV_SUCCESS;

+

+	

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_VolteReadStop_Vbuffer();

+	    return ret;

+	}

+

+	

 #ifdef  CONFIG_VOICE_BUFFER_DRV  

 	zOss_PutSemaphore(s_voiceRdSema);

 #else

@@ -2844,46 +3048,54 @@
 	}

 

 	g_voiceVar.vpI2sStatus = VP_I2S_INUSE;

+	

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		vp_VolteWriteStart_Vbuffer();	

+	}

+	else

+	{

 #ifdef  CONFIG_VOICE_BUFFER_DRV  

 #ifdef _VBUFF_IN_MULTI_CORE

-	voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+		voice_buffer_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

 

 #else

-	voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

+		voicebuffer_dlqueue_write(s_speechState.pVpTempRxOutPutBuffer, s_speechState.totalFrameBufSize);

 #endif

 #else

-	ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error1:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

-		zDrvExtAudio_Write_Stop();

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret = zDrvExtAudio_Write(write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error2:zDrvI2S_Write I2S_1 ret=%d", ret);

-		zDrvExtAudio_Write_Stop();

-		return DRV_ERROR;

-	}

-	ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error3:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

-		zDrvExtAudio_Write_Stop();

-		return DRV_ERROR;

-	}

-	zOss_Memset(write_buf, 0, write_len);

-	ret = zDrvExtAudio_Write(write_buf, write_len);

-	if (ret != DRV_SUCCESS)

-	{

-		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error4:zDrvI2S_Write I2S_1 ret=%d", ret);

-		zDrvExtAudio_Write_Stop();

-		return DRV_ERROR;

-	}

+		ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error1:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

+			zDrvExtAudio_Write_Stop();

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret = zDrvExtAudio_Write(write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error2:zDrvI2S_Write I2S_1 ret=%d", ret);

+			zDrvExtAudio_Write_Stop();

+			return DRV_ERROR;

+		}

+		ret = zDrvExtAudio_GetBuf(&write_buf, &write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error3:zDrvI2S_GetBuf I2S_1 ret=%d", ret);

+			zDrvExtAudio_Write_Stop();

+			return DRV_ERROR;

+		}

+		zOss_Memset(write_buf, 0, write_len);

+		ret = zDrvExtAudio_Write(write_buf, write_len);

+		if (ret != DRV_SUCCESS)

+		{

+			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_VolteWriteStart error4:zDrvI2S_Write I2S_1 ret=%d", ret);

+			zDrvExtAudio_Write_Stop();

+			return DRV_ERROR;

+		}

 #endif

-	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "vp_VolteWriteStart \n");

+	}

+	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO,  "vp_VolteWriteStart end\n");

 

 	return DRV_SUCCESS;

 }

@@ -2891,6 +3103,13 @@
 SINT32 vp_VolteWriteStop(VOID)

 {

 	SINT32  ret = DRV_SUCCESS;

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_VolteWriteStop_Vbuffer();

+	    return ret;

+	}

+

+

 

 #ifdef  CONFIG_VOICE_BUFFER_DRV  

 	//complete_all(&s_voice_completion);

@@ -2961,6 +3180,11 @@
 	//UINT8 *pVoiceTempBuf = s_voiceTempBuffer;

 #endif

 

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_WriteDataToCodec_Vbuffer(pBuf, count);

+	    return ret;

+	}

 

 

 	if (pBuf == NULL)

@@ -3285,6 +3509,14 @@
 	UINT8 *ptemp8bit = NULL;

 #endif

 

+	if (g_voiceVar.useVoiceBuffer == 1)

+	{

+		ret = vp_ReadDataFromCodec_Vbuffer(pBuf, count);

+	    return ret;

+	}

+

+

+

 	if (pBuf == NULL)

 	{

 		return DRV_ERR_INVALID_PARAM;

@@ -3313,6 +3545,8 @@
 //	wait_for_completion_timeout(&s_voice_completion, 60);

 	zOss_GetSemaphore(s_voiceRdSema,  60);

 	#ifdef _VBUFF_IN_MULTI_CORE

+

+	

 	voice_buffer_read(s_speechState.pVpTempTxInBuffer,  s_speechState.totalFrameBufSize);

 

 	#else

@@ -3911,11 +4145,14 @@
 

 SINT32 vp_CreateThreadSemaph(VOID)

 {

+	SINT32 ret = 0;

+

 	s_vpState.vpSemaphore = zOss_CreateSemaphore("VpI2sReadWriteSemaphore", 0);

 #ifdef _USE_WEBRTC_AUD

 	s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 8192, 15, 0, 1);

 #else

-	s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 1024, 15, 0, 1);

+	//s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 1024, 15, 0, 1);

+	s_vpState.vpThread = zOss_CreateThread("vp_DataProcessThreadEntry", vp_DataProcessThreadEntry, 0, 8192, 15, 0, 1);	

 #endif

 

 #ifdef  _OS_TOS

@@ -3937,6 +4174,9 @@
 		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create vp Thread sem err s_vpState.vpThread=%p,s_vpState.vpSemaphore=%p !\r\n", s_vpState.vpThread, s_vpState.vpSemaphore);

 		return DRV_ERROR;

 	}

+

+

+

 #ifdef CONFIG_VOICE_BUFFER_DRV  	

 //	init_completion(&s_voice_completion);

 	s_voiceRdSema = zOss_CreateSemaphore("voice_rx_sem", 0);

@@ -3959,50 +4199,57 @@
 		return DRV_ERROR;

 	}

 #ifdef _VBUFF_IN_MULTI_CORE

-		SINT32 ret = 0;

+	//SINT32 ret = 0;

 

-		//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

-		ret = zDrvRpMsg_CreateChannel_Cap(RPMSG_CAP_ID,channel_41,0x10);

+	//ret = zDrvRpMsg_CreateChannel(IPC_MSG_ACTOR_A9,channel_41,0x10);

+	ret = zDrvRpMsg_CreateChannel_Cap(RPMSG_CAP_ID,channel_41,0x10);

 

-		if(DRV_SUCCESS != ret) {

-			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create rpmsg err(%d) \n",ret);

-			return DRV_ERROR;

-		}

+	if(DRV_SUCCESS != ret) {

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "create rpmsg err(%d) \n",ret);

+		return DRV_ERROR;

+	}

+	

+	volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

+	volatile unsigned int rpMsgBuf[2] = {0,0}; 

+	//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

+	icp_pMsg.actorID = RPMSG_CAP_ID;

+	icp_pMsg.chID = channel_41;

+	icp_pMsg.flag &= ~RPMSG_READ_POLL;

+	icp_pMsg.buf = rpMsgBuf;

+	icp_pMsg.len = 8;

+	ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

+	if(ret <= 0){

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

+		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

 		

-		volatile T_ZDrvRpMsg_Msg icp_pMsg = {0}; 

-		volatile unsigned int rpMsgBuf[2] = {0,0}; 

-		//printk( "vir_buf1:0x%x, vir_buf2:0x%x, phy_buf1:0x%x, phy_buf2:0x%x,\n",voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1]);

-		icp_pMsg.actorID = RPMSG_CAP_ID;

-		icp_pMsg.chID = channel_41;

-		icp_pMsg.flag &= ~RPMSG_READ_POLL;

-		icp_pMsg.buf = rpMsgBuf;

-		icp_pMsg.len = 8;

-		ret = zDrvRpMsg_Read_Cap(&icp_pMsg);

-		if(ret <= 0){

-			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

-			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps voice buffer  rpmsg addr read  fail,ret=%d \n",ret);

-			

 

-		}

-		else{

-			#if 0

+	}

+	else{

+		#if 0

 

-			voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

-			voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

-			#else

+		voice_buff[UP_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[0]);

+		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)(rpMsgBuf[1]);	

+		#else

 

-			voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

-			voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

-			#endif

-	

-			zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+		voice_buff[UP_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[0], (sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+		voice_buff[DOWN_LINK] = (struct voice_ring_buffer *)ioremap_wc(rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));	

+		#endif

+

+		zOss_Printf(SUBMDL_HAL, PRINT_LEVEL_NORMAL, "ps rpmsg voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

+		,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

+		zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

 			,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

-			zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "voice buffer addr,up vir buf=0x%x,  down vir buf=0x%x ,up phy buf=0x%x,  down phy buf=0x%x,size=%d \n" \

-				,voice_buff[0],voice_buff[1],rpMsgBuf[0],rpMsgBuf[1],(sizeof(struct voice_ring_buffer) + MAX_BUF_SIZE*MAX_BUF_NUM));

-		}

+	}

 #endif

+

+#else

+    //flag ctrl voicebuffer func

+	vp_CreateThreadSemaph_Vbuffer();

+

+

 #endif

-	

+

+

 	zDrvRamlog_PRINTF(RAMLOG_MOD_AUDIO, "vp_CreateThreadSemaph success. \r\n");

 	return DRV_SUCCESS;

 }

diff --git a/pub/project/zx297520v3/include/drv/NvParam_drv.h b/pub/project/zx297520v3/include/drv/NvParam_drv.h
index 66c6f6d..95c3158 100755
--- a/pub/project/zx297520v3/include/drv/NvParam_drv.h
+++ b/pub/project/zx297520v3/include/drv/NvParam_drv.h
@@ -214,8 +214,10 @@
 	UINT8			isUseTxDtmfDet;     

     UINT8			isUseRxMixData;

 	UINT8			isUseTxMixData;//12

-	UINT8			isUseEcall;

-    UINT8           reserved[19];//32-13

+	UINT8			isUseEcall; //13

+	UINT8 			isUseVoiceBuffer; //14  0 not use,1 use

+	UINT8 			selVoiceBufferType; //15 0 single core, 1 dual core	

+    UINT8           reserved[17];//32-15

 	

 }  T_Audio_NvFlag;