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