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