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