Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1 | /* |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 3 | * Not a contribution. |
| 4 | * |
Shiv Maliyappanahalli | 8911f28 | 2014-01-10 15:56:19 -0800 | [diff] [blame] | 5 | * Copyright (C) 2013 The Android Open Source Project |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #define LOG_TAG "voice" |
| 21 | /*#define LOG_NDEBUG 0*/ |
| 22 | #define LOG_NDDEBUG 0 |
| 23 | |
| 24 | #include <errno.h> |
Sharad Sangle | b27354b | 2015-06-18 15:58:55 +0530 | [diff] [blame] | 25 | #include <stdlib.h> |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 26 | #include <math.h> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 27 | #include <log/log.h> |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 28 | #include <cutils/str_parms.h> |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 29 | #include <cutils/properties.h> |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 30 | #include "audio_hw.h" |
| 31 | #include "voice.h" |
| 32 | #include "voice_extn/voice_extn.h" |
| 33 | #include "platform.h" |
| 34 | #include "platform_api.h" |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 35 | #include "audio_extn.h" |
Pallavi | 009b521 | 2020-10-01 22:53:09 +0530 | [diff] [blame] | 36 | #ifndef LINUX_ENABLED |
| 37 | #include <hardware_legacy/power.h> |
| 38 | #else |
| 39 | #define acquire_wake_lock(a, b) (0) |
| 40 | #define release_wake_lock(a) (0) |
| 41 | #define PARTIAL_WAKE_LOCK 1 |
| 42 | #endif |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 43 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 44 | #ifdef DYNAMIC_LOG_ENABLED |
| 45 | #include <log_xml_parser.h> |
| 46 | #define LOG_MASK HAL_MOD_FILE_VOICE |
| 47 | #include <log_utils.h> |
| 48 | #endif |
| 49 | |
Pallavi | 009b521 | 2020-10-01 22:53:09 +0530 | [diff] [blame] | 50 | #define TRANSIT_WAKE_LOCK_NAME "audiohal_transit_wake_lock" |
| 51 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 52 | struct pcm_config pcm_config_voice_call = { |
| 53 | .channels = 1, |
| 54 | .rate = 8000, |
| 55 | .period_size = 160, |
| 56 | .period_count = 2, |
| 57 | .format = PCM_FORMAT_S16_LE, |
| 58 | }; |
| 59 | |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 60 | struct pcm *voice_loopback_tx = NULL; |
| 61 | struct pcm *voice_loopback_rx = NULL; |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 62 | |
| 63 | static bool voice_external_baseband_supported(struct audio_device *adev) |
| 64 | { |
| 65 | /* If platform is apq8084 and baseband is MDM, load CSD Client specific |
| 66 | * symbols. Voice call is handled by MDM and apps processor talks to |
| 67 | * MDM through CSD Client |
| 68 | */ |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 69 | char *snd_card_name = NULL; |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 70 | char baseband[100]; |
| 71 | snd_card_name = strdup(mixer_get_name(adev->mixer)); |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 72 | if (!snd_card_name) |
| 73 | return 0; |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 74 | property_get("ro.baseband", baseband, ""); |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 75 | if (((!strncmp("hana55", snd_card_name, sizeof("hana55"))) && |
| 76 | ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) || |
| 77 | !strncmp("sdx", baseband, (sizeof("sdx")-1)))) || |
| 78 | ((!strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) && |
| 79 | ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) || |
| 80 | !strncmp("sdx", baseband, (sizeof("sdx")-1))))) { |
| 81 | return 1; |
| 82 | } else { |
| 83 | return 0; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static bool voice_update_pcm_config(struct audio_device *adev) |
| 88 | { |
| 89 | /* If platform is apq8084 and baseband is MDM, load CSD Client specific |
| 90 | * symbols. Voice call is handled by MDM and apps processor talks to |
| 91 | * MDM through CSD Client |
| 92 | */ |
| 93 | char *snd_card_name = NULL; |
| 94 | char baseband[100]; |
| 95 | snd_card_name = strdup(mixer_get_name(adev->mixer)); |
| 96 | if (!snd_card_name) |
| 97 | return 0; |
| 98 | property_get("ro.baseband", baseband, ""); |
| 99 | if ((!strncmp("sm8150-pcie-snd-card", snd_card_name, sizeof("sm8150-pcie-snd-card"))) && |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 100 | ( !strncmp("mdm", baseband, (sizeof("mdm")-1)) || |
| 101 | !strncmp("sdx", baseband, (sizeof("sdx")-1)))) { |
| 102 | return 1; |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 103 | } else { |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 104 | return 0; |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 105 | } |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 106 | } |
| 107 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 108 | static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev, |
| 109 | audio_usecase_t usecase_id) |
| 110 | { |
| 111 | struct voice_session *session = NULL; |
| 112 | int ret = 0; |
| 113 | |
| 114 | ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session); |
| 115 | if (ret == -ENOSYS) { |
| 116 | session = &adev->voice.session[VOICE_SESS_IDX]; |
| 117 | } |
| 118 | |
| 119 | return session; |
| 120 | } |
| 121 | |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 122 | static bool voice_is_sidetone_device(snd_device_t out_device, |
| 123 | char *mixer_path) |
| 124 | { |
| 125 | bool is_sidetone_dev; |
| 126 | |
| 127 | switch (out_device) { |
| 128 | case SND_DEVICE_OUT_VOICE_HANDSET: |
| 129 | is_sidetone_dev = true; |
| 130 | strlcpy(mixer_path, "sidetone-handset", MIXER_PATH_MAX_LENGTH); |
| 131 | break; |
| 132 | case SND_DEVICE_OUT_VOICE_HEADPHONES: |
Samyak Jain | fd24f1e | 2019-04-30 11:58:43 +0530 | [diff] [blame] | 133 | case SND_DEVICE_OUT_VOICE_HEADSET: |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 134 | case SND_DEVICE_OUT_VOICE_ANC_HEADSET: |
| 135 | case SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET: |
| 136 | is_sidetone_dev = true; |
| 137 | strlcpy(mixer_path, "sidetone-headphones", MIXER_PATH_MAX_LENGTH); |
| 138 | break; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 139 | case SND_DEVICE_OUT_VOICE_USB_HEADSET: |
Kuirong Wang | 1cad714 | 2016-05-24 15:21:56 -0700 | [diff] [blame] | 140 | case SND_DEVICE_OUT_USB_HEADSET: |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 141 | // USB does not use a QC mixer. |
| 142 | mixer_path[0] = '\0'; |
Kuirong Wang | 1cad714 | 2016-05-24 15:21:56 -0700 | [diff] [blame] | 143 | is_sidetone_dev = true; |
| 144 | break; |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 145 | default: |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 146 | ALOGW("%s: %d is not a sidetone device", __func__, out_device); |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 147 | is_sidetone_dev = false; |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | return is_sidetone_dev; |
| 152 | } |
| 153 | |
| 154 | void voice_set_sidetone(struct audio_device *adev, |
| 155 | snd_device_t out_snd_device, bool enable) |
| 156 | { |
| 157 | char mixer_path[MIXER_PATH_MAX_LENGTH]; |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 158 | ALOGD("%s: %s, out_snd_device: %d\n", |
| 159 | __func__, (enable ? "enable" : "disable"), |
| 160 | out_snd_device); |
Kuirong Wang | 1cad714 | 2016-05-24 15:21:56 -0700 | [diff] [blame] | 161 | if (voice_is_sidetone_device(out_snd_device, mixer_path)) |
| 162 | platform_set_sidetone(adev, out_snd_device, enable, mixer_path); |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 163 | return; |
| 164 | } |
| 165 | |
Vidyakumar Athota | ea269c6 | 2016-10-31 09:05:59 -0700 | [diff] [blame] | 166 | static bool voice_is_aanc_device(snd_device_t out_device, |
| 167 | char *mixer_path) |
| 168 | { |
| 169 | bool is_aanc_dev; |
| 170 | |
| 171 | switch (out_device) { |
| 172 | case SND_DEVICE_OUT_ANC_HANDSET: |
| 173 | is_aanc_dev = true; |
| 174 | strlcpy(mixer_path, "aanc-path", MIXER_PATH_MAX_LENGTH); |
| 175 | break; |
| 176 | default: |
| 177 | is_aanc_dev = false; |
| 178 | break; |
| 179 | } |
| 180 | |
| 181 | return is_aanc_dev; |
| 182 | } |
| 183 | |
| 184 | void voice_check_and_update_aanc_path(struct audio_device *adev, |
| 185 | snd_device_t out_snd_device, |
| 186 | bool enable) |
| 187 | { |
| 188 | char mixer_path[MIXER_PATH_MAX_LENGTH]; |
| 189 | |
| 190 | ALOGV("%s: %s, out_snd_device: %d\n", |
| 191 | __func__, (enable ? "enable" : "disable"), out_snd_device); |
| 192 | |
| 193 | if (voice_is_aanc_device(out_snd_device, mixer_path)) |
| 194 | platform_update_aanc_path(adev, out_snd_device, enable, mixer_path); |
| 195 | |
| 196 | return; |
| 197 | } |
| 198 | |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 199 | int voice_stop_usecase(struct audio_device *adev, audio_usecase_t usecase_id) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 200 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 201 | int ret = 0; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 202 | struct audio_usecase *uc_info; |
| 203 | struct voice_session *session = NULL; |
| 204 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 205 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 206 | |
| 207 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 208 | if (!session) { |
| 209 | ALOGE("stop_call: couldn't find voice session"); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 213 | uc_info = get_usecase_from_list(adev, usecase_id); |
| 214 | if (uc_info == NULL) { |
| 215 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 216 | __func__, usecase_id); |
| 217 | return -EINVAL; |
| 218 | } |
| 219 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 220 | session->state.current = CALL_INACTIVE; |
| 221 | |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 222 | /* Disable sidetone only when no calls are active */ |
| 223 | if (!voice_is_call_state_active(adev)) |
| 224 | voice_set_sidetone(adev, uc_info->out_snd_device, false); |
| 225 | |
Vidyakumar Athota | ea269c6 | 2016-10-31 09:05:59 -0700 | [diff] [blame] | 226 | /* Disable aanc only when no calls are active */ |
| 227 | if (!voice_is_call_state_active(adev)) |
| 228 | voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, false); |
| 229 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 230 | ret = platform_stop_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 231 | |
| 232 | /* 1. Close the PCM devices */ |
| 233 | if (session->pcm_rx) { |
| 234 | pcm_close(session->pcm_rx); |
| 235 | session->pcm_rx = NULL; |
| 236 | } |
| 237 | if (session->pcm_tx) { |
| 238 | pcm_close(session->pcm_tx); |
| 239 | session->pcm_tx = NULL; |
| 240 | } |
| 241 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 242 | if (voice_external_baseband_supported(adev)) { |
| 243 | if(voice_loopback_rx) { |
| 244 | pcm_close(voice_loopback_rx); |
| 245 | voice_loopback_rx = NULL; |
| 246 | } |
| 247 | if(voice_loopback_tx) { |
| 248 | pcm_close(voice_loopback_tx); |
| 249 | voice_loopback_tx = NULL; |
| 250 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 251 | } |
Pallavi | 009b521 | 2020-10-01 22:53:09 +0530 | [diff] [blame] | 252 | |
| 253 | if (voice_update_pcm_config(adev)) { |
| 254 | ret = release_wake_lock(TRANSIT_WAKE_LOCK_NAME); |
| 255 | if (ret) |
| 256 | ALOGE("%s: failed to release voicecall wake lock. ret: %d",__func__, ret); |
| 257 | } |
| 258 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 259 | /* 2. Get and set stream specific mixer controls */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 260 | disable_audio_route(adev, uc_info); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 261 | |
| 262 | /* 3. Disable the rx and tx devices */ |
Haynes Mathew George | 1376ca6 | 2014-04-24 11:55:48 -0700 | [diff] [blame] | 263 | disable_snd_device(adev, uc_info->out_snd_device); |
| 264 | disable_snd_device(adev, uc_info->in_snd_device); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 265 | |
| 266 | list_remove(&uc_info->list); |
| 267 | free(uc_info); |
| 268 | |
| 269 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 270 | return ret; |
| 271 | } |
| 272 | |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 273 | int voice_start_usecase(struct audio_device *adev, audio_usecase_t usecase_id) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 274 | { |
Satya Krishna Pindiproli | f1cd92b | 2016-04-14 19:05:23 +0530 | [diff] [blame] | 275 | int ret = 0; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 276 | struct audio_usecase *uc_info; |
| 277 | int pcm_dev_rx_id, pcm_dev_tx_id; |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 278 | int pcm_dev_loopback_rx_id, pcm_dev_loopback_tx_id; |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 279 | uint32_t sample_rate = 8000; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 280 | struct voice_session *session = NULL; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 281 | struct pcm_config voice_config = pcm_config_voice_call; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 282 | |
| 283 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 284 | |
| 285 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 286 | if (!session) { |
| 287 | ALOGE("start_call: couldn't find voice session"); |
| 288 | return -EINVAL; |
| 289 | } |
| 290 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 291 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
Haynes Mathew George | b51ceb1 | 2014-06-30 13:56:18 -0700 | [diff] [blame] | 292 | if (!uc_info) { |
| 293 | ALOGE("start_call: couldn't allocate mem for audio_usecase"); |
| 294 | return -ENOMEM; |
| 295 | } |
| 296 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 297 | uc_info->id = usecase_id; |
| 298 | uc_info->type = VOICE_CALL; |
kunleiz | 3251d23 | 2017-11-15 16:28:55 +0800 | [diff] [blame] | 299 | uc_info->stream.out = adev->current_call_output; |
| 300 | uc_info->devices = adev->current_call_output->devices; |
| 301 | |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 302 | if (voice_update_pcm_config(adev)) { |
| 303 | sample_rate = 48000; |
| 304 | voice_config.rate = 48000; |
| 305 | } |
| 306 | |
kunleiz | 3251d23 | 2017-11-15 16:28:55 +0800 | [diff] [blame] | 307 | if (popcount(uc_info->devices) == 2) { |
| 308 | ALOGE("%s: Invalid combo device(%#x) for voice call", __func__, |
| 309 | uc_info->devices); |
| 310 | ret = -EIO; |
| 311 | goto error_start_voice; |
| 312 | } |
| 313 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 314 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 315 | uc_info->out_snd_device = SND_DEVICE_NONE; |
Arun Mirpuri | ef53ce5 | 2018-09-11 18:00:09 -0700 | [diff] [blame] | 316 | adev->voice.use_device_mute = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 317 | |
kunleiz | f175f67 | 2017-09-12 17:02:52 +0800 | [diff] [blame] | 318 | if (audio_is_bluetooth_sco_device(uc_info->devices) && !adev->bt_sco_on) { |
| 319 | ALOGE("start_call: couldn't find BT SCO, SCO is not ready"); |
| 320 | adev->voice.in_call = false; |
| 321 | ret = -EIO; |
| 322 | goto error_start_voice; |
| 323 | } |
| 324 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 325 | list_add_tail(&adev->usecase_list, &uc_info->list); |
| 326 | |
| 327 | select_devices(adev, usecase_id); |
| 328 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 329 | if (voice_external_baseband_supported(adev)) { |
| 330 | pcm_dev_loopback_rx_id = HOST_LESS_RX_ID; |
| 331 | pcm_dev_loopback_tx_id = HOST_LESS_TX_ID; |
| 332 | } |
| 333 | |
Anurag Chouhan | d986732 | 2020-03-09 13:26:25 +0530 | [diff] [blame] | 334 | if (voice_update_pcm_config(adev)) { |
| 335 | pcm_dev_loopback_rx_id = PCIE_HOST_LESS_RX_ID; |
| 336 | pcm_dev_loopback_tx_id = PCIE_HOST_LESS_TX_ID; |
| 337 | } |
| 338 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 339 | pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); |
| 340 | pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); |
| 341 | |
| 342 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) { |
| 343 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)", |
| 344 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id); |
| 345 | ret = -EIO; |
| 346 | goto error_start_voice; |
| 347 | } |
Helen Zeng | 6a16ad7 | 2014-02-23 22:04:44 -0800 | [diff] [blame] | 348 | ret = platform_get_sample_rate(adev->platform, &sample_rate); |
| 349 | if (ret < 0) { |
| 350 | ALOGE("platform_get_sample_rate error %d\n", ret); |
| 351 | } else { |
| 352 | voice_config.rate = sample_rate; |
| 353 | } |
| 354 | ALOGD("voice_config.rate %d\n", voice_config.rate); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 355 | |
Vidyakumar Athota | b000e0b | 2015-04-09 17:45:20 -0700 | [diff] [blame] | 356 | voice_set_mic_mute(adev, adev->voice.mic_mute); |
| 357 | |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 358 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
| 359 | __func__, adev->snd_card, pcm_dev_tx_id); |
| 360 | session->pcm_tx = pcm_open(adev->snd_card, |
| 361 | pcm_dev_tx_id, |
| 362 | PCM_IN, &voice_config); |
| 363 | if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) { |
| 364 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx)); |
| 365 | ret = -EIO; |
| 366 | goto error_start_voice; |
| 367 | } |
| 368 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 369 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 370 | __func__, adev->snd_card, pcm_dev_rx_id); |
| 371 | session->pcm_rx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 372 | pcm_dev_rx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 373 | PCM_OUT, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 374 | if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) { |
| 375 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx)); |
| 376 | ret = -EIO; |
| 377 | goto error_start_voice; |
| 378 | } |
| 379 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 380 | if (voice_external_baseband_supported(adev)) { |
| 381 | voice_loopback_rx = pcm_open(adev->snd_card, |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 382 | pcm_dev_loopback_rx_id, |
| 383 | PCM_OUT, &voice_config); |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 384 | if (voice_loopback_rx < 0 || !pcm_is_ready(voice_loopback_rx)) { |
| 385 | ALOGE("%s: Either could not open pcm_dev_loopback_rx_id %d or %s", |
| 386 | __func__, pcm_dev_loopback_rx_id, pcm_get_error(voice_loopback_rx)); |
| 387 | ret = -EIO; |
| 388 | goto error_start_voice; |
| 389 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 390 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 391 | voice_loopback_tx = pcm_open(adev->snd_card, |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 392 | pcm_dev_loopback_tx_id, |
| 393 | PCM_IN, &voice_config); |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 394 | if (voice_loopback_tx < 0 || !pcm_is_ready(voice_loopback_tx)) { |
| 395 | ALOGE("%s: Either could not open pcm_dev_loopback_tx_id %d or %s", |
| 396 | __func__, pcm_dev_loopback_tx_id, pcm_get_error(voice_loopback_tx)); |
| 397 | ret = -EIO; |
| 398 | goto error_start_voice; |
| 399 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 400 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 401 | |
Pallavi | 009b521 | 2020-10-01 22:53:09 +0530 | [diff] [blame] | 402 | if (voice_update_pcm_config(adev)) { |
| 403 | ret = acquire_wake_lock(PARTIAL_WAKE_LOCK, TRANSIT_WAKE_LOCK_NAME); |
| 404 | if (ret) |
| 405 | ALOGE("%s: acquiring wake lock failed for voice call ret: %d",__func__, ret); |
| 406 | } |
| 407 | |
Weiyin Jiang | 095e444 | 2019-07-15 11:49:15 +0800 | [diff] [blame] | 408 | if (adev->mic_break_enabled) |
Vignesh Kulothungan | 7d37431 | 2018-02-21 17:12:00 -0800 | [diff] [blame] | 409 | platform_set_mic_break_det(adev->platform, true); |
| 410 | |
Vignesh Kulothungan | cf4b932 | 2019-05-03 13:52:50 -0700 | [diff] [blame] | 411 | ret = pcm_start(session->pcm_tx); |
| 412 | if (ret != 0) { |
| 413 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx)); |
| 414 | goto error_start_voice; |
| 415 | } |
| 416 | |
| 417 | ret = pcm_start(session->pcm_rx); |
| 418 | if (ret != 0) { |
| 419 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx)); |
| 420 | goto error_start_voice; |
| 421 | } |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 422 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 423 | if (voice_external_baseband_supported(adev)) { |
| 424 | ret = pcm_start(voice_loopback_tx); |
| 425 | if (ret != 0) { |
| 426 | ALOGE("%s: %s", __func__, pcm_get_error(voice_loopback_tx)); |
| 427 | goto error_start_voice; |
| 428 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 429 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 430 | ret = pcm_start(voice_loopback_rx); |
| 431 | if (ret != 0) { |
| 432 | ALOGE("%s: %s", __func__, pcm_get_error(voice_loopback_rx)); |
| 433 | goto error_start_voice; |
| 434 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 435 | } |
Suprith Malligere Shankaregowda | 7400b21 | 2019-03-22 19:48:44 +0530 | [diff] [blame] | 436 | |
Vidyakumar Athota | ea269c6 | 2016-10-31 09:05:59 -0700 | [diff] [blame] | 437 | /* Enable aanc only when no calls are active */ |
| 438 | if (!voice_is_call_state_active(adev)) |
| 439 | voice_check_and_update_aanc_path(adev, uc_info->out_snd_device, true); |
| 440 | |
Bhalchandra Gajare | 45fee28 | 2015-06-09 22:23:45 -0700 | [diff] [blame] | 441 | /* Enable sidetone only when no calls are already active */ |
| 442 | if (!voice_is_call_state_active(adev)) |
| 443 | voice_set_sidetone(adev, uc_info->out_snd_device, true); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 444 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 445 | voice_set_volume(adev, adev->voice.volume); |
| 446 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 447 | ret = platform_start_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 448 | if (ret < 0) { |
| 449 | ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret); |
| 450 | goto error_start_voice; |
| 451 | } |
| 452 | |
| 453 | session->state.current = CALL_ACTIVE; |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 454 | goto done; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 455 | |
| 456 | error_start_voice: |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 457 | voice_stop_usecase(adev, usecase_id); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 458 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 459 | done: |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 460 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 461 | return ret; |
| 462 | } |
| 463 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 464 | bool voice_is_call_state_active(struct audio_device *adev) |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 465 | { |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 466 | bool call_state = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 467 | int ret = 0; |
| 468 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 469 | ret = voice_extn_is_call_state_active(adev, &call_state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 470 | if (ret == -ENOSYS) { |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 471 | call_state = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 474 | return call_state; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 477 | bool voice_is_in_call(const struct audio_device *adev) |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 478 | { |
| 479 | return adev->voice.in_call; |
| 480 | } |
| 481 | |
Alexy Joseph | b137994 | 2016-01-29 15:49:38 -0800 | [diff] [blame] | 482 | bool voice_is_in_call_rec_stream(const struct stream_in *in) |
kunleiz | c5a639b | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 483 | { |
| 484 | bool in_call_rec = false; |
kunleiz | c5a639b | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 485 | |
Anish Kumar | 50ebcbf | 2014-12-09 04:01:39 +0530 | [diff] [blame] | 486 | if (!in) { |
| 487 | ALOGE("%s: input stream is NULL", __func__); |
| 488 | return in_call_rec; |
| 489 | } |
| 490 | |
Arun Mirpuri | ef53ce5 | 2018-09-11 18:00:09 -0700 | [diff] [blame] | 491 | if (in->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 492 | in->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 493 | in->source == AUDIO_SOURCE_VOICE_CALL) { |
| 494 | in_call_rec = true; |
kunleiz | c5a639b | 2014-04-24 18:46:22 +0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | return in_call_rec; |
| 498 | } |
| 499 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 500 | uint32_t voice_get_active_session_id(struct audio_device *adev) |
| 501 | { |
| 502 | int ret = 0; |
| 503 | uint32_t session_id; |
| 504 | |
| 505 | ret = voice_extn_get_active_session_id(adev, &session_id); |
| 506 | if (ret == -ENOSYS) { |
| 507 | session_id = VOICE_VSID; |
| 508 | } |
| 509 | return session_id; |
| 510 | } |
| 511 | |
Kunlei Zhang | a3b3abf | 2019-06-25 15:42:21 +0800 | [diff] [blame] | 512 | bool voice_check_voicecall_usecases_active(struct audio_device *adev) |
| 513 | { |
| 514 | struct listnode *node; |
| 515 | struct audio_usecase *usecase = NULL; |
| 516 | |
| 517 | list_for_each(node, &adev->usecase_list) { |
| 518 | usecase = node_to_item(node, struct audio_usecase, list); |
| 519 | if (usecase->type == VOICE_CALL) { |
| 520 | ALOGV("%s: voice usecase:%s is active", __func__, |
| 521 | use_case_table[usecase->id]); |
| 522 | return true; |
| 523 | } |
| 524 | } |
| 525 | return false; |
| 526 | } |
| 527 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 528 | int voice_check_and_set_incall_rec_usecase(struct audio_device *adev, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 529 | struct stream_in *in) |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 530 | { |
| 531 | int ret = 0; |
| 532 | uint32_t session_id; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 533 | int rec_mode = INCALL_REC_NONE; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 534 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 535 | if (voice_is_call_state_active(adev)) { |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 536 | switch (in->source) { |
| 537 | case AUDIO_SOURCE_VOICE_UPLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 538 | if (audio_extn_compr_cap_enabled() && |
| 539 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 540 | in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS; |
| 541 | } else |
| 542 | in->usecase = USECASE_INCALL_REC_UPLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 543 | rec_mode = INCALL_REC_UPLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 544 | break; |
| 545 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 546 | if (audio_extn_compr_cap_enabled() && |
| 547 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 548 | in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS; |
| 549 | } else |
| 550 | in->usecase = USECASE_INCALL_REC_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 551 | rec_mode = INCALL_REC_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 552 | break; |
| 553 | case AUDIO_SOURCE_VOICE_CALL: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 554 | if (audio_extn_compr_cap_enabled() && |
| 555 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 556 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS; |
| 557 | } else |
| 558 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 559 | rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 560 | break; |
| 561 | default: |
| 562 | ALOGV("%s: Source type %d doesnt match incall recording criteria", |
| 563 | __func__, in->source); |
| 564 | return ret; |
| 565 | } |
| 566 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 567 | session_id = voice_get_active_session_id(adev); |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 568 | ret = platform_set_incall_recording_session_id(adev->platform, |
| 569 | session_id, rec_mode); |
Yunfei Zhang | 3714bd1 | 2019-04-11 09:04:28 +0800 | [diff] [blame] | 570 | platform_set_incall_recording_session_channels(adev->platform, |
| 571 | in->config.channels); |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 572 | ALOGV("%s: Update usecase to %d",__func__, in->usecase); |
| 573 | } else { |
Venkata Narendra Kumar Gutta | 76440ba | 2015-03-30 19:16:14 +0530 | [diff] [blame] | 574 | /* |
| 575 | * Reject the recording instances, where the recording is started |
| 576 | * with In-call voice recording source types but voice call is not |
| 577 | * active by the time input is started |
| 578 | */ |
| 579 | if ((in->source == AUDIO_SOURCE_VOICE_UPLINK) || |
| 580 | (in->source == AUDIO_SOURCE_VOICE_DOWNLINK) || |
| 581 | (in->source == AUDIO_SOURCE_VOICE_CALL)) { |
| 582 | ret = -EINVAL; |
| 583 | ALOGE("%s: As voice call is not active, Incall rec usecase can't be \ |
| 584 | selected for requested source:%d",__func__, in->source); |
| 585 | } |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 586 | ALOGV("%s: voice call not active", __func__); |
| 587 | } |
| 588 | |
| 589 | return ret; |
| 590 | } |
| 591 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 592 | int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev, |
| 593 | struct stream_in *in) |
| 594 | { |
| 595 | int ret = 0; |
| 596 | |
| 597 | if (in->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 598 | in->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 599 | in->source == AUDIO_SOURCE_VOICE_CALL) { |
| 600 | ret = platform_stop_incall_recording_usecase(adev->platform); |
| 601 | ALOGV("%s: Stop In-call recording", __func__); |
| 602 | } |
| 603 | |
| 604 | return ret; |
| 605 | } |
| 606 | |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 607 | snd_device_t voice_get_incall_rec_backend_device(struct stream_in *in) |
| 608 | { |
| 609 | snd_device_t incall_record_device = {0}; |
| 610 | |
Aditya Bavanari | 9e957d8 | 2019-01-29 17:47:13 +0530 | [diff] [blame] | 611 | if (!in) { |
| 612 | ALOGE("%s: input stream is NULL", __func__); |
| 613 | return 0; |
| 614 | } |
| 615 | |
Divya Narayanan Poojary | 85d0a59 | 2018-02-06 14:25:16 +0530 | [diff] [blame] | 616 | switch(in->source) { |
| 617 | case AUDIO_SOURCE_VOICE_UPLINK: |
| 618 | incall_record_device = SND_DEVICE_IN_INCALL_REC_TX; |
| 619 | break; |
| 620 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
| 621 | incall_record_device = SND_DEVICE_IN_INCALL_REC_RX; |
| 622 | break; |
| 623 | case AUDIO_SOURCE_VOICE_CALL: |
| 624 | incall_record_device = SND_DEVICE_IN_INCALL_REC_RX_TX; |
| 625 | break; |
| 626 | default: |
| 627 | ALOGI("Invalid source %d", in->source); |
| 628 | } |
| 629 | |
| 630 | return incall_record_device; |
| 631 | } |
| 632 | |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 633 | snd_device_t voice_get_incall_rec_snd_device(snd_device_t in_snd_device) |
| 634 | { |
| 635 | snd_device_t incall_record_device = in_snd_device; |
| 636 | |
| 637 | /* |
| 638 | * For incall recording stream, AUDIO_COPP topology will be picked up |
| 639 | * from the calibration data of the input sound device which is nothing |
| 640 | * but the voice call's input device. But there are requirements to use |
| 641 | * AUDIO_COPP_MONO topology even if the voice call's input device is |
| 642 | * different. Hence override the input device with the one which uses |
| 643 | * the AUDIO_COPP_MONO topology. |
| 644 | */ |
| 645 | switch(in_snd_device) { |
| 646 | case SND_DEVICE_IN_HANDSET_MIC: |
| 647 | case SND_DEVICE_IN_VOICE_DMIC: |
| 648 | case SND_DEVICE_IN_AANC_HANDSET_MIC: |
| 649 | incall_record_device = SND_DEVICE_IN_HANDSET_MIC; |
Shiv Maliyappanahalli | 4d2d97c | 2015-02-19 14:29:01 -0800 | [diff] [blame] | 650 | break; |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 651 | case SND_DEVICE_IN_VOICE_SPEAKER_MIC: |
| 652 | case SND_DEVICE_IN_VOICE_SPEAKER_DMIC: |
| 653 | case SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BROADSIDE: |
| 654 | case SND_DEVICE_IN_VOICE_SPEAKER_QMIC: |
| 655 | incall_record_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
Shiv Maliyappanahalli | 4d2d97c | 2015-02-19 14:29:01 -0800 | [diff] [blame] | 656 | break; |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 657 | default: |
| 658 | incall_record_device = in_snd_device; |
| 659 | } |
| 660 | |
Shiv Maliyappanahalli | 4d2d97c | 2015-02-19 14:29:01 -0800 | [diff] [blame] | 661 | ALOGD("%s: in_snd_device(%d: %s) incall_record_device(%d: %s)", __func__, |
| 662 | in_snd_device, platform_get_snd_device_name(in_snd_device), |
| 663 | incall_record_device, platform_get_snd_device_name(incall_record_device)); |
| 664 | |
Narsinga Rao Chella | 212e254 | 2014-11-17 19:57:04 -0800 | [diff] [blame] | 665 | return incall_record_device; |
| 666 | } |
| 667 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 668 | int voice_set_mic_mute(struct audio_device *adev, bool state) |
| 669 | { |
| 670 | int err = 0; |
| 671 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 672 | adev->voice.mic_mute = state; |
Arun Mirpuri | ef53ce5 | 2018-09-11 18:00:09 -0700 | [diff] [blame] | 673 | |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 674 | if (audio_extn_hfp_is_active(adev)) { |
Arun Mirpuri | e008ed2 | 2019-03-21 11:21:04 -0700 | [diff] [blame] | 675 | err = audio_extn_hfp_set_mic_mute2(adev, state); |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 676 | } else if (adev->mode == AUDIO_MODE_IN_CALL) { |
Arun Mirpuri | ef53ce5 | 2018-09-11 18:00:09 -0700 | [diff] [blame] | 677 | /* Use device mute if incall music delivery usecase is in progress */ |
| 678 | if (adev->voice.use_device_mute) |
| 679 | err = platform_set_device_mute(adev->platform, state, "tx"); |
| 680 | else |
| 681 | err = platform_set_mic_mute(adev->platform, state); |
| 682 | ALOGV("%s: voice mute status=%d, use_device_mute flag=%d", |
| 683 | __func__, state, adev->voice.use_device_mute); |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 684 | } else if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) { |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 685 | err = voice_extn_compress_voip_set_mic_mute(adev, state); |
Dhanalakshmi Siddani | 823dc5a | 2016-09-28 14:47:26 +0530 | [diff] [blame] | 686 | } |
Arun Mirpuri | ef53ce5 | 2018-09-11 18:00:09 -0700 | [diff] [blame] | 687 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 688 | return err; |
| 689 | } |
| 690 | |
| 691 | bool voice_get_mic_mute(struct audio_device *adev) |
| 692 | { |
| 693 | return adev->voice.mic_mute; |
| 694 | } |
| 695 | |
Arun Mirpuri | ef53ce5 | 2018-09-11 18:00:09 -0700 | [diff] [blame] | 696 | /* |
| 697 | * Following function is called when incall music uplink usecase is |
| 698 | * created or destroyed while mic is muted. If incall music uplink |
| 699 | * usecase is active, apply voice device mute to mute only voice Tx |
| 700 | * path and not the mixed voice Tx + inncall-music path. Revert to |
| 701 | * voice stream mute once incall music uplink usecase is inactive |
| 702 | */ |
| 703 | void voice_set_device_mute_flag(struct audio_device *adev, bool state) |
| 704 | { |
| 705 | if (adev->voice.mic_mute) { |
| 706 | if (state) { |
| 707 | platform_set_device_mute(adev->platform, true, "tx"); |
| 708 | platform_set_mic_mute(adev->platform, false); |
| 709 | } else { |
| 710 | platform_set_mic_mute(adev->platform, true); |
| 711 | platform_set_device_mute(adev->platform, false, "tx"); |
| 712 | } |
| 713 | } |
| 714 | adev->voice.use_device_mute = state; |
| 715 | } |
| 716 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 717 | int voice_set_volume(struct audio_device *adev, float volume) |
| 718 | { |
| 719 | int vol, err = 0; |
| 720 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 721 | adev->voice.volume = volume; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 722 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 723 | if (volume < 0.0) { |
| 724 | volume = 0.0; |
| 725 | } else if (volume > 1.0) { |
| 726 | volume = 1.0; |
| 727 | } |
| 728 | |
| 729 | vol = lrint(volume * 100.0); |
| 730 | |
| 731 | // Voice volume levels from android are mapped to driver volume levels as follows. |
| 732 | // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0 |
| 733 | // So adjust the volume to get the correct volume index in driver |
| 734 | vol = 100 - vol; |
| 735 | |
| 736 | err = platform_set_voice_volume(adev->platform, vol); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 737 | } |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 738 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 739 | err = voice_extn_compress_voip_set_volume(adev, volume); |
| 740 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 741 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 742 | return err; |
| 743 | } |
| 744 | |
| 745 | int voice_start_call(struct audio_device *adev) |
| 746 | { |
| 747 | int ret = 0; |
| 748 | |
Ravi Kumar Alamanda | be14939 | 2014-10-20 17:07:43 -0700 | [diff] [blame] | 749 | adev->voice.in_call = true; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 750 | |
| 751 | voice_set_mic_mute(adev, adev->voice.mic_mute); |
| 752 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 753 | ret = voice_extn_start_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 754 | if (ret == -ENOSYS) { |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 755 | ret = voice_start_usecase(adev, USECASE_VOICE_CALL); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | return ret; |
| 759 | } |
| 760 | |
| 761 | int voice_stop_call(struct audio_device *adev) |
| 762 | { |
| 763 | int ret = 0; |
| 764 | |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 765 | adev->voice.in_call = false; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 766 | ret = voice_extn_stop_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 767 | if (ret == -ENOSYS) { |
Ravi Kumar Alamanda | 263d80c | 2014-08-20 16:24:38 -0700 | [diff] [blame] | 768 | ret = voice_stop_usecase(adev, USECASE_VOICE_CALL); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | return ret; |
| 772 | } |
| 773 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 774 | void voice_get_parameters(struct audio_device *adev, |
| 775 | struct str_parms *query, |
| 776 | struct str_parms *reply) |
| 777 | { |
| 778 | voice_extn_get_parameters(adev, query, reply); |
| 779 | } |
| 780 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 781 | int voice_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 782 | { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 783 | char value[32]; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 784 | int ret = 0, err; |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 785 | char *kv_pairs = str_parms_to_str(parms); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 786 | |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 787 | ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 788 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 789 | ret = voice_extn_set_parameters(adev, parms); |
Vidyakumar Athota | 8d931f0 | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 790 | if (ret != 0) { |
| 791 | if (ret == -ENOSYS) |
| 792 | ret = 0; |
| 793 | else |
| 794 | goto done; |
| 795 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 796 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 797 | ret = voice_extn_compress_voip_set_parameters(adev, parms); |
Vidyakumar Athota | 8d931f0 | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 798 | if (ret != 0) { |
| 799 | if (ret == -ENOSYS) |
| 800 | ret = 0; |
| 801 | else |
| 802 | goto done; |
| 803 | } |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 804 | |
| 805 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value)); |
| 806 | if (err >= 0) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 807 | int tty_mode; |
| 808 | str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE); |
| 809 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0) |
| 810 | tty_mode = TTY_MODE_OFF; |
| 811 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0) |
| 812 | tty_mode = TTY_MODE_VCO; |
| 813 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0) |
| 814 | tty_mode = TTY_MODE_HCO; |
| 815 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0) |
| 816 | tty_mode = TTY_MODE_FULL; |
| 817 | else { |
| 818 | ret = -EINVAL; |
| 819 | goto done; |
| 820 | } |
| 821 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 822 | if (tty_mode != adev->voice.tty_mode) { |
| 823 | adev->voice.tty_mode = tty_mode; |
| 824 | adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode; |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 825 | if (voice_is_call_state_active(adev)) |
Narsinga Rao Chella | 22d8d7a | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 826 | voice_update_devices_for_all_voice_usecases(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 827 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 830 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_HAC, |
| 831 | value, sizeof(value)); |
| 832 | if (err >= 0) { |
| 833 | bool hac = false; |
| 834 | str_parms_del(parms, AUDIO_PARAMETER_KEY_HAC); |
| 835 | if (strcmp(value, AUDIO_PARAMETER_VALUE_HAC_ON) == 0) |
| 836 | hac = true; |
| 837 | |
| 838 | if (hac != adev->voice.hac) { |
| 839 | adev->voice.hac = hac; |
| 840 | if (voice_is_in_call(adev)) |
| 841 | voice_update_devices_for_all_voice_usecases(adev); |
| 842 | } |
| 843 | } |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 844 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 845 | value, sizeof(value)); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 846 | if (err >= 0) { |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 847 | str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC); |
| 848 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0) |
| 849 | platform_start_incall_music_usecase(adev->platform); |
| 850 | else |
| 851 | platform_stop_incall_music_usecase(adev->platform); |
Vidyakumar Athota | 8d931f0 | 2014-07-21 14:51:44 -0700 | [diff] [blame] | 852 | } |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 853 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 854 | done: |
| 855 | ALOGV("%s: exit with code(%d)", __func__, ret); |
Krishnankutty Kolathappilly | 061a949 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 856 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 857 | return ret; |
| 858 | } |
| 859 | |
| 860 | void voice_init(struct audio_device *adev) |
| 861 | { |
| 862 | int i = 0; |
Weiyin Jiang | 095e444 | 2019-07-15 11:49:15 +0800 | [diff] [blame] | 863 | int max_voice_sessions = MAX_VOICE_SESSIONS; |
| 864 | |
| 865 | if (!voice_extn_is_multi_session_supported()) |
| 866 | max_voice_sessions = 1; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 867 | |
| 868 | memset(&adev->voice, 0, sizeof(adev->voice)); |
| 869 | adev->voice.tty_mode = TTY_MODE_OFF; |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame] | 870 | adev->voice.hac = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 871 | adev->voice.volume = 1.0f; |
| 872 | adev->voice.mic_mute = false; |
Vidyakumar Athota | ad34d57 | 2014-08-05 18:20:42 -0700 | [diff] [blame] | 873 | adev->voice.in_call = false; |
Weiyin Jiang | 095e444 | 2019-07-15 11:49:15 +0800 | [diff] [blame] | 874 | for (i = 0; i < max_voice_sessions; i++) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 875 | adev->voice.session[i].pcm_rx = NULL; |
| 876 | adev->voice.session[i].pcm_tx = NULL; |
| 877 | adev->voice.session[i].state.current = CALL_INACTIVE; |
| 878 | adev->voice.session[i].state.new = CALL_INACTIVE; |
Ravi Kumar Alamanda | bdf1416 | 2014-09-05 16:14:17 -0700 | [diff] [blame] | 879 | adev->voice.session[i].vsid = VOICE_VSID; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | voice_extn_init(adev); |
| 883 | } |
| 884 | |
Narsinga Rao Chella | 22d8d7a | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 885 | void voice_update_devices_for_all_voice_usecases(struct audio_device *adev) |
| 886 | { |
| 887 | struct listnode *node; |
| 888 | struct audio_usecase *usecase; |
| 889 | |
| 890 | list_for_each(node, &adev->usecase_list) { |
| 891 | usecase = node_to_item(node, struct audio_usecase, list); |
| 892 | if (usecase->type == VOICE_CALL) { |
| 893 | ALOGV("%s: updating device for usecase:%s", __func__, |
| 894 | use_case_table[usecase->id]); |
Ravi Kumar Alamanda | 060bc5a | 2014-09-05 13:51:35 -0700 | [diff] [blame] | 895 | usecase->stream.out = adev->current_call_output; |
Narsinga Rao Chella | 22d8d7a | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 896 | select_devices(adev, usecase->id); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 901 | |
Pallavi Mishra | 5627c16 | 2020-02-15 19:00:40 +0530 | [diff] [blame] | 902 | |