[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/lib/libaudiomix/Makefile b/ap/lib/libaudiomix/Makefile
new file mode 100755
index 0000000..fb5acd5
--- /dev/null
+++ b/ap/lib/libaudiomix/Makefile
@@ -0,0 +1,100 @@
+# /*****************************************************************************

+#* °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£

+#* 

+#* ÎļþÃû³Æ:     Makefile

+#* Îļþ±êʶ:     Makefile

+#* ÄÚÈÝÕªÒª:     Makefile of ZTE librarys

+#* ʹÓ÷½·¨:     void

+#* 

+#* ÐÞ¸ÄÈÕÆÚ        °æ±¾ºÅ      Ð޸ıê¼Ç        ÐÞ¸ÄÈË          ÐÞ¸ÄÄÚÈÝ

+#* -----------------------------------------------------------------------------

+#* 2019/09/25     V1.0        Create          xxq        ´´½¨

+#* 

+# ******************************************************************************/

+

+#*******************************************************************************

+# include ZTE library makefile

+#*******************************************************************************

+include $(COMMON_MK)

+

+

+#*******************************************************************************

+# library

+#*******************************************************************************

+LIB_SHARED = libaudiomix.so

+LIB_STATIC = libaudiomix.a

+

+OBJS = mix.o mixtest.o

+CFLAGS += -g

+LDFLAGS += -lpthread

+

+##############USER COMIZE END##################

+

+CFLAGS += -I$(zte_lib_path)/libaudiomix/include

+CFLAGS += -I$(STAGEDIR)/include

+CFLAGS += -I$(APP_DIR)/include

+CFLAGS += -fPIC

+

+LDFLAGS_SHARED += -shared

+

+

+#*******************************************************************************

+# comp test app and 

+#*******************************************************************************	

+EXEC_mixtest = mixtest

+

+	

+#*******************************************************************************

+# objects

+#*******************************************************************************

+mixtest_OBJECTS += mix.o mixtest.o

+

+

+

+#########################for linux######################################

+ifeq ($(V3PHONE_TYPE), K318)

+	CFLAGS += -D_USE_7520V3_PHONE_TYPE_K318

+endif

+ifeq ($(V3PHONE_TYPE), C31F)

+	CFLAGS += -D_USE_7520V3_PHONE_TYPE_C31F

+endif

+ifeq ($(V3PHONE_TYPE), XRSD)

+	CFLAGS += -D_USE_7520V3_PHONE_TYPE_XRSD

+endif

+ifeq ($(V3PHONE_TYPE), FWP)

+	CFLAGS += -D_USE_7520V3_PHONE_TYPE_FWP

+endif

+ifeq ($(V3PHONE_TYPE), WTWD)

+	CFLAGS += -D_USE_7520V3_PHONE_TYPE_WTWD

+endif

+

+

+

+CFLAGS	+= -I./include/

+CFLAGS += -g -Werror=implicit-function-declaration

+SHAREDFLAG := -shared -lc

+LDLIBS += -L$(LIB_DIR)/libtinyalsa

+LDLIBS += -ltinyalsa

+

+all: $(LIB_STATIC) $(LIB_SHARED) $(EXEC_mixtest)

+

+$(LIB_STATIC) : $(OBJS)

+	$(AR) rcs $(LIB_STATIC) $(OBJS)

+

+$(LIB_SHARED): $(OBJS)

+	$(CC) $(LDFLAGS) $(LDFLAGS_SHARED) -o $@ $^

+

+	

+$(EXEC_mixtest): $(mixtest_OBJECTS)

+	$(CC) $(LDFLAGS) -o $@ $(mixtest_OBJECTS) -Wl,--start-group $(LDLIBS) -Wl,--end-group

+	

+clean:

+	rm -f $(mixtest_OBJECTS) $(lib_OBJECTS) $(LIB_SHARED) $(LIB_STATIC) $(EXEC_mixtest)  *.elf *.gdb *.o core

+

+romfs:

+	$(ROMFSINST) $(LIB_SHARED) /lib/$(LIB_SHARED)

+

+	cp -v $(EXEC_mixtest)    $(APP_DIR)/test_tools/

+	

+

+

diff --git a/ap/lib/libaudiomix/include/audiomix_lib.h b/ap/lib/libaudiomix/include/audiomix_lib.h
new file mode 100755
index 0000000..5d88b23
--- /dev/null
+++ b/ap/lib/libaudiomix/include/audiomix_lib.h
@@ -0,0 +1,17 @@
+
+/*
+ * Copyright (C) 2019 ZTE, China
+ *
+ * This is the header file for the audio_mix lib.
+ *
+ */
+#include <linux/volte_drv.h>
+
+#ifndef __AUDIO_MIX_LIB_H
+#define __AUDIO_MIX_LIB_H
+
+ int zDrvAudioMix_Write(unsigned char *pBuf, unsigned int uiLen);
+ int zDrvAudioMix_Open(T_ZDrvAudioMix_Cfg *cfgParam);
+ int zDrvAudioMix_Close(void);
+
+#endif
diff --git a/ap/lib/libaudiomix/mix.c b/ap/lib/libaudiomix/mix.c
new file mode 100755
index 0000000..f0de0f9
--- /dev/null
+++ b/ap/lib/libaudiomix/mix.c
@@ -0,0 +1,86 @@
+/*****************************************************************************

+** °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£

+** 

+** ÎļþÃû³Æ: mix.c

+** Îļþ±êʶ:     

+** ÄÚÈÝÕªÒª:    

+** ʹÓ÷½·¨:     

+** 

+** ÐÞ¸ÄÈÕÆÚ        °æ±¾ºÅ      Ð޸ıê¼Ç        ÐÞ¸ÄÈË          ÐÞ¸ÄÄÚÈÝ

+** -----------------------------------------------------------------------------

+** 2019/09/25     V1.0        Create          xxq        ´´½¨

+** 

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

+

+#include <stdio.h>

+#include <unistd.h>

+#include <string.h>

+#include <stdlib.h>

+ 

+#include <stdint.h>

+#include <linux/volte_drv.h>

+#include <sys/ioctl.h>

+#include <fcntl.h>

+

+#define MIX_DEV_INVALID_ID (-1)

+#define DRV_SUCCESS 0

+#define DRV_ERROR (-1)

+#define AUDIO_MIX_DEV_NAME "/dev/audio_mix_device"

+ 

+int audio_mix_devfd = MIX_DEV_INVALID_ID;

+

+int zDrvAudioMix_Write(unsigned char *pBuf, unsigned int uiLen) 

+{ 

+	if(audio_mix_devfd == MIX_DEV_INVALID_ID)

+	{

+        printf("zte audio /dev/audio_mix_device zDrvAudioMix_WriteOneFrame invalid dev!\n");

+        return DRV_ERROR;

+	} 

+    

+	if(write(audio_mix_devfd, pBuf, uiLen) <= 0)

+	{

+        printf("zte audio /dev/audio_mix_device zDrvAudioMix_WriteOneFrame write failed!\n");

+		return DRV_ERROR;

+	} 

+

+	return DRV_SUCCESS;

+}  

+

+int zDrvAudioMix_Open(T_ZDrvAudioMix_Cfg *cfgParam) 

+{

+	audio_mix_devfd = open(AUDIO_MIX_DEV_NAME, O_RDWR);

+    printf("open end! audio_mix_devfd=%d, audioType=%d, sample_rate=%d\n", audio_mix_devfd, cfgParam->audioType, cfgParam->sample_rate);

+	if(audio_mix_devfd < 0)

+	{

+        printf("zte audio /dev/audio_mix_device zDrvAudioMix_Open failed!\n");

+		return DRV_ERROR;

+	}  

+     

+	if(ioctl(audio_mix_devfd, AUDIOMIX_IOCTL_SET_CFG, cfgParam) < 0)

+	{ 

+        printf("zte audio /dev/audio_mix_device set cfg failed!\n");

+		goto err;

+	}

+    

+	return DRV_SUCCESS;

+err: 

+	close(audio_mix_devfd);

+	audio_mix_devfd = MIX_DEV_INVALID_ID;

+    printf("zte audio /dev/audio_mix_device zDrvAudioMix_Open failed!\n");

+	return DRV_ERROR;

+

+}

+

+int zDrvAudioMix_Close(void)   

+{

+	if(audio_mix_devfd == MIX_DEV_INVALID_ID)

+	{

+        printf("zte audio /dev/audio_mix_device zDrvAudioMix_Close invalid dev!\n");

+		return DRV_ERROR;

+	}

+	close(audio_mix_devfd); 

+	audio_mix_devfd = MIX_DEV_INVALID_ID;

+    

+	return DRV_SUCCESS;

+}

+

diff --git a/ap/lib/libaudiomix/mixtest.c b/ap/lib/libaudiomix/mixtest.c
new file mode 100755
index 0000000..bec220d
--- /dev/null
+++ b/ap/lib/libaudiomix/mixtest.c
@@ -0,0 +1,87 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <signal.h> 
+ 
+#include <linux/volte_drv.h>
+#include "../libaudiomix/include/audiomix_lib.h"
+
+T_ZDrvAudioMix_Cfg testParam;
+#define BUFFER_BYTES 1024//×î´ó1024×Ö½Ú 
+int main(int argc, char **argv) //×¢Ê͵ô±àÒë¿ÉÖ´ÐÐÎļþ+++++
+{
+    FILE *file;  
+    
+    char *filename;  
+    int more_chunks = 1;
+    unsigned char buffer[BUFFER_BYTES] = {0};  
+    int ret = 0;
+    
+    testParam.sample_rate = 8000;//Òª±£Ö¤Í¬²ÉÑùƵÂÊ(½öÏÞ16KºÍ8K)
+    testParam.audioType = 1;//1-TX,2-RX//RX±»×¢Ê͵ô£¬Ö§³ÖºóÐøÀ©Õ¹
+    
+    printf("enter main\n"); 
+    
+    if (argc < 2) {
+        fprintf(stderr, "Usage: %s \n", argv[0]);
+        printf("Usage: %s \n", argv[0]);
+        return 1;
+    }
+
+    filename = argv[1];
+    file = fopen(filename, "rb");
+    printf("fopen '%s' end\n", filename); 
+    if (!file) {
+        fprintf(stderr, "Unable to open file '%s'\n", filename);
+        printf("Unable to open file '%s'\n", filename);
+        return 1;
+    }
+
+    fseek(file, 0, SEEK_SET);
+    long begin = ftell(file);
+    fseek(file, 0, SEEK_END);
+    long end = ftell(file);
+    long file_size = end - begin;//×Ö½ÚÊý
+    int read_times = 0;
+    int remain_size = 0;
+
+    fseek(file, 0, SEEK_SET);//ÖØÐÂÖûØÎļþ¿ªÍ·
+    
+    printf("zDrvAudioMix_Open start, file size is %ld\n", file_size);  
+    ret = zDrvAudioMix_Open(&testParam); 
+    if(ret != 0)
+        return 1;
+    printf("zDrvAudioMix_Open end\n"); 
+
+    while (more_chunks){
+        more_chunks = fread(buffer, sizeof(buffer), 1, file);
+        
+        if(more_chunks == 1){
+            read_times++;
+            ret = zDrvAudioMix_Write(buffer, sizeof(buffer));
+            if(ret != 0)
+                break;
+        }
+        else{ 
+            remain_size = file_size - read_times * sizeof(buffer);
+            printf("more_chunks=%d, read_times=%d, remain_size is %d\n", more_chunks, read_times, remain_size);
+            if(remain_size == 0)
+                break;
+            ret = zDrvAudioMix_Write(buffer, remain_size);
+            if(ret != 0)
+                break;
+        } 
+    } 
+    printf("while(more_chunks) end\n"); 
+
+    ret = zDrvAudioMix_Close();
+    if(ret != 0)
+        return 1;
+    printf("zDrvAudioMix_Close end\n");
+    fclose(file);
+    printf("fclose end\n");
+
+    return ret;
+}
+