[Feature][ZXW-33]merge ZXW 0428 version
Change-Id: I11f167edfea428d9fab198ff00ff1364932d1b0b
diff --git a/ap/lib/libvoice/voice_api.c b/ap/lib/libvoice/voice_api.c
new file mode 100755
index 0000000..e6262fb
--- /dev/null
+++ b/ap/lib/libvoice/voice_api.c
@@ -0,0 +1,423 @@
+/**
+ * @file voice_api.c
+ * @brief Implementation of the public APIs of libvoice.
+ *
+ * Copyright (C) 2023 Sanechips Technology Co., Ltd.
+ * @author
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
+ *
+ */
+
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <stdint.h>
+//#include "volte_drv.h"
+#include <linux/volte_drv.h>
+
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <tinyalsa/audio_mixer_ctrl.h>
+#include "voice_lib.h"
+
+#define VOCIE_SND_CARD_NUM 0
+
+
+extern int mix_set_voice_vol(struct mixer *mixer, int volume);
+extern int mix_get_voice_vol(struct mixer *mixer, int *volume);
+extern int mix_set_tx_voice_vol(struct mixer *mixer, int volume);
+extern int mix_get_tx_voice_vol(struct mixer *mixer, int *volume);
+extern int mix_set_voice_mute(struct mixer *mixer, bool enable);
+extern int mix_get_voice_mute(struct mixer *mixer, int *enable);
+extern int mix_set_rx_voice_mute(struct mixer *mixer, bool enable);
+extern int mix_get_rx_voice_mute(struct mixer *mixer, int *enable);
+extern int mix_set_voice_path(struct mixer *mixer, int path);
+extern int mix_set_vp_path(struct mixer *mixer, char path);
+extern int mix_get_vp_path(struct mixer *mixer, int *path);
+extern int mix_get_voice_path(struct mixer *mixer, int *path);
+
+
+
+#define VOCIE_SND_CARD_NUM 0
+
+
+
+//设置voiceé³é¢è®¾å¤æ¨¡å¼ dev_modeï¼handset,speaker,headset 0 表示æåï¼?å
¶å®è¡¨ç¤ºæéè¯?
+int set_voice_device_mode(int dev_mode)
+{
+
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
+
+ if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
+ printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
+ return -1;
+ }
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_set_voice_path(voice_mixer, dev_mode);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+
+ return 0;
+
+
+}
+
+
+
+int sc_audio_set_voice_device_mode(int dev_mode)
+{
+
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start dev_mode=%d!\n",__func__, dev_mode);
+
+ if ((dev_mode < T_OUTPUT_HANDSET ) ||(dev_mode >= T_OUTPUT_MAX)){
+ printf("%s: dev_mode not support, dev_mode=%d!\n",__func__, dev_mode);
+ return -1;
+ }
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+#ifdef _ALSA_CODEC_IN_CAP
+ mix_set_vp_path(voice_mixer,dev_mode);
+
+#else
+ //config mixer dev
+ mix_set_voice_path(voice_mixer, dev_mode);
+#endif
+
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+
+ return 0;
+
+
+}
+
+
+int sc_audio_get_voice_device_mode(int *p_dev_mode)
+{
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start!\n",__func__);
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_get_vp_path(voice_mixer, p_dev_mode);
+
+
+ if((*p_dev_mode < T_OUTPUT_HANDSET ) ||(*p_dev_mode >= T_OUTPUT_MAX)){
+ printf("%s: dev_mode not support, *p_dev_mode=%d!\n",__func__, *p_dev_mode);
+ //return -1;
+ }
+ printf("%s: start *p_dev_mode=%d!\n",__func__, *p_dev_mode);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+ return 0;
+
+}
+
+
+int sc_audio_set_rx_voice_vol(int vol)
+{
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start vol=%d!\n",__func__, vol);
+
+ if ((vol < 0 ) ||(vol > 11)){
+ printf("%s: vol not support, vol=%d!\n",__func__, vol);
+ return -1;
+ }
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_set_voice_vol(voice_mixer, vol);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+
+ return 0;
+
+
+
+
+}
+
+
+
+int sc_audio_get_rx_voice_vol(int * p_vol)
+{
+ struct mixer *voice_mixer = NULL;
+
+ printf("%s: start!\n",__func__);
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_get_voice_vol(voice_mixer, p_vol);
+
+
+ if ((*p_vol < 0 ) ||(*p_vol > 11)){
+ printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
+ //return -1;
+ }
+ printf("%s: *p_vol=%d!\n",__func__, *p_vol);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+
+ return 0;
+
+
+
+}
+
+
+
+int sc_audio_set_tx_voice_vol(int vol)
+{
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start vol=%d!\n",__func__, vol);
+
+ if ((vol < 0 ) ||(vol > 11)){
+ printf("%s: vol not support, vol=%d!\n",__func__, vol);
+ return -1;
+ }
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_set_tx_voice_vol(voice_mixer, vol);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+
+ return 0;
+
+
+}
+
+
+
+int sc_audio_get_tx_voice_vol(int *p_vol)
+{
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start!\n",__func__);
+
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_get_tx_voice_vol(voice_mixer, p_vol);
+
+
+ if((*p_vol < 0 ) ||(*p_vol > 5)){
+ printf("%s: vol not support, *p_vol=%d!\n",__func__, *p_vol);
+ //return -1;
+ }
+ printf("%s: *p_vol=%d!\n",__func__, *p_vol);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+ return 0;
+}
+
+
+
+int sc_audio_set_tx_voice_mute_state(int mute )
+{
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start mute=%d!\n",__func__, mute);
+
+ if((mute != 0 ) &&(mute != 1)) {
+ printf("%s: mute not support, mute=%d!\n",__func__, mute);
+ return -1;
+ }
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_set_voice_mute(voice_mixer, mute);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+ return 0;
+
+}
+
+int sc_audio_get_tx_voice_mute_state(int *p_mute)
+{
+ struct mixer *voice_mixer = NULL;
+
+ printf("%s: start!\n",__func__);
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_get_voice_mute(voice_mixer, p_mute);
+
+
+ if((*p_mute != 0 ) &&(*p_mute != 1)) {
+ printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+ return -1;
+ }
+ printf("%s: *p_mute=%d!\n",__func__, *p_mute);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+ return 0;
+}
+
+
+
+
+
+
+
+int sc_audio_set_rx_voice_mute_state(int mute)
+{
+ struct mixer *voice_mixer = NULL;
+ printf("%s: start mute=%d!\n",__func__, mute);
+
+ if((mute != 0 ) &&(mute != 1)) {
+ printf("%s: mute not support, mute=%d!\n",__func__, mute);
+ return -1;
+ }
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_set_rx_voice_mute(voice_mixer, mute);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+ return 0;
+
+}
+
+
+int sc_audio_get_rx_voice_mute_state(int *p_mute){
+ struct mixer *voice_mixer = NULL;
+
+ printf("%s: start!\n",__func__);
+
+ //open mixer dev for control
+ voice_mixer = mixer_open(VOCIE_SND_CARD_NUM);
+ if (!voice_mixer) {
+ printf("voice_mixer open failed!\n");
+ return -1;
+ }
+
+ //config mixer dev
+ mix_get_rx_voice_mute(voice_mixer, p_mute);
+
+ if((*p_mute != 0 ) &&(*p_mute != 1)) {
+
+ printf("%s: *p_mute not support, *p_mute=%d!\n",__func__, *p_mute);
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+ return -1;
+ }
+ printf("%s: *p_mute=%d!\n",__func__, *p_mute);
+
+ //close mixer
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+ return 0;
+
+}
+
+int sc_audio_set_loopback_enable_state(int enable)
+{
+ return 0;
+}
+
+int sc_audio_get_loopback_enable_state(int *p_enable)
+{
+ return 0;
+}
+