Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 1 | /* |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, 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> |
| 25 | #include <math.h> |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/str_parms.h> |
| 28 | |
| 29 | #include "audio_hw.h" |
| 30 | #include "voice.h" |
| 31 | #include "voice_extn/voice_extn.h" |
| 32 | #include "platform.h" |
| 33 | #include "platform_api.h" |
Kiran Kandi | 910e186 | 2013-10-29 13:29:42 -0700 | [diff] [blame] | 34 | #include "audio_extn.h" |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 35 | |
| 36 | struct pcm_config pcm_config_voice_call = { |
| 37 | .channels = 1, |
| 38 | .rate = 8000, |
| 39 | .period_size = 160, |
| 40 | .period_count = 2, |
| 41 | .format = PCM_FORMAT_S16_LE, |
| 42 | }; |
| 43 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 44 | extern const char * const use_case_table[AUDIO_USECASE_MAX]; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 45 | |
| 46 | static struct voice_session *voice_get_session_from_use_case(struct audio_device *adev, |
| 47 | audio_usecase_t usecase_id) |
| 48 | { |
| 49 | struct voice_session *session = NULL; |
| 50 | int ret = 0; |
| 51 | |
| 52 | ret = voice_extn_get_session_from_use_case(adev, usecase_id, &session); |
| 53 | if (ret == -ENOSYS) { |
| 54 | session = &adev->voice.session[VOICE_SESS_IDX]; |
| 55 | } |
| 56 | |
| 57 | return session; |
| 58 | } |
| 59 | |
| 60 | int stop_call(struct audio_device *adev, audio_usecase_t usecase_id) |
| 61 | { |
| 62 | int i, ret = 0; |
| 63 | struct audio_usecase *uc_info; |
| 64 | struct voice_session *session = NULL; |
| 65 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 66 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 67 | |
| 68 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
| 69 | session->state.current = CALL_INACTIVE; |
| 70 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 71 | ret = platform_stop_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 72 | |
| 73 | /* 1. Close the PCM devices */ |
| 74 | if (session->pcm_rx) { |
| 75 | pcm_close(session->pcm_rx); |
| 76 | session->pcm_rx = NULL; |
| 77 | } |
| 78 | if (session->pcm_tx) { |
| 79 | pcm_close(session->pcm_tx); |
| 80 | session->pcm_tx = NULL; |
| 81 | } |
| 82 | |
| 83 | uc_info = get_usecase_from_list(adev, usecase_id); |
| 84 | if (uc_info == NULL) { |
| 85 | ALOGE("%s: Could not find the usecase (%d) in the list", |
| 86 | __func__, usecase_id); |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | |
| 90 | /* 2. Get and set stream specific mixer controls */ |
| 91 | disable_audio_route(adev, uc_info, true); |
| 92 | |
| 93 | /* 3. Disable the rx and tx devices */ |
| 94 | disable_snd_device(adev, uc_info->out_snd_device, false); |
| 95 | disable_snd_device(adev, uc_info->in_snd_device, true); |
| 96 | |
| 97 | list_remove(&uc_info->list); |
| 98 | free(uc_info); |
| 99 | |
| 100 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | int start_call(struct audio_device *adev, audio_usecase_t usecase_id) |
| 105 | { |
| 106 | int i, ret = 0; |
| 107 | struct audio_usecase *uc_info; |
| 108 | int pcm_dev_rx_id, pcm_dev_tx_id; |
| 109 | struct voice_session *session = NULL; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 110 | struct pcm_config voice_config = pcm_config_voice_call; |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 111 | |
| 112 | ALOGD("%s: enter usecase:%s", __func__, use_case_table[usecase_id]); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 113 | |
| 114 | session = (struct voice_session *)voice_get_session_from_use_case(adev, usecase_id); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 115 | uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase)); |
| 116 | uc_info->id = usecase_id; |
| 117 | uc_info->type = VOICE_CALL; |
| 118 | uc_info->stream.out = adev->primary_output; |
| 119 | uc_info->devices = adev->primary_output->devices; |
| 120 | uc_info->in_snd_device = SND_DEVICE_NONE; |
| 121 | uc_info->out_snd_device = SND_DEVICE_NONE; |
| 122 | |
| 123 | list_add_tail(&adev->usecase_list, &uc_info->list); |
| 124 | |
| 125 | select_devices(adev, usecase_id); |
| 126 | |
| 127 | pcm_dev_rx_id = platform_get_pcm_device_id(uc_info->id, PCM_PLAYBACK); |
| 128 | pcm_dev_tx_id = platform_get_pcm_device_id(uc_info->id, PCM_CAPTURE); |
| 129 | |
| 130 | if (pcm_dev_rx_id < 0 || pcm_dev_tx_id < 0) { |
| 131 | ALOGE("%s: Invalid PCM devices (rx: %d tx: %d) for the usecase(%d)", |
| 132 | __func__, pcm_dev_rx_id, pcm_dev_tx_id, uc_info->id); |
| 133 | ret = -EIO; |
| 134 | goto error_start_voice; |
| 135 | } |
| 136 | |
| 137 | ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 138 | __func__, adev->snd_card, pcm_dev_rx_id); |
| 139 | session->pcm_rx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 140 | pcm_dev_rx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 141 | PCM_OUT, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 142 | if (session->pcm_rx && !pcm_is_ready(session->pcm_rx)) { |
| 143 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_rx)); |
| 144 | ret = -EIO; |
| 145 | goto error_start_voice; |
| 146 | } |
| 147 | |
| 148 | ALOGV("%s: Opening PCM capture device card_id(%d) device_id(%d)", |
Apoorv Raghuvanshi | 84fa2fe | 2013-12-04 11:57:47 -0800 | [diff] [blame] | 149 | __func__, adev->snd_card, pcm_dev_tx_id); |
| 150 | session->pcm_tx = pcm_open(adev->snd_card, |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 151 | pcm_dev_tx_id, |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 152 | PCM_IN, &voice_config); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 153 | if (session->pcm_tx && !pcm_is_ready(session->pcm_tx)) { |
| 154 | ALOGE("%s: %s", __func__, pcm_get_error(session->pcm_tx)); |
| 155 | ret = -EIO; |
| 156 | goto error_start_voice; |
| 157 | } |
| 158 | pcm_start(session->pcm_rx); |
| 159 | pcm_start(session->pcm_tx); |
| 160 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 161 | voice_set_volume(adev, adev->voice.volume); |
| 162 | |
Vidyakumar Athota | d9d9ff3 | 2013-11-13 11:46:52 -0800 | [diff] [blame] | 163 | ret = platform_start_voice_call(adev->platform, session->vsid); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 164 | if (ret < 0) { |
| 165 | ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret); |
| 166 | goto error_start_voice; |
| 167 | } |
| 168 | |
| 169 | session->state.current = CALL_ACTIVE; |
| 170 | return 0; |
| 171 | |
| 172 | error_start_voice: |
| 173 | stop_call(adev, usecase_id); |
| 174 | |
| 175 | ALOGD("%s: exit: status(%d)", __func__, ret); |
| 176 | return ret; |
| 177 | } |
| 178 | |
| 179 | bool voice_is_in_call(struct audio_device *adev) |
| 180 | { |
| 181 | bool in_call = false; |
| 182 | int ret = 0; |
| 183 | |
| 184 | ret = voice_extn_is_in_call(adev, &in_call); |
| 185 | if (ret == -ENOSYS) { |
| 186 | in_call = (adev->voice.session[VOICE_SESS_IDX].state.current == CALL_ACTIVE) ? true : false; |
| 187 | } |
| 188 | |
| 189 | return in_call; |
| 190 | } |
| 191 | |
kunleiz | a1a9ee0 | 2014-04-24 18:46:22 +0800 | [diff] [blame^] | 192 | bool voice_is_in_call_rec_stream(struct stream_in *in) |
| 193 | { |
| 194 | bool in_call_rec = false; |
| 195 | int ret = 0; |
| 196 | |
| 197 | ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec); |
| 198 | if (ret == -ENOSYS) { |
| 199 | in_call_rec = false; |
| 200 | } |
| 201 | |
| 202 | return in_call_rec; |
| 203 | } |
| 204 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 205 | uint32_t voice_get_active_session_id(struct audio_device *adev) |
| 206 | { |
| 207 | int ret = 0; |
| 208 | uint32_t session_id; |
| 209 | |
| 210 | ret = voice_extn_get_active_session_id(adev, &session_id); |
| 211 | if (ret == -ENOSYS) { |
| 212 | session_id = VOICE_VSID; |
| 213 | } |
| 214 | return session_id; |
| 215 | } |
| 216 | |
| 217 | int voice_check_and_set_incall_rec_usecase(struct audio_device *adev, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 218 | struct stream_in *in) |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 219 | { |
| 220 | int ret = 0; |
| 221 | uint32_t session_id; |
| 222 | int usecase_id; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 223 | int rec_mode = INCALL_REC_NONE; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 224 | |
| 225 | if (voice_is_in_call(adev)) { |
| 226 | switch (in->source) { |
| 227 | case AUDIO_SOURCE_VOICE_UPLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 228 | if (audio_extn_compr_cap_enabled() && |
| 229 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 230 | in->usecase = USECASE_INCALL_REC_UPLINK_COMPRESS; |
| 231 | } else |
| 232 | in->usecase = USECASE_INCALL_REC_UPLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 233 | rec_mode = INCALL_REC_UPLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 234 | break; |
| 235 | case AUDIO_SOURCE_VOICE_DOWNLINK: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 236 | if (audio_extn_compr_cap_enabled() && |
| 237 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 238 | in->usecase = USECASE_INCALL_REC_DOWNLINK_COMPRESS; |
| 239 | } else |
| 240 | in->usecase = USECASE_INCALL_REC_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 241 | rec_mode = INCALL_REC_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 242 | break; |
| 243 | case AUDIO_SOURCE_VOICE_CALL: |
Helen Zeng | e56b485 | 2013-12-03 16:54:40 -0800 | [diff] [blame] | 244 | if (audio_extn_compr_cap_enabled() && |
| 245 | audio_extn_compr_cap_format_supported(in->config.format)) { |
| 246 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK_COMPRESS; |
| 247 | } else |
| 248 | in->usecase = USECASE_INCALL_REC_UPLINK_AND_DOWNLINK; |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 249 | rec_mode = INCALL_REC_UPLINK_AND_DOWNLINK; |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 250 | break; |
| 251 | default: |
| 252 | ALOGV("%s: Source type %d doesnt match incall recording criteria", |
| 253 | __func__, in->source); |
| 254 | return ret; |
| 255 | } |
| 256 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 257 | session_id = voice_get_active_session_id(adev); |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 258 | ret = platform_set_incall_recording_session_id(adev->platform, |
| 259 | session_id, rec_mode); |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame] | 260 | ALOGV("%s: Update usecase to %d",__func__, in->usecase); |
| 261 | } else { |
| 262 | ALOGV("%s: voice call not active", __func__); |
| 263 | } |
| 264 | |
| 265 | return ret; |
| 266 | } |
| 267 | |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 268 | int voice_check_and_stop_incall_rec_usecase(struct audio_device *adev, |
| 269 | struct stream_in *in) |
| 270 | { |
| 271 | int ret = 0; |
| 272 | |
| 273 | if (in->source == AUDIO_SOURCE_VOICE_UPLINK || |
| 274 | in->source == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 275 | in->source == AUDIO_SOURCE_VOICE_CALL) { |
| 276 | ret = platform_stop_incall_recording_usecase(adev->platform); |
| 277 | ALOGV("%s: Stop In-call recording", __func__); |
| 278 | } |
| 279 | |
| 280 | return ret; |
| 281 | } |
| 282 | |
Shiv Maliyappanahalli | f3b9a42 | 2013-10-22 16:38:08 -0700 | [diff] [blame] | 283 | int voice_check_and_set_incall_music_usecase(struct audio_device *adev, |
| 284 | struct stream_out *out) |
| 285 | { |
| 286 | int ret = 0; |
| 287 | |
| 288 | ret = voice_extn_check_and_set_incall_music_usecase(adev, out); |
| 289 | if (ret == -ENOSYS) { |
| 290 | /* Incall music delivery is used only for LCH call state */ |
| 291 | ret = -EINVAL; |
| 292 | } |
| 293 | |
| 294 | return ret; |
| 295 | } |
| 296 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 297 | int voice_set_mic_mute(struct audio_device *adev, bool state) |
| 298 | { |
| 299 | int err = 0; |
| 300 | |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 301 | adev->voice.mic_mute = state; |
| 302 | if (adev->mode == AUDIO_MODE_IN_CALL) |
| 303 | err = platform_set_mic_mute(adev->platform, state); |
| 304 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 305 | err = voice_extn_compress_voip_set_mic_mute(adev, state); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 306 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 307 | return err; |
| 308 | } |
| 309 | |
| 310 | bool voice_get_mic_mute(struct audio_device *adev) |
| 311 | { |
| 312 | return adev->voice.mic_mute; |
| 313 | } |
| 314 | |
| 315 | int voice_set_volume(struct audio_device *adev, float volume) |
| 316 | { |
| 317 | int vol, err = 0; |
| 318 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 319 | adev->voice.volume = volume; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 320 | if (adev->mode == AUDIO_MODE_IN_CALL) { |
| 321 | if (volume < 0.0) { |
| 322 | volume = 0.0; |
| 323 | } else if (volume > 1.0) { |
| 324 | volume = 1.0; |
| 325 | } |
| 326 | |
| 327 | vol = lrint(volume * 100.0); |
| 328 | |
| 329 | // Voice volume levels from android are mapped to driver volume levels as follows. |
| 330 | // 0 -> 5, 20 -> 4, 40 ->3, 60 -> 2, 80 -> 1, 100 -> 0 |
| 331 | // So adjust the volume to get the correct volume index in driver |
| 332 | vol = 100 - vol; |
| 333 | |
| 334 | err = platform_set_voice_volume(adev->platform, vol); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 335 | } |
Narsinga Rao Chella | 05573b7 | 2013-11-15 15:21:40 -0800 | [diff] [blame] | 336 | if (adev->mode == AUDIO_MODE_IN_COMMUNICATION) |
| 337 | err = voice_extn_compress_voip_set_volume(adev, volume); |
| 338 | |
Shruthi Krishna | ace1085 | 2013-10-25 14:32:12 -0700 | [diff] [blame] | 339 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 340 | return err; |
| 341 | } |
| 342 | |
| 343 | int voice_start_call(struct audio_device *adev) |
| 344 | { |
| 345 | int ret = 0; |
| 346 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 347 | ret = voice_extn_start_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 348 | if (ret == -ENOSYS) { |
| 349 | ret = start_call(adev, USECASE_VOICE_CALL); |
| 350 | } |
| 351 | |
| 352 | return ret; |
| 353 | } |
| 354 | |
| 355 | int voice_stop_call(struct audio_device *adev) |
| 356 | { |
| 357 | int ret = 0; |
| 358 | |
Shiv Maliyappanahalli | 3bb7358 | 2013-11-05 12:49:15 -0800 | [diff] [blame] | 359 | ret = voice_extn_stop_call(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 360 | if (ret == -ENOSYS) { |
| 361 | ret = stop_call(adev, USECASE_VOICE_CALL); |
| 362 | } |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
Shiv Maliyappanahalli | f930849 | 2013-12-12 12:18:09 -0800 | [diff] [blame] | 367 | void voice_get_parameters(struct audio_device *adev, |
| 368 | struct str_parms *query, |
| 369 | struct str_parms *reply) |
| 370 | { |
| 371 | voice_extn_get_parameters(adev, query, reply); |
| 372 | } |
| 373 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 374 | int voice_set_parameters(struct audio_device *adev, struct str_parms *parms) |
| 375 | { |
| 376 | char *str; |
| 377 | char value[32]; |
| 378 | int val; |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 379 | int ret = 0, err; |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 380 | char *kv_pairs = str_parms_to_str(parms); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 381 | |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 382 | ALOGV_IF(kv_pairs != NULL, "%s: enter: %s", __func__, kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 383 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 384 | ret = voice_extn_set_parameters(adev, parms); |
| 385 | if (ret != 0) |
| 386 | goto done; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 387 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 388 | ret = voice_extn_compress_voip_set_parameters(adev, parms); |
| 389 | if (ret != 0) |
| 390 | goto done; |
| 391 | |
| 392 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_TTY_MODE, value, sizeof(value)); |
| 393 | if (err >= 0) { |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 394 | int tty_mode; |
| 395 | str_parms_del(parms, AUDIO_PARAMETER_KEY_TTY_MODE); |
| 396 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_OFF) == 0) |
| 397 | tty_mode = TTY_MODE_OFF; |
| 398 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_VCO) == 0) |
| 399 | tty_mode = TTY_MODE_VCO; |
| 400 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_HCO) == 0) |
| 401 | tty_mode = TTY_MODE_HCO; |
| 402 | else if (strcmp(value, AUDIO_PARAMETER_VALUE_TTY_FULL) == 0) |
| 403 | tty_mode = TTY_MODE_FULL; |
| 404 | else { |
| 405 | ret = -EINVAL; |
| 406 | goto done; |
| 407 | } |
| 408 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 409 | if (tty_mode != adev->voice.tty_mode) { |
| 410 | adev->voice.tty_mode = tty_mode; |
| 411 | adev->acdb_settings = (adev->acdb_settings & TTY_MODE_CLEAR) | tty_mode; |
| 412 | if (voice_is_in_call(adev)) |
Narsinga Rao Chella | c9bf40d | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 413 | voice_update_devices_for_all_voice_usecases(adev); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 414 | } |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 417 | err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC, |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 418 | value, sizeof(value)); |
Shiv Maliyappanahalli | 3e064fd | 2013-12-16 15:54:40 -0800 | [diff] [blame] | 419 | if (err >= 0) { |
Vidyakumar Athota | 2850d53 | 2013-11-19 16:02:12 -0800 | [diff] [blame] | 420 | str_parms_del(parms, AUDIO_PARAMETER_KEY_INCALLMUSIC); |
| 421 | if (strcmp(value, AUDIO_PARAMETER_VALUE_TRUE) == 0) |
| 422 | platform_start_incall_music_usecase(adev->platform); |
| 423 | else |
| 424 | platform_stop_incall_music_usecase(adev->platform); |
| 425 | } |
| 426 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 427 | done: |
| 428 | ALOGV("%s: exit with code(%d)", __func__, ret); |
Krishnankutty Kolathappilly | 301cc36 | 2014-01-31 18:12:13 -0800 | [diff] [blame] | 429 | free(kv_pairs); |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 430 | return ret; |
| 431 | } |
| 432 | |
| 433 | void voice_init(struct audio_device *adev) |
| 434 | { |
| 435 | int i = 0; |
| 436 | |
| 437 | memset(&adev->voice, 0, sizeof(adev->voice)); |
| 438 | adev->voice.tty_mode = TTY_MODE_OFF; |
| 439 | adev->voice.volume = 1.0f; |
| 440 | adev->voice.mic_mute = false; |
Shiv Maliyappanahalli | 07a9ea2 | 2014-01-06 14:53:52 -0800 | [diff] [blame] | 441 | adev->voice.voice_device_set = false; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 442 | for (i = 0; i < MAX_VOICE_SESSIONS; i++) { |
| 443 | adev->voice.session[i].pcm_rx = NULL; |
| 444 | adev->voice.session[i].pcm_tx = NULL; |
| 445 | adev->voice.session[i].state.current = CALL_INACTIVE; |
| 446 | adev->voice.session[i].state.new = CALL_INACTIVE; |
| 447 | adev->voice.session[i].vsid = 0; |
| 448 | } |
| 449 | |
| 450 | voice_extn_init(adev); |
| 451 | } |
| 452 | |
Narsinga Rao Chella | c9bf40d | 2014-02-06 14:05:14 -0800 | [diff] [blame] | 453 | void voice_update_devices_for_all_voice_usecases(struct audio_device *adev) |
| 454 | { |
| 455 | struct listnode *node; |
| 456 | struct audio_usecase *usecase; |
| 457 | |
| 458 | list_for_each(node, &adev->usecase_list) { |
| 459 | usecase = node_to_item(node, struct audio_usecase, list); |
| 460 | if (usecase->type == VOICE_CALL) { |
| 461 | ALOGV("%s: updating device for usecase:%s", __func__, |
| 462 | use_case_table[usecase->id]); |
| 463 | select_devices(adev, usecase->id); |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 468 | |