├── Android.mk ├── METADATA ├── OWNERS ├── hal ├── Android.mk ├── acdb.c ├── acdb.h ├── audio_extn │ ├── a2dp.c │ ├── audio_extn.c │ ├── audio_extn.h │ ├── audiozoom.c │ ├── audiozoom.h │ ├── cirrus_playback.c │ ├── dsm_feedback.c │ ├── ext_speaker.c │ ├── hfp.c │ ├── hwdep_cal.c │ ├── maxxaudio.c │ ├── maxxaudio.h │ ├── sndmonitor.c │ ├── soundtrigger.c │ ├── spkr_protection.c │ ├── tfa_98xx.c │ ├── tfa_98xx.h │ ├── usb.c │ └── utils.c ├── audio_hw.c ├── audio_hw.h ├── audio_perf.cpp ├── audio_perf.h ├── msm8974 │ ├── hw_info.c │ ├── platform.c │ └── platform.h ├── platform_api.h ├── platform_info.c ├── voice.c ├── voice.h └── voice_extn │ ├── voice_extn.c │ └── voice_extn.h ├── post_proc ├── Android.mk ├── bass_boost.c ├── bass_boost.h ├── bundle.c ├── bundle.h ├── effect_api.c ├── effect_api.h ├── equalizer.c ├── equalizer.h ├── ma_listener.c ├── reverb.c ├── reverb.h ├── virtualizer.c ├── virtualizer.h └── volume_listener.c ├── visualizer ├── Android.mk ├── MODULE_LICENSE_APACHE2 ├── NOTICE └── offload_visualizer.c └── voice_processing ├── Android.mk └── voice_processing.c /Android.mk: -------------------------------------------------------------------------------- 1 | # TODO: Find a better way to separate build configs for ADP vs non-ADP devices 2 | ifneq ($(TARGET_BOARD_AUTO),true) 3 | ifneq ($(filter msm8996 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) 4 | MY_LOCAL_PATH := $(call my-dir) 5 | include $(MY_LOCAL_PATH)/hal/Android.mk 6 | include $(MY_LOCAL_PATH)/voice_processing/Android.mk 7 | include $(MY_LOCAL_PATH)/visualizer/Android.mk 8 | include $(MY_LOCAL_PATH)/post_proc/Android.mk 9 | endif 10 | endif 11 | -------------------------------------------------------------------------------- /METADATA: -------------------------------------------------------------------------------- 1 | third_party { 2 | license_note: "would be NOTICE save for legacy/libalsa-intf/alsa_ucm.h" 3 | license_type: RESTRICTED 4 | } 5 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # Default code reviewers picked from top 3 or more developers. 2 | # Please update this list if you find better candidates. 3 | hunga@google.com 4 | mnaganov@google.com 5 | elaurent@google.com 6 | -------------------------------------------------------------------------------- /hal/Android.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(BOARD_USES_ALSA_AUDIO)),true) 2 | 3 | LOCAL_PATH := $(call my-dir) 4 | 5 | include $(CLEAR_VARS) 6 | 7 | LOCAL_ARM_MODE := arm 8 | 9 | AUDIO_PLATFORM := $(TARGET_BOARD_PLATFORM) 10 | ifneq ($(filter msm8996 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) 11 | # B-family platform uses msm8974 code base 12 | AUDIO_PLATFORM = msm8974 13 | ifneq ($(filter msm8996,$(TARGET_BOARD_PLATFORM)),) 14 | LOCAL_CFLAGS := -DPLATFORM_MSM8996 15 | LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4" 16 | LOCAL_CFLAGS += -DKPI_OPTIMIZE_ENABLED 17 | LOCAL_CFLAGS += -DINCALL_MUSIC_ENABLED 18 | MULTIPLE_HW_VARIANTS_ENABLED := true 19 | endif 20 | ifneq ($(filter msm8998,$(TARGET_BOARD_PLATFORM)),) 21 | LOCAL_CFLAGS := -DPLATFORM_MSM8998 22 | LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4" 23 | LOCAL_CFLAGS += -DINCALL_MUSIC_ENABLED 24 | MULTIPLE_HW_VARIANTS_ENABLED := true 25 | endif 26 | ifneq ($(filter sdm845,$(TARGET_BOARD_PLATFORM)),) 27 | LOCAL_CFLAGS := -DPLATFORM_SDM845 28 | LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4" 29 | LOCAL_CFLAGS += -DINCALL_MUSIC_ENABLED 30 | LOCAL_CFLAGS += -DINCALL_STEREO_CAPTURE_ENABLED 31 | MULTIPLE_HW_VARIANTS_ENABLED := true 32 | endif 33 | ifneq ($(filter sdm710,$(TARGET_BOARD_PLATFORM)),) 34 | LOCAL_CFLAGS := -DPLATFORM_SDM710 35 | LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4" 36 | LOCAL_CFLAGS += -DINCALL_MUSIC_ENABLED 37 | LOCAL_CFLAGS += -DINCALL_STEREO_CAPTURE_ENABLED 38 | MULTIPLE_HW_VARIANTS_ENABLED := true 39 | endif 40 | endif 41 | 42 | LOCAL_SRC_FILES := \ 43 | audio_hw.c \ 44 | voice.c \ 45 | platform_info.c \ 46 | audio_extn/ext_speaker.c \ 47 | audio_extn/audio_extn.c \ 48 | audio_extn/utils.c \ 49 | $(AUDIO_PLATFORM)/platform.c \ 50 | acdb.c 51 | 52 | ifdef MULTIPLE_HW_VARIANTS_ENABLED 53 | LOCAL_CFLAGS += -DHW_VARIANTS_ENABLED 54 | LOCAL_SRC_FILES += $(AUDIO_PLATFORM)/hw_info.c 55 | endif 56 | 57 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_USB_TUNNEL)),true) 58 | LOCAL_CFLAGS += -DUSB_TUNNEL_ENABLED 59 | LOCAL_SRC_FILES += audio_extn/usb.c 60 | endif 61 | 62 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_USB_SIDETONE_VOLUME)),true) 63 | LOCAL_CFLAGS += -DUSB_SIDETONE_VOLUME 64 | endif 65 | 66 | LOCAL_SHARED_LIBRARIES := \ 67 | libaudioutils \ 68 | liblog \ 69 | libcutils \ 70 | libprocessgroup \ 71 | libtinyalsa \ 72 | libtinycompress \ 73 | libaudioroute \ 74 | libdl \ 75 | libexpat 76 | 77 | LOCAL_C_INCLUDES += \ 78 | external/tinyalsa/include \ 79 | external/tinycompress/include \ 80 | $(call include-path-for, audio-route) \ 81 | $(call include-path-for, audio-effects) \ 82 | $(LOCAL_PATH)/$(AUDIO_PLATFORM) \ 83 | $(LOCAL_PATH)/audio_extn \ 84 | $(LOCAL_PATH)/voice_extn \ 85 | external/expat/lib 86 | 87 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_SMART_PA_TFA_98XX)),true) 88 | LOCAL_SHARED_LIBRARIES += libexTfa98xx 89 | LOCAL_CFLAGS += -DSMART_PA_TFA_98XX_SUPPORTED 90 | LOCAL_SRC_FILES += audio_extn/tfa_98xx.c 91 | endif 92 | 93 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_MULTI_VOICE_SESSIONS)),true) 94 | LOCAL_CFLAGS += -DMULTI_VOICE_SESSION_ENABLED 95 | LOCAL_SRC_FILES += voice_extn/voice_extn.c 96 | endif 97 | 98 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_HFP)),true) 99 | LOCAL_CFLAGS += -DHFP_ENABLED 100 | LOCAL_SRC_FILES += audio_extn/hfp.c 101 | endif 102 | 103 | ifeq ($(strip $(AUDIO_FEATURE_SUPPORTED_EXTERNAL_BT)),true) 104 | LOCAL_CFLAGS += -DEXTERNAL_BT_SUPPORTED 105 | endif 106 | 107 | ifeq ($(strip $(AUDIO_FEATURE_FLICKER_SENSOR_INPUT)),true) 108 | LOCAL_CFLAGS += -DFLICKER_SENSOR_INPUT 109 | endif 110 | 111 | ifeq ($(strip $(AUDIO_FEATURE_NO_AUDIO_OUT)),true) 112 | LOCAL_CFLAGS += -DNO_AUDIO_OUT 113 | endif 114 | 115 | ifeq ($(strip $(BOARD_SUPPORTS_SOUND_TRIGGER)),true) 116 | LOCAL_CFLAGS += -DSOUND_TRIGGER_ENABLED 117 | LOCAL_CFLAGS += -DSOUND_TRIGGER_PLATFORM_NAME=$(TARGET_BOARD_PLATFORM) 118 | LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/mm-audio/sound_trigger 119 | LOCAL_SRC_FILES += audio_extn/soundtrigger.c 120 | ifneq ($(filter msm8996,$(TARGET_BOARD_PLATFORM)),) 121 | LOCAL_HEADER_LIBRARIES := sound_trigger.primary_headers 122 | endif 123 | 124 | endif 125 | 126 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_SPKR_PROTECTION)),true) 127 | LOCAL_CFLAGS += -DSPKR_PROT_ENABLED 128 | LOCAL_SRC_FILES += audio_extn/spkr_protection.c 129 | endif 130 | 131 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_CIRRUS_SPKR_PROTECTION)),true) 132 | LOCAL_CFLAGS += -DSPKR_PROT_ENABLED 133 | LOCAL_SRC_FILES += audio_extn/cirrus_playback.c 134 | endif 135 | 136 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_DSM_FEEDBACK)),true) 137 | LOCAL_CFLAGS += -DDSM_FEEDBACK_ENABLED 138 | LOCAL_SRC_FILES += audio_extn/dsm_feedback.c 139 | endif 140 | 141 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_A2DP_OFFLOAD)),true) 142 | LOCAL_CFLAGS += -DA2DP_OFFLOAD_ENABLED 143 | LOCAL_SRC_FILES += audio_extn/a2dp.c 144 | endif 145 | 146 | ifneq ($(filter msm8996 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) 147 | # push codec/mad calibration to HW dep node 148 | # applicable to msm8992/8994 or newer platforms 149 | LOCAL_CFLAGS += -DHWDEP_CAL_ENABLED 150 | LOCAL_SRC_FILES += audio_extn/hwdep_cal.c 151 | endif 152 | 153 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_SND_MONITOR)), true) 154 | LOCAL_CFLAGS += -DSND_MONITOR_ENABLED 155 | LOCAL_SRC_FILES += audio_extn/sndmonitor.c 156 | endif 157 | 158 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_USB_SERVICE_INTERVAL)), true) 159 | LOCAL_CFLAGS += -DUSB_SERVICE_INTERVAL_ENABLED 160 | endif 161 | 162 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_MAXX_AUDIO)), true) 163 | LOCAL_CFLAGS += -DMAXXAUDIO_QDSP_ENABLED 164 | LOCAL_SRC_FILES += audio_extn/maxxaudio.c 165 | endif 166 | 167 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_AUDIO_ZOOM)), true) 168 | LOCAL_CFLAGS += -DAUDIOZOOM_QDSP_ENABLED 169 | LOCAL_SRC_FILES += audio_extn/audiozoom.c 170 | endif 171 | 172 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_24BITS_CAMCORDER)), true) 173 | LOCAL_CFLAGS += -DENABLED_24BITS_CAMCORDER 174 | endif 175 | 176 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_BG_CAL)),true) 177 | LOCAL_CFLAGS += -DBG_CODEC_CAL 178 | endif 179 | 180 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_DYNAMIC_ECNS)),true) 181 | LOCAL_CFLAGS += -DDYNAMIC_ECNS_ENABLED 182 | endif 183 | 184 | LOCAL_SHARED_LIBRARIES += libbase libhidlbase libutils android.hardware.power@1.2 liblog 185 | 186 | LOCAL_SHARED_LIBRARIES += android.hardware.power-V1-ndk 187 | LOCAL_SHARED_LIBRARIES += libbinder_ndk 188 | 189 | LOCAL_SRC_FILES += audio_perf.cpp 190 | 191 | LOCAL_HEADER_LIBRARIES += libhardware_headers 192 | 193 | LOCAL_HEADER_LIBRARIES += audio_headers generated_kernel_headers 194 | 195 | LOCAL_MODULE := audio.primary.$(TARGET_BOARD_PLATFORM) 196 | LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 197 | LOCAL_LICENSE_CONDITIONS := notice 198 | 199 | LOCAL_MODULE_RELATIVE_PATH := hw 200 | 201 | LOCAL_MODULE_TAGS := optional 202 | 203 | LOCAL_MODULE_OWNER := qcom 204 | 205 | LOCAL_PROPRIETARY_MODULE := true 206 | 207 | LOCAL_CFLAGS += -Werror 208 | 209 | include $(BUILD_SHARED_LIBRARY) 210 | 211 | include $(CLEAR_VARS) 212 | LOCAL_MODULE := audio_headers 213 | LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/audio_extn 214 | include $(BUILD_HEADER_LIBRARY) 215 | 216 | endif 217 | -------------------------------------------------------------------------------- /hal/acdb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "audio_hw_acdb" 18 | //#define LOG_NDEBUG 0 19 | #define LOG_NDDEBUG 0 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "acdb.h" 30 | #include 31 | 32 | #define PLATFORM_CONFIG_KEY_SOUNDCARD_NAME "snd_card_name" 33 | 34 | int acdb_init(int snd_card_num) 35 | { 36 | 37 | int result = -1; 38 | char *cvd_version = NULL; 39 | 40 | char *snd_card_name = NULL; 41 | struct mixer *mixer = NULL; 42 | struct acdb_platform_data *my_data = NULL; 43 | 44 | if(snd_card_num < 0) { 45 | ALOGE("invalid sound card number"); 46 | return result; 47 | } 48 | 49 | mixer = mixer_open(snd_card_num); 50 | if (!mixer) { 51 | ALOGE("%s: Unable to open the mixer card: %d", __func__, 52 | snd_card_num); 53 | goto cleanup; 54 | } 55 | 56 | my_data = calloc(1, sizeof(struct acdb_platform_data)); 57 | if (!my_data) { 58 | ALOGE("failed to allocate acdb platform data"); 59 | goto cleanup; 60 | } 61 | 62 | list_init(&my_data->acdb_meta_key_list); 63 | 64 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); 65 | if (my_data->acdb_handle == NULL) { 66 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); 67 | goto cleanup; 68 | } 69 | 70 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); 71 | 72 | my_data->acdb_init_v3 = (acdb_init_v3_t)dlsym(my_data->acdb_handle, 73 | "acdb_loader_init_v3"); 74 | if (my_data->acdb_init_v3 == NULL) 75 | ALOGE("%s: dlsym error %s for acdb_loader_init_v3", __func__, dlerror()); 76 | 77 | my_data->acdb_init_v2 = (acdb_init_v2_cvd_t)dlsym(my_data->acdb_handle, 78 | "acdb_loader_init_v2"); 79 | if (my_data->acdb_init_v2 == NULL) 80 | ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror()); 81 | 82 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, 83 | "acdb_loader_init_ACDB"); 84 | if (my_data->acdb_init == NULL && my_data->acdb_init_v2 == NULL 85 | && my_data->acdb_init_v3 == NULL) { 86 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror()); 87 | goto cleanup; 88 | } 89 | 90 | /* Get CVD version */ 91 | cvd_version = calloc(1, MAX_CVD_VERSION_STRING_SIZE); 92 | if (!cvd_version) { 93 | ALOGE("%s: Failed to allocate cvd version", __func__); 94 | goto cleanup; 95 | } else { 96 | struct mixer_ctl *ctl = NULL; 97 | int count = 0; 98 | 99 | ctl = mixer_get_ctl_by_name(mixer, CVD_VERSION_MIXER_CTL); 100 | if (!ctl) { 101 | ALOGE("%s: Could not get ctl for mixer cmd - %s", __func__, CVD_VERSION_MIXER_CTL); 102 | goto cleanup; 103 | } 104 | mixer_ctl_update(ctl); 105 | 106 | count = mixer_ctl_get_num_values(ctl); 107 | if (count > MAX_CVD_VERSION_STRING_SIZE) 108 | count = MAX_CVD_VERSION_STRING_SIZE; 109 | 110 | result = mixer_ctl_get_array(ctl, cvd_version, count); 111 | if (result != 0) { 112 | ALOGE("%s: ERROR! mixer_ctl_get_array() failed to get CVD Version", __func__); 113 | goto cleanup; 114 | } 115 | } 116 | 117 | /* Get Sound card name */ 118 | snd_card_name = strdup(mixer_get_name(mixer)); 119 | if (!snd_card_name) { 120 | ALOGE("failed to allocate memory for snd_card_name"); 121 | result = -1; 122 | goto cleanup; 123 | } 124 | 125 | if (my_data->acdb_init_v3) 126 | result = my_data->acdb_init_v3(snd_card_name, cvd_version, 127 | &my_data->acdb_meta_key_list); 128 | else if (my_data->acdb_init_v2) 129 | result = my_data->acdb_init_v2(snd_card_name, cvd_version, 0); 130 | else 131 | result = my_data->acdb_init(); 132 | 133 | cleanup: 134 | if (NULL != my_data) { 135 | if (my_data->acdb_handle) 136 | dlclose(my_data->acdb_handle); 137 | 138 | struct listnode *node; 139 | struct meta_key_list *key_info; 140 | list_for_each(node, &my_data->acdb_meta_key_list) { 141 | key_info = node_to_item(node, struct meta_key_list, list); 142 | free(key_info); 143 | } 144 | free(my_data); 145 | } 146 | 147 | mixer_close(mixer); 148 | free(cvd_version); 149 | free(snd_card_name); 150 | 151 | return result; 152 | } 153 | 154 | int acdb_set_parameters(void *platform, struct str_parms *parms) 155 | { 156 | struct acdb_platform_data *my_data = (struct acdb_platform_data *)platform; 157 | char value[128]; 158 | char *kv_pairs = str_parms_to_str(parms); 159 | int ret = 0; 160 | 161 | if (kv_pairs == NULL) { 162 | ret = -EINVAL; 163 | ALOGE("%s: key-value pair is NULL",__func__); 164 | goto done; 165 | } 166 | 167 | ret = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME, 168 | value, sizeof(value)); 169 | if (ret >= 0) { 170 | str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME); 171 | my_data->snd_card_name = strdup(value); 172 | ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name); 173 | } 174 | 175 | done: 176 | free(kv_pairs); 177 | 178 | return ret; 179 | } 180 | -------------------------------------------------------------------------------- /hal/acdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ACDB_H 18 | #define ACDB_H 19 | 20 | #include 21 | #include 22 | 23 | #define MAX_CVD_VERSION_STRING_SIZE 100 24 | #define LIB_ACDB_LOADER "libacdbloader.so" 25 | #define CVD_VERSION_MIXER_CTL "CVD Version" 26 | #define ACDB_METAINFO_KEY_MODULE_NAME_LEN 100 27 | 28 | /* Audio calibration related functions */ 29 | typedef void (*acdb_deallocate_t)(void); 30 | typedef int (*acdb_init_v3_t)(const char *, char *, struct listnode *); 31 | typedef int (*acdb_init_v2_cvd_t)(char *, char *, int); 32 | typedef int (*acdb_init_v2_t)(char *); 33 | typedef int (*acdb_init_t)(); 34 | typedef void (*acdb_send_audio_cal_t)(int, int); 35 | typedef void (*acdb_send_voice_cal_t)(int, int); 36 | typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*); 37 | typedef int (*acdb_reload_vocvoltable_t)(int); 38 | typedef int (*acdb_send_gain_dep_cal_t)(int, int, int, int, int); 39 | typedef int (*acdb_send_custom_top_t) (void); 40 | typedef int (*acdb_set_audio_cal_t) (void *, void *, uint32_t); 41 | 42 | struct meta_key_list { 43 | struct listnode list; 44 | struct audio_cal_info_metainfo cal_info; 45 | char name[ACDB_METAINFO_KEY_MODULE_NAME_LEN]; 46 | }; 47 | 48 | struct acdb_platform_data { 49 | /* Audio calibration related functions */ 50 | void *acdb_handle; 51 | acdb_init_t acdb_init; 52 | acdb_init_v2_cvd_t acdb_init_v2; 53 | acdb_init_v3_t acdb_init_v3; 54 | char *snd_card_name; 55 | struct listnode acdb_meta_key_list; 56 | }; 57 | 58 | int acdb_init(int); 59 | 60 | int acdb_set_metainfo_key(void *platform, char *name, int key); 61 | int acdb_set_parameters(void *platform, struct str_parms *parms); 62 | #endif //ACDB_H 63 | -------------------------------------------------------------------------------- /hal/audio_extn/audio_extn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "audio_hw_extn" 18 | /*#define LOG_NDEBUG 0*/ 19 | #define LOG_NDDEBUG 0 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "audio_hw.h" 28 | #include "audio_extn.h" 29 | #include "platform.h" 30 | #include "platform_api.h" 31 | 32 | struct snd_card_split cur_snd_card_split = { 33 | .device = {0}, 34 | .snd_card = {0}, 35 | .form_factor = {0}, 36 | }; 37 | 38 | struct snd_card_split *audio_extn_get_snd_card_split() 39 | { 40 | return &cur_snd_card_split; 41 | } 42 | 43 | void audio_extn_set_snd_card_split(const char* in_snd_card_name) 44 | { 45 | /* sound card name follows below mentioned convention 46 | --
-snd-card 47 | parse target name, sound card name and form factor 48 | */ 49 | char *snd_card_name = strdup(in_snd_card_name); 50 | char *tmp = NULL; 51 | char *device = NULL; 52 | char *snd_card = NULL; 53 | char *form_factor = NULL; 54 | 55 | if (in_snd_card_name == NULL) { 56 | ALOGE("%s: snd_card_name passed is NULL", __func__); 57 | goto on_error; 58 | } 59 | 60 | device = strtok_r(snd_card_name, "-", &tmp); 61 | if (device == NULL) { 62 | ALOGE("%s: called on invalid snd card name", __func__); 63 | goto on_error; 64 | } 65 | strlcpy(cur_snd_card_split.device, device, HW_INFO_ARRAY_MAX_SIZE); 66 | 67 | snd_card = strtok_r(NULL, "-", &tmp); 68 | if (snd_card == NULL) { 69 | ALOGE("%s: called on invalid snd card name", __func__); 70 | goto on_error; 71 | } 72 | strlcpy(cur_snd_card_split.snd_card, snd_card, HW_INFO_ARRAY_MAX_SIZE); 73 | 74 | form_factor = strtok_r(NULL, "-", &tmp); 75 | if (form_factor == NULL) { 76 | ALOGE("%s: called on invalid snd card name", __func__); 77 | goto on_error; 78 | } 79 | strlcpy(cur_snd_card_split.form_factor, form_factor, HW_INFO_ARRAY_MAX_SIZE); 80 | 81 | ALOGI("%s: snd_card_name(%s) device(%s) snd_card(%s) form_factor(%s)", 82 | __func__, in_snd_card_name, device, snd_card, form_factor); 83 | 84 | on_error: 85 | if (snd_card_name) 86 | free(snd_card_name); 87 | } 88 | 89 | #ifdef KPI_OPTIMIZE_ENABLED 90 | typedef int (*perf_lock_acquire_t)(int, int, int*, int); 91 | typedef int (*perf_lock_release_t)(int); 92 | 93 | static void *qcopt_handle; 94 | static perf_lock_acquire_t perf_lock_acq; 95 | static perf_lock_release_t perf_lock_rel; 96 | 97 | static int perf_lock_handle; 98 | char opt_lib_path[PROPERTY_VALUE_MAX] = {0}; 99 | 100 | int perf_lock_opts[] = {0x101, 0x20E, 0x30E}; 101 | 102 | int audio_extn_perf_lock_init(void) 103 | { 104 | int ret = 0; 105 | if (qcopt_handle == NULL) { 106 | if (property_get("ro.vendor.extension_library", 107 | opt_lib_path, NULL) <= 0) { 108 | ALOGE("%s: Failed getting perf property", __func__); 109 | ret = -EINVAL; 110 | goto err; 111 | } 112 | if ((qcopt_handle = dlopen(opt_lib_path, RTLD_NOW)) == NULL) { 113 | ALOGE("%s: Failed to open perf handle", __func__); 114 | ret = -EINVAL; 115 | goto err; 116 | } else { 117 | perf_lock_acq = (perf_lock_acquire_t)dlsym(qcopt_handle, 118 | "perf_lock_acq"); 119 | if (perf_lock_acq == NULL) { 120 | ALOGE("%s: Perf lock Acquire NULL", __func__); 121 | dlclose(qcopt_handle); 122 | qcopt_handle = NULL; 123 | ret = -EINVAL; 124 | goto err; 125 | } 126 | perf_lock_rel = (perf_lock_release_t)dlsym(qcopt_handle, 127 | "perf_lock_rel"); 128 | if (perf_lock_rel == NULL) { 129 | ALOGE("%s: Perf lock Release NULL", __func__); 130 | dlclose(qcopt_handle); 131 | qcopt_handle = NULL; 132 | ret = -EINVAL; 133 | goto err; 134 | } 135 | ALOGD("%s: Perf lock handles Success", __func__); 136 | } 137 | } 138 | err: 139 | return ret; 140 | } 141 | 142 | void audio_extn_perf_lock_acquire(void) 143 | { 144 | if (perf_lock_acq) { 145 | perf_lock_handle = perf_lock_acq(perf_lock_handle, 0, perf_lock_opts, 3); 146 | ALOGV("%s: Perf lock acquired", __func__); 147 | } else { 148 | ALOGE("%s: Perf lock acquire error", __func__); 149 | } 150 | } 151 | 152 | void audio_extn_perf_lock_release(void) 153 | { 154 | if (perf_lock_rel && perf_lock_handle) { 155 | perf_lock_rel(perf_lock_handle); 156 | perf_lock_handle = 0; 157 | ALOGV("%s: Perf lock released", __func__); 158 | } else { 159 | ALOGE("%s: Perf lock release error", __func__); 160 | } 161 | } 162 | #endif /* KPI_OPTIMIZE_ENABLED */ 163 | -------------------------------------------------------------------------------- /hal/audio_extn/audio_extn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef AUDIO_EXTN_H 18 | #define AUDIO_EXTN_H 19 | 20 | #include 21 | 22 | #define HW_INFO_ARRAY_MAX_SIZE 32 23 | 24 | struct snd_card_split { 25 | char device[HW_INFO_ARRAY_MAX_SIZE]; 26 | char snd_card[HW_INFO_ARRAY_MAX_SIZE]; 27 | char form_factor[HW_INFO_ARRAY_MAX_SIZE]; 28 | }; 29 | 30 | void *audio_extn_extspk_init(struct audio_device *adev); 31 | void audio_extn_extspk_deinit(void *extn); 32 | void audio_extn_extspk_update(void* extn); 33 | void audio_extn_extspk_set_mode(void* extn, audio_mode_t mode); 34 | void audio_extn_extspk_set_voice_vol(void* extn, float vol); 35 | struct snd_card_split *audio_extn_get_snd_card_split(); 36 | void audio_extn_set_snd_card_split(const char* in_snd_card_name); 37 | 38 | #ifndef SPKR_PROT_ENABLED 39 | #define audio_extn_spkr_prot_init(adev) (0) 40 | #define audio_extn_spkr_prot_start_processing(snd_device) (-EINVAL) 41 | #define audio_extn_spkr_prot_calib_cancel(adev) (0) 42 | #define audio_extn_spkr_prot_stop_processing(snd_device) (0) 43 | #define audio_extn_spkr_prot_is_enabled() (false) 44 | #define audio_extn_get_spkr_prot_snd_device(snd_device) (snd_device) 45 | #define audio_extn_spkr_prot_deinit(adev) (0) 46 | #else 47 | void audio_extn_spkr_prot_init(void *adev); 48 | int audio_extn_spkr_prot_start_processing(snd_device_t snd_device); 49 | void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device); 50 | bool audio_extn_spkr_prot_is_enabled(); 51 | int audio_extn_get_spkr_prot_snd_device(snd_device_t snd_device); 52 | void audio_extn_spkr_prot_calib_cancel(void *adev); 53 | void audio_extn_spkr_prot_deinit(void *adev); 54 | 55 | #endif 56 | 57 | #ifndef HFP_ENABLED 58 | #define audio_extn_hfp_is_active(adev) (0) 59 | #define audio_extn_hfp_get_usecase() (-1) 60 | #define audio_extn_hfp_set_parameters(adev, params) (0) 61 | #define audio_extn_hfp_set_mic_mute(adev, state) (0) 62 | 63 | #else 64 | bool audio_extn_hfp_is_active(struct audio_device *adev); 65 | 66 | audio_usecase_t audio_extn_hfp_get_usecase(); 67 | 68 | void audio_extn_hfp_set_parameters(struct audio_device *adev, 69 | struct str_parms *parms); 70 | int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state); 71 | 72 | #endif 73 | 74 | #ifndef USB_TUNNEL_ENABLED 75 | #define audio_extn_usb_init(adev) (0) 76 | #define audio_extn_usb_deinit() (0) 77 | #define audio_extn_usb_add_device(device, card) (0) 78 | #define audio_extn_usb_remove_device(device, card) (0) 79 | #define audio_extn_usb_is_config_supported(bit_width, sample_rate, ch, pb) (false) 80 | #define audio_extn_usb_enable_sidetone(device, enable) (0) 81 | #define audio_extn_usb_set_sidetone_gain(parms, value, len) (0) 82 | #define audio_extn_usb_is_capture_supported() (false) 83 | #define audio_extn_usb_get_max_channels(dir) (0) 84 | #define audio_extn_usb_get_max_bit_width(dir) (0) 85 | #define audio_extn_usb_sup_sample_rates(t, s, l) ((t), (s), (l), 0) /* fix unused warn */ 86 | #define audio_extn_usb_alive(adev) (false) 87 | #define audio_extn_usb_find_service_interval(m, p) ((m), (p), 0) /* fix unused warn */ 88 | #define audio_extn_usb_altset_for_service_interval(p, si, bw, sr, ch) (-1) 89 | #define audio_extn_usb_usbid() (NULL) 90 | #else 91 | void audio_extn_usb_init(void *adev); 92 | void audio_extn_usb_deinit(); 93 | void audio_extn_usb_add_device(audio_devices_t device, int card); 94 | void audio_extn_usb_remove_device(audio_devices_t device, int card); 95 | bool audio_extn_usb_is_config_supported(unsigned int *bit_width, 96 | unsigned int *sample_rate, 97 | unsigned int *ch, 98 | bool is_playback); 99 | int audio_extn_usb_enable_sidetone(int device, bool enable); 100 | int audio_extn_usb_set_sidetone_gain(struct str_parms *parms, 101 | char *value, int len); 102 | bool audio_extn_usb_is_capture_supported(); 103 | int audio_extn_usb_get_max_channels(bool is_playback); 104 | int audio_extn_usb_get_max_bit_width(bool is_playback); 105 | int audio_extn_usb_sup_sample_rates(bool is_playback, uint32_t *sr, uint32_t l); 106 | bool audio_extn_usb_alive(int card); 107 | unsigned long audio_extn_usb_find_service_interval(bool min, bool playback); 108 | int audio_extn_usb_altset_for_service_interval(bool is_playback, 109 | unsigned long service_interval, 110 | uint32_t *bit_width, 111 | uint32_t *sample_rate, 112 | uint32_t *channel_count); 113 | char *audio_extn_usb_usbid(void); 114 | #endif 115 | 116 | 117 | #ifndef SOUND_TRIGGER_ENABLED 118 | #define audio_extn_sound_trigger_init(adev) (0) 119 | #define audio_extn_sound_trigger_deinit(adev) (0) 120 | #define audio_extn_sound_trigger_update_device_status(snd_dev, event) (0) 121 | #define audio_extn_sound_trigger_update_stream_status(uc_info, event) (0) 122 | #define audio_extn_sound_trigger_set_parameters(adev, parms) (0) 123 | #define audio_extn_sound_trigger_check_and_get_session(in) (0) 124 | #define audio_extn_sound_trigger_stop_lab(in) (0) 125 | #define audio_extn_sound_trigger_read(in, buffer, bytes) (0) 126 | 127 | #else 128 | 129 | enum st_event_type { 130 | ST_EVENT_SND_DEVICE_FREE, 131 | ST_EVENT_SND_DEVICE_BUSY, 132 | ST_EVENT_STREAM_FREE, 133 | ST_EVENT_STREAM_BUSY 134 | }; 135 | typedef enum st_event_type st_event_type_t; 136 | 137 | int audio_extn_sound_trigger_init(struct audio_device *adev); 138 | void audio_extn_sound_trigger_deinit(struct audio_device *adev); 139 | void audio_extn_sound_trigger_update_device_status(snd_device_t snd_device, 140 | st_event_type_t event); 141 | void audio_extn_sound_trigger_update_stream_status(struct audio_usecase *uc_info, 142 | st_event_type_t event); 143 | void audio_extn_sound_trigger_set_parameters(struct audio_device *adev, 144 | struct str_parms *parms); 145 | void audio_extn_sound_trigger_check_and_get_session(struct stream_in *in); 146 | void audio_extn_sound_trigger_stop_lab(struct stream_in *in); 147 | int audio_extn_sound_trigger_read(struct stream_in *in, void *buffer, 148 | size_t bytes); 149 | #endif 150 | 151 | #ifndef A2DP_OFFLOAD_ENABLED 152 | #define audio_extn_a2dp_init(adev) (0) 153 | #define audio_extn_a2dp_start_playback() (0) 154 | #define audio_extn_a2dp_stop_playback() (0) 155 | #define audio_extn_a2dp_set_parameters(parms, reconfig) (0) 156 | #define audio_extn_a2dp_get_parameters(query, reply) (0) 157 | #define audio_extn_a2dp_is_force_device_switch() (0) 158 | #define audio_extn_a2dp_set_handoff_mode(is_on) (0) 159 | #define audio_extn_a2dp_get_sample_rate(sample_rate) (0) 160 | #define audio_extn_a2dp_get_encoder_latency() (0) 161 | #define audio_extn_a2dp_is_ready() (0) 162 | #define audio_extn_a2dp_is_suspended() (0) 163 | #else 164 | void audio_extn_a2dp_init(void *adev); 165 | int audio_extn_a2dp_start_playback(); 166 | int audio_extn_a2dp_stop_playback(); 167 | int audio_extn_a2dp_set_parameters(struct str_parms *parms, bool *reconfig); 168 | int audio_extn_a2dp_get_parameters(struct str_parms *query, 169 | struct str_parms *reply); 170 | bool audio_extn_a2dp_is_force_device_switch(); 171 | void audio_extn_a2dp_set_handoff_mode(bool is_on); 172 | void audio_extn_a2dp_get_sample_rate(int *sample_rate); 173 | uint32_t audio_extn_a2dp_get_encoder_latency(); 174 | bool audio_extn_a2dp_is_ready(); 175 | bool audio_extn_a2dp_is_suspended(); 176 | #endif 177 | 178 | #ifndef DSM_FEEDBACK_ENABLED 179 | #define audio_extn_dsm_feedback_enable(adev, snd_device, benable) (0) 180 | #else 181 | void audio_extn_dsm_feedback_enable(struct audio_device *adev, 182 | snd_device_t snd_device, 183 | bool benable); 184 | #endif 185 | 186 | void audio_extn_utils_send_default_app_type_cfg(void *platform, struct mixer *mixer); 187 | int audio_extn_utils_send_app_type_cfg(struct audio_device *adev, 188 | struct audio_usecase *usecase); 189 | void audio_extn_utils_send_audio_calibration(struct audio_device *adev, 190 | struct audio_usecase *usecase); 191 | int audio_extn_utils_send_app_type_gain(struct audio_device *adev, 192 | int app_type, 193 | int *gain); 194 | #ifndef HWDEP_CAL_ENABLED 195 | #define audio_extn_hwdep_cal_send(snd_card, acdb_handle) (0) 196 | #else 197 | void audio_extn_hwdep_cal_send(int snd_card, void *acdb_handle); 198 | #endif 199 | 200 | #ifndef KPI_OPTIMIZE_ENABLED 201 | #define audio_extn_perf_lock_init() (0) 202 | #define audio_extn_perf_lock_acquire() (0) 203 | #define audio_extn_perf_lock_release() (0) 204 | #else 205 | int audio_extn_perf_lock_init(void); 206 | void audio_extn_perf_lock_acquire(void); 207 | void audio_extn_perf_lock_release(void); 208 | #endif /* KPI_OPTIMIZE_ENABLED */ 209 | 210 | #ifndef HW_VARIANTS_ENABLED 211 | #define hw_info_init(snd_card_name) (0) 212 | #define hw_info_deinit(hw_info) (0) 213 | #define hw_info_append_hw_type(hw_info,\ 214 | snd_device, device_name) (0) 215 | #else 216 | void *hw_info_init(const char *snd_card_name); 217 | void hw_info_deinit(void *hw_info); 218 | void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device, 219 | char *device_name); 220 | #endif /* HW_VARIANTS_ENABLED */ 221 | 222 | typedef void (* snd_mon_cb)(void * stream, struct str_parms * parms); 223 | #ifndef SND_MONITOR_ENABLED 224 | #define audio_extn_snd_mon_init() (0) 225 | #define audio_extn_snd_mon_deinit() (0) 226 | #define audio_extn_snd_mon_register_listener(stream, cb) (0) 227 | #define audio_extn_snd_mon_unregister_listener(stream) (0) 228 | #else 229 | int audio_extn_snd_mon_init(); 230 | int audio_extn_snd_mon_deinit(); 231 | int audio_extn_snd_mon_register_listener(void *stream, snd_mon_cb cb); 232 | int audio_extn_snd_mon_unregister_listener(void *stream); 233 | #endif 234 | 235 | bool audio_extn_utils_resolve_config_file(char[]); 236 | int audio_extn_utils_get_platform_info(const char* snd_card_name, 237 | char* platform_info_file); 238 | int audio_extn_utils_get_snd_card_num(); 239 | #endif /* AUDIO_EXTN_H */ 240 | -------------------------------------------------------------------------------- /hal/audio_extn/audiozoom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "audio_hw_audiozoom" 18 | /*#define LOG_NDEBUG 0*/ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "audio_extn.h" 28 | 29 | #include "audiozoom.h" 30 | 31 | #include 32 | 33 | #define AUDIOZOOM_PRESET_FILE "/vendor/etc/audiozoom.xml" 34 | 35 | typedef struct qdsp_audiozoom_cfg { 36 | uint32_t topo_id; 37 | uint32_t module_id; 38 | uint32_t instance_id; 39 | uint32_t zoom_param_id; 40 | uint32_t wide_param_id; 41 | uint32_t dir_param_id; 42 | uint32_t app_type; 43 | } qdsp_audiozoom_cfg_t; 44 | 45 | static qdsp_audiozoom_cfg_t qdsp_audiozoom; 46 | 47 | static void start_tag(void *userdata __unused, const XML_Char *tag_name, 48 | const XML_Char **attr) 49 | { 50 | uint32_t index = 0; 51 | 52 | if (!attr) { 53 | ALOGE("%s: NULL platform/tag_name/attr", __func__); 54 | return; 55 | } 56 | 57 | if (strcmp(tag_name, "topo") == 0) { 58 | if (strcmp(attr[0], "id") == 0) { 59 | if (attr[1]) 60 | qdsp_audiozoom.topo_id = atoi(attr[1]); 61 | } 62 | } else if (strcmp(tag_name, "module") == 0) { 63 | if (strcmp(attr[0], "id") == 0) { 64 | if (attr[1]) 65 | qdsp_audiozoom.module_id = atoi(attr[1]); 66 | } 67 | } else if (strcmp(tag_name, "param") == 0) { 68 | while (attr[index] != NULL) { 69 | if (strcmp(attr[index], "zoom_id") == 0) { 70 | index++; 71 | if (attr[index]) 72 | qdsp_audiozoom.zoom_param_id = atoi(attr[index]); 73 | else 74 | break; 75 | } else if (strcmp(attr[index], "wide_id") == 0) { 76 | index++; 77 | if (attr[index]) 78 | qdsp_audiozoom.wide_param_id = atoi(attr[index]); 79 | else 80 | break; 81 | } else if (strcmp(attr[index], "dir_id") == 0) { 82 | index++; 83 | if (attr[index]) 84 | qdsp_audiozoom.dir_param_id = atoi(attr[index]); 85 | else 86 | break; 87 | } 88 | index++; 89 | } 90 | } else if (strcmp(tag_name, "app_type") == 0) { 91 | if (strcmp(attr[0], "id") == 0) { 92 | if (attr[1]) 93 | qdsp_audiozoom.app_type = atoi(attr[1]); 94 | } 95 | } else if (strcmp(tag_name, "instance") == 0) { 96 | if (strcmp(attr[0], "id") == 0) { 97 | if (attr[1]) 98 | qdsp_audiozoom.instance_id = atoi(attr[1]); 99 | } 100 | } else { 101 | ALOGE("%s: %s is not a supported tag", __func__, tag_name); 102 | } 103 | 104 | return; 105 | } 106 | 107 | static void end_tag(void *userdata __unused, const XML_Char *tag_name) 108 | { 109 | if (strcmp(tag_name, "topo") == 0) { 110 | } else if (strcmp(tag_name, "module") == 0) { 111 | } else if (strcmp(tag_name, "param") == 0) { 112 | } else if (strcmp(tag_name, "app_type") == 0) { 113 | } else if (strcmp(tag_name, "instance") == 0) { 114 | } else { 115 | ALOGE("%s: %s is not a supported tag", __func__, tag_name); 116 | } 117 | } 118 | 119 | static int audio_extn_audiozoom_parse_info(const char *filename) 120 | { 121 | XML_Parser parser; 122 | FILE *file; 123 | int ret = 0; 124 | int bytes_read; 125 | void *buf; 126 | static const uint32_t kBufSize = 1024; 127 | 128 | file = fopen(filename, "r"); 129 | if (!file) { 130 | ALOGE("%s: Failed to open %s", __func__, filename); 131 | ret = -ENODEV; 132 | goto done; 133 | } 134 | 135 | parser = XML_ParserCreate(NULL); 136 | if (!parser) { 137 | ALOGE("%s: Failed to create XML parser!", __func__); 138 | ret = -ENODEV; 139 | goto err_close_file; 140 | } 141 | 142 | XML_SetElementHandler(parser, start_tag, end_tag); 143 | 144 | while (1) { 145 | buf = XML_GetBuffer(parser, kBufSize); 146 | if (buf == NULL) { 147 | ALOGE("%s: XML_GetBuffer failed", __func__); 148 | ret = -ENOMEM; 149 | goto err_free_parser; 150 | } 151 | 152 | bytes_read = fread(buf, 1, kBufSize, file); 153 | if (bytes_read < 0) { 154 | ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); 155 | ret = bytes_read; 156 | goto err_free_parser; 157 | } 158 | 159 | if (XML_ParseBuffer(parser, bytes_read, 160 | bytes_read == 0) == XML_STATUS_ERROR) { 161 | ALOGE("%s: XML_ParseBuffer failed, for %s", 162 | __func__, filename); 163 | ret = -EINVAL; 164 | goto err_free_parser; 165 | } 166 | 167 | if (bytes_read == 0) 168 | break; 169 | } 170 | 171 | err_free_parser: 172 | XML_ParserFree(parser); 173 | err_close_file: 174 | fclose(file); 175 | done: 176 | return ret; 177 | } 178 | 179 | int audio_extn_audiozoom_set_microphone_direction( 180 | struct stream_in *in, audio_microphone_direction_t dir) 181 | { 182 | (void)in; 183 | (void)dir; 184 | return 0; 185 | } 186 | 187 | static int audio_extn_audiozoom_set_microphone_field_dimension_zoom( 188 | struct stream_in *in, float zoom) 189 | { 190 | struct audio_device *adev = in->dev; 191 | struct str_parms *parms = str_parms_create(); 192 | /* The encoding process in b64_ntop represents 24-bit groups of input bits 193 | as output strings of 4 encoded characters. */ 194 | char data[((sizeof(zoom) + 2) / 3) * 4 + 1] = {0}; 195 | int32_t ret; 196 | 197 | if (zoom > 1.0 || zoom < 0) 198 | return -EINVAL; 199 | 200 | if (qdsp_audiozoom.topo_id == 0 || qdsp_audiozoom.module_id == 0 || 201 | qdsp_audiozoom.zoom_param_id == 0) 202 | return -ENOSYS; 203 | 204 | str_parms_add_int(parms, "cal_devid", in->device); 205 | str_parms_add_int(parms, "cal_apptype", in->app_type_cfg.app_type); 206 | str_parms_add_int(parms, "cal_topoid", qdsp_audiozoom.topo_id); 207 | str_parms_add_int(parms, "cal_moduleid", qdsp_audiozoom.module_id); 208 | str_parms_add_int(parms, "cal_instanceid", qdsp_audiozoom.instance_id); 209 | str_parms_add_int(parms, "cal_paramid", qdsp_audiozoom.zoom_param_id); 210 | 211 | ret = b64_ntop((uint8_t*)&zoom, sizeof(zoom), data, sizeof(data)); 212 | if (ret > 0) { 213 | str_parms_add_str(parms, "cal_data", data); 214 | 215 | platform_set_parameters(adev->platform, parms); 216 | } else { 217 | ALOGE("%s: failed to convert data to string, ret %d", __func__, ret); 218 | } 219 | 220 | str_parms_destroy(parms); 221 | 222 | return 0; 223 | } 224 | 225 | static int audio_extn_audiozoom_set_microphone_field_dimension_wide_angle( 226 | struct stream_in *in, float zoom) 227 | { 228 | (void)in; 229 | (void)zoom; 230 | return 0; 231 | } 232 | 233 | int audio_extn_audiozoom_set_microphone_field_dimension( 234 | struct stream_in *in, float zoom) 235 | { 236 | if (zoom > 1.0 || zoom < -1.0) 237 | return -EINVAL; 238 | 239 | if (zoom >= 0 && zoom <= 1.0) 240 | return audio_extn_audiozoom_set_microphone_field_dimension_zoom(in, zoom); 241 | 242 | if (zoom >= -1.0 && zoom <= 0) 243 | return audio_extn_audiozoom_set_microphone_field_dimension_wide_angle(in, zoom); 244 | 245 | return 0; 246 | } 247 | 248 | int audio_extn_audiozoom_init() 249 | { 250 | audio_extn_audiozoom_parse_info(AUDIOZOOM_PRESET_FILE); 251 | 252 | ALOGV("%s: topo_id=%d, module_id=%d, instance_id=%d, zoom__id=%d, dir_id=%d, app_type=%d", 253 | __func__, qdsp_audiozoom.topo_id, qdsp_audiozoom.module_id, qdsp_audiozoom.instance_id, 254 | qdsp_audiozoom.zoom_param_id, qdsp_audiozoom.dir_param_id,qdsp_audiozoom.app_type); 255 | 256 | return 0; 257 | } 258 | -------------------------------------------------------------------------------- /hal/audio_extn/audiozoom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef AUDIOZOOM_H_ 18 | #define AUDIOZOOM_H_ 19 | 20 | #ifndef AUDIOZOOM_QDSP_ENABLED 21 | #define audio_extn_audiozoom_init() (0) 22 | #define audio_extn_audiozoom_set_microphone_direction(stream, dir) (-ENOSYS) 23 | #define audio_extn_audiozoom_set_microphone_field_dimension(stream, zoom) (-ENOSYS) 24 | #else 25 | int audio_extn_audiozoom_init(); 26 | int audio_extn_audiozoom_set_microphone_direction(struct stream_in *stream, 27 | audio_microphone_direction_t dir); 28 | int audio_extn_audiozoom_set_microphone_field_dimension(struct stream_in *stream, float zoom); 29 | #endif 30 | 31 | #endif /* AUDIOZOOM_H_ */ 32 | -------------------------------------------------------------------------------- /hal/audio_extn/dsm_feedback.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "audio_hw_dsm_feedback" 18 | /*#define LOG_NDEBUG 0*/ 19 | #define LOG_NDDEBUG 0 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "audio_hw.h" 26 | #include "platform.h" 27 | #include "platform_api.h" 28 | #include 29 | 30 | 31 | static struct pcm_config pcm_config_dsm = { 32 | .channels = 2, 33 | .rate = 48000, 34 | .period_size = 256, 35 | .period_count = 4, 36 | .format = PCM_FORMAT_S16_LE, 37 | .start_threshold = 0, 38 | .stop_threshold = INT_MAX, 39 | .avail_min = 0, 40 | }; 41 | 42 | int start_dsm_feedback_processing(struct audio_device *adev, int enable) 43 | { 44 | int ret = 0; 45 | int32_t pcm_dev_tx_id = -1; 46 | static struct pcm *dsm_pcm_handle = NULL; 47 | 48 | if (enable) { 49 | /*do nothing if already enabled*/ 50 | if (dsm_pcm_handle) 51 | return ret; 52 | 53 | pcm_dev_tx_id = platform_get_pcm_device_id(USECASE_AUDIO_DSM_FEEDBACK, PCM_CAPTURE); 54 | if (pcm_dev_tx_id < 0) { 55 | ALOGE("%s: Invalid pcm device for usecase (%d)", 56 | __func__, USECASE_AUDIO_DSM_FEEDBACK); 57 | ret = -ENODEV; 58 | goto close; 59 | } 60 | 61 | dsm_pcm_handle = pcm_open(adev->snd_card, 62 | pcm_dev_tx_id, 63 | PCM_IN, &pcm_config_dsm); 64 | if (dsm_pcm_handle && !pcm_is_ready(dsm_pcm_handle)) { 65 | ALOGE("%s: %s", __func__, pcm_get_error(dsm_pcm_handle)); 66 | ret = -EIO; 67 | goto close; 68 | } 69 | 70 | if (pcm_start(dsm_pcm_handle) < 0) { 71 | ALOGE("%s: pcm start for RX failed", __func__); 72 | ret = -EINVAL; 73 | goto close; 74 | } 75 | 76 | return ret; 77 | } 78 | 79 | close: 80 | /*close pcm if disable or error happend in opening*/ 81 | if (dsm_pcm_handle) { 82 | pcm_close(dsm_pcm_handle); 83 | dsm_pcm_handle = NULL; 84 | } 85 | 86 | return ret; 87 | } 88 | 89 | void audio_extn_dsm_feedback_enable(struct audio_device *adev, 90 | snd_device_t snd_device, 91 | int benable) 92 | { 93 | if ( NULL == adev ) 94 | return; 95 | 96 | if( snd_device == SND_DEVICE_OUT_SPEAKER || 97 | snd_device == SND_DEVICE_OUT_SPEAKER_REVERSE || 98 | snd_device == SND_DEVICE_OUT_VOICE_SPEAKER || 99 | snd_device == SND_DEVICE_OUT_SPEAKER_SAFE || 100 | snd_device == SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES || 101 | snd_device == SND_DEVICE_OUT_SPEAKER_AND_LINE || 102 | snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES || 103 | snd_device == SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE ) 104 | start_dsm_feedback_processing(adev, benable); 105 | } 106 | -------------------------------------------------------------------------------- /hal/audio_extn/ext_speaker.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "ext_speaker" 18 | /*#define LOG_NDEBUG 0*/ 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef __LP64__ 26 | #define LIB_SPEAKER_BUNDLE "/vendor/lib64/soundfx/libspeakerbundle.so" 27 | #else 28 | #define LIB_SPEAKER_BUNDLE "/vendor/lib/soundfx/libspeakerbundle.so" 29 | #endif 30 | 31 | typedef void (*set_mode_t)(int); 32 | typedef void (*set_speaker_on_t)(bool); 33 | typedef void (*set_earpiece_on_t)(bool); 34 | typedef void (*set_voice_vol_t)(float); 35 | 36 | struct speaker_data { 37 | struct audio_device *adev; 38 | void *speaker_bundle; 39 | set_mode_t set_mode; 40 | set_speaker_on_t set_speaker_on; 41 | set_earpiece_on_t set_earpiece_on; 42 | set_voice_vol_t set_voice_vol; 43 | }; 44 | 45 | static struct speaker_data* open_speaker_bundle() 46 | { 47 | struct speaker_data *sd = calloc(1, sizeof(struct speaker_data)); 48 | 49 | sd->speaker_bundle = dlopen(LIB_SPEAKER_BUNDLE, RTLD_NOW); 50 | if (sd->speaker_bundle == NULL) { 51 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_SPEAKER_BUNDLE); 52 | goto error; 53 | } else { 54 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_SPEAKER_BUNDLE); 55 | 56 | sd->set_mode = (set_mode_t)dlsym(sd->speaker_bundle, 57 | "set_mode"); 58 | if (sd->set_mode == NULL) { 59 | ALOGE("%s: dlsym error %s for set_mode", __func__, 60 | dlerror()); 61 | goto error; 62 | } 63 | sd->set_speaker_on = (set_speaker_on_t)dlsym(sd->speaker_bundle, 64 | "set_speaker_on"); 65 | if (sd->set_speaker_on == NULL) { 66 | ALOGE("%s: dlsym error %s for set_speaker_on", __func__, 67 | dlerror()); 68 | goto error; 69 | } 70 | sd->set_earpiece_on = (set_earpiece_on_t)dlsym(sd->speaker_bundle, 71 | "set_earpiece_on"); 72 | if (sd->set_earpiece_on == NULL) { 73 | ALOGE("%s: dlsym error %s for set_earpiece_on", __func__, 74 | dlerror()); 75 | goto error; 76 | } 77 | sd->set_voice_vol = (set_voice_vol_t)dlsym(sd->speaker_bundle, 78 | "set_voice_volume"); 79 | if (sd->set_voice_vol == NULL) { 80 | ALOGE("%s: dlsym error %s for set_voice_volume", 81 | __func__, dlerror()); 82 | goto error; 83 | } 84 | } 85 | return sd; 86 | 87 | error: 88 | free(sd); 89 | return 0; 90 | } 91 | 92 | static void close_speaker_bundle(struct speaker_data *sd) 93 | { 94 | if (sd != NULL) { 95 | dlclose(sd->speaker_bundle); 96 | free(sd); 97 | sd = NULL; 98 | } 99 | } 100 | 101 | void *audio_extn_extspk_init(struct audio_device *adev) 102 | { 103 | struct speaker_data *data = open_speaker_bundle(); 104 | 105 | if (data) 106 | data->adev = adev; 107 | 108 | return data; 109 | } 110 | 111 | void audio_extn_extspk_deinit(void *extn) 112 | { 113 | struct speaker_data *data = (struct speaker_data*)extn; 114 | close_speaker_bundle(data); 115 | } 116 | 117 | void audio_extn_extspk_update(void* extn) 118 | { 119 | struct speaker_data *data = (struct speaker_data*)extn; 120 | 121 | if (data) { 122 | bool speaker_on = false; 123 | bool earpiece_on = false; 124 | struct listnode *node; 125 | struct audio_usecase *usecase; 126 | list_for_each(node, &data->adev->usecase_list) { 127 | usecase = node_to_item(node, struct audio_usecase, list); 128 | if (usecase->devices & AUDIO_DEVICE_OUT_EARPIECE) { 129 | if(data->adev->snd_dev_ref_cnt[usecase->out_snd_device] != 0) { 130 | earpiece_on = true; 131 | } 132 | } 133 | if (usecase->devices & AUDIO_DEVICE_OUT_SPEAKER) { 134 | if(data->adev->snd_dev_ref_cnt[usecase->out_snd_device] != 0) { 135 | speaker_on = true; 136 | } 137 | } 138 | } 139 | data->set_earpiece_on(earpiece_on); 140 | data->set_speaker_on(speaker_on); 141 | } 142 | } 143 | 144 | void audio_extn_extspk_set_mode(void* extn, audio_mode_t mode) 145 | { 146 | struct speaker_data *data = (struct speaker_data*)extn; 147 | 148 | if (data) 149 | data->set_mode(mode); 150 | } 151 | 152 | void audio_extn_extspk_set_voice_vol(void* extn, float vol) 153 | { 154 | struct speaker_data *data = (struct speaker_data*)extn; 155 | 156 | if (data) 157 | data->set_voice_vol(vol); 158 | } 159 | -------------------------------------------------------------------------------- /hal/audio_extn/hfp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "audio_hw_hfp" 18 | /*#define LOG_NDEBUG 0*/ 19 | #define LOG_NDDEBUG 0 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "audio_hw.h" 26 | #include "platform.h" 27 | #include "platform_api.h" 28 | #include 29 | #include 30 | #include "audio_extn/tfa_98xx.h" 31 | #include "audio_extn.h" 32 | 33 | #define AUDIO_PARAMETER_HFP_ENABLE "hfp_enable" 34 | #define AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate" 35 | #define AUDIO_PARAMETER_KEY_HFP_VOLUME "hfp_volume" 36 | #define AUDIO_PARAMETER_HFP_VOL_MIXER_CTL "hfp_vol_mixer_ctl" 37 | #define AUDIO_PARAMATER_HFP_VALUE_MAX 128 38 | 39 | #define AUDIO_PARAMETER_KEY_HFP_MIC_VOLUME "hfp_mic_volume" 40 | #define PLAYBACK_VOLUME_MAX 0x2000 41 | #define CAPTURE_VOLUME_DEFAULT (15.0) 42 | 43 | static int32_t start_hfp(struct audio_device *adev, 44 | struct str_parms *parms); 45 | 46 | static int32_t stop_hfp(struct audio_device *adev); 47 | 48 | struct hfp_module { 49 | struct pcm *hfp_sco_rx; 50 | struct pcm *hfp_sco_tx; 51 | struct pcm *hfp_pcm_rx; 52 | struct pcm *hfp_pcm_tx; 53 | float hfp_volume; 54 | float mic_volume; 55 | char hfp_vol_mixer_ctl[AUDIO_PARAMATER_HFP_VALUE_MAX]; 56 | bool is_hfp_running; 57 | bool mic_mute; 58 | audio_usecase_t ucid; 59 | }; 60 | 61 | static struct hfp_module hfpmod = { 62 | .hfp_sco_rx = NULL, 63 | .hfp_sco_tx = NULL, 64 | .hfp_pcm_rx = NULL, 65 | .hfp_pcm_tx = NULL, 66 | .hfp_volume = 0, 67 | .mic_volume = CAPTURE_VOLUME_DEFAULT, 68 | .hfp_vol_mixer_ctl = {0, }, 69 | .is_hfp_running = 0, 70 | .mic_mute = 0, 71 | .ucid = USECASE_AUDIO_HFP_SCO, 72 | }; 73 | static struct pcm_config pcm_config_hfp = { 74 | .channels = 1, 75 | .rate = 8000, 76 | .period_size = 240, 77 | .period_count = 2, 78 | .format = PCM_FORMAT_S16_LE, 79 | .start_threshold = 0, 80 | .stop_threshold = INT_MAX, 81 | .avail_min = 0, 82 | }; 83 | 84 | static int32_t hfp_set_volume(struct audio_device *adev, float value) 85 | { 86 | int32_t vol, ret = 0; 87 | struct mixer_ctl *ctl; 88 | 89 | ALOGV("%s: entry", __func__); 90 | ALOGD("%s: (%f)\n", __func__, value); 91 | 92 | hfpmod.hfp_volume = value; 93 | audio_extn_tfa_98xx_set_voice_vol(value); 94 | 95 | if (value < 0.0) { 96 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); 97 | value = 0.0; 98 | } else { 99 | value = ((value > 15.000000) ? 1.0 : (value / 15)); 100 | ALOGW("%s: Volume brought with in range (%f)\n", __func__, value); 101 | } 102 | vol = lrint((value * 0x2000) + 0.5); 103 | 104 | if (!hfpmod.is_hfp_running) { 105 | ALOGV("%s: HFP not active, ignoring set_hfp_volume call", __func__); 106 | return -EIO; 107 | } 108 | 109 | ALOGD("%s: Setting HFP volume to %d \n", __func__, vol); 110 | if (0 == hfpmod.hfp_vol_mixer_ctl[0]) { 111 | #ifdef EXTERNAL_BT_SUPPORTED 112 | strcpy(hfpmod.hfp_vol_mixer_ctl, "PRI AUXPCM LOOPBACK Volume"); 113 | #else 114 | strcpy(hfpmod.hfp_vol_mixer_ctl, "Internal HFP RX Volume"); 115 | #endif 116 | ALOGW("%s: Defaulting hfp mixer control to: %s", 117 | __func__, hfpmod.hfp_vol_mixer_ctl); 118 | } 119 | ctl = mixer_get_ctl_by_name(adev->mixer, hfpmod.hfp_vol_mixer_ctl); 120 | if (!ctl) { 121 | ALOGE("%s: Could not get ctl for mixer cmd - %s", 122 | __func__, hfpmod.hfp_vol_mixer_ctl); 123 | return -EINVAL; 124 | } 125 | if(mixer_ctl_set_value(ctl, 0, vol) < 0) { 126 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, vol); 127 | return -EINVAL; 128 | } 129 | 130 | ALOGV("%s: exit", __func__); 131 | return ret; 132 | } 133 | 134 | 135 | /*Set mic volume to value. 136 | * 137 | * This interface is used for mic volume control, set mic volume as value(range 0 ~ 15). 138 | */ 139 | static int hfp_set_mic_volume(struct audio_device *adev, float value) 140 | { 141 | int volume, ret = 0; 142 | char mixer_ctl_name[128]; 143 | struct mixer_ctl *ctl; 144 | int pcm_device_id = HFP_ASM_RX_TX; 145 | 146 | if (!hfpmod.is_hfp_running) { 147 | ALOGE("%s: HFP not active, ignoring set_hfp_mic_volume call", __func__); 148 | return -EIO; 149 | } 150 | 151 | if (value < 0.0) { 152 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); 153 | value = 0.0; 154 | } else if (value > CAPTURE_VOLUME_DEFAULT) { 155 | value = CAPTURE_VOLUME_DEFAULT; 156 | ALOGW("%s: Volume brought within range (%f)\n", __func__, value); 157 | } 158 | 159 | value = value / CAPTURE_VOLUME_DEFAULT; 160 | memset(mixer_ctl_name, 0, sizeof(mixer_ctl_name)); 161 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), 162 | "Playback %d Volume", pcm_device_id); 163 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); 164 | if (!ctl) { 165 | ALOGE("%s: Could not get ctl for mixer cmd - %s", 166 | __func__, mixer_ctl_name); 167 | return -EINVAL; 168 | } 169 | volume = (int)(value * PLAYBACK_VOLUME_MAX); 170 | 171 | ALOGD("%s: Setting volume to %d (%s)\n", __func__, volume, mixer_ctl_name); 172 | if (mixer_ctl_set_value(ctl, 0, volume) < 0) { 173 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, volume); 174 | return -EINVAL; 175 | } 176 | 177 | return ret; 178 | } 179 | 180 | static float hfp_get_mic_volume(struct audio_device *adev) 181 | { 182 | int volume, ret = 0; 183 | char mixer_ctl_name[128]; 184 | struct mixer_ctl *ctl; 185 | int pcm_device_id = HFP_ASM_RX_TX; 186 | float value = 0.0; 187 | 188 | if (!hfpmod.is_hfp_running) { 189 | ALOGE("%s: HFP not active, ignoring set_hfp_mic_volume call", __func__); 190 | return -EIO; 191 | } 192 | 193 | memset(mixer_ctl_name, 0, sizeof(mixer_ctl_name)); 194 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), 195 | "Playback %d Volume", pcm_device_id); 196 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); 197 | if (!ctl) { 198 | ALOGE("%s: Could not get ctl for mixer cmd - %s", 199 | __func__, mixer_ctl_name); 200 | return -EINVAL; 201 | } 202 | 203 | volume = mixer_ctl_get_value(ctl, 0); 204 | if ( volume < 0) { 205 | ALOGE("%s: Couldn't set HFP Volume: [%d]", __func__, volume); 206 | return -EINVAL; 207 | } 208 | ALOGD("%s: getting mic volume %d \n", __func__, volume); 209 | 210 | value = (volume / PLAYBACK_VOLUME_MAX) * CAPTURE_VOLUME_DEFAULT; 211 | if (value < 0.0) { 212 | ALOGW("%s: (%f) Under 0.0, assuming 0.0\n", __func__, value); 213 | value = 0.0; 214 | } else if (value > CAPTURE_VOLUME_DEFAULT) { 215 | value = CAPTURE_VOLUME_DEFAULT; 216 | ALOGW("%s: Volume brought within range (%f)\n", __func__, value); 217 | } 218 | 219 | return value; 220 | } 221 | 222 | /*Set mic mute state. 223 | * 224 | * This interface is used for mic mute state control 225 | */ 226 | int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state) 227 | { 228 | int rc = 0; 229 | 230 | if (state == hfpmod.mic_mute) 231 | return rc; 232 | 233 | if (state == true) { 234 | hfpmod.mic_volume = hfp_get_mic_volume(adev); 235 | } 236 | rc = hfp_set_mic_volume(adev, (state == true) ? 0.0 : hfpmod.mic_volume); 237 | adev->voice.mic_mute = state; 238 | hfpmod.mic_mute = state; 239 | ALOGD("%s: Setting mute state %d, rc %d\n", __func__, state, rc); 240 | return rc; 241 | } 242 | 243 | static int32_t start_hfp(struct audio_device *adev, 244 | struct str_parms *parms __unused) 245 | { 246 | int32_t i, ret = 0; 247 | struct audio_usecase *uc_info; 248 | int32_t pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, pcm_dev_asm_tx_id; 249 | 250 | ALOGD("%s: enter", __func__); 251 | 252 | if (adev->enable_hfp == true) { 253 | ALOGD("%s: HFP is already active!\n", __func__); 254 | return 0; 255 | } 256 | adev->enable_hfp = true; 257 | platform_set_mic_mute(adev->platform, false); 258 | 259 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); 260 | uc_info->id = hfpmod.ucid; 261 | uc_info->type = PCM_HFP_CALL; 262 | uc_info->stream.out = adev->primary_output; 263 | uc_info->devices = adev->primary_output->devices; 264 | uc_info->in_snd_device = SND_DEVICE_NONE; 265 | uc_info->out_snd_device = SND_DEVICE_NONE; 266 | 267 | list_add_tail(&adev->usecase_list, &uc_info->list); 268 | 269 | audio_extn_tfa_98xx_set_mode_bt(); 270 | 271 | select_devices(adev, hfpmod.ucid); 272 | 273 | pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); 274 | pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); 275 | pcm_dev_asm_rx_id = HFP_ASM_RX_TX; 276 | pcm_dev_asm_tx_id = HFP_ASM_RX_TX; 277 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0 || 278 | pcm_dev_asm_rx_id < 0 || pcm_dev_asm_tx_id < 0 ) { 279 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d asm: rx tx %d) for the usecase(%d)", 280 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, pcm_dev_asm_rx_id, uc_info->id); 281 | ret = -EIO; 282 | goto exit; 283 | } 284 | 285 | ALOGV("%s: HFP PCM devices (hfp rx tx: %d pcm rx tx: %d) for the usecase(%d)", 286 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id); 287 | 288 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", 289 | __func__, adev->snd_card, pcm_dev_rx_id); 290 | hfpmod.hfp_sco_rx = pcm_open(adev->snd_card, 291 | pcm_dev_asm_rx_id, 292 | PCM_OUT, &pcm_config_hfp); 293 | if (hfpmod.hfp_sco_rx && !pcm_is_ready(hfpmod.hfp_sco_rx)) { 294 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_rx)); 295 | ret = -EIO; 296 | goto exit; 297 | } 298 | ALOGD("%s: Opening PCM capture device card_id(%d) device_id(%d)", 299 | __func__, adev->snd_card, pcm_dev_tx_id); 300 | 301 | if (audio_extn_tfa_98xx_is_supported() == false) { 302 | hfpmod.hfp_pcm_rx = pcm_open(adev->snd_card, 303 | pcm_dev_rx_id, 304 | PCM_OUT, &pcm_config_hfp); 305 | if (hfpmod.hfp_pcm_rx && !pcm_is_ready(hfpmod.hfp_pcm_rx)) { 306 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_rx)); 307 | ret = -EIO; 308 | goto exit; 309 | } 310 | } 311 | hfpmod.hfp_sco_tx = pcm_open(adev->snd_card, 312 | pcm_dev_asm_tx_id, 313 | PCM_IN, &pcm_config_hfp); 314 | if (hfpmod.hfp_sco_tx && !pcm_is_ready(hfpmod.hfp_sco_tx)) { 315 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_sco_tx)); 316 | ret = -EIO; 317 | goto exit; 318 | } 319 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", 320 | __func__, adev->snd_card, pcm_dev_tx_id); 321 | 322 | if (audio_extn_tfa_98xx_is_supported() == false) { 323 | hfpmod.hfp_pcm_tx = pcm_open(adev->snd_card, 324 | pcm_dev_tx_id, 325 | PCM_IN, &pcm_config_hfp); 326 | if (hfpmod.hfp_pcm_tx && !pcm_is_ready(hfpmod.hfp_pcm_tx)) { 327 | ALOGE("%s: %s", __func__, pcm_get_error(hfpmod.hfp_pcm_tx)); 328 | ret = -EIO; 329 | goto exit; 330 | } 331 | } 332 | pcm_start(hfpmod.hfp_sco_rx); 333 | pcm_start(hfpmod.hfp_sco_tx); 334 | if (audio_extn_tfa_98xx_is_supported() == false) { 335 | pcm_start(hfpmod.hfp_pcm_rx); 336 | pcm_start(hfpmod.hfp_pcm_tx); 337 | } 338 | 339 | audio_extn_tfa_98xx_enable_speaker(); 340 | 341 | hfpmod.is_hfp_running = true; 342 | hfp_set_volume(adev, hfpmod.hfp_volume); 343 | 344 | /* Set mic volume by mute status, we don't provide set mic volume in phone app, only 345 | provide mute and unmute. */ 346 | audio_extn_hfp_set_mic_mute(adev, adev->mic_muted); 347 | 348 | ALOGD("%s: exit: status(%d)", __func__, ret); 349 | return 0; 350 | 351 | exit: 352 | stop_hfp(adev); 353 | ALOGE("%s: Problem in HFP start: status(%d)", __func__, ret); 354 | return ret; 355 | } 356 | 357 | static int32_t stop_hfp(struct audio_device *adev) 358 | { 359 | int32_t i, ret = 0; 360 | struct audio_usecase *uc_info; 361 | 362 | ALOGD("%s: enter", __func__); 363 | hfpmod.is_hfp_running = false; 364 | 365 | /* 1. Close the PCM devices */ 366 | if (hfpmod.hfp_sco_rx) { 367 | pcm_close(hfpmod.hfp_sco_rx); 368 | hfpmod.hfp_sco_rx = NULL; 369 | } 370 | if (hfpmod.hfp_sco_tx) { 371 | pcm_close(hfpmod.hfp_sco_tx); 372 | hfpmod.hfp_sco_tx = NULL; 373 | } 374 | if (hfpmod.hfp_pcm_rx) { 375 | pcm_close(hfpmod.hfp_pcm_rx); 376 | hfpmod.hfp_pcm_rx = NULL; 377 | } 378 | if (hfpmod.hfp_pcm_tx) { 379 | pcm_close(hfpmod.hfp_pcm_tx); 380 | hfpmod.hfp_pcm_tx = NULL; 381 | } 382 | 383 | uc_info = get_usecase_from_list(adev, hfpmod.ucid); 384 | if (uc_info == NULL) { 385 | ALOGE("%s: Could not find the usecase (%d) in the list", 386 | __func__, hfpmod.ucid); 387 | return -EINVAL; 388 | } 389 | 390 | /* 2. Get and set stream specific mixer controls */ 391 | disable_audio_route(adev, uc_info); 392 | 393 | /* 3. Disable the rx and tx devices */ 394 | disable_snd_device(adev, uc_info->out_snd_device); 395 | disable_snd_device(adev, uc_info->in_snd_device); 396 | 397 | /* Disable the echo reference for HFP Tx */ 398 | platform_set_echo_reference(adev, false, AUDIO_DEVICE_NONE); 399 | 400 | /* Set the unmute Tx mixer control */ 401 | if (voice_get_mic_mute(adev)) { 402 | platform_set_mic_mute(adev->platform, false); 403 | ALOGD("%s: unMute HFP Tx", __func__); 404 | } 405 | adev->enable_hfp = false; 406 | 407 | list_remove(&uc_info->list); 408 | free(uc_info); 409 | 410 | ALOGD("%s: exit: status(%d)", __func__, ret); 411 | return ret; 412 | } 413 | 414 | bool audio_extn_hfp_is_active(struct audio_device *adev) 415 | { 416 | struct audio_usecase *hfp_usecase = NULL; 417 | hfp_usecase = get_usecase_from_list(adev, hfpmod.ucid); 418 | 419 | if (hfp_usecase != NULL) 420 | return true; 421 | else 422 | return false; 423 | } 424 | 425 | audio_usecase_t audio_extn_hfp_get_usecase() 426 | { 427 | return hfpmod.ucid; 428 | } 429 | 430 | void audio_extn_hfp_set_parameters(struct audio_device *adev, struct str_parms *parms) 431 | { 432 | int ret; 433 | int rate; 434 | int val; 435 | float vol; 436 | char value[AUDIO_PARAMATER_HFP_VALUE_MAX] = {0, }; 437 | 438 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_ENABLE, value, 439 | sizeof(value)); 440 | if (ret >= 0) { 441 | if (!strncmp(value,"true",sizeof(value))) { 442 | if (!hfpmod.is_hfp_running) 443 | start_hfp(adev,parms); 444 | else 445 | ALOGW("%s: HFP is already active.", __func__); 446 | } else { 447 | if (hfpmod.is_hfp_running) 448 | stop_hfp(adev); 449 | else 450 | ALOGW("%s: ignore STOP, HFC not active", __func__); 451 | } 452 | } 453 | memset(value, 0, sizeof(value)); 454 | ret = str_parms_get_str(parms,AUDIO_PARAMETER_HFP_SET_SAMPLING_RATE, value, 455 | sizeof(value)); 456 | if (ret >= 0) { 457 | rate = atoi(value); 458 | if (rate == 8000){ 459 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO; 460 | pcm_config_hfp.rate = rate; 461 | } else if (rate == 16000){ 462 | hfpmod.ucid = USECASE_AUDIO_HFP_SCO_WB; 463 | pcm_config_hfp.rate = rate; 464 | } else 465 | ALOGE("Unsupported rate.."); 466 | } 467 | 468 | if (hfpmod.is_hfp_running) { 469 | memset(value, 0, sizeof(value)); 470 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, 471 | value, sizeof(value)); 472 | if (ret >= 0) { 473 | val = atoi(value); 474 | if (val > 0) 475 | select_devices(adev, hfpmod.ucid); 476 | } 477 | } 478 | 479 | memset(value, 0, sizeof(value)); 480 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_HFP_VOL_MIXER_CTL, 481 | value, sizeof(value)); 482 | if (ret >= 0) { 483 | ALOGD("%s: mixer ctl name: %s", __func__, value); 484 | strcpy(hfpmod.hfp_vol_mixer_ctl, value); 485 | str_parms_del(parms, AUDIO_PARAMETER_HFP_VOL_MIXER_CTL); 486 | } 487 | 488 | memset(value, 0, sizeof(value)); 489 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_VOLUME, 490 | value, sizeof(value)); 491 | if (ret >= 0) { 492 | if (sscanf(value, "%f", &vol) != 1){ 493 | ALOGE("%s: error in retrieving hfp volume", __func__); 494 | ret = -EIO; 495 | goto exit; 496 | } 497 | ALOGD("%s: set_hfp_volume usecase, Vol: [%f]", __func__, vol); 498 | hfp_set_volume(adev, vol); 499 | } 500 | 501 | memset(value, 0, sizeof(value)); 502 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HFP_MIC_VOLUME, 503 | value, sizeof(value)); 504 | if (ret >= 0) { 505 | if (sscanf(value, "%f", &vol) != 1){ 506 | ALOGE("%s: error in retrieving hfp mic volume", __func__); 507 | ret = -EIO; 508 | goto exit; 509 | } 510 | ALOGD("%s: set_hfp_mic_volume usecase, Vol: [%f]", __func__, vol); 511 | hfp_set_mic_volume(adev, vol); 512 | } 513 | 514 | exit: 515 | ALOGV("%s Exit",__func__); 516 | } 517 | -------------------------------------------------------------------------------- /hal/audio_extn/hwdep_cal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "hardware_cal" 18 | /*#define LOG_NDEBUG 0*/ 19 | #define LOG_NDDEBUG 0 20 | 21 | #ifdef HWDEP_CAL_ENABLED 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "audio_extn.h" 31 | #include "sound/msmcal-hwdep.h" 32 | 33 | #define SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID (100) 34 | #define MAX_CAL_NAME 20 35 | 36 | typedef struct acdb_audio_cal_cfg { 37 | uint32_t persist; 38 | uint32_t snd_dev_id; 39 | audio_devices_t dev_id; 40 | int32_t acdb_dev_id; 41 | uint32_t app_type; 42 | uint32_t topo_id; 43 | uint32_t sampling_rate; 44 | uint32_t cal_type; 45 | uint32_t module_id; 46 | uint32_t param_id; 47 | } acdb_audio_cal_cfg_t; 48 | 49 | struct param_data { 50 | int use_case; 51 | int acdb_id; 52 | int get_size; 53 | int buff_size; 54 | int data_size; 55 | void *buff; 56 | }; 57 | 58 | char cal_name_info[WCD9XXX_MAX_CAL][MAX_CAL_NAME] = { 59 | [WCD9XXX_ANC_CAL] = "anc_cal", 60 | [WCD9XXX_MBHC_CAL] = "mbhc_cal", 61 | [WCD9XXX_MAD_CAL] = "mad_cal", 62 | }; 63 | 64 | typedef int (*acdb_get_calibration_t)(char *attr, int size, void *data); 65 | acdb_get_calibration_t acdb_get_calibration; 66 | 67 | static int hw_util_open(int card_no) 68 | { 69 | int fd = -1; 70 | char dev_name[256]; 71 | 72 | snprintf(dev_name, sizeof(dev_name), "/dev/snd/hwC%uD%u", 73 | card_no, WCD9XXX_CODEC_HWDEP_NODE); 74 | ALOGD("%s: Opening device %s\n", __func__, dev_name); 75 | fd = open(dev_name, O_WRONLY); 76 | if (fd < 0) { 77 | ALOGE("%s: cannot open device '%s'\n", __func__, dev_name); 78 | return fd; 79 | } 80 | ALOGD("%s: success", __func__); 81 | return fd; 82 | } 83 | 84 | static int send_codec_cal(acdb_get_calibration_t acdb_loader_get_calibration, int fd) 85 | { 86 | int ret = 0, type; 87 | 88 | for (type = WCD9XXX_ANC_CAL; type < WCD9XXX_MAX_CAL; type++) { 89 | struct wcdcal_ioctl_buffer codec_buffer; 90 | struct param_data calib; 91 | 92 | if (!strcmp(cal_name_info[type], "mad_cal")) 93 | calib.acdb_id = SOUND_TRIGGER_DEVICE_HANDSET_MONO_LOW_POWER_ACDB_ID; 94 | calib.get_size = 1; 95 | ret = acdb_loader_get_calibration(cal_name_info[type], sizeof(struct param_data), 96 | &calib); 97 | if (ret < 0) { 98 | ALOGE("%s get_calibration failed\n", __func__); 99 | return ret; 100 | } 101 | calib.get_size = 0; 102 | calib.buff = malloc(calib.buff_size); 103 | ret = acdb_loader_get_calibration(cal_name_info[type], 104 | sizeof(struct param_data), &calib); 105 | if (ret < 0) { 106 | ALOGE("%s get_calibration failed\n", __func__); 107 | free(calib.buff); 108 | return ret; 109 | } 110 | codec_buffer.buffer = calib.buff; 111 | codec_buffer.size = calib.data_size; 112 | codec_buffer.cal_type = type; 113 | if (ioctl(fd, SNDRV_CTL_IOCTL_HWDEP_CAL_TYPE, &codec_buffer) < 0) 114 | ALOGE("Failed to call ioctl for %s err=%d", 115 | cal_name_info[type], errno); 116 | ALOGD("%s cal sent for %s", __func__, cal_name_info[type]); 117 | free(calib.buff); 118 | } 119 | return ret; 120 | } 121 | 122 | 123 | void audio_extn_hwdep_cal_send(int snd_card, void *acdb_handle) 124 | { 125 | int fd; 126 | 127 | fd = hw_util_open(snd_card); 128 | if (fd == -1) { 129 | ALOGE("%s error open\n", __func__); 130 | return; 131 | } 132 | 133 | acdb_get_calibration = (acdb_get_calibration_t) 134 | dlsym(acdb_handle, "acdb_loader_get_calibration"); 135 | 136 | if (acdb_get_calibration == NULL) { 137 | ALOGE("%s: ERROR. dlsym Error:%s acdb_loader_get_calibration", __func__, 138 | dlerror()); 139 | return; 140 | } 141 | if (send_codec_cal(acdb_get_calibration, fd) < 0) 142 | ALOGE("%s: Could not send anc cal", __FUNCTION__); 143 | 144 | close(fd); 145 | } 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /hal/audio_extn/maxxaudio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef MAXXAUDIO_H_ 18 | #define MAXXAUDIO_H_ 19 | 20 | #ifndef MAXXAUDIO_QDSP_ENABLED 21 | #define audio_extn_ma_init(platform) (0) 22 | #define audio_extn_ma_deinit() (0) 23 | #define audio_extn_ma_set_state(adev, type, vol, active) (false) 24 | #define audio_extn_ma_set_device(usecase) (0) 25 | #define audio_extn_ma_set_parameters(adev, param) (0) 26 | #define audio_extn_ma_supported_usb() (false) 27 | #else 28 | void audio_extn_ma_init(void *platform); 29 | void audio_extn_ma_deinit(); 30 | bool audio_extn_ma_set_state(struct audio_device *adev, int stream_type, 31 | float vol, bool active); 32 | void audio_extn_ma_set_device(struct audio_usecase *usecase); 33 | void audio_extn_ma_set_parameters(struct audio_device *adev, 34 | struct str_parms *parms); 35 | bool audio_extn_ma_supported_usb(); 36 | #endif /* MAXXAUDIO_QDSP_ENABLED */ 37 | 38 | #endif /* MAXXAUDIO_H_ */ 39 | 40 | -------------------------------------------------------------------------------- /hal/audio_extn/tfa_98xx.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "tfa_98xx" 18 | /*#define LOG_NDEBUG 0*/ 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include "audio_extn.h" 25 | #include 26 | #include 27 | 28 | #define LIB_SPEAKER_BUNDLE "/system/lib/libexTfa98xx.so" 29 | 30 | 31 | enum exTfa98xx_Audio_Mode 32 | { 33 | Audio_Mode_None = -1, 34 | Audio_Mode_Music_Normal, 35 | Audio_Mode_Hfp_Client, 36 | Audio_Mode_Voice, 37 | Audio_Mode_Hs_Hfp, 38 | Audio_Mode_Max 39 | }; 40 | typedef enum exTfa98xx_Audio_Mode exTfa98xx_audio_mode_t; 41 | 42 | enum exTfa98xx_Func_Mode 43 | { 44 | Func_Mode_None = -1, 45 | Func_Mode_Speaker, 46 | Func_Mode_BT 47 | }; 48 | typedef enum exTfa98xx_Func_Mode exTfa98xx_func_mode_t; 49 | 50 | #define I2S_CLOCK_ENABLE 1 51 | #define I2S_CLOCK_DISABLE 0 52 | #define HFP_MAX_VOLUME (15.000000) 53 | #define TFA_98XX_HFP_VSETPS (5.0) 54 | 55 | exTfa98xx_audio_mode_t current_audio_mode = Audio_Mode_None; 56 | 57 | typedef int (*set_speaker_on_t)(exTfa98xx_audio_mode_t); 58 | typedef int (*set_speaker_off_t)(void); 59 | typedef int (*set_speaker_calibration_t)(int); 60 | typedef void (*set_speaker_volume_step_t)(int, int); 61 | 62 | 63 | struct speaker_data { 64 | struct audio_device *adev; 65 | void *speaker_bundle; 66 | set_speaker_on_t set_speaker_on; 67 | set_speaker_off_t set_speaker_off; 68 | set_speaker_calibration_t set_speaker_calibration; 69 | set_speaker_volume_step_t set_speaker_volume_step; 70 | int ref_cnt[Audio_Mode_Max]; 71 | int route_cnt[Audio_Mode_Max]; 72 | bool update_ref_cnt; 73 | }; 74 | 75 | struct speaker_data *tfa98xx_speaker_data = NULL; 76 | 77 | static struct speaker_data* open_speaker_bundle() 78 | { 79 | struct speaker_data *sd = calloc(1, sizeof(struct speaker_data)); 80 | 81 | sd->speaker_bundle = dlopen(LIB_SPEAKER_BUNDLE, RTLD_NOW); 82 | if (sd->speaker_bundle == NULL) { 83 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_SPEAKER_BUNDLE); 84 | goto error; 85 | } else { 86 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_SPEAKER_BUNDLE); 87 | 88 | sd->set_speaker_on = (set_speaker_on_t)dlsym(sd->speaker_bundle, 89 | "exTfa98xx_speakeron"); 90 | if (sd->set_speaker_on == NULL) { 91 | ALOGE("%s: dlsym error %s for exTfa98xx_speakeron", __func__, 92 | dlerror()); 93 | goto error; 94 | } 95 | sd->set_speaker_off = (set_speaker_off_t)dlsym(sd->speaker_bundle, 96 | "exTfa98xx_speakeroff"); 97 | if (sd->set_speaker_off == NULL) { 98 | ALOGE("%s: dlsym error %s for exTfa98xx_speakeroff", __func__, 99 | dlerror()); 100 | goto error; 101 | } 102 | sd->set_speaker_volume_step = (set_speaker_volume_step_t)dlsym(sd->speaker_bundle, 103 | "exTfa98xx_setvolumestep"); 104 | if (sd->set_speaker_volume_step == NULL) { 105 | ALOGE("%s: dlsym error %s for exTfa98xx_setvolumestep", 106 | __func__, dlerror()); 107 | goto error; 108 | } 109 | sd->set_speaker_calibration = (set_speaker_calibration_t)dlsym(sd->speaker_bundle, 110 | "exTfa98xx_calibration"); 111 | if (sd->set_speaker_calibration == NULL) { 112 | ALOGE("%s: dlsym error %s for exTfa98xx_calibration", 113 | __func__, dlerror()); 114 | goto error; 115 | } 116 | } 117 | return sd; 118 | 119 | error: 120 | free(sd); 121 | return 0; 122 | } 123 | 124 | static void close_speaker_bundle(struct speaker_data *sd) 125 | { 126 | if (sd != NULL) { 127 | dlclose(sd->speaker_bundle); 128 | free(sd); 129 | sd = NULL; 130 | } 131 | } 132 | 133 | static int adev_i2s_clock_operation(int enable, struct audio_device *adev, char *paths) 134 | { 135 | int ret = -1; 136 | 137 | ALOGD("%s: mixer paths is: %s, enable: %d\n", __func__, paths, enable); 138 | if(I2S_CLOCK_ENABLE == enable) { 139 | ret = audio_route_apply_and_update_path(adev->audio_route, paths); 140 | if(ret) { 141 | ALOGE("%s: audio_route_apply_and_update_path return %d\n", __func__, ret); 142 | return ret; 143 | } 144 | } else { 145 | ret = audio_route_reset_and_update_path(adev->audio_route, paths); 146 | if(ret) { 147 | ALOGE("%s: audio_route_reset_and_update_path return %d\n", __func__, ret); 148 | return ret; 149 | } 150 | } 151 | return 0; 152 | } 153 | 154 | static int tfa_98xx_set_audio_mode(int enable, struct audio_device *adev, exTfa98xx_audio_mode_t audio_mode) 155 | { 156 | char paths[32] = "init_smart_pa"; 157 | 158 | switch(audio_mode) { 159 | case Audio_Mode_Music_Normal: 160 | strcat(paths, " music"); 161 | break; 162 | case Audio_Mode_Voice: 163 | case Audio_Mode_Hfp_Client: 164 | case Audio_Mode_Hs_Hfp: 165 | strcat(paths, " voice"); 166 | break; 167 | default: 168 | ALOGE("%s: function %d not support!\n",__func__, audio_mode); 169 | return -EINVAL; 170 | } 171 | 172 | ALOGV("%s: mixer paths is: %s, enable: %d\n", __func__, paths, enable); 173 | adev_i2s_clock_operation(enable, adev, paths); 174 | return 0; 175 | 176 | } 177 | 178 | static exTfa98xx_audio_mode_t tfa_98xx_get_audio_mode(struct speaker_data *data) 179 | { 180 | exTfa98xx_audio_mode_t tfa_98xx_audio_mode = Audio_Mode_None; 181 | struct listnode *node; 182 | struct audio_usecase *usecase; 183 | audio_mode_t mode = data->adev->mode; 184 | int i = 0; 185 | 186 | ALOGV("%s: enter\n", __func__); 187 | 188 | for (i = 0; i < Audio_Mode_Max; i++) 189 | data->route_cnt[i] = 0; 190 | 191 | list_for_each(node, &data->adev->usecase_list) { 192 | usecase = node_to_item(node, struct audio_usecase, list); 193 | if (usecase->devices & AUDIO_DEVICE_OUT_ALL_SCO) { 194 | if(data->adev->snd_dev_ref_cnt[usecase->out_snd_device] != 0) { 195 | tfa_98xx_audio_mode = Audio_Mode_Hs_Hfp; 196 | data->route_cnt[tfa_98xx_audio_mode]++; 197 | ALOGV("%s: audio_mode hs_hfp\n", __func__); 198 | } 199 | } else if (usecase->devices & AUDIO_DEVICE_OUT_SPEAKER) { 200 | if ((mode == AUDIO_MODE_IN_CALL) || audio_extn_hfp_is_active(data->adev)) { 201 | if (audio_extn_hfp_is_active(data->adev)) { 202 | if(data->adev->snd_dev_ref_cnt[usecase->out_snd_device] != 0) { 203 | tfa_98xx_audio_mode = Audio_Mode_Hfp_Client; 204 | data->route_cnt[tfa_98xx_audio_mode]++; 205 | ALOGV("%s: audio_mode hfp client\n", __func__); 206 | } 207 | } else { 208 | if(data->adev->snd_dev_ref_cnt[usecase->out_snd_device] != 0) { 209 | tfa_98xx_audio_mode = Audio_Mode_Voice; 210 | data->route_cnt[tfa_98xx_audio_mode]++; 211 | ALOGV("%s: audio_mode voice\n", __func__); 212 | } 213 | } 214 | } else { 215 | if (data->adev->snd_dev_ref_cnt[usecase->out_snd_device] != 0) { 216 | tfa_98xx_audio_mode = Audio_Mode_Music_Normal; 217 | data->route_cnt[tfa_98xx_audio_mode]++; 218 | ALOGV("%s: tfa_98xx_audio_mode music\n", __func__); 219 | } 220 | } 221 | } else { 222 | ALOGE("%s: no device match \n", __func__); 223 | } 224 | } 225 | ALOGV("%s: tfa_98xx_audio_mode %d exit\n", __func__, tfa_98xx_audio_mode); 226 | 227 | return tfa_98xx_audio_mode; 228 | } 229 | 230 | static int tfa_98xx_set_func_mode(int enable, struct audio_device *adev, exTfa98xx_func_mode_t func_mode) 231 | { 232 | struct speaker_data *data = tfa98xx_speaker_data; 233 | char paths[32] = "init_smart_pa"; 234 | 235 | if (data) { 236 | switch(func_mode) { 237 | case Func_Mode_Speaker: 238 | strcat(paths, " func_speaker"); 239 | break; 240 | case Func_Mode_BT: 241 | strcat(paths, " func_bt"); 242 | break; 243 | default: 244 | ALOGE("%s: function %d not support!\n",__func__, func_mode); 245 | return -EINVAL; 246 | } 247 | 248 | ALOGV("%s: mixer paths is: %s, enable: %d\n", __func__, paths, enable); 249 | adev_i2s_clock_operation(enable, adev, paths); 250 | } 251 | return 0; 252 | } 253 | 254 | static exTfa98xx_func_mode_t tfa_98xx_get_func_mode(exTfa98xx_audio_mode_t audio_mode) 255 | { 256 | exTfa98xx_func_mode_t func_mode = Func_Mode_None; 257 | 258 | switch(audio_mode) { 259 | case Audio_Mode_Music_Normal: 260 | case Audio_Mode_Voice: 261 | ALOGV("%s: tfa_98xx_func_mode speaker \n", __func__); 262 | func_mode = Func_Mode_Speaker; 263 | break; 264 | case Audio_Mode_Hfp_Client: 265 | case Audio_Mode_Hs_Hfp: 266 | ALOGV("%s: tfa_98xx_func_mode bt \n", __func__); 267 | func_mode = Func_Mode_BT; 268 | break; 269 | default: 270 | break; 271 | } 272 | return func_mode; 273 | } 274 | 275 | static void tfa_98xx_disable_speaker(void) 276 | { 277 | struct speaker_data *data = tfa98xx_speaker_data; 278 | int ret = 0; 279 | 280 | ret = data->set_speaker_off(); 281 | if (ret) { 282 | ALOGE("%s: exTfa98xx_speakeroff failed result = %d\n", __func__, ret); 283 | goto on_error; 284 | } 285 | 286 | ret = tfa_98xx_set_audio_mode(I2S_CLOCK_DISABLE, data->adev, current_audio_mode); 287 | if (ret) { 288 | ALOGE("%s: tfa_98xx_set_audio_mode disable failed return %d\n", __func__, ret); 289 | goto on_error; 290 | } 291 | current_audio_mode = Audio_Mode_None; 292 | on_error: 293 | return; 294 | 295 | } 296 | 297 | 298 | void audio_extn_tfa_98xx_disable_speaker(snd_device_t snd_device) 299 | { 300 | struct speaker_data *data = tfa98xx_speaker_data; 301 | int i = 0; 302 | exTfa98xx_audio_mode_t new_audio_mode = Audio_Mode_None; 303 | 304 | ALOGV("%s: enter\n", __func__); 305 | 306 | if (data) { 307 | if ((current_audio_mode == Audio_Mode_None) || (snd_device > SND_DEVICE_OUT_END)) 308 | goto on_exit; 309 | 310 | switch(snd_device) { 311 | case SND_DEVICE_OUT_SPEAKER: 312 | new_audio_mode = Audio_Mode_Music_Normal; 313 | break; 314 | case SND_DEVICE_OUT_VOICE_SPEAKER: 315 | new_audio_mode = Audio_Mode_Voice; 316 | break; 317 | case SND_DEVICE_OUT_VOICE_SPEAKER_HFP: 318 | new_audio_mode = Audio_Mode_Hfp_Client; 319 | break; 320 | case SND_DEVICE_OUT_BT_SCO: 321 | new_audio_mode = Audio_Mode_Hs_Hfp; 322 | break; 323 | default: 324 | break; 325 | } 326 | 327 | if ((new_audio_mode == Audio_Mode_None) || (data->ref_cnt[new_audio_mode] <= 0)) { 328 | ALOGE("%s: device ref cnt is already 0", __func__); 329 | goto on_exit; 330 | } 331 | 332 | data->ref_cnt[new_audio_mode]--; 333 | 334 | for (i = 0; i < Audio_Mode_Max; i++) { 335 | if (data->ref_cnt[i] > 0) { 336 | ALOGD("%s: exTfa98xx_speaker still in use\n", __func__); 337 | goto on_exit; 338 | } 339 | } 340 | 341 | if (data->adev->enable_hfp) 342 | data->set_speaker_volume_step(0, 0); 343 | 344 | tfa_98xx_disable_speaker(); 345 | } 346 | 347 | ALOGV("%s: exit\n", __func__); 348 | on_exit: 349 | return; 350 | } 351 | 352 | int audio_extn_tfa_98xx_enable_speaker(void) 353 | { 354 | struct speaker_data *data = tfa98xx_speaker_data; 355 | exTfa98xx_audio_mode_t new_audio_mode = Audio_Mode_Music_Normal; 356 | int ret = 0; 357 | int i = 0; 358 | 359 | ALOGV("%s: enter\n", __func__); 360 | 361 | if (data) { 362 | 363 | new_audio_mode = tfa_98xx_get_audio_mode(data); 364 | if ((new_audio_mode != Audio_Mode_None) && (data->ref_cnt[new_audio_mode] >= 1)) { 365 | ALOGD("%s, mode %d already active!", __func__, new_audio_mode); 366 | data->ref_cnt[new_audio_mode]++; 367 | goto on_exit; 368 | } 369 | 370 | ret = tfa_98xx_set_audio_mode(I2S_CLOCK_ENABLE, data->adev, new_audio_mode); 371 | if (ret) { 372 | ALOGE("%s: tfa_98xx_set_audio_mode enable failed return %d\n", __func__, ret); 373 | goto on_exit; 374 | } 375 | 376 | ret = data->set_speaker_on(new_audio_mode); 377 | if (ret) { 378 | ALOGE("%s: exTfa98xx_speakeron failed result = %d\n", __func__, ret); 379 | goto on_exit; 380 | } 381 | 382 | current_audio_mode = new_audio_mode; 383 | for (i = 0; i < Audio_Mode_Max; i++) { 384 | data->ref_cnt[i] = data->route_cnt[i]; 385 | } 386 | data->update_ref_cnt = false; 387 | } 388 | 389 | ALOGV("%s: exit\n", __func__); 390 | 391 | on_exit: 392 | return ret; 393 | 394 | } 395 | 396 | void audio_extn_tfa_98xx_set_mode(void) 397 | { 398 | int ret = 0; 399 | struct speaker_data *data = tfa98xx_speaker_data; 400 | exTfa98xx_audio_mode_t new_audio_mode = Audio_Mode_None; 401 | exTfa98xx_func_mode_t new_func_mode = Func_Mode_None; 402 | 403 | ALOGV("%s: enter\n", __func__); 404 | 405 | if (data) { 406 | new_audio_mode = tfa_98xx_get_audio_mode(data); 407 | 408 | new_func_mode = tfa_98xx_get_func_mode(new_audio_mode); 409 | if (new_func_mode == Func_Mode_None) 410 | return; 411 | 412 | ret = tfa_98xx_set_func_mode(I2S_CLOCK_ENABLE, data->adev, new_func_mode); 413 | if (ret) { 414 | ALOGE("%s: tfa_98xx_set_func_mode enable return %d\n", __func__, ret); 415 | } 416 | data->update_ref_cnt = true; 417 | } 418 | 419 | ALOGV("%s: exit\n", __func__); 420 | } 421 | 422 | void audio_extn_tfa_98xx_set_mode_bt(void) 423 | { 424 | struct speaker_data *data = tfa98xx_speaker_data; 425 | int ret = 0; 426 | 427 | if (data) { 428 | ret = tfa_98xx_set_func_mode(I2S_CLOCK_ENABLE, data->adev, Func_Mode_BT); 429 | if (ret) { 430 | ALOGE("%s: tfa_98xx_set_func_mode enable return %d\n", __func__, ret); 431 | } 432 | } 433 | } 434 | 435 | void audio_extn_tfa_98xx_update(void) 436 | { 437 | struct speaker_data *data = tfa98xx_speaker_data; 438 | exTfa98xx_audio_mode_t new_audio_mode = Audio_Mode_Music_Normal; 439 | 440 | ALOGD("%s: enter\n", __func__); 441 | 442 | if (data) { 443 | 444 | new_audio_mode = tfa_98xx_get_audio_mode(data); 445 | if (new_audio_mode <= current_audio_mode) { 446 | ALOGE("%s: audio_extn_tfa_98xx_update same mode\n", __func__); 447 | if (data->update_ref_cnt == true) { 448 | data->ref_cnt[new_audio_mode]++; 449 | data->update_ref_cnt = false; 450 | } 451 | goto on_error; 452 | } 453 | 454 | if (current_audio_mode != Audio_Mode_None) { 455 | tfa_98xx_disable_speaker(); 456 | } 457 | 458 | audio_extn_tfa_98xx_enable_speaker(); 459 | 460 | } 461 | 462 | ALOGV("%s: exit\n", __func__); 463 | on_error: 464 | return; 465 | 466 | } 467 | 468 | void audio_extn_tfa_98xx_set_voice_vol(float vol) 469 | { 470 | struct speaker_data *data = tfa98xx_speaker_data; 471 | int vsteps = 0; 472 | 473 | if (data) { 474 | if (data->adev->enable_hfp) { 475 | if (vol < 0.0) { 476 | vol = 0.0; 477 | } else { 478 | vol = ((vol > HFP_MAX_VOLUME) ? 1.0 : (vol / HFP_MAX_VOLUME)); 479 | } 480 | vsteps = (int)floorf((1.0 - vol) * TFA_98XX_HFP_VSETPS); 481 | } else { 482 | return; 483 | } 484 | ALOGD("%s: vsteps %d\n", __func__, vsteps); 485 | data->set_speaker_volume_step(vsteps, vsteps); 486 | } 487 | } 488 | 489 | bool audio_extn_tfa_98xx_is_supported(void) 490 | { 491 | struct speaker_data *data = tfa98xx_speaker_data; 492 | if (data) 493 | return true; 494 | else 495 | return false; 496 | } 497 | 498 | int audio_extn_tfa_98xx_init(struct audio_device *adev) 499 | { 500 | int ret = 0; 501 | struct speaker_data *data = open_speaker_bundle(); 502 | 503 | ALOGV("%s: enter\n", __func__); 504 | 505 | if (data) { 506 | ret = tfa_98xx_set_audio_mode(I2S_CLOCK_ENABLE, adev, Audio_Mode_Music_Normal); 507 | if (ret) { 508 | ALOGE("%s: tfa_98xx_set_audio_mode enable return %d\n", __func__, ret); 509 | goto err_init; 510 | } 511 | 512 | ret = data->set_speaker_calibration(0); 513 | if (ret) { 514 | ALOGE("%s: exTfa98xx_calibration return %d\n", __func__, ret); 515 | } 516 | 517 | ret = tfa_98xx_set_audio_mode(I2S_CLOCK_DISABLE, adev, Audio_Mode_Music_Normal); 518 | if (ret) { 519 | ALOGE("%s: tfa_98xx_set_audio_mode disable return %d\n", __func__, ret); 520 | goto err_init; 521 | } 522 | 523 | data->adev = adev; 524 | tfa98xx_speaker_data = data; 525 | ALOGV("%s: exit\n", __func__); 526 | return 0; 527 | 528 | } 529 | 530 | err_init: 531 | close_speaker_bundle(data); 532 | return -EINVAL; 533 | } 534 | 535 | void audio_extn_tfa_98xx_deinit(void) 536 | { 537 | struct speaker_data *data = tfa98xx_speaker_data; 538 | 539 | if (data) { 540 | data->set_speaker_off(); 541 | close_speaker_bundle(data); 542 | tfa98xx_speaker_data = NULL; 543 | } 544 | } 545 | 546 | -------------------------------------------------------------------------------- /hal/audio_extn/tfa_98xx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef TFA_98XX_H 18 | #define TFA_98XX_H 19 | 20 | #ifdef SMART_PA_TFA_98XX_SUPPORTED 21 | int audio_extn_tfa_98xx_enable_speaker(void); 22 | void audio_extn_tfa_98xx_disable_speaker(snd_device_t snd_device); 23 | void audio_extn_tfa_98xx_set_mode(); 24 | void audio_extn_tfa_98xx_set_mode_bt(void); 25 | void audio_extn_tfa_98xx_update(void); 26 | void audio_extn_tfa_98xx_set_voice_vol(float vol); 27 | int audio_extn_tfa_98xx_init(struct audio_device *adev); 28 | void audio_extn_tfa_98xx_deinit(void); 29 | bool audio_extn_tfa_98xx_is_supported(void); 30 | #else 31 | #define audio_extn_tfa_98xx_enable_speaker(void) (0) 32 | #define audio_extn_tfa_98xx_disable_speaker(snd_device) (0) 33 | #define audio_extn_tfa_98xx_set_mode() (0) 34 | #define audio_extn_tfa_98xx_set_mode_bt() (0) 35 | #define audio_extn_tfa_98xx_update(void) (0) 36 | #define audio_extn_tfa_98xx_set_voice_vol(vol) (0) 37 | #define audio_extn_tfa_98xx_init(adev) (0) 38 | #define audio_extn_tfa_98xx_deinit(void) (0) 39 | #define audio_extn_tfa_98xx_is_supported(void) (false) 40 | #endif 41 | 42 | #endif /* TFA_98XX_H */ 43 | -------------------------------------------------------------------------------- /hal/audio_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef QCOM_AUDIO_HW_H 18 | #define QCOM_AUDIO_HW_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include "voice.h" 31 | 32 | // dlopen() does not go through default library path search if there is a "/" in the library name. 33 | #ifdef __LP64__ 34 | #define VISUALIZER_LIBRARY_PATH "/vendor/lib64/soundfx/libqcomvisualizer.so" 35 | #define OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH "/vendor/lib64/soundfx/libqcompostprocbundle.so" 36 | #else 37 | #define VISUALIZER_LIBRARY_PATH "/vendor/lib/soundfx/libqcomvisualizer.so" 38 | #define OFFLOAD_EFFECTS_BUNDLE_LIBRARY_PATH "/vendor/lib/soundfx/libqcompostprocbundle.so" 39 | #endif 40 | #define ADM_LIBRARY_PATH "libadm.so" 41 | 42 | /* Flags used to initialize acdb_settings variable that goes to ACDB library */ 43 | #define DMIC_FLAG 0x00000002 44 | #define TTY_MODE_OFF 0x00000010 45 | #define TTY_MODE_FULL 0x00000020 46 | #define TTY_MODE_VCO 0x00000040 47 | #define TTY_MODE_HCO 0x00000080 48 | #define TTY_MODE_CLEAR 0xFFFFFF0F 49 | 50 | #define ACDB_DEV_TYPE_OUT 1 51 | #define ACDB_DEV_TYPE_IN 2 52 | 53 | #define MAX_SUPPORTED_CHANNEL_MASKS (2 * FCC_8) /* support positional and index masks to 8ch */ 54 | #define MAX_SUPPORTED_FORMATS 15 55 | #define MAX_SUPPORTED_SAMPLE_RATES 7 56 | #define DEFAULT_HDMI_OUT_CHANNELS 2 57 | 58 | #define ERROR_LOG_ENTRIES 16 59 | 60 | /* Error types for the error log */ 61 | enum { 62 | ERROR_CODE_STANDBY = 1, 63 | ERROR_CODE_WRITE, 64 | ERROR_CODE_READ, 65 | }; 66 | 67 | typedef enum card_status_t { 68 | CARD_STATUS_OFFLINE, 69 | CARD_STATUS_ONLINE 70 | } card_status_t; 71 | 72 | /* These are the supported use cases by the hardware. 73 | * Each usecase is mapped to a specific PCM device. 74 | * Refer to pcm_device_table[]. 75 | */ 76 | enum { 77 | USECASE_INVALID = -1, 78 | /* Playback usecases */ 79 | USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0, 80 | USECASE_AUDIO_PLAYBACK_LOW_LATENCY, 81 | USECASE_AUDIO_PLAYBACK_HIFI, 82 | USECASE_AUDIO_PLAYBACK_OFFLOAD, 83 | USECASE_AUDIO_PLAYBACK_TTS, 84 | USECASE_AUDIO_PLAYBACK_ULL, 85 | USECASE_AUDIO_PLAYBACK_MMAP, 86 | USECASE_AUDIO_PLAYBACK_WITH_HAPTICS, 87 | 88 | /* HFP Use case*/ 89 | USECASE_AUDIO_HFP_SCO, 90 | USECASE_AUDIO_HFP_SCO_WB, 91 | 92 | /* Capture usecases */ 93 | USECASE_AUDIO_RECORD, 94 | USECASE_AUDIO_RECORD_LOW_LATENCY, 95 | USECASE_AUDIO_RECORD_MMAP, 96 | USECASE_AUDIO_RECORD_HIFI, 97 | 98 | /* Voice extension usecases 99 | * 100 | * Following usecase are specific to voice session names created by 101 | * MODEM and APPS on 8992/8994/8084/8974 platforms. 102 | */ 103 | USECASE_VOICE_CALL, /* Usecase setup for voice session on first subscription for DSDS/DSDA */ 104 | USECASE_VOICE2_CALL, /* Usecase setup for voice session on second subscription for DSDS/DSDA */ 105 | USECASE_VOLTE_CALL, /* Usecase setup for VoLTE session on first subscription */ 106 | USECASE_QCHAT_CALL, /* Usecase setup for QCHAT session */ 107 | USECASE_VOWLAN_CALL, /* Usecase setup for VoWLAN session */ 108 | 109 | /* 110 | * Following usecase are specific to voice session names created by 111 | * MODEM and APPS on 8996 platforms. 112 | */ 113 | 114 | USECASE_VOICEMMODE1_CALL, /* Usecase setup for Voice/VoLTE/VoWLAN sessions on first 115 | * subscription for DSDS/DSDA 116 | */ 117 | USECASE_VOICEMMODE2_CALL, /* Usecase setup for voice/VoLTE/VoWLAN sessions on second 118 | * subscription for DSDS/DSDA 119 | */ 120 | 121 | USECASE_INCALL_REC_UPLINK, 122 | USECASE_INCALL_REC_DOWNLINK, 123 | USECASE_INCALL_REC_UPLINK_AND_DOWNLINK, 124 | 125 | USECASE_AUDIO_SPKR_CALIB_RX, 126 | USECASE_AUDIO_SPKR_CALIB_TX, 127 | 128 | USECASE_AUDIO_PLAYBACK_AFE_PROXY, 129 | USECASE_AUDIO_RECORD_AFE_PROXY, 130 | USECASE_AUDIO_DSM_FEEDBACK, 131 | 132 | /* VOIP usecase*/ 133 | USECASE_AUDIO_PLAYBACK_VOIP, 134 | USECASE_AUDIO_RECORD_VOIP, 135 | 136 | USECASE_INCALL_MUSIC_UPLINK, 137 | USECASE_INCALL_MUSIC_UPLINK2, 138 | 139 | USECASE_AUDIO_A2DP_ABR_FEEDBACK, 140 | 141 | AUDIO_USECASE_MAX 142 | }; 143 | 144 | const char * const use_case_table[AUDIO_USECASE_MAX]; 145 | 146 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 147 | 148 | /* 149 | * tinyAlsa library interprets period size as number of frames 150 | * one frame = channel_count * sizeof (pcm sample) 151 | * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes 152 | * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes 153 | * We should take care of returning proper size when AudioFlinger queries for 154 | * the buffer size of an input/output stream 155 | */ 156 | 157 | enum { 158 | OFFLOAD_CMD_EXIT, /* exit compress offload thread loop*/ 159 | OFFLOAD_CMD_DRAIN, /* send a full drain request to DSP */ 160 | OFFLOAD_CMD_PARTIAL_DRAIN, /* send a partial drain request to DSP */ 161 | OFFLOAD_CMD_WAIT_FOR_BUFFER, /* wait for buffer released by DSP */ 162 | OFFLOAD_CMD_ERROR, /* offload playback hit some error */ 163 | }; 164 | 165 | /* 166 | * Camera selection indicated via set_parameters "cameraFacing=front|back and 167 | * "rotation=0|90|180|270"" 168 | */ 169 | enum { 170 | CAMERA_FACING_BACK = 0x0, 171 | CAMERA_FACING_FRONT = 0x1, 172 | CAMERA_FACING_MASK = 0x0F, 173 | CAMERA_ROTATION_LANDSCAPE = 0x0, 174 | CAMERA_ROTATION_INVERT_LANDSCAPE = 0x10, 175 | CAMERA_ROTATION_PORTRAIT = 0x20, 176 | CAMERA_ROTATION_MASK = 0xF0, 177 | CAMERA_BACK_LANDSCAPE = (CAMERA_FACING_BACK|CAMERA_ROTATION_LANDSCAPE), 178 | CAMERA_BACK_INVERT_LANDSCAPE = (CAMERA_FACING_BACK|CAMERA_ROTATION_INVERT_LANDSCAPE), 179 | CAMERA_BACK_PORTRAIT = (CAMERA_FACING_BACK|CAMERA_ROTATION_PORTRAIT), 180 | CAMERA_FRONT_LANDSCAPE = (CAMERA_FACING_FRONT|CAMERA_ROTATION_LANDSCAPE), 181 | CAMERA_FRONT_INVERT_LANDSCAPE = (CAMERA_FACING_FRONT|CAMERA_ROTATION_INVERT_LANDSCAPE), 182 | CAMERA_FRONT_PORTRAIT = (CAMERA_FACING_FRONT|CAMERA_ROTATION_PORTRAIT), 183 | 184 | CAMERA_DEFAULT = CAMERA_BACK_LANDSCAPE, 185 | }; 186 | 187 | //FIXME: to be replaced by proper video capture properties API 188 | #define AUDIO_PARAMETER_KEY_CAMERA_FACING "cameraFacing" 189 | #define AUDIO_PARAMETER_VALUE_FRONT "front" 190 | #define AUDIO_PARAMETER_VALUE_BACK "back" 191 | 192 | enum { 193 | OFFLOAD_STATE_IDLE, 194 | OFFLOAD_STATE_PLAYING, 195 | OFFLOAD_STATE_PAUSED, 196 | }; 197 | 198 | struct offload_cmd { 199 | struct listnode node; 200 | int cmd; 201 | int data[]; 202 | }; 203 | 204 | struct stream_app_type_cfg { 205 | int sample_rate; 206 | uint32_t bit_width; // unused 207 | const char *mode; 208 | int app_type; 209 | int gain[2]; 210 | }; 211 | 212 | struct stream_out { 213 | struct audio_stream_out stream; 214 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ 215 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by playback thread */ 216 | pthread_mutex_t compr_mute_lock; /* acquire before setting compress volume */ 217 | pthread_cond_t cond; 218 | struct pcm_config config; 219 | struct compr_config compr_config; 220 | struct pcm *pcm; 221 | struct compress *compr; 222 | int standby; 223 | int pcm_device_id; 224 | unsigned int sample_rate; 225 | audio_channel_mask_t channel_mask; 226 | audio_format_t format; 227 | audio_devices_t devices; 228 | audio_output_flags_t flags; 229 | audio_usecase_t usecase; 230 | /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */ 231 | audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1]; 232 | audio_format_t supported_formats[MAX_SUPPORTED_FORMATS + 1]; 233 | uint32_t supported_sample_rates[MAX_SUPPORTED_SAMPLE_RATES + 1]; 234 | bool muted; 235 | uint64_t written; /* total frames written, not cleared when entering standby */ 236 | int64_t mmap_time_offset_nanos; /* fudge factor to correct inaccuracies in DSP */ 237 | int mmap_shared_memory_fd; /* file descriptor associated with MMAP NOIRQ shared memory */ 238 | audio_io_handle_t handle; 239 | 240 | int non_blocking; 241 | int playback_started; 242 | int offload_state; 243 | pthread_cond_t offload_cond; 244 | pthread_t offload_thread; 245 | struct listnode offload_cmd_list; 246 | bool offload_thread_blocked; 247 | 248 | stream_callback_t offload_callback; 249 | void *offload_cookie; 250 | struct compr_gapless_mdata gapless_mdata; 251 | int send_new_metadata; 252 | bool realtime; 253 | int af_period_multiplier; 254 | struct audio_device *dev; 255 | card_status_t card_status; 256 | bool a2dp_compress_mute; 257 | float volume_l; 258 | float volume_r; 259 | float applied_volume_l; 260 | float applied_volume_r; 261 | 262 | error_log_t *error_log; 263 | 264 | struct stream_app_type_cfg app_type_cfg; 265 | 266 | size_t kernel_buffer_size; // cached value of the alsa buffer size, const after open(). 267 | 268 | // last out_get_presentation_position() cached info. 269 | bool last_fifo_valid; 270 | unsigned int last_fifo_frames_remaining; 271 | int64_t last_fifo_time_ns; 272 | 273 | simple_stats_t fifo_underruns; // TODO: keep a list of the last N fifo underrun times. 274 | simple_stats_t start_latency_ms; 275 | }; 276 | 277 | struct stream_in { 278 | struct audio_stream_in stream; 279 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ 280 | pthread_mutex_t pre_lock; /* acquire before lock to avoid DOS by capture thread */ 281 | struct pcm_config config; 282 | struct pcm *pcm; 283 | int standby; 284 | int source; 285 | int pcm_device_id; 286 | audio_devices_t device; 287 | audio_channel_mask_t channel_mask; 288 | unsigned int sample_rate; 289 | audio_usecase_t usecase; 290 | bool enable_aec; 291 | bool enable_ns; 292 | bool enable_ec_port; 293 | bool ec_opened; 294 | struct listnode aec_list; 295 | struct listnode ns_list; 296 | int64_t frames_read; /* total frames read, not cleared when entering standby */ 297 | int64_t frames_muted; /* total frames muted, not cleared when entering standby */ 298 | int64_t mmap_time_offset_nanos; /* fudge factor to correct inaccuracies in DSP */ 299 | int mmap_shared_memory_fd; /* file descriptor associated with MMAP NOIRQ shared memory */ 300 | 301 | audio_io_handle_t capture_handle; 302 | audio_input_flags_t flags; 303 | bool is_st_session; 304 | bool is_st_session_active; 305 | bool realtime; 306 | int af_period_multiplier; 307 | struct audio_device *dev; 308 | audio_format_t format; 309 | card_status_t card_status; 310 | int capture_started; 311 | float zoom; 312 | audio_microphone_direction_t direction; 313 | 314 | struct stream_app_type_cfg app_type_cfg; 315 | 316 | /* Array of supported channel mask configurations. 317 | +1 so that the last entry is always 0 */ 318 | audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1]; 319 | audio_format_t supported_formats[MAX_SUPPORTED_FORMATS + 1]; 320 | uint32_t supported_sample_rates[MAX_SUPPORTED_SAMPLE_RATES + 1]; 321 | 322 | error_log_t *error_log; 323 | 324 | simple_stats_t start_latency_ms; 325 | }; 326 | 327 | typedef enum usecase_type_t { 328 | PCM_PLAYBACK, 329 | PCM_CAPTURE, 330 | VOICE_CALL, 331 | PCM_HFP_CALL, 332 | USECASE_TYPE_MAX 333 | } usecase_type_t; 334 | 335 | union stream_ptr { 336 | struct stream_in *in; 337 | struct stream_out *out; 338 | }; 339 | 340 | struct audio_usecase { 341 | struct listnode list; 342 | audio_usecase_t id; 343 | usecase_type_t type; 344 | audio_devices_t devices; 345 | snd_device_t out_snd_device; 346 | snd_device_t in_snd_device; 347 | union stream_ptr stream; 348 | }; 349 | 350 | typedef void* (*adm_init_t)(); 351 | typedef void (*adm_deinit_t)(void *); 352 | typedef void (*adm_register_output_stream_t)(void *, audio_io_handle_t, audio_output_flags_t); 353 | typedef void (*adm_register_input_stream_t)(void *, audio_io_handle_t, audio_input_flags_t); 354 | typedef void (*adm_deregister_stream_t)(void *, audio_io_handle_t); 355 | typedef void (*adm_request_focus_t)(void *, audio_io_handle_t); 356 | typedef void (*adm_abandon_focus_t)(void *, audio_io_handle_t); 357 | typedef void (*adm_set_config_t)(void *, audio_io_handle_t, 358 | struct pcm *, 359 | struct pcm_config *); 360 | typedef void (*adm_request_focus_v2_t)(void *, audio_io_handle_t, long); 361 | typedef bool (*adm_is_noirq_avail_t)(void *, int, int, int); 362 | typedef void (*adm_on_routing_change_t)(void *, audio_io_handle_t); 363 | 364 | struct audio_device { 365 | struct audio_hw_device device; 366 | 367 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ 368 | struct mixer *mixer; 369 | audio_mode_t mode; 370 | struct stream_out *primary_output; 371 | struct stream_out *voice_tx_output; 372 | struct stream_out *current_call_output; 373 | bool bluetooth_nrec; 374 | bool screen_off; 375 | int *snd_dev_ref_cnt; 376 | struct listnode usecase_list; 377 | struct audio_route *audio_route; 378 | int acdb_settings; 379 | struct voice voice; 380 | unsigned int cur_hdmi_channels; 381 | bool bt_wb_speech_enabled; 382 | bool mic_muted; 383 | bool enable_voicerx; 384 | bool enable_hfp; 385 | bool mic_break_enabled; 386 | bool use_voice_device_mute; 387 | 388 | int snd_card; 389 | void *platform; 390 | void *extspk; 391 | 392 | card_status_t card_status; 393 | 394 | void *visualizer_lib; 395 | int (*visualizer_start_output)(audio_io_handle_t, int, int, int); 396 | int (*visualizer_stop_output)(audio_io_handle_t, int); 397 | 398 | /* The pcm_params use_case_table is loaded by adev_verify_devices() upon 399 | * calling adev_open(). 400 | * 401 | * If an entry is not NULL, it can be used to determine if extended precision 402 | * or other capabilities are present for the device corresponding to that usecase. 403 | */ 404 | struct pcm_params *use_case_table[AUDIO_USECASE_MAX]; 405 | void *offload_effects_lib; 406 | int (*offload_effects_start_output)(audio_io_handle_t, int); 407 | int (*offload_effects_stop_output)(audio_io_handle_t, int); 408 | 409 | void *adm_data; 410 | void *adm_lib; 411 | 412 | struct pcm_config haptics_config; 413 | struct pcm *haptic_pcm; 414 | int haptic_pcm_device_id; 415 | uint8_t *haptic_buffer; 416 | size_t haptic_buffer_size; 417 | 418 | adm_init_t adm_init; 419 | adm_deinit_t adm_deinit; 420 | adm_register_input_stream_t adm_register_input_stream; 421 | adm_register_output_stream_t adm_register_output_stream; 422 | adm_deregister_stream_t adm_deregister_stream; 423 | adm_request_focus_t adm_request_focus; 424 | adm_abandon_focus_t adm_abandon_focus; 425 | adm_set_config_t adm_set_config; 426 | adm_request_focus_v2_t adm_request_focus_v2; 427 | adm_is_noirq_avail_t adm_is_noirq_avail; 428 | adm_on_routing_change_t adm_on_routing_change; 429 | 430 | /* logging */ 431 | snd_device_t last_logged_snd_device[AUDIO_USECASE_MAX][2]; /* [out, in] */ 432 | int camera_orientation; /* CAMERA_BACK_LANDSCAPE ... CAMERA_FRONT_PORTRAIT */ 433 | bool bt_sco_on; 434 | bool a2dp_started; 435 | }; 436 | 437 | int select_devices(struct audio_device *adev, 438 | audio_usecase_t uc_id); 439 | 440 | int disable_audio_route(struct audio_device *adev, 441 | struct audio_usecase *usecase); 442 | 443 | int disable_snd_device(struct audio_device *adev, 444 | snd_device_t snd_device); 445 | 446 | int enable_snd_device(struct audio_device *adev, 447 | snd_device_t snd_device); 448 | 449 | int enable_audio_route(struct audio_device *adev, 450 | struct audio_usecase *usecase); 451 | 452 | struct audio_usecase *get_usecase_from_list(struct audio_device *adev, 453 | audio_usecase_t uc_id); 454 | 455 | int check_a2dp_restore(struct audio_device *adev, struct stream_out *out, bool restore); 456 | 457 | #define LITERAL_TO_STRING(x) #x 458 | #define CHECK(condition) LOG_ALWAYS_FATAL_IF(!(condition), "%s",\ 459 | __FILE__ ":" LITERAL_TO_STRING(__LINE__)\ 460 | " ASSERT_FATAL(" #condition ") failed.") 461 | 462 | /* 463 | * NOTE: when multiple mutexes have to be acquired, always take the 464 | * stream_in or stream_out mutex first, followed by the audio_device mutex. 465 | */ 466 | 467 | #endif // QCOM_AUDIO_HW_H 468 | -------------------------------------------------------------------------------- /hal/audio_perf.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "audio_hw_primary" 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "audio_perf.h" 31 | 32 | // Protect gPowerHal_1_2_ and gPowerHal_Aidl_ 33 | static android::sp gPowerHal_1_2_; 34 | static std::shared_ptr gPowerHal_Aidl_; 35 | static std::mutex gPowerHalMutex; 36 | static constexpr int kDefaultBoostDurationMs = 2000; 37 | static constexpr int kBoostOff = -1; 38 | 39 | static const std::string kInstance = 40 | std::string(aidl::android::hardware::power::IPower::descriptor) + "/default"; 41 | 42 | enum hal_version { 43 | NONE, 44 | HIDL_1_2, 45 | AIDL, 46 | }; 47 | 48 | // Connnect PowerHAL 49 | static hal_version connectPowerHalLocked() { 50 | static bool gPowerHalHidlExists = true; 51 | static bool gPowerHalAidlExists = true; 52 | 53 | if (!gPowerHalHidlExists && !gPowerHalAidlExists) { 54 | return NONE; 55 | } 56 | 57 | if (gPowerHalHidlExists) { 58 | // (re)connect if handle is null 59 | if (!gPowerHal_1_2_) { 60 | gPowerHal_1_2_ = 61 | android::hardware::power::V1_2::IPower::getService(); 62 | } 63 | if (gPowerHal_1_2_) { 64 | ALOGV("Successfully connected to Power Hal Hidl service."); 65 | return HIDL_1_2; 66 | } else { 67 | // no more try on this handle 68 | gPowerHalHidlExists = false; 69 | } 70 | } 71 | 72 | if (gPowerHalAidlExists) { 73 | // (re)connect if handle is null 74 | if (!gPowerHal_Aidl_) { 75 | ndk::SpAIBinder pwBinder = ndk::SpAIBinder( 76 | AServiceManager_getService(kInstance.c_str())); 77 | gPowerHal_Aidl_ = aidl::android::hardware::power::IPower::fromBinder(pwBinder); 78 | } 79 | if (gPowerHal_Aidl_) { 80 | ALOGV("Successfully connected to Power Hal Aidl service."); 81 | return AIDL; 82 | } else { 83 | // no more try on this handle 84 | gPowerHalAidlExists = false; 85 | } 86 | } 87 | 88 | return NONE; 89 | } 90 | 91 | bool audio_streaming_hint_start() { 92 | std::lock_guard lock(gPowerHalMutex); 93 | switch(connectPowerHalLocked()) { 94 | case NONE: 95 | return false; 96 | case HIDL_1_2: 97 | { 98 | auto ret = gPowerHal_1_2_->powerHintAsync_1_2( 99 | android::hardware::power::V1_2::PowerHint::AUDIO_STREAMING, 100 | 1); 101 | if (!ret.isOk()) { 102 | ALOGE("powerHint failed, error: %s", 103 | ret.description().c_str()); 104 | gPowerHal_1_2_ = nullptr; 105 | return false; 106 | } 107 | return true; 108 | } 109 | case AIDL: 110 | { 111 | auto ret = gPowerHal_Aidl_->setBoost( 112 | aidl::android::hardware::power::Boost::AUDIO_LAUNCH, 113 | kDefaultBoostDurationMs); 114 | if (!ret.isOk()) { 115 | std::string err = ret.getDescription(); 116 | ALOGE("Failed to set power hint. Error: %s", err.c_str()); 117 | gPowerHal_Aidl_ = nullptr; 118 | return false; 119 | } 120 | return true; 121 | } 122 | default: 123 | ALOGE("Unknown HAL state"); 124 | return false; 125 | } 126 | } 127 | 128 | bool audio_streaming_hint_end() { 129 | std::lock_guard lock(gPowerHalMutex); 130 | switch(connectPowerHalLocked()) { 131 | case NONE: 132 | return false; 133 | case HIDL_1_2: 134 | { 135 | auto ret = gPowerHal_1_2_->powerHintAsync_1_2( 136 | android::hardware::power::V1_2::PowerHint::AUDIO_STREAMING, 137 | 0); 138 | if (!ret.isOk()) { 139 | ALOGE("powerHint failed, error: %s", 140 | ret.description().c_str()); 141 | gPowerHal_1_2_ = nullptr; 142 | return false; 143 | } 144 | return true; 145 | } 146 | case AIDL: 147 | { 148 | auto ret = gPowerHal_Aidl_->setBoost( 149 | aidl::android::hardware::power::Boost::AUDIO_LAUNCH, 150 | kBoostOff); 151 | if (!ret.isOk()) { 152 | std::string err = ret.getDescription(); 153 | ALOGE("Failed to set power hint. Error: %s", err.c_str()); 154 | gPowerHal_Aidl_ = nullptr; 155 | return false; 156 | } 157 | return true; 158 | } 159 | default: 160 | ALOGE("Unknown HAL state"); 161 | return false; 162 | } 163 | } 164 | 165 | bool audio_low_latency_hint_start() { 166 | std::lock_guard lock(gPowerHalMutex); 167 | switch(connectPowerHalLocked()) { 168 | case NONE: 169 | return false; 170 | case HIDL_1_2: 171 | { 172 | auto ret = gPowerHal_1_2_->powerHintAsync_1_2( 173 | android::hardware::power::V1_2::PowerHint::AUDIO_LOW_LATENCY, 174 | 1); 175 | if (!ret.isOk()) { 176 | ALOGE("powerHint failed, error: %s", 177 | ret.description().c_str()); 178 | gPowerHal_1_2_ = nullptr; 179 | return false; 180 | } 181 | return true; 182 | } 183 | case AIDL: 184 | { 185 | auto ret = gPowerHal_Aidl_->setMode( 186 | aidl::android::hardware::power::Mode::AUDIO_STREAMING_LOW_LATENCY, 187 | true); 188 | if (!ret.isOk()) { 189 | std::string err = ret.getDescription(); 190 | ALOGE("Failed to set power hint. Error: %s", err.c_str()); 191 | gPowerHal_Aidl_ = nullptr; 192 | return false; 193 | } 194 | return true; 195 | } 196 | default: 197 | ALOGE("Unknown HAL state"); 198 | return false; 199 | } 200 | } 201 | 202 | bool audio_low_latency_hint_end() { 203 | std::lock_guard lock(gPowerHalMutex); 204 | switch(connectPowerHalLocked()) { 205 | case NONE: 206 | return false; 207 | case HIDL_1_2: 208 | { 209 | auto ret = gPowerHal_1_2_->powerHintAsync_1_2( 210 | android::hardware::power::V1_2::PowerHint::AUDIO_LOW_LATENCY, 211 | 0); 212 | if (!ret.isOk()) { 213 | ALOGE("powerHint failed, error: %s", 214 | ret.description().c_str()); 215 | gPowerHal_1_2_ = nullptr; 216 | return false; 217 | } 218 | return true; 219 | } 220 | case AIDL: 221 | { 222 | auto ret = gPowerHal_Aidl_->setMode( 223 | aidl::android::hardware::power::Mode::AUDIO_STREAMING_LOW_LATENCY, 224 | false); 225 | if (!ret.isOk()) { 226 | std::string err = ret.getDescription(); 227 | ALOGE("Failed to set power hint. Error: %s", err.c_str()); 228 | gPowerHal_Aidl_ = nullptr; 229 | return false; 230 | } 231 | return true; 232 | } 233 | default: 234 | ALOGE("Unknown HAL state"); 235 | return false; 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /hal/audio_perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __QAUDIOPERF_H__ 18 | #define __QAUDIOPERF_H__ 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // return true on success, false on failure 27 | bool audio_streaming_hint_start(); 28 | bool audio_streaming_hint_end(); 29 | bool audio_low_latency_hint_start(); 30 | bool audio_low_latency_hint_end(); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif //__QAUDIOPERF_H__ 37 | -------------------------------------------------------------------------------- /hal/msm8974/hw_info.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "hardware_info" 18 | /*#define LOG_NDEBUG 0*/ 19 | #define LOG_NDDEBUG 0 20 | 21 | #include 22 | #include 23 | #include "audio_hw.h" 24 | #include "platform.h" 25 | #include "audio_extn.h" 26 | 27 | struct hardware_info { 28 | char name[HW_INFO_ARRAY_MAX_SIZE]; 29 | char type[HW_INFO_ARRAY_MAX_SIZE]; 30 | /* variables for handling target variants */ 31 | uint32_t num_snd_devices; 32 | char dev_extn[HW_INFO_ARRAY_MAX_SIZE]; 33 | snd_device_t *snd_devices; 34 | }; 35 | 36 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 37 | 38 | 39 | static const snd_device_t tasha_db_variant_devices[] = { 40 | SND_DEVICE_OUT_SPEAKER 41 | }; 42 | 43 | static const snd_device_t tasha_fluid_variant_devices[] = { 44 | SND_DEVICE_OUT_SPEAKER, 45 | SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES, 46 | SND_DEVICE_OUT_VOICE_SPEAKER, 47 | SND_DEVICE_OUT_SPEAKER_AND_HDMI, 48 | SND_DEVICE_OUT_SPEAKER_PROTECTED, 49 | SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED, 50 | }; 51 | 52 | static const snd_device_t tasha_liquid_variant_devices[] = { 53 | SND_DEVICE_OUT_SPEAKER, 54 | SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES, 55 | SND_DEVICE_IN_SPEAKER_MIC, 56 | SND_DEVICE_IN_HEADSET_MIC, 57 | SND_DEVICE_IN_VOICE_DMIC, 58 | SND_DEVICE_IN_VOICE_SPEAKER_DMIC, 59 | SND_DEVICE_IN_VOICE_REC_DMIC_STEREO, 60 | SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE, 61 | SND_DEVICE_IN_QUAD_MIC, 62 | }; 63 | 64 | static void update_hardware_info_8996(struct hardware_info *hw_info) 65 | { 66 | struct snd_card_split *tmp_handle = audio_extn_get_snd_card_split(); 67 | ALOGV("%s: device %s snd_card %s form_factor %s", 68 | __func__, tmp_handle->device, tmp_handle->snd_card, tmp_handle->form_factor); 69 | 70 | strlcpy(hw_info->name, tmp_handle->device, sizeof(hw_info->name)); 71 | snprintf(hw_info->type, sizeof(hw_info->type), " %s", tmp_handle->form_factor); 72 | snprintf(hw_info->dev_extn, sizeof(hw_info->dev_extn), "-%s", tmp_handle->form_factor); 73 | 74 | if (!strncmp(tmp_handle->form_factor, "fluid", sizeof("fluid"))) { 75 | hw_info->snd_devices = (snd_device_t *)tasha_fluid_variant_devices; 76 | hw_info->num_snd_devices = ARRAY_SIZE(tasha_fluid_variant_devices); 77 | } else if (!strncmp(tmp_handle->form_factor, "liquid", sizeof("liquid"))) { 78 | hw_info->snd_devices = (snd_device_t *)tasha_liquid_variant_devices; 79 | hw_info->num_snd_devices = ARRAY_SIZE(tasha_liquid_variant_devices); 80 | } else if (!strncmp(tmp_handle->form_factor, "db", sizeof("db"))) { 81 | hw_info->snd_devices = (snd_device_t *)tasha_db_variant_devices; 82 | hw_info->num_snd_devices = ARRAY_SIZE(tasha_db_variant_devices); 83 | } else { 84 | ALOGW("%s: %s form factor doesnt need mixer path over ride", __func__, tmp_handle->form_factor); 85 | } 86 | 87 | ALOGV("name %s type %s dev_extn %s", hw_info->name, hw_info->type, hw_info->dev_extn); 88 | } 89 | 90 | 91 | void *hw_info_init(const char *snd_card_name) 92 | { 93 | struct hardware_info *hw_info = NULL; 94 | bool hw_supported = false; 95 | 96 | if (strstr(snd_card_name, "msm8996")) { 97 | ALOGD("8996 - variant soundcard"); 98 | hw_supported = true; 99 | } else { 100 | ALOGE("%s: Unsupported target %s:",__func__, snd_card_name); 101 | } 102 | 103 | if (hw_supported) { 104 | hw_info = malloc(sizeof(struct hardware_info)); 105 | if (!hw_info) { 106 | ALOGE("failed to allocate mem for hardware info"); 107 | goto on_finish; 108 | } 109 | 110 | hw_info->snd_devices = NULL; 111 | hw_info->num_snd_devices = 0; 112 | strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn)); 113 | strlcpy(hw_info->type, "", sizeof(hw_info->type)); 114 | strlcpy(hw_info->name, "", sizeof(hw_info->name)); 115 | update_hardware_info_8996(hw_info); 116 | } 117 | 118 | on_finish: 119 | return hw_info; 120 | } 121 | 122 | void hw_info_deinit(void *hw_info) 123 | { 124 | free(hw_info); 125 | } 126 | 127 | void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device, 128 | char *device_name) 129 | { 130 | struct hardware_info *my_data = (struct hardware_info*) hw_info; 131 | uint32_t i = 0; 132 | 133 | if (my_data == NULL) 134 | return; 135 | 136 | snd_device_t *snd_devices = 137 | (snd_device_t *) my_data->snd_devices; 138 | 139 | if (snd_devices != NULL) { 140 | for (i = 0; i < my_data->num_snd_devices; i++) { 141 | if (snd_device == (snd_device_t)snd_devices[i]) { 142 | ALOGV("extract dev_extn device %d, device_name %s extn = %s ", 143 | (snd_device_t)snd_devices[i], device_name, my_data->dev_extn); 144 | CHECK(strlcat(device_name, my_data->dev_extn, 145 | DEVICE_NAME_MAX_SIZE) < DEVICE_NAME_MAX_SIZE); 146 | break; 147 | } 148 | } 149 | } 150 | ALOGD("%s : device_name = %s", __func__,device_name); 151 | } 152 | -------------------------------------------------------------------------------- /hal/msm8974/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2017 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef QCOM_AUDIO_PLATFORM_H 18 | #define QCOM_AUDIO_PLATFORM_H 19 | 20 | enum { 21 | FLUENCE_DISABLE, /* Target dosent support fluence */ 22 | FLUENCE_ENABLE = 0x1, /* Target supports fluence */ 23 | FLUENCE_PRO_ENABLE = 0x2, /* Target supports fluence pro */ 24 | }; 25 | 26 | enum { 27 | SOURCE_MONO_MIC = 0x1, /* Target contains 1 mic */ 28 | SOURCE_DUAL_MIC = 0x2, /* Target contains 2 mics */ 29 | SOURCE_THREE_MIC = 0x4, /* Target contains 3 mics */ 30 | SOURCE_QUAD_MIC = 0x8, /* Target contains 4 mics */ 31 | }; 32 | 33 | /* 34 | * Below are the devices for which is back end is same, SLIMBUS_0_RX. 35 | * All these devices are handled by the internal HW codec. We can 36 | * enable any one of these devices at any time 37 | */ 38 | #define AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND \ 39 | (AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER | \ 40 | AUDIO_DEVICE_OUT_SPEAKER_SAFE | \ 41 | AUDIO_DEVICE_OUT_WIRED_HEADSET | AUDIO_DEVICE_OUT_WIRED_HEADPHONE | \ 42 | AUDIO_DEVICE_OUT_LINE) 43 | 44 | /* 45 | * Below are the input devices for which back end is same, SLIMBUS_0_TX. 46 | * All these devices are handled by the internal HW codec. We can 47 | * enable any one of these devices at any time 48 | */ 49 | #define AUDIO_DEVICE_IN_ALL_CODEC_BACKEND \ 50 | (AUDIO_DEVICE_IN_BUILTIN_MIC | AUDIO_DEVICE_IN_BACK_MIC | \ 51 | AUDIO_DEVICE_IN_WIRED_HEADSET | AUDIO_DEVICE_IN_VOICE_CALL) & ~AUDIO_DEVICE_BIT_IN 52 | 53 | /* Sound devices specific to the platform 54 | * The DEVICE_OUT_* and DEVICE_IN_* should be mapped to these sound 55 | * devices to enable corresponding mixer paths 56 | */ 57 | enum { 58 | SND_DEVICE_NONE = 0, 59 | 60 | /* Playback devices */ 61 | SND_DEVICE_MIN, 62 | SND_DEVICE_OUT_BEGIN = SND_DEVICE_MIN, 63 | SND_DEVICE_OUT_HANDSET = SND_DEVICE_OUT_BEGIN, 64 | SND_DEVICE_OUT_SPEAKER, 65 | SND_DEVICE_OUT_SPEAKER_REVERSE, 66 | SND_DEVICE_OUT_SPEAKER_SAFE, 67 | SND_DEVICE_OUT_HEADPHONES, 68 | SND_DEVICE_OUT_LINE, 69 | SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES, 70 | SND_DEVICE_OUT_SPEAKER_SAFE_AND_HEADPHONES, 71 | SND_DEVICE_OUT_SPEAKER_AND_LINE, 72 | SND_DEVICE_OUT_SPEAKER_SAFE_AND_LINE, 73 | SND_DEVICE_OUT_VOICE_HANDSET, 74 | SND_DEVICE_OUT_VOICE_SPEAKER, 75 | SND_DEVICE_OUT_VOICE_HEADPHONES, 76 | SND_DEVICE_OUT_VOICE_HEADSET, 77 | SND_DEVICE_OUT_VOICE_LINE, 78 | SND_DEVICE_OUT_HDMI, 79 | SND_DEVICE_OUT_SPEAKER_AND_HDMI, 80 | SND_DEVICE_OUT_BT_SCO, 81 | SND_DEVICE_OUT_BT_SCO_WB, 82 | SND_DEVICE_OUT_BT_A2DP, 83 | SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP, 84 | SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_A2DP, 85 | SND_DEVICE_OUT_VOICE_HANDSET_TMUS, 86 | SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES, 87 | SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES, 88 | SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET, 89 | SND_DEVICE_OUT_VOICE_TTY_FULL_USB, 90 | SND_DEVICE_OUT_VOICE_TTY_VCO_USB, 91 | SND_DEVICE_OUT_VOICE_HAC_HANDSET, 92 | SND_DEVICE_OUT_VOICE_TX, 93 | SND_DEVICE_OUT_VOICE_MUSIC_TX, 94 | SND_DEVICE_OUT_SPEAKER_PROTECTED, 95 | SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED, 96 | SND_DEVICE_OUT_VOICE_SPEAKER_HFP, 97 | SND_DEVICE_OUT_SPEAKER_AND_BT_SCO, 98 | SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO, 99 | SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB, 100 | SND_DEVICE_OUT_SPEAKER_SAFE_AND_BT_SCO_WB, 101 | SND_DEVICE_OUT_USB_HEADSET, 102 | SND_DEVICE_OUT_USB_HEADPHONES, 103 | SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET, 104 | SND_DEVICE_OUT_SPEAKER_SAFE_AND_USB_HEADSET, 105 | SND_DEVICE_OUT_VOICE_USB_HEADPHONES, 106 | SND_DEVICE_OUT_VOICE_USB_HEADSET, 107 | /* Specific snd_devices */ 108 | SND_DEVICE_OUT_USB_HEADSET_SPEC, 109 | SND_DEVICE_OUT_VOICE_HEARING_AID, 110 | SND_DEVICE_OUT_END, 111 | 112 | /* 113 | * Note: IN_BEGIN should be same as OUT_END because total number of devices 114 | * SND_DEVICES_MAX should not exceed MAX_RX + MAX_TX devices. 115 | */ 116 | /* Capture devices */ 117 | SND_DEVICE_IN_BEGIN = SND_DEVICE_OUT_END, 118 | SND_DEVICE_IN_HANDSET_MIC = SND_DEVICE_IN_BEGIN, 119 | SND_DEVICE_IN_HANDSET_MIC_AEC, 120 | SND_DEVICE_IN_HANDSET_MIC_NS, 121 | SND_DEVICE_IN_HANDSET_MIC_AEC_NS, 122 | SND_DEVICE_IN_HANDSET_DMIC, 123 | SND_DEVICE_IN_HANDSET_DMIC_AEC, 124 | SND_DEVICE_IN_HANDSET_DMIC_NS, 125 | SND_DEVICE_IN_HANDSET_DMIC_AEC_NS, 126 | SND_DEVICE_IN_HANDSET_DMIC_STEREO, 127 | 128 | SND_DEVICE_IN_SPEAKER_MIC, 129 | SND_DEVICE_IN_SPEAKER_MIC_AEC, 130 | SND_DEVICE_IN_SPEAKER_MIC_NS, 131 | SND_DEVICE_IN_SPEAKER_MIC_AEC_NS, 132 | SND_DEVICE_IN_SPEAKER_DMIC, 133 | SND_DEVICE_IN_SPEAKER_DMIC_AEC, 134 | SND_DEVICE_IN_SPEAKER_DMIC_NS, 135 | SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS, 136 | SND_DEVICE_IN_SPEAKER_DMIC_STEREO, 137 | 138 | SND_DEVICE_IN_HEADSET_MIC, 139 | SND_DEVICE_IN_HEADSET_MIC_AEC, 140 | 141 | SND_DEVICE_IN_HDMI_MIC, 142 | SND_DEVICE_IN_BT_SCO_MIC, 143 | SND_DEVICE_IN_BT_SCO_MIC_NREC, 144 | SND_DEVICE_IN_BT_SCO_MIC_WB, 145 | SND_DEVICE_IN_BT_SCO_MIC_WB_NREC, 146 | SND_DEVICE_IN_CAMCORDER_LANDSCAPE, 147 | 148 | SND_DEVICE_IN_VOICE_DMIC, 149 | SND_DEVICE_IN_VOICE_DMIC_TMUS, 150 | SND_DEVICE_IN_VOICE_SPEAKER_MIC, 151 | SND_DEVICE_IN_VOICE_SPEAKER_MIC_HFP, 152 | SND_DEVICE_IN_VOICE_SPEAKER_DMIC, 153 | SND_DEVICE_IN_VOICE_HEADSET_MIC, 154 | SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC, 155 | SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC, 156 | SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC, 157 | SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC, 158 | SND_DEVICE_IN_VOICE_TTY_HCO_USB_MIC, 159 | 160 | SND_DEVICE_IN_VOICE_REC_MIC, 161 | SND_DEVICE_IN_VOICE_REC_MIC_NS, 162 | SND_DEVICE_IN_VOICE_REC_MIC_AEC, 163 | SND_DEVICE_IN_VOICE_REC_MIC_AEC_NS, 164 | SND_DEVICE_IN_VOICE_REC_DMIC_STEREO, 165 | SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE, 166 | SND_DEVICE_IN_VOICE_REC_HEADSET_MIC, 167 | 168 | SND_DEVICE_IN_UNPROCESSED_MIC, 169 | SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC, 170 | SND_DEVICE_IN_UNPROCESSED_STEREO_MIC, 171 | SND_DEVICE_IN_UNPROCESSED_THREE_MIC, 172 | SND_DEVICE_IN_UNPROCESSED_QUAD_MIC, 173 | 174 | SND_DEVICE_IN_VOICE_RX, 175 | 176 | SND_DEVICE_IN_USB_HEADSET_MIC, 177 | SND_DEVICE_IN_USB_HEADSET_MIC_AEC, 178 | SND_DEVICE_IN_VOICE_USB_HEADSET_MIC, 179 | SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC, 180 | SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC, 181 | SND_DEVICE_IN_THREE_MIC, 182 | SND_DEVICE_IN_QUAD_MIC, 183 | SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, 184 | 185 | SND_DEVICE_IN_HANDSET_TMIC, 186 | SND_DEVICE_IN_HANDSET_QMIC, 187 | SND_DEVICE_IN_HANDSET_TMIC_AEC, 188 | SND_DEVICE_IN_HANDSET_QMIC_AEC, 189 | SND_DEVICE_IN_CAMCORDER_INVERT_LANDSCAPE, 190 | SND_DEVICE_IN_CAMCORDER_PORTRAIT, 191 | SND_DEVICE_IN_CAMCORDER_SELFIE_LANDSCAPE, 192 | SND_DEVICE_IN_CAMCORDER_SELFIE_INVERT_LANDSCAPE, 193 | SND_DEVICE_IN_CAMCORDER_SELFIE_PORTRAIT, 194 | SND_DEVICE_IN_SPEAKER_QMIC_NS, 195 | SND_DEVICE_IN_SPEAKER_QMIC_AEC_NS, 196 | SND_DEVICE_IN_VOICE_HEARING_AID, 197 | SND_DEVICE_IN_END, 198 | 199 | SND_DEVICE_MAX = SND_DEVICE_IN_END, 200 | /* For legacy xml file parsing */ 201 | SND_DEVICE_IN_CAMCORDER_MIC = SND_DEVICE_IN_CAMCORDER_LANDSCAPE, 202 | }; 203 | #define DEFAULT_OUTPUT_SAMPLING_RATE 48000 204 | #define OUTPUT_SAMPLING_RATE_44100 44100 205 | #define DEFAULT_INPUT_SAMPLING_RATE 48000 206 | 207 | enum { 208 | DEFAULT_CODEC_BACKEND, 209 | SLIMBUS_0_RX = DEFAULT_CODEC_BACKEND, 210 | HEADPHONE_BACKEND, 211 | SLIMBUS_6_RX = HEADPHONE_BACKEND, 212 | HDMI_RX_BACKEND, 213 | USB_AUDIO_RX_BACKEND, 214 | MAX_RX_CODEC_BACKENDS = USB_AUDIO_RX_BACKEND, 215 | /* TX BE follows RX BE */ 216 | SLIMBUS_0_TX, 217 | DEFAULT_CODEC_TX_BACKEND = SLIMBUS_0_TX, 218 | USB_AUDIO_TX_BACKEND, 219 | BT_SCO_TX_BACKEND, 220 | MAX_CODEC_BACKENDS 221 | }; 222 | 223 | #define DEVICE_NAME_MAX_SIZE 128 224 | #define HW_INFO_ARRAY_MAX_SIZE 32 225 | 226 | #define ALL_SESSION_VSID 0xFFFFFFFF 227 | #define DEFAULT_MUTE_RAMP_DURATION_MS 20 228 | #define DEFAULT_VOLUME_RAMP_DURATION_MS 20 229 | #define MIXER_PATH_MAX_LENGTH 100 230 | 231 | #define ACDB_ID_VOICE_SPEAKER 15 232 | #define ACDB_ID_VOICE_HANDSET 7 233 | #define ACDB_ID_VOICE_HANDSET_TMUS 88 234 | #define ACDB_ID_VOICE_DMIC_EF_TMUS 89 235 | #define ACDB_ID_HEADSET_MIC_AEC 8 236 | #define ACDB_ID_VOICE_REC_MIC 62 237 | 238 | #define MAX_VOL_INDEX 5 239 | #define MIN_VOL_INDEX 0 240 | #define percent_to_index(val, min, max) \ 241 | ((val) * ((max) - (min)) * 0.01 + (min) + .5) 242 | 243 | /* 244 | * tinyAlsa library interprets period size as number of frames 245 | * one frame = channel_count * sizeof (pcm sample) 246 | * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes 247 | * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes 248 | * We should take care of returning proper size when AudioFlinger queries for 249 | * the buffer size of an input/output stream 250 | */ 251 | 252 | /* 1920 frames(40ms) at 2 buffers gives a good tradeoff between power and latency */ 253 | #define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 1920 254 | #define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 2 255 | 256 | #define LOW_LATENCY_OUTPUT_PERIOD_SIZE 240 257 | #define LOW_LATENCY_OUTPUT_PERIOD_COUNT 2 258 | 259 | #define HDMI_MULTI_PERIOD_SIZE 336 260 | #define HDMI_MULTI_PERIOD_COUNT 8 261 | #define HDMI_MULTI_DEFAULT_CHANNEL_COUNT 6 262 | #define HDMI_MULTI_PERIOD_BYTES (HDMI_MULTI_PERIOD_SIZE * HDMI_MULTI_DEFAULT_CHANNEL_COUNT * 2) 263 | 264 | #define AUDIO_CAPTURE_PERIOD_DURATION_MSEC 20 265 | #define AUDIO_CAPTURE_PERIOD_COUNT 2 266 | 267 | #define VOIP_CAPTURE_PERIOD_DURATION_MSEC 20 268 | #define VOIP_CAPTURE_PERIOD_COUNT 2 269 | 270 | #define VOIP_PLAYBACK_PERIOD_DURATION_MSEC 20 271 | #define VOIP_PLAYBACK_PERIOD_COUNT 2 272 | 273 | #define LOW_LATENCY_CAPTURE_SAMPLE_RATE 48000 274 | #define LOW_LATENCY_CAPTURE_PERIOD_SIZE 240 275 | #define LOW_LATENCY_CAPTURE_USE_CASE 1 276 | 277 | #define DEEP_BUFFER_PCM_DEVICE 0 278 | #define AUDIO_RECORD_PCM_DEVICE 0 279 | #define MULTIMEDIA2_PCM_DEVICE 1 280 | 281 | #define SPKR_PROT_CALIB_RX_PCM_DEVICE 5 282 | #define SPKR_PROT_CALIB_TX_PCM_DEVICE 25 283 | 284 | #define MULTIMEDIA3_PCM_DEVICE 4 285 | 286 | #define MMAP_PLAYBACK_PCM_DEVICE 18 287 | #define MMAP_RECORD_PCM_DEVICE 18 288 | 289 | #define QUAT_MI2S_PCM_DEVICE 44 290 | #define PLAYBACK_OFFLOAD_DEVICE 9 291 | #define LOWLATENCY_PCM_DEVICE 15 292 | #define VOICE_VSID 0x10C01000 293 | 294 | #define AUDIO_HAPTICS_PCM_DEVICE 43 295 | #define HAPTICS_PCM_DEVICE 44 296 | 297 | //needs verification 298 | #define AUDIO_PLAYBACK_VOIP_PCM_DEVICE 5 299 | #define AUDIO_RECORD_VOIP_PCM_DEVICE 6 300 | 301 | #ifdef PLATFORM_MSM8x26 302 | #define VOICE_CALL_PCM_DEVICE 2 303 | #define VOICE2_CALL_PCM_DEVICE 14 304 | #define VOLTE_CALL_PCM_DEVICE 17 305 | #define QCHAT_CALL_PCM_DEVICE 18 306 | #define VOWLAN_CALL_PCM_DEVICE 30 307 | #elif PLATFORM_MSM8084 308 | #define VOICE_CALL_PCM_DEVICE 20 309 | #define VOICE2_CALL_PCM_DEVICE 25 310 | #define VOLTE_CALL_PCM_DEVICE 21 311 | #define QCHAT_CALL_PCM_DEVICE 33 312 | #define VOWLAN_CALL_PCM_DEVICE -1 313 | #elif PLATFORM_MSM8996 314 | #define VOICE_CALL_PCM_DEVICE 40 315 | #define VOICE2_CALL_PCM_DEVICE 41 316 | #define VOLTE_CALL_PCM_DEVICE 14 317 | #define QCHAT_CALL_PCM_DEVICE 20 318 | #define VOWLAN_CALL_PCM_DEVICE 33 319 | #else 320 | #define VOICE_CALL_PCM_DEVICE 2 321 | #define VOICE2_CALL_PCM_DEVICE 22 322 | #define VOLTE_CALL_PCM_DEVICE 14 323 | #define QCHAT_CALL_PCM_DEVICE 20 324 | #define VOWLAN_CALL_PCM_DEVICE 36 325 | #endif 326 | 327 | #ifdef PLATFORM_MSM8996 328 | #define VOICEMMODE1_CALL_PCM_DEVICE 2 329 | #define VOICEMMODE2_CALL_PCM_DEVICE 22 330 | #else 331 | #define VOICEMMODE1_CALL_PCM_DEVICE 44 332 | #define VOICEMMODE2_CALL_PCM_DEVICE 45 333 | #endif 334 | 335 | #define AFE_PROXY_PLAYBACK_PCM_DEVICE 7 336 | #define AFE_PROXY_RECORD_PCM_DEVICE 8 337 | 338 | #define INCALL_MUSIC_UPLINK_PCM_DEVICE 27 339 | #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 27 340 | 341 | #define HFP_PCM_RX 5 342 | #ifdef PLATFORM_MSM8x26 343 | #ifdef EXTERNAL_BT_SUPPORTED 344 | #define HFP_SCO_RX 10 // AUXPCM Hostless 345 | #else 346 | #define HFP_SCO_RX 28 // INT_HFP_BT Hostless 347 | #endif 348 | #define HFP_ASM_RX_TX 29 349 | #else 350 | #define HFP_SCO_RX 23 351 | #define HFP_ASM_RX_TX 24 352 | #endif 353 | 354 | #define TX_VOICE_FLUENCE_PROV2 0x10F17 355 | #define TX_VOICE_DM_FV5_BROADSIDE 0x10F18 356 | #define TX_VOICE_FV5ECNS_SM 0x10F09 357 | #define TX_VOICE_FV5ECNS_DM 0x10F0A 358 | 359 | #define LIB_CSD_CLIENT "libcsd-client.so" 360 | #define LIB_MDM_DETECT "libmdmdetect.so" 361 | 362 | #define PLATFORM_CONFIG_KEY_SOUNDCARD_NAME "snd_card_name" 363 | #define PLATFORM_CONFIG_KEY_MAX_MIC_COUNT "input_mic_max_count" 364 | #define PLATFORM_DEFAULT_MIC_COUNT 2 365 | 366 | #define AUDIO_MAKE_STRING_FROM_ENUM(X) { #X, X } 367 | 368 | /* CSD-CLIENT related functions */ 369 | typedef int (*init_t)(bool); 370 | typedef int (*deinit_t)(); 371 | typedef int (*disable_device_t)(); 372 | typedef int (*enable_device_config_t)(int, int); 373 | typedef int (*enable_device_t)(int, int, uint32_t); 374 | typedef int (*volume_t)(uint32_t, int, uint16_t); 375 | typedef int (*mic_mute_t)(uint32_t, int, uint16_t); 376 | typedef int (*slow_talk_t)(uint32_t, uint8_t); 377 | typedef int (*start_voice_t)(uint32_t); 378 | typedef int (*stop_voice_t)(uint32_t); 379 | typedef int (*start_playback_t)(uint32_t); 380 | typedef int (*stop_playback_t)(uint32_t); 381 | typedef int (*start_record_t)(uint32_t, int); 382 | typedef int (*stop_record_t)(uint32_t); 383 | typedef int (*get_sample_rate_t)(uint32_t *); 384 | /* CSD Client structure */ 385 | struct csd_data { 386 | void *csd_client; 387 | init_t init; 388 | deinit_t deinit; 389 | disable_device_t disable_device; 390 | enable_device_config_t enable_device_config; 391 | enable_device_t enable_device; 392 | volume_t volume; 393 | mic_mute_t mic_mute; 394 | slow_talk_t slow_talk; 395 | start_voice_t start_voice; 396 | stop_voice_t stop_voice; 397 | start_playback_t start_playback; 398 | stop_playback_t stop_playback; 399 | start_record_t start_record; 400 | stop_record_t stop_record; 401 | get_sample_rate_t get_sample_rate; 402 | }; 403 | 404 | struct audio_backend_cfg { 405 | unsigned int sample_rate; 406 | unsigned int channels; 407 | unsigned int bit_width; 408 | bool passthrough_enabled; 409 | audio_format_t format; 410 | }; 411 | 412 | typedef struct codec_backend_cfg { 413 | uint32_t sample_rate; 414 | uint32_t bit_width; 415 | uint32_t channels; 416 | char *bitwidth_mixer_ctl; 417 | char *samplerate_mixer_ctl; 418 | char *channels_mixer_ctl; 419 | } codec_backend_cfg_t; 420 | 421 | #define PLATFORM_INFO_XML_PATH "audio_platform_info.xml" 422 | #define PLATFORM_INFO_XML_BASE_STRING "audio_platform_info" 423 | #endif // QCOM_AUDIO_PLATFORM_H 424 | -------------------------------------------------------------------------------- /hal/platform_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef AUDIO_PLATFORM_API_H 18 | #define AUDIO_PLATFORM_API_H 19 | 20 | #include "voice.h" 21 | #define MAX_VOLUME_CAL_STEPS 15 22 | #define CODEC_BACKEND_DEFAULT_SAMPLE_RATE 48000 23 | #define CODEC_BACKEND_DEFAULT_BIT_WIDTH 16 24 | #define CODEC_BACKEND_DEFAULT_CHANNELS 2 25 | #define CODEC_BACKEND_DEFAULT_TX_CHANNELS 1 26 | #define SAMPLE_RATE_8000 8000 27 | #define SAMPLE_RATE_11025 11025 28 | #define sample_rate_multiple(sr, base) ((sr % base)== 0?true:false) 29 | 30 | typedef enum { 31 | EFFECT_NONE = 0, 32 | EFFECT_AEC, 33 | EFFECT_NS, 34 | EFFECT_COUNT 35 | } effect_type_t; 36 | 37 | struct audio_effect_config { 38 | uint32_t module_id; 39 | uint32_t instance_id; 40 | uint32_t param_id; 41 | uint32_t param_value; 42 | }; 43 | 44 | struct amp_db_and_gain_table { 45 | float amp; 46 | float db; 47 | uint32_t level; 48 | }; 49 | 50 | struct mic_info { 51 | char device_id[AUDIO_MICROPHONE_ID_MAX_LEN]; 52 | size_t channel_count; 53 | audio_microphone_channel_mapping_t channel_mapping[AUDIO_CHANNEL_COUNT_MAX]; 54 | }; 55 | 56 | enum card_status_t; 57 | struct audio_usecase; 58 | enum usecase_type_t; 59 | struct audio_backend_cfg; 60 | 61 | void *platform_init(struct audio_device *adev); 62 | void platform_deinit(void *platform); 63 | const char *platform_get_snd_device_name(snd_device_t snd_device); 64 | int platform_get_snd_device_name_extn(void *platform, snd_device_t snd_device, 65 | char *device_name); 66 | void platform_add_backend_name(void *platform, char *mixer_path, 67 | snd_device_t snd_device); 68 | bool platform_send_gain_dep_cal(void *platform, int level); 69 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type); 70 | int platform_get_snd_device_index(char *snd_device_index_name); 71 | int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id); 72 | int platform_get_snd_device_acdb_id(snd_device_t snd_device); 73 | int platform_set_effect_config_data(snd_device_t snd_device, 74 | struct audio_effect_config effect_config, 75 | effect_type_t effect_type); 76 | int platform_get_effect_config_data(snd_device_t snd_device, 77 | struct audio_effect_config *effect_config, 78 | effect_type_t effect_type); 79 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device); 80 | int platform_send_audio_calibration_v2(void *platform, struct audio_usecase *usecase, 81 | int app_type, int sample_rate); 82 | int platform_set_acdb_metainfo_key(void *platform, char *name, int key); 83 | int platform_get_default_app_type_v2(void *platform, enum usecase_type_t type, int *app_type); 84 | int platform_switch_voice_call_device_pre(void *platform); 85 | int platform_switch_voice_call_enable_device_config(void *platform, 86 | snd_device_t out_snd_device, 87 | snd_device_t in_snd_device); 88 | int platform_switch_voice_call_device_post(void *platform, 89 | snd_device_t out_snd_device, 90 | snd_device_t in_snd_device); 91 | int platform_switch_voice_call_usecase_route_post(void *platform, 92 | snd_device_t out_snd_device, 93 | snd_device_t in_snd_device); 94 | int platform_start_voice_call(void *platform, uint32_t vsid); 95 | int platform_stop_voice_call(void *platform, uint32_t vsid); 96 | int platform_set_mic_break_det(void *platform, bool enable); 97 | int platform_set_voice_volume(void *platform, int volume); 98 | void platform_set_speaker_gain_in_combo(struct audio_device *adev, 99 | snd_device_t snd_device, 100 | bool enable); 101 | int platform_set_mic_mute(void *platform, bool state); 102 | int platform_get_sample_rate(void *platform, uint32_t *rate); 103 | int platform_set_device_mute(void *platform, bool state, char *dir); 104 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices); 105 | snd_device_t platform_get_input_snd_device(void *platform, 106 | struct stream_in *in, 107 | audio_devices_t out_device); 108 | int platform_set_hdmi_channels(void *platform, int channel_count); 109 | int platform_edid_get_max_channels(void *platform); 110 | void platform_add_operator_specific_device(snd_device_t snd_device, 111 | const char *operator, 112 | const char *mixer_path, 113 | unsigned int acdb_id); 114 | void platform_add_external_specific_device(snd_device_t snd_device, 115 | const char *name, 116 | unsigned int acdb_id); 117 | /* return true if adding entry success 118 | return false if adding entry fails */ 119 | 120 | bool platform_add_gain_level_mapping(struct amp_db_and_gain_table *tbl_entry); 121 | 122 | /* return 0 if no custome mapping table found or when error detected 123 | use default mapping in this case 124 | return > 0 indicates number of entries in mapping table */ 125 | 126 | int platform_get_gain_level_mapping(struct amp_db_and_gain_table *mapping_tbl, 127 | int table_size); 128 | 129 | /* returns the latency for a usecase in Us */ 130 | int64_t platform_render_latency(struct stream_out *out); 131 | int64_t platform_capture_latency(struct stream_in *in); 132 | 133 | int platform_set_incall_recording_session_id(void *platform, 134 | uint32_t session_id, int rec_mode); 135 | int platform_set_incall_recording_session_channels(void *platform, 136 | uint32_t session_channels); 137 | int platform_stop_incall_recording_usecase(void *platform); 138 | int platform_start_incall_music_usecase(void *platform); 139 | int platform_stop_incall_music_usecase(void *platform); 140 | 141 | int platform_set_snd_device_backend(snd_device_t snd_device, const char * backend, 142 | const char * hw_interface); 143 | 144 | bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id); 145 | 146 | typedef int (*set_parameters_fn)(void *platform, struct str_parms *parms); 147 | 148 | /* From platform_info.c */ 149 | int platform_info_init(const char *filename, void *, 150 | bool do_full_parse, set_parameters_fn); 151 | 152 | int platform_get_usecase_index(const char * usecase); 153 | int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id); 154 | void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device); 155 | int platform_check_and_set_swap_lr_channels(struct audio_device *adev, bool swap_channels); 156 | int platform_set_swap_channels(struct audio_device *adev, bool swap_channels); 157 | 158 | int platform_can_split_snd_device(snd_device_t in_snd_device, 159 | int *num_devices, 160 | snd_device_t *out_snd_devices); 161 | 162 | bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2); 163 | 164 | int platform_set_parameters(void *platform, struct str_parms *parms); 165 | 166 | bool platform_check_and_set_playback_backend_cfg(struct audio_device* adev, 167 | struct audio_usecase *usecase, snd_device_t snd_device); 168 | 169 | bool platform_check_and_set_capture_backend_cfg(struct audio_device* adev, 170 | struct audio_usecase *usecase, snd_device_t snd_device); 171 | 172 | int platform_snd_card_update(void *platform, enum card_status_t status); 173 | void platform_check_and_update_copp_sample_rate(void *platform, snd_device_t snd_device, 174 | unsigned int stream_sr,int *sample_rate); 175 | int platform_get_snd_device_backend_index(snd_device_t snd_device); 176 | bool platform_supports_app_type_cfg(); 177 | int platform_get_app_type_v2(void *platform, 178 | enum usecase_type_t type, 179 | const char *mode, 180 | int bw, int sr, int *app_type); 181 | void platform_add_app_type(const char *uc_type, 182 | const char *mode, 183 | int bw, int app_type, int max_sr); 184 | int platform_get_snd_device_backend_index(snd_device_t snd_device); 185 | int platform_set_sidetone(struct audio_device *adev, 186 | snd_device_t out_snd_device, 187 | bool enable, char * str); 188 | int platform_get_mmap_data_fd(void *platform, int dev, int dir, 189 | int *fd, uint32_t *size); 190 | bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id); 191 | bool platform_snd_device_has_speaker(snd_device_t dev); 192 | 193 | bool platform_set_microphone_characteristic(void *platform, 194 | struct audio_microphone_characteristic_t mic); 195 | bool platform_set_microphone_map(void *platform, snd_device_t in_snd_device, 196 | const struct mic_info *info); 197 | int platform_get_microphones(void *platform, 198 | struct audio_microphone_characteristic_t *mic_array, 199 | size_t *mic_count); 200 | int platform_get_active_microphones(void *platform, unsigned int channels, 201 | audio_usecase_t usecase, 202 | struct audio_microphone_characteristic_t *mic_array, 203 | size_t *mic_count); 204 | int platform_set_usb_service_interval(void *platform, 205 | bool playback, 206 | unsigned long service_interval, 207 | bool *reconfig); 208 | int platform_get_usb_service_interval(void *platform, 209 | bool playback, 210 | unsigned long *service_interval); 211 | int platform_get_haptics_pcm_device_id(); 212 | 213 | void platform_set_audio_source_delay(audio_source_t audio_source, int delay_ms); 214 | 215 | int platform_get_audio_source_index(const char *audio_source_name); 216 | 217 | void platform_set_audio_usecase_delay(audio_usecase_t usecase, int delay_ms); 218 | 219 | /* callback functions from platform to common audio HAL */ 220 | struct stream_in *adev_get_active_input(const struct audio_device *adev); 221 | 222 | #endif // AUDIO_PLATFORM_API_H 223 | -------------------------------------------------------------------------------- /hal/voice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2016 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef VOICE_H 18 | #define VOICE_H 19 | 20 | #define BASE_SESS_IDX 0 21 | #define VOICE_SESS_IDX (BASE_SESS_IDX) 22 | 23 | #ifdef MULTI_VOICE_SESSION_ENABLED 24 | #define MAX_VOICE_SESSIONS 7 25 | #else 26 | #define MAX_VOICE_SESSIONS 1 27 | #endif 28 | 29 | #define BASE_CALL_STATE 1 30 | #define CALL_INACTIVE (BASE_CALL_STATE) 31 | #define CALL_ACTIVE (BASE_CALL_STATE + 1) 32 | 33 | #define VOICE_VSID 0x10C01000 34 | 35 | #define AUDIO_PARAMETER_KEY_INCALLMUSIC "incall_music_enabled" 36 | #define AUDIO_PARAMETER_VALUE_TRUE "true" 37 | 38 | struct audio_device; 39 | struct str_parms; 40 | struct stream_in; 41 | struct stream_out; 42 | typedef int audio_usecase_t; 43 | typedef int snd_device_t; 44 | 45 | struct call_state { 46 | int current; 47 | int new; 48 | }; 49 | 50 | struct voice_session { 51 | struct pcm *pcm_rx; 52 | struct pcm *pcm_tx; 53 | struct call_state state; 54 | uint32_t vsid; 55 | }; 56 | 57 | struct voice { 58 | struct voice_session session[MAX_VOICE_SESSIONS]; 59 | int tty_mode; 60 | bool hac; 61 | bool mic_mute; 62 | float volume; 63 | bool in_call; 64 | }; 65 | 66 | enum { 67 | INCALL_REC_NONE = -1, 68 | INCALL_REC_UPLINK, 69 | INCALL_REC_DOWNLINK, 70 | INCALL_REC_UPLINK_AND_DOWNLINK, 71 | }; 72 | 73 | int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id); 74 | int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id); 75 | 76 | int voice_start_call(struct audio_device *adev); 77 | int voice_stop_call(struct audio_device *adev); 78 | int voice_set_parameters(struct audio_device *adev, struct str_parms *parms); 79 | void voice_get_parameters(struct audio_device *adev, struct str_parms *query, 80 | struct str_parms *reply); 81 | void voice_init(struct audio_device *adev); 82 | bool voice_is_in_call(struct audio_device *adev); 83 | bool voice_is_in_call_rec_stream(struct stream_in *in); 84 | int voice_set_mic_mute(struct audio_device *dev, bool state); 85 | bool voice_get_mic_mute(struct audio_device *dev); 86 | int voice_set_volume(struct audio_device *adev, float volume); 87 | int voice_check_and_set_incall_rec_usecase(struct audio_device *adev, 88 | struct stream_in *in); 89 | int voice_check_and_set_incall_music_usecase(struct audio_device *adev, 90 | struct stream_out *out); 91 | int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev, 92 | struct stream_in *in); 93 | void voice_update_devices_for_all_voice_usecases(struct audio_device *adev); 94 | void voice_set_sidetone(struct audio_device *adev, 95 | snd_device_t out_snd_device, 96 | bool enable); 97 | bool voice_is_call_state_active(struct audio_device *adev); 98 | void voice_set_device_mute_flag (struct audio_device *adev, bool state); 99 | 100 | #endif //VOICE_H 101 | -------------------------------------------------------------------------------- /hal/voice_extn/voice_extn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef VOICE_EXTN_H 18 | #define VOICE_EXTN_H 19 | 20 | #ifdef MULTI_VOICE_SESSION_ENABLED 21 | int voice_extn_start_call(struct audio_device *adev); 22 | int voice_extn_stop_call(struct audio_device *adev); 23 | int voice_extn_get_session_from_use_case(struct audio_device *adev, 24 | const audio_usecase_t usecase_id, 25 | struct voice_session **session); 26 | void voice_extn_init(struct audio_device *adev); 27 | int voice_extn_set_parameters(struct audio_device *adev, 28 | struct str_parms *parms); 29 | void voice_extn_get_parameters(const struct audio_device *adev, 30 | struct str_parms *query, 31 | struct str_parms *reply); 32 | int voice_extn_is_in_call_rec_stream(struct stream_in *in, bool *in_call_rec); 33 | int voice_extn_get_active_session_id(struct audio_device *adev, 34 | uint32_t *session_id); 35 | int voice_extn_is_call_state_active(struct audio_device *adev, 36 | bool *is_call_active); 37 | #else 38 | static int voice_extn_start_call(struct audio_device *adev __unused) 39 | { 40 | return -ENOSYS; 41 | } 42 | 43 | static int voice_extn_stop_call(struct audio_device *adev __unused) 44 | { 45 | return -ENOSYS; 46 | } 47 | 48 | static int voice_extn_get_session_from_use_case(struct audio_device *adev __unused, 49 | const audio_usecase_t usecase_id __unused, 50 | struct voice_session **session __unused) 51 | { 52 | return -ENOSYS; 53 | } 54 | 55 | static void voice_extn_init(struct audio_device *adev __unused) 56 | { 57 | } 58 | 59 | static int voice_extn_set_parameters(struct audio_device *adev __unused, 60 | struct str_parms *parms __unused) 61 | { 62 | return -ENOSYS; 63 | } 64 | 65 | static void voice_extn_get_parameters(const struct audio_device *adev __unused, 66 | struct str_parms *query __unused, 67 | struct str_parms *reply __unused) 68 | { 69 | } 70 | 71 | static int voice_extn_is_call_state_active(struct audio_device *adev __unused, 72 | bool *is_call_active __unused) 73 | { 74 | return -ENOSYS; 75 | } 76 | 77 | static int voice_extn_is_in_call_rec_stream(struct stream_in *in __unused, bool *in_call_rec __unused) 78 | { 79 | return -ENOSYS; 80 | } 81 | 82 | static int voice_extn_get_active_session_id(struct audio_device *adev __unused, 83 | uint32_t *session_id __unused) 84 | { 85 | return -ENOSYS; 86 | } 87 | 88 | #endif 89 | 90 | #ifdef INCALL_MUSIC_ENABLED 91 | int voice_extn_check_and_set_incall_music_usecase(struct audio_device *adev, 92 | struct stream_out *out); 93 | #else 94 | static int voice_extn_check_and_set_incall_music_usecase(struct audio_device *adev __unused, 95 | struct stream_out *out __unused) 96 | { 97 | return -ENOSYS; 98 | } 99 | #endif 100 | 101 | #endif //VOICE_EXTN_H 102 | -------------------------------------------------------------------------------- /post_proc/Android.mk: -------------------------------------------------------------------------------- 1 | ifneq ($(filter msm8996 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) 2 | 3 | LOCAL_PATH:= $(call my-dir) 4 | 5 | qcom_post_proc_common_cflags := \ 6 | -O2 -fvisibility=hidden \ 7 | -Wall -Werror \ 8 | -Wno-unused-function \ 9 | -Wno-unused-variable \ 10 | 11 | include $(CLEAR_VARS) 12 | 13 | LOCAL_SRC_FILES:= \ 14 | bundle.c \ 15 | equalizer.c \ 16 | bass_boost.c \ 17 | virtualizer.c \ 18 | reverb.c \ 19 | effect_api.c 20 | 21 | LOCAL_CFLAGS += $(qcom_post_proc_common_cflags) 22 | 23 | LOCAL_SHARED_LIBRARIES := \ 24 | libcutils \ 25 | liblog \ 26 | libtinyalsa 27 | 28 | LOCAL_MODULE_TAGS := optional 29 | LOCAL_MODULE_OWNER := qcom 30 | LOCAL_PROPRIETARY_MODULE := true 31 | 32 | LOCAL_MODULE_RELATIVE_PATH := soundfx 33 | LOCAL_MODULE:= libqcompostprocbundle 34 | LOCAL_LICENSE_KINDS:= SPDX-license-identifier-Apache-2.0 35 | LOCAL_LICENSE_CONDITIONS:= notice 36 | 37 | LOCAL_C_INCLUDES := \ 38 | external/tinyalsa/include \ 39 | $(call include-path-for, audio-effects) 40 | 41 | LOCAL_HEADER_LIBRARIES += libhardware_headers 42 | LOCAL_HEADER_LIBRARIES += libsystem_headers 43 | 44 | LOCAL_HEADER_LIBRARIES += generated_kernel_headers 45 | 46 | include $(BUILD_SHARED_LIBRARY) 47 | endif 48 | 49 | ################################################################################ 50 | 51 | ifneq ($(filter msm8996 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) 52 | 53 | include $(CLEAR_VARS) 54 | 55 | LOCAL_CFLAGS := -DLIB_AUDIO_HAL="audio.primary."$(TARGET_BOARD_PLATFORM)".so" 56 | 57 | LOCAL_SRC_FILES:= \ 58 | volume_listener.c 59 | 60 | LOCAL_CFLAGS += $(qcom_post_proc_common_cflags) 61 | 62 | LOCAL_SHARED_LIBRARIES := \ 63 | libcutils \ 64 | liblog \ 65 | libdl 66 | 67 | LOCAL_MODULE_RELATIVE_PATH := soundfx 68 | LOCAL_MODULE:= libvolumelistener 69 | LOCAL_LICENSE_KINDS:= SPDX-license-identifier-Apache-2.0 70 | LOCAL_LICENSE_CONDITIONS:= notice 71 | LOCAL_MODULE_OWNER := qcom 72 | LOCAL_PROPRIETARY_MODULE := true 73 | 74 | LOCAL_C_INCLUDES := \ 75 | hardware/qcom/audio/hal \ 76 | $(call include-path-for, audio-effects) 77 | 78 | LOCAL_HEADER_LIBRARIES += libhardware_headers 79 | LOCAL_HEADER_LIBRARIES += libsystem_headers 80 | 81 | LOCAL_HEADER_LIBRARIES += generated_kernel_headers 82 | 83 | include $(BUILD_SHARED_LIBRARY) 84 | 85 | endif 86 | 87 | ################################################################################ 88 | ifeq ($(strip $(AUDIO_FEATURE_ENABLED_MAXX_AUDIO)), true) 89 | 90 | include $(CLEAR_VARS) 91 | 92 | LOCAL_CFLAGS := -D HAL_LIB_NAME=\"audio.primary."$(TARGET_BOARD_PLATFORM)".so\" 93 | 94 | LOCAL_SRC_FILES:= \ 95 | ma_listener.c 96 | 97 | LOCAL_CFLAGS += $(qcom_post_proc_common_cflags) 98 | 99 | LOCAL_SHARED_LIBRARIES := \ 100 | libcutils \ 101 | liblog \ 102 | libdl 103 | 104 | LOCAL_MODULE_RELATIVE_PATH := soundfx 105 | LOCAL_MODULE:= libmalistener 106 | LOCAL_LICENSE_KINDS:= SPDX-license-identifier-Apache-2.0 107 | LOCAL_LICENSE_CONDITIONS:= notice 108 | LOCAL_MODULE_OWNER := google 109 | LOCAL_PROPRIETARY_MODULE := true 110 | 111 | LOCAL_C_INCLUDES := \ 112 | hardware/qcom/audio/hal \ 113 | system/media/audio/include/system \ 114 | $(call include-path-for, audio-effects) 115 | 116 | LOCAL_HEADER_LIBRARIES += libhardware_headers 117 | LOCAL_HEADER_LIBRARIES += libsystem_headers 118 | 119 | LOCAL_HEADER_LIBRARIES += generated_kernel_headers 120 | 121 | include $(BUILD_SHARED_LIBRARY) 122 | 123 | endif 124 | -------------------------------------------------------------------------------- /post_proc/bass_boost.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "offload_effect_bass_boost" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "effect_api.h" 27 | #include "bass_boost.h" 28 | 29 | /* Offload bassboost UUID: 2c4a8c24-1581-487f-94f6-0002a5d5c51b */ 30 | const effect_descriptor_t bassboost_descriptor = { 31 | {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, 32 | {0x2c4a8c24, 0x1581, 0x487f, 0x94f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid 33 | EFFECT_CONTROL_API_VERSION, 34 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL | 35 | EFFECT_FLAG_VOLUME_CTRL), 36 | 0, /* TODO */ 37 | 1, 38 | "MSM offload bassboost", 39 | "The Android Open Source Project", 40 | }; 41 | 42 | /* 43 | * Bassboost operations 44 | */ 45 | 46 | int bassboost_get_strength(bassboost_context_t *context) 47 | { 48 | ALOGV("%s: strength: %d", __func__, context->strength); 49 | return context->strength; 50 | } 51 | 52 | int bassboost_set_strength(bassboost_context_t *context, uint32_t strength) 53 | { 54 | ALOGV("%s: strength: %d", __func__, strength); 55 | context->strength = strength; 56 | 57 | offload_bassboost_set_strength(&(context->offload_bass), strength); 58 | if (context->ctl) 59 | offload_bassboost_send_params(context->ctl, &context->offload_bass, 60 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | 61 | OFFLOAD_SEND_BASSBOOST_STRENGTH); 62 | return 0; 63 | } 64 | 65 | int bassboost_get_parameter(effect_context_t *context, effect_param_t *p, 66 | uint32_t *size) 67 | { 68 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 69 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 70 | int32_t *param_tmp = (int32_t *)p->data; 71 | int32_t param = *param_tmp++; 72 | void *value = p->data + voffset; 73 | int i; 74 | 75 | ALOGV("%s", __func__); 76 | 77 | p->status = 0; 78 | 79 | switch (param) { 80 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: 81 | if (p->vsize < sizeof(uint32_t)) 82 | p->status = -EINVAL; 83 | p->vsize = sizeof(uint32_t); 84 | break; 85 | case BASSBOOST_PARAM_STRENGTH: 86 | if (p->vsize < sizeof(int16_t)) 87 | p->status = -EINVAL; 88 | p->vsize = sizeof(int16_t); 89 | break; 90 | default: 91 | p->status = -EINVAL; 92 | } 93 | 94 | *size = sizeof(effect_param_t) + voffset + p->vsize; 95 | 96 | if (p->status != 0) 97 | return 0; 98 | 99 | switch (param) { 100 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: 101 | ALOGV("%s: BASSBOOST_PARAM_STRENGTH_SUPPORTED", __func__); 102 | *(uint32_t *)value = 1; 103 | break; 104 | 105 | case BASSBOOST_PARAM_STRENGTH: 106 | ALOGV("%s: BASSBOOST_PARAM_STRENGTH", __func__); 107 | *(int16_t *)value = bassboost_get_strength(bass_ctxt); 108 | break; 109 | 110 | default: 111 | p->status = -EINVAL; 112 | break; 113 | } 114 | 115 | return 0; 116 | } 117 | 118 | int bassboost_set_parameter(effect_context_t *context, effect_param_t *p, 119 | uint32_t size __unused) 120 | { 121 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 122 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 123 | void *value = p->data + voffset; 124 | int32_t *param_tmp = (int32_t *)p->data; 125 | int32_t param = *param_tmp++; 126 | uint32_t strength; 127 | 128 | ALOGV("%s", __func__); 129 | 130 | p->status = 0; 131 | 132 | switch (param) { 133 | case BASSBOOST_PARAM_STRENGTH: 134 | ALOGV("%s BASSBOOST_PARAM_STRENGTH", __func__); 135 | strength = (uint32_t)(*(int16_t *)value); 136 | bassboost_set_strength(bass_ctxt, strength); 137 | break; 138 | default: 139 | p->status = -EINVAL; 140 | break; 141 | } 142 | 143 | return 0; 144 | } 145 | 146 | int bassboost_set_device(effect_context_t *context, uint32_t device) 147 | { 148 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 149 | 150 | ALOGV("%s: device: %d", __func__, device); 151 | bass_ctxt->device = device; 152 | if ((device == AUDIO_DEVICE_OUT_SPEAKER) || 153 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) || 154 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER) || 155 | (device == AUDIO_DEVICE_OUT_AUX_DIGITAL) || 156 | (device == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET)) { 157 | if (!bass_ctxt->temp_disabled) { 158 | if (effect_is_active(&bass_ctxt->common)) { 159 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false); 160 | if (bass_ctxt->ctl) 161 | offload_bassboost_send_params(bass_ctxt->ctl, 162 | &bass_ctxt->offload_bass, 163 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); 164 | } 165 | bass_ctxt->temp_disabled = true; 166 | } 167 | } else { 168 | if (bass_ctxt->temp_disabled) { 169 | if (effect_is_active(&bass_ctxt->common)) { 170 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true); 171 | if (bass_ctxt->ctl) 172 | offload_bassboost_send_params(bass_ctxt->ctl, 173 | &bass_ctxt->offload_bass, 174 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); 175 | } 176 | bass_ctxt->temp_disabled = false; 177 | } 178 | } 179 | offload_bassboost_set_device(&(bass_ctxt->offload_bass), device); 180 | return 0; 181 | } 182 | 183 | int bassboost_reset(effect_context_t *context) 184 | { 185 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 186 | 187 | return 0; 188 | } 189 | 190 | int bassboost_init(effect_context_t *context) 191 | { 192 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 193 | 194 | ALOGV("%s", __func__); 195 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; 196 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; 197 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; 198 | context->config.inputCfg.samplingRate = 44100; 199 | context->config.inputCfg.bufferProvider.getBuffer = NULL; 200 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; 201 | context->config.inputCfg.bufferProvider.cookie = NULL; 202 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; 203 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; 204 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; 205 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; 206 | context->config.outputCfg.samplingRate = 44100; 207 | context->config.outputCfg.bufferProvider.getBuffer = NULL; 208 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; 209 | context->config.outputCfg.bufferProvider.cookie = NULL; 210 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; 211 | 212 | set_config(context, &context->config); 213 | 214 | bass_ctxt->temp_disabled = false; 215 | memset(&(bass_ctxt->offload_bass), 0, sizeof(struct bass_boost_params)); 216 | 217 | return 0; 218 | } 219 | 220 | int bassboost_enable(effect_context_t *context) 221 | { 222 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 223 | 224 | ALOGV("%s", __func__); 225 | 226 | if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) && 227 | !(bass_ctxt->temp_disabled)) { 228 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true); 229 | if (bass_ctxt->ctl && bass_ctxt->strength) 230 | offload_bassboost_send_params(bass_ctxt->ctl, 231 | &bass_ctxt->offload_bass, 232 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | 233 | OFFLOAD_SEND_BASSBOOST_STRENGTH); 234 | } 235 | return 0; 236 | } 237 | 238 | int bassboost_disable(effect_context_t *context) 239 | { 240 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 241 | 242 | ALOGV("%s", __func__); 243 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) { 244 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false); 245 | if (bass_ctxt->ctl) 246 | offload_bassboost_send_params(bass_ctxt->ctl, 247 | &bass_ctxt->offload_bass, 248 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); 249 | } 250 | return 0; 251 | } 252 | 253 | int bassboost_start(effect_context_t *context, output_context_t *output) 254 | { 255 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 256 | 257 | ALOGV("%s", __func__); 258 | bass_ctxt->ctl = output->ctl; 259 | ALOGV("output->ctl: %p", output->ctl); 260 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) 261 | if (bass_ctxt->ctl) 262 | offload_bassboost_send_params(bass_ctxt->ctl, &bass_ctxt->offload_bass, 263 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | 264 | OFFLOAD_SEND_BASSBOOST_STRENGTH); 265 | return 0; 266 | } 267 | 268 | int bassboost_stop(effect_context_t *context, output_context_t *output __unused) 269 | { 270 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; 271 | 272 | ALOGV("%s", __func__); 273 | bass_ctxt->ctl = NULL; 274 | return 0; 275 | } 276 | -------------------------------------------------------------------------------- /post_proc/bass_boost.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OFFLOAD_EFFECT_BASS_BOOST_H_ 18 | #define OFFLOAD_EFFECT_BASS_BOOST_H_ 19 | 20 | #include "bundle.h" 21 | 22 | extern const effect_descriptor_t bassboost_descriptor; 23 | 24 | typedef struct bassboost_context_s { 25 | effect_context_t common; 26 | 27 | int strength; 28 | 29 | // Offload vars 30 | struct mixer_ctl *ctl; 31 | bool temp_disabled; 32 | uint32_t device; 33 | struct bass_boost_params offload_bass; 34 | } bassboost_context_t; 35 | 36 | int bassboost_get_parameter(effect_context_t *context, effect_param_t *p, 37 | uint32_t *size); 38 | 39 | int bassboost_set_parameter(effect_context_t *context, effect_param_t *p, 40 | uint32_t size); 41 | 42 | int bassboost_set_device(effect_context_t *context, uint32_t device); 43 | 44 | int bassboost_reset(effect_context_t *context); 45 | 46 | int bassboost_init(effect_context_t *context); 47 | 48 | int bassboost_enable(effect_context_t *context); 49 | 50 | int bassboost_disable(effect_context_t *context); 51 | 52 | int bassboost_start(effect_context_t *context, output_context_t *output); 53 | 54 | int bassboost_stop(effect_context_t *context, output_context_t *output); 55 | 56 | #endif /* OFFLOAD_EFFECT_BASS_BOOST_H_ */ 57 | -------------------------------------------------------------------------------- /post_proc/bundle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OFFLOAD_EFFECT_BUNDLE_H 18 | #define OFFLOAD_EFFECT_BUNDLE_H 19 | 20 | #include 21 | #include 22 | #include "effect_api.h" 23 | 24 | /* Retry for delay for mixer open */ 25 | #define RETRY_NUMBER 10 26 | #define RETRY_US 500000 27 | 28 | #define MIXER_CARD 0 29 | #define SOUND_CARD 0 30 | 31 | extern const struct effect_interface_s effect_interface; 32 | 33 | typedef struct output_context_s output_context_t; 34 | typedef struct effect_ops_s effect_ops_t; 35 | typedef struct effect_context_s effect_context_t; 36 | 37 | struct output_context_s { 38 | /* node in active_outputs_list */ 39 | struct listnode outputs_list_node; 40 | /* io handle */ 41 | audio_io_handle_t handle; 42 | /* list of effects attached to this output */ 43 | struct listnode effects_list; 44 | /* pcm device id */ 45 | int pcm_device_id; 46 | struct mixer *mixer; 47 | struct mixer_ctl *ctl; 48 | }; 49 | 50 | /* effect specific operations. 51 | * Only the init() and process() operations must be defined. 52 | * Others are optional. 53 | */ 54 | struct effect_ops_s { 55 | int (*init)(effect_context_t *context); 56 | int (*release)(effect_context_t *context); 57 | int (*reset)(effect_context_t *context); 58 | int (*enable)(effect_context_t *context); 59 | int (*start)(effect_context_t *context, output_context_t *output); 60 | int (*stop)(effect_context_t *context, output_context_t *output); 61 | int (*disable)(effect_context_t *context); 62 | int (*process)(effect_context_t *context, audio_buffer_t *in, audio_buffer_t *out); 63 | int (*set_parameter)(effect_context_t *context, effect_param_t *param, uint32_t size); 64 | int (*get_parameter)(effect_context_t *context, effect_param_t *param, uint32_t *size); 65 | int (*set_device)(effect_context_t *context, uint32_t device); 66 | int (*command)(effect_context_t *context, uint32_t cmdCode, uint32_t cmdSize, 67 | void *pCmdData, uint32_t *replySize, void *pReplyData); 68 | }; 69 | 70 | struct effect_context_s { 71 | const struct effect_interface_s *itfe; 72 | /* node in created_effects_list */ 73 | struct listnode effects_list_node; 74 | /* node in output_context_t.effects_list */ 75 | struct listnode output_node; 76 | effect_config_t config; 77 | const effect_descriptor_t *desc; 78 | /* io handle of the output the effect is attached to */ 79 | audio_io_handle_t out_handle; 80 | uint32_t state; 81 | bool offload_enabled; 82 | effect_ops_t ops; 83 | }; 84 | 85 | int set_config(effect_context_t *context, effect_config_t *config); 86 | 87 | bool effect_is_active(effect_context_t *context); 88 | 89 | #endif /* OFFLOAD_EFFECT_BUNDLE_H */ 90 | -------------------------------------------------------------------------------- /post_proc/effect_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OFFLOAD_EFFECT_API_H_ 18 | #define OFFLOAD_EFFECT_API_H_ 19 | 20 | int offload_update_mixer_and_effects_ctl(int card, int device_id, 21 | struct mixer *mixer, 22 | struct mixer_ctl *ctl); 23 | void offload_close_mixer(struct mixer *mixer); 24 | 25 | #define OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG (1 << 0) 26 | #define OFFLOAD_SEND_BASSBOOST_STRENGTH \ 27 | (OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG << 1) 28 | #define OFFLOAD_SEND_BASSBOOST_MODE \ 29 | (OFFLOAD_SEND_BASSBOOST_STRENGTH << 1) 30 | void offload_bassboost_set_device(struct bass_boost_params *bassboost, 31 | uint32_t device); 32 | void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost, 33 | bool enable); 34 | int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost); 35 | void offload_bassboost_set_strength(struct bass_boost_params *bassboost, 36 | int strength); 37 | void offload_bassboost_set_mode(struct bass_boost_params *bassboost, 38 | int mode); 39 | int offload_bassboost_send_params(struct mixer_ctl *ctl, 40 | struct bass_boost_params *bassboost, 41 | unsigned param_send_flags); 42 | 43 | #define OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG (1 << 0) 44 | #define OFFLOAD_SEND_VIRTUALIZER_STRENGTH \ 45 | (OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG << 1) 46 | #define OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE \ 47 | (OFFLOAD_SEND_VIRTUALIZER_STRENGTH << 1) 48 | #define OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST \ 49 | (OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE << 1) 50 | void offload_virtualizer_set_device(struct virtualizer_params *virtualizer, 51 | uint32_t device); 52 | void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer, 53 | bool enable); 54 | int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer); 55 | void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer, 56 | int strength); 57 | void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer, 58 | int out_type); 59 | void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer, 60 | int gain_adjust); 61 | int offload_virtualizer_send_params(struct mixer_ctl *ctl, 62 | struct virtualizer_params *virtualizer, 63 | unsigned param_send_flags); 64 | 65 | #define OFFLOAD_SEND_EQ_ENABLE_FLAG (1 << 0) 66 | #define OFFLOAD_SEND_EQ_PRESET \ 67 | (OFFLOAD_SEND_EQ_ENABLE_FLAG << 1) 68 | #define OFFLOAD_SEND_EQ_BANDS_LEVEL \ 69 | (OFFLOAD_SEND_EQ_PRESET << 1) 70 | void offload_eq_set_device(struct eq_params *eq, uint32_t device); 71 | void offload_eq_set_enable_flag(struct eq_params *eq, bool enable); 72 | int offload_eq_get_enable_flag(struct eq_params *eq); 73 | void offload_eq_set_preset(struct eq_params *eq, int preset); 74 | void offload_eq_set_bands_level(struct eq_params *eq, int num_bands, 75 | const uint16_t *band_freq_list, 76 | int *band_gain_list); 77 | int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq, 78 | unsigned param_send_flags); 79 | 80 | #define OFFLOAD_SEND_REVERB_ENABLE_FLAG (1 << 0) 81 | #define OFFLOAD_SEND_REVERB_MODE \ 82 | (OFFLOAD_SEND_REVERB_ENABLE_FLAG << 1) 83 | #define OFFLOAD_SEND_REVERB_PRESET \ 84 | (OFFLOAD_SEND_REVERB_MODE << 1) 85 | #define OFFLOAD_SEND_REVERB_WET_MIX \ 86 | (OFFLOAD_SEND_REVERB_PRESET << 1) 87 | #define OFFLOAD_SEND_REVERB_GAIN_ADJUST \ 88 | (OFFLOAD_SEND_REVERB_WET_MIX << 1) 89 | #define OFFLOAD_SEND_REVERB_ROOM_LEVEL \ 90 | (OFFLOAD_SEND_REVERB_GAIN_ADJUST << 1) 91 | #define OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL \ 92 | (OFFLOAD_SEND_REVERB_ROOM_LEVEL << 1) 93 | #define OFFLOAD_SEND_REVERB_DECAY_TIME \ 94 | (OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL << 1) 95 | #define OFFLOAD_SEND_REVERB_DECAY_HF_RATIO \ 96 | (OFFLOAD_SEND_REVERB_DECAY_TIME << 1) 97 | #define OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL \ 98 | (OFFLOAD_SEND_REVERB_DECAY_HF_RATIO << 1) 99 | #define OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY \ 100 | (OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL << 1) 101 | #define OFFLOAD_SEND_REVERB_LEVEL \ 102 | (OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY << 1) 103 | #define OFFLOAD_SEND_REVERB_DELAY \ 104 | (OFFLOAD_SEND_REVERB_LEVEL << 1) 105 | #define OFFLOAD_SEND_REVERB_DIFFUSION \ 106 | (OFFLOAD_SEND_REVERB_DELAY << 1) 107 | #define OFFLOAD_SEND_REVERB_DENSITY \ 108 | (OFFLOAD_SEND_REVERB_DIFFUSION << 1) 109 | void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device); 110 | void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable); 111 | int offload_reverb_get_enable_flag(struct reverb_params *reverb); 112 | void offload_reverb_set_mode(struct reverb_params *reverb, int mode); 113 | void offload_reverb_set_preset(struct reverb_params *reverb, int preset); 114 | void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix); 115 | void offload_reverb_set_gain_adjust(struct reverb_params *reverb, 116 | int gain_adjust); 117 | void offload_reverb_set_room_level(struct reverb_params *reverb, 118 | int room_level); 119 | void offload_reverb_set_room_hf_level(struct reverb_params *reverb, 120 | int room_hf_level); 121 | void offload_reverb_set_decay_time(struct reverb_params *reverb, 122 | int decay_time); 123 | void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb, 124 | int decay_hf_ratio); 125 | void offload_reverb_set_reflections_level(struct reverb_params *reverb, 126 | int reflections_level); 127 | void offload_reverb_set_reflections_delay(struct reverb_params *reverb, 128 | int reflections_delay); 129 | void offload_reverb_set_reverb_level(struct reverb_params *reverb, 130 | int reverb_level); 131 | void offload_reverb_set_delay(struct reverb_params *reverb, int delay); 132 | void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion); 133 | void offload_reverb_set_density(struct reverb_params *reverb, int density); 134 | int offload_reverb_send_params(struct mixer_ctl *ctl, 135 | struct reverb_params *reverb, 136 | unsigned param_send_flags); 137 | 138 | #endif /*OFFLOAD_EFFECT_API_H_*/ 139 | -------------------------------------------------------------------------------- /post_proc/equalizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OFFLOAD_EQUALIZER_H_ 18 | #define OFFLOAD_EQUALIZER_H_ 19 | 20 | #include "bundle.h" 21 | 22 | #define NUM_EQ_BANDS 5 23 | #define INVALID_PRESET -2 24 | #define PRESET_CUSTOM -1 25 | 26 | extern const effect_descriptor_t equalizer_descriptor; 27 | 28 | typedef struct equalizer_context_s { 29 | effect_context_t common; 30 | 31 | int preset; 32 | int band_levels[NUM_EQ_BANDS]; 33 | 34 | // Offload vars 35 | struct mixer_ctl *ctl; 36 | uint32_t device; 37 | struct eq_params offload_eq; 38 | } equalizer_context_t; 39 | 40 | int equalizer_get_parameter(effect_context_t *context, effect_param_t *p, 41 | uint32_t *size); 42 | 43 | int equalizer_set_parameter(effect_context_t *context, effect_param_t *p, 44 | uint32_t size); 45 | 46 | int equalizer_set_device(effect_context_t *context, uint32_t device); 47 | 48 | int equalizer_reset(effect_context_t *context); 49 | 50 | int equalizer_init(effect_context_t *context); 51 | 52 | int equalizer_enable(effect_context_t *context); 53 | 54 | int equalizer_disable(effect_context_t *context); 55 | 56 | int equalizer_start(effect_context_t *context, output_context_t *output); 57 | 58 | int equalizer_stop(effect_context_t *context, output_context_t *output); 59 | 60 | #endif /*OFFLOAD_EQUALIZER_H_*/ 61 | -------------------------------------------------------------------------------- /post_proc/reverb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OFFLOAD_REVERB_H_ 18 | #define OFFLOAD_REVERB_H_ 19 | 20 | #include "bundle.h" 21 | 22 | #define REVERB_DEFAULT_PRESET REVERB_PRESET_NONE 23 | 24 | extern const effect_descriptor_t aux_env_reverb_descriptor; 25 | extern const effect_descriptor_t ins_env_reverb_descriptor; 26 | extern const effect_descriptor_t aux_preset_reverb_descriptor; 27 | extern const effect_descriptor_t ins_preset_reverb_descriptor; 28 | 29 | typedef struct reverb_settings_s { 30 | int16_t roomLevel; 31 | int16_t roomHFLevel; 32 | uint32_t decayTime; 33 | int16_t decayHFRatio; 34 | int16_t reflectionsLevel; 35 | uint32_t reflectionsDelay; 36 | int16_t reverbLevel; 37 | uint32_t reverbDelay; 38 | int16_t diffusion; 39 | int16_t density; 40 | } reverb_settings_t; 41 | 42 | typedef struct reverb_context_s { 43 | effect_context_t common; 44 | 45 | // Offload vars 46 | struct mixer_ctl *ctl; 47 | bool auxiliary; 48 | bool preset; 49 | uint16_t cur_preset; 50 | uint16_t next_preset; 51 | reverb_settings_t reverb_settings; 52 | uint32_t device; 53 | struct reverb_params offload_reverb; 54 | } reverb_context_t; 55 | 56 | 57 | void reverb_auxiliary_init(reverb_context_t *context); 58 | 59 | void reverb_preset_init(reverb_context_t *context); 60 | 61 | void reverb_insert_init(reverb_context_t *context); 62 | 63 | int reverb_get_parameter(effect_context_t *context, effect_param_t *p, 64 | uint32_t *size); 65 | 66 | int reverb_set_parameter(effect_context_t *context, effect_param_t *p, 67 | uint32_t size); 68 | 69 | int reverb_set_device(effect_context_t *context, uint32_t device); 70 | 71 | int reverb_reset(effect_context_t *context); 72 | 73 | int reverb_init(effect_context_t *context); 74 | 75 | int reverb_enable(effect_context_t *context); 76 | 77 | int reverb_disable(effect_context_t *context); 78 | 79 | int reverb_start(effect_context_t *context, output_context_t *output); 80 | 81 | int reverb_stop(effect_context_t *context, output_context_t *output); 82 | 83 | #endif /* OFFLOAD_REVERB_H_ */ 84 | -------------------------------------------------------------------------------- /post_proc/virtualizer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define LOG_TAG "offload_effect_virtualizer" 18 | //#define LOG_NDEBUG 0 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "effect_api.h" 27 | #include "virtualizer.h" 28 | 29 | /* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */ 30 | const effect_descriptor_t virtualizer_descriptor = { 31 | {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, 32 | {0x509a4498, 0x561a, 0x4bea, 0xb3b1, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid 33 | EFFECT_CONTROL_API_VERSION, 34 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL | 35 | EFFECT_FLAG_VOLUME_CTRL), 36 | 0, /* TODO */ 37 | 1, 38 | "MSM offload virtualizer", 39 | "The Android Open Source Project", 40 | }; 41 | 42 | /* 43 | * Virtualizer operations 44 | */ 45 | 46 | int virtualizer_get_strength(virtualizer_context_t *context) 47 | { 48 | ALOGV("%s: strength: %d", __func__, context->strength); 49 | return context->strength; 50 | } 51 | 52 | int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength) 53 | { 54 | ALOGV("%s: strength: %d", __func__, strength); 55 | context->strength = strength; 56 | 57 | offload_virtualizer_set_strength(&(context->offload_virt), strength); 58 | if (context->ctl) 59 | offload_virtualizer_send_params(context->ctl, &context->offload_virt, 60 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | 61 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); 62 | return 0; 63 | } 64 | 65 | int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p, 66 | uint32_t *size) 67 | { 68 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 69 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 70 | int32_t *param_tmp = (int32_t *)p->data; 71 | int32_t param = *param_tmp++; 72 | void *value = p->data + voffset; 73 | int i; 74 | 75 | ALOGV("%s", __func__); 76 | 77 | p->status = 0; 78 | 79 | switch (param) { 80 | case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: 81 | if (p->vsize < sizeof(uint32_t)) 82 | p->status = -EINVAL; 83 | p->vsize = sizeof(uint32_t); 84 | break; 85 | case VIRTUALIZER_PARAM_STRENGTH: 86 | if (p->vsize < sizeof(int16_t)) 87 | p->status = -EINVAL; 88 | p->vsize = sizeof(int16_t); 89 | break; 90 | default: 91 | p->status = -EINVAL; 92 | } 93 | 94 | *size = sizeof(effect_param_t) + voffset + p->vsize; 95 | 96 | if (p->status != 0) 97 | return 0; 98 | 99 | switch (param) { 100 | case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: 101 | ALOGV("%s: VIRTUALIZER_PARAM_STRENGTH_SUPPORTED", __func__); 102 | *(uint32_t *)value = 1; 103 | break; 104 | 105 | case VIRTUALIZER_PARAM_STRENGTH: 106 | ALOGV("%s: VIRTUALIZER_PARAM_STRENGTH", __func__); 107 | *(int16_t *)value = virtualizer_get_strength(virt_ctxt); 108 | break; 109 | 110 | default: 111 | p->status = -EINVAL; 112 | break; 113 | } 114 | 115 | return 0; 116 | } 117 | 118 | int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p, 119 | uint32_t size __unused) 120 | { 121 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 122 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 123 | void *value = p->data + voffset; 124 | int32_t *param_tmp = (int32_t *)p->data; 125 | int32_t param = *param_tmp++; 126 | uint32_t strength; 127 | 128 | ALOGV("%s", __func__); 129 | 130 | p->status = 0; 131 | 132 | switch (param) { 133 | case VIRTUALIZER_PARAM_STRENGTH: 134 | ALOGV("%s VIRTUALIZER_PARAM_STRENGTH", __func__); 135 | strength = (uint32_t)(*(int16_t *)value); 136 | virtualizer_set_strength(virt_ctxt, strength); 137 | break; 138 | default: 139 | p->status = -EINVAL; 140 | break; 141 | } 142 | 143 | return 0; 144 | } 145 | 146 | int virtualizer_set_device(effect_context_t *context, uint32_t device) 147 | { 148 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 149 | 150 | ALOGV("%s: device: %d", __func__, device); 151 | virt_ctxt->device = device; 152 | if ((device == AUDIO_DEVICE_OUT_SPEAKER) || 153 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) || 154 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER) || 155 | (device == AUDIO_DEVICE_OUT_AUX_DIGITAL) || 156 | (device == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET)) { 157 | if (!virt_ctxt->temp_disabled) { 158 | if (effect_is_active(&virt_ctxt->common)) { 159 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false); 160 | if (virt_ctxt->ctl) 161 | offload_virtualizer_send_params(virt_ctxt->ctl, 162 | &virt_ctxt->offload_virt, 163 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); 164 | } 165 | virt_ctxt->temp_disabled = true; 166 | } 167 | } else { 168 | if (virt_ctxt->temp_disabled) { 169 | if (effect_is_active(&virt_ctxt->common)) { 170 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true); 171 | if (virt_ctxt->ctl) 172 | offload_virtualizer_send_params(virt_ctxt->ctl, 173 | &virt_ctxt->offload_virt, 174 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); 175 | } 176 | virt_ctxt->temp_disabled = false; 177 | } 178 | } 179 | offload_virtualizer_set_device(&(virt_ctxt->offload_virt), device); 180 | return 0; 181 | } 182 | 183 | int virtualizer_reset(effect_context_t *context) 184 | { 185 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 186 | 187 | return 0; 188 | } 189 | 190 | int virtualizer_init(effect_context_t *context) 191 | { 192 | ALOGV("%s", __func__); 193 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 194 | 195 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; 196 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; 197 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; 198 | context->config.inputCfg.samplingRate = 44100; 199 | context->config.inputCfg.bufferProvider.getBuffer = NULL; 200 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; 201 | context->config.inputCfg.bufferProvider.cookie = NULL; 202 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; 203 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; 204 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; 205 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; 206 | context->config.outputCfg.samplingRate = 44100; 207 | context->config.outputCfg.bufferProvider.getBuffer = NULL; 208 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; 209 | context->config.outputCfg.bufferProvider.cookie = NULL; 210 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; 211 | 212 | set_config(context, &context->config); 213 | 214 | virt_ctxt->temp_disabled = false; 215 | memset(&(virt_ctxt->offload_virt), 0, sizeof(struct virtualizer_params)); 216 | 217 | return 0; 218 | } 219 | 220 | int virtualizer_enable(effect_context_t *context) 221 | { 222 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 223 | 224 | ALOGV("%s", __func__); 225 | 226 | if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) && 227 | !(virt_ctxt->temp_disabled)) { 228 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), true); 229 | if (virt_ctxt->ctl && virt_ctxt->strength) 230 | offload_virtualizer_send_params(virt_ctxt->ctl, 231 | &virt_ctxt->offload_virt, 232 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | 233 | OFFLOAD_SEND_BASSBOOST_STRENGTH); 234 | } 235 | return 0; 236 | } 237 | 238 | int virtualizer_disable(effect_context_t *context) 239 | { 240 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 241 | 242 | ALOGV("%s", __func__); 243 | if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) { 244 | offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false); 245 | if (virt_ctxt->ctl) 246 | offload_virtualizer_send_params(virt_ctxt->ctl, 247 | &virt_ctxt->offload_virt, 248 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG); 249 | } 250 | return 0; 251 | } 252 | 253 | int virtualizer_start(effect_context_t *context, output_context_t *output) 254 | { 255 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 256 | 257 | ALOGV("%s", __func__); 258 | virt_ctxt->ctl = output->ctl; 259 | if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) 260 | if (virt_ctxt->ctl) 261 | offload_virtualizer_send_params(virt_ctxt->ctl, &virt_ctxt->offload_virt, 262 | OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG | 263 | OFFLOAD_SEND_VIRTUALIZER_STRENGTH); 264 | return 0; 265 | } 266 | 267 | int virtualizer_stop(effect_context_t *context, output_context_t *output __unused) 268 | { 269 | virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context; 270 | 271 | ALOGV("%s", __func__); 272 | virt_ctxt->ctl = NULL; 273 | return 0; 274 | } 275 | -------------------------------------------------------------------------------- /post_proc/virtualizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OFFLOAD_VIRTUALIZER_H_ 18 | #define OFFLOAD_VIRTUALIZER_H_ 19 | 20 | #include "bundle.h" 21 | 22 | extern const effect_descriptor_t virtualizer_descriptor; 23 | 24 | typedef struct virtualizer_context_s { 25 | effect_context_t common; 26 | 27 | int strength; 28 | 29 | // Offload vars 30 | struct mixer_ctl *ctl; 31 | bool temp_disabled; 32 | uint32_t device; 33 | struct virtualizer_params offload_virt; 34 | } virtualizer_context_t; 35 | 36 | int virtualizer_get_parameter(effect_context_t *context, effect_param_t *p, 37 | uint32_t *size); 38 | 39 | int virtualizer_set_parameter(effect_context_t *context, effect_param_t *p, 40 | uint32_t size); 41 | 42 | int virtualizer_set_device(effect_context_t *context, uint32_t device); 43 | 44 | int virtualizer_reset(effect_context_t *context); 45 | 46 | int virtualizer_init(effect_context_t *context); 47 | 48 | int virtualizer_enable(effect_context_t *context); 49 | 50 | int virtualizer_disable(effect_context_t *context); 51 | 52 | int virtualizer_start(effect_context_t *context, output_context_t *output); 53 | 54 | int virtualizer_stop(effect_context_t *context, output_context_t *output); 55 | 56 | #endif /* OFFLOAD_VIRTUALIZER_H_ */ 57 | -------------------------------------------------------------------------------- /visualizer/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2013 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH:= $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_SRC_FILES:= \ 20 | offload_visualizer.c 21 | 22 | LOCAL_CFLAGS+= -O2 -fvisibility=hidden 23 | 24 | LOCAL_SHARED_LIBRARIES := \ 25 | libcutils \ 26 | liblog \ 27 | libdl \ 28 | libtinyalsa 29 | 30 | LOCAL_CFLAGS += \ 31 | -Wall \ 32 | -Werror \ 33 | -Wno-unused-variable \ 34 | 35 | LOCAL_HEADER_LIBRARIES := libhardware_headers 36 | 37 | LOCAL_MODULE_RELATIVE_PATH := soundfx 38 | LOCAL_MODULE:= libqcomvisualizer 39 | LOCAL_LICENSE_KINDS:= SPDX-license-identifier-Apache-2.0 40 | LOCAL_LICENSE_CONDITIONS:= notice 41 | LOCAL_NOTICE_FILE:= $(LOCAL_PATH)/NOTICE 42 | LOCAL_MODULE_OWNER := qcom 43 | LOCAL_PROPRIETARY_MODULE := true 44 | 45 | LOCAL_C_INCLUDES := \ 46 | external/tinyalsa/include \ 47 | $(call include-path-for, audio-effects) 48 | 49 | LOCAL_HEADER_LIBRARIES += libsystem_headers 50 | include $(BUILD_SHARED_LIBRARY) 51 | -------------------------------------------------------------------------------- /visualizer/MODULE_LICENSE_APACHE2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LineageOS/android_hardware_qcom_audio/e5ddeb997aec21ab73448128ee9daf4ed2ada3b9/visualizer/MODULE_LICENSE_APACHE2 -------------------------------------------------------------------------------- /visualizer/NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2013, The Android Open Source Project 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | 14 | Apache License 15 | Version 2.0, January 2004 16 | http://www.apache.org/licenses/ 17 | 18 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 19 | 20 | 1. Definitions. 21 | 22 | "License" shall mean the terms and conditions for use, reproduction, 23 | and distribution as defined by Sections 1 through 9 of this document. 24 | 25 | "Licensor" shall mean the copyright owner or entity authorized by 26 | the copyright owner that is granting the License. 27 | 28 | "Legal Entity" shall mean the union of the acting entity and all 29 | other entities that control, are controlled by, or are under common 30 | control with that entity. For the purposes of this definition, 31 | "control" means (i) the power, direct or indirect, to cause the 32 | direction or management of such entity, whether by contract or 33 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 34 | outstanding shares, or (iii) beneficial ownership of such entity. 35 | 36 | "You" (or "Your") shall mean an individual or Legal Entity 37 | exercising permissions granted by this License. 38 | 39 | "Source" form shall mean the preferred form for making modifications, 40 | including but not limited to software source code, documentation 41 | source, and configuration files. 42 | 43 | "Object" form shall mean any form resulting from mechanical 44 | transformation or translation of a Source form, including but 45 | not limited to compiled object code, generated documentation, 46 | and conversions to other media types. 47 | 48 | "Work" shall mean the work of authorship, whether in Source or 49 | Object form, made available under the License, as indicated by a 50 | copyright notice that is included in or attached to the work 51 | (an example is provided in the Appendix below). 52 | 53 | "Derivative Works" shall mean any work, whether in Source or Object 54 | form, that is based on (or derived from) the Work and for which the 55 | editorial revisions, annotations, elaborations, or other modifications 56 | represent, as a whole, an original work of authorship. For the purposes 57 | of this License, Derivative Works shall not include works that remain 58 | separable from, or merely link (or bind by name) to the interfaces of, 59 | the Work and Derivative Works thereof. 60 | 61 | "Contribution" shall mean any work of authorship, including 62 | the original version of the Work and any modifications or additions 63 | to that Work or Derivative Works thereof, that is intentionally 64 | submitted to Licensor for inclusion in the Work by the copyright owner 65 | or by an individual or Legal Entity authorized to submit on behalf of 66 | the copyright owner. For the purposes of this definition, "submitted" 67 | means any form of electronic, verbal, or written communication sent 68 | to the Licensor or its representatives, including but not limited to 69 | communication on electronic mailing lists, source code control systems, 70 | and issue tracking systems that are managed by, or on behalf of, the 71 | Licensor for the purpose of discussing and improving the Work, but 72 | excluding communication that is conspicuously marked or otherwise 73 | designated in writing by the copyright owner as "Not a Contribution." 74 | 75 | "Contributor" shall mean Licensor and any individual or Legal Entity 76 | on behalf of whom a Contribution has been received by Licensor and 77 | subsequently incorporated within the Work. 78 | 79 | 2. Grant of Copyright License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | copyright license to reproduce, prepare Derivative Works of, 83 | publicly display, publicly perform, sublicense, and distribute the 84 | Work and such Derivative Works in Source or Object form. 85 | 86 | 3. Grant of Patent License. Subject to the terms and conditions of 87 | this License, each Contributor hereby grants to You a perpetual, 88 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 89 | (except as stated in this section) patent license to make, have made, 90 | use, offer to sell, sell, import, and otherwise transfer the Work, 91 | where such license applies only to those patent claims licensable 92 | by such Contributor that are necessarily infringed by their 93 | Contribution(s) alone or by combination of their Contribution(s) 94 | with the Work to which such Contribution(s) was submitted. If You 95 | institute patent litigation against any entity (including a 96 | cross-claim or counterclaim in a lawsuit) alleging that the Work 97 | or a Contribution incorporated within the Work constitutes direct 98 | or contributory patent infringement, then any patent licenses 99 | granted to You under this License for that Work shall terminate 100 | as of the date such litigation is filed. 101 | 102 | 4. Redistribution. You may reproduce and distribute copies of the 103 | Work or Derivative Works thereof in any medium, with or without 104 | modifications, and in Source or Object form, provided that You 105 | meet the following conditions: 106 | 107 | (a) You must give any other recipients of the Work or 108 | Derivative Works a copy of this License; and 109 | 110 | (b) You must cause any modified files to carry prominent notices 111 | stating that You changed the files; and 112 | 113 | (c) You must retain, in the Source form of any Derivative Works 114 | that You distribute, all copyright, patent, trademark, and 115 | attribution notices from the Source form of the Work, 116 | excluding those notices that do not pertain to any part of 117 | the Derivative Works; and 118 | 119 | (d) If the Work includes a "NOTICE" text file as part of its 120 | distribution, then any Derivative Works that You distribute must 121 | include a readable copy of the attribution notices contained 122 | within such NOTICE file, excluding those notices that do not 123 | pertain to any part of the Derivative Works, in at least one 124 | of the following places: within a NOTICE text file distributed 125 | as part of the Derivative Works; within the Source form or 126 | documentation, if provided along with the Derivative Works; or, 127 | within a display generated by the Derivative Works, if and 128 | wherever such third-party notices normally appear. The contents 129 | of the NOTICE file are for informational purposes only and 130 | do not modify the License. You may add Your own attribution 131 | notices within Derivative Works that You distribute, alongside 132 | or as an addendum to the NOTICE text from the Work, provided 133 | that such additional attribution notices cannot be construed 134 | as modifying the License. 135 | 136 | You may add Your own copyright statement to Your modifications and 137 | may provide additional or different license terms and conditions 138 | for use, reproduction, or distribution of Your modifications, or 139 | for any such Derivative Works as a whole, provided Your use, 140 | reproduction, and distribution of the Work otherwise complies with 141 | the conditions stated in this License. 142 | 143 | 5. Submission of Contributions. Unless You explicitly state otherwise, 144 | any Contribution intentionally submitted for inclusion in the Work 145 | by You to the Licensor shall be under the terms and conditions of 146 | this License, without any additional terms or conditions. 147 | Notwithstanding the above, nothing herein shall supersede or modify 148 | the terms of any separate license agreement you may have executed 149 | with Licensor regarding such Contributions. 150 | 151 | 6. Trademarks. This License does not grant permission to use the trade 152 | names, trademarks, service marks, or product names of the Licensor, 153 | except as required for reasonable and customary use in describing the 154 | origin of the Work and reproducing the content of the NOTICE file. 155 | 156 | 7. Disclaimer of Warranty. Unless required by applicable law or 157 | agreed to in writing, Licensor provides the Work (and each 158 | Contributor provides its Contributions) on an "AS IS" BASIS, 159 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 160 | implied, including, without limitation, any warranties or conditions 161 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 162 | PARTICULAR PURPOSE. You are solely responsible for determining the 163 | appropriateness of using or redistributing the Work and assume any 164 | risks associated with Your exercise of permissions under this License. 165 | 166 | 8. Limitation of Liability. In no event and under no legal theory, 167 | whether in tort (including negligence), contract, or otherwise, 168 | unless required by applicable law (such as deliberate and grossly 169 | negligent acts) or agreed to in writing, shall any Contributor be 170 | liable to You for damages, including any direct, indirect, special, 171 | incidental, or consequential damages of any character arising as a 172 | result of this License or out of the use or inability to use the 173 | Work (including but not limited to damages for loss of goodwill, 174 | work stoppage, computer failure or malfunction, or any and all 175 | other commercial damages or losses), even if such Contributor 176 | has been advised of the possibility of such damages. 177 | 178 | 9. Accepting Warranty or Additional Liability. While redistributing 179 | the Work or Derivative Works thereof, You may choose to offer, 180 | and charge a fee for, acceptance of support, warranty, indemnity, 181 | or other liability obligations and/or rights consistent with this 182 | License. However, in accepting such obligations, You may act only 183 | on Your own behalf and on Your sole responsibility, not on behalf 184 | of any other Contributor, and only if You agree to indemnify, 185 | defend, and hold each Contributor harmless for any liability 186 | incurred by, or claims asserted against, such Contributor by reason 187 | of your accepting any such warranty or additional liability. 188 | 189 | END OF TERMS AND CONDITIONS 190 | 191 | -------------------------------------------------------------------------------- /voice_processing/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | 3 | # audio preprocessing wrapper 4 | include $(CLEAR_VARS) 5 | 6 | LOCAL_MODULE:= libqcomvoiceprocessing 7 | LOCAL_LICENSE_KINDS:= SPDX-license-identifier-Apache-2.0 8 | LOCAL_LICENSE_CONDITIONS:= notice 9 | LOCAL_MODULE_TAGS := optional 10 | LOCAL_MODULE_OWNER := qcom 11 | LOCAL_PROPRIETARY_MODULE := true 12 | LOCAL_MODULE_RELATIVE_PATH := soundfx 13 | 14 | LOCAL_SRC_FILES:= \ 15 | voice_processing.c 16 | 17 | LOCAL_CFLAGS += \ 18 | -Wall \ 19 | -Werror \ 20 | -Wno-unused-function \ 21 | -Wno-unused-variable \ 22 | 23 | LOCAL_C_INCLUDES += \ 24 | $(call include-path-for, audio-effects) 25 | 26 | LOCAL_SHARED_LIBRARIES := \ 27 | liblog \ 28 | libcutils 29 | 30 | LOCAL_SHARED_LIBRARIES += libdl 31 | 32 | LOCAL_CFLAGS += -fvisibility=hidden 33 | 34 | LOCAL_HEADER_LIBRARIES += libhardware_headers 35 | include $(BUILD_SHARED_LIBRARY) 36 | --------------------------------------------------------------------------------