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