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