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